TheDan64 / inkwell

It's a New Kind of Wrapper for Exposing LLVM (Safely)
https://thedan64.github.io/inkwell/
Apache License 2.0
2.38k stars 229 forks source link

Couldn't compile #422

Closed thi8v closed 1 year ago

thi8v commented 1 year ago

Describe the Bug I've just git clone the workspace checkout the last stable release, 0.2.0 and I wanted to run the kaleidoscope example, but I found cargo very unhappy,

To Reproduce

  1. git clone https://github.com/TheDan64/inkwell
  2. cargo run --example kaleidoscope

Expected Behavior The kaleidoscope program should open.

LLVM Version (please complete the following information):

Desktop (please complete the following information):

Additional Context An extract of the errors messages :

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMIsGlobalConstant` in this scope
   --> src/values/global_value.rs:191:18
    |
191 |         unsafe { LLVMIsGlobalConstant(self.as_value_ref()) == 1 }
    |                  ^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMSetGlobalConstant` in this scope
   --> src/values/global_value.rs:195:18
    |
195 |         unsafe { LLVMSetGlobalConstant(self.as_value_ref(), is_constant as i32) }
    |                  ^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMIsExternallyInitialized` in this scope
   --> src/values/global_value.rs:199:18
    |
199 |         unsafe { LLVMIsExternallyInitialized(self.as_value_ref()) == 1 }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMSetExternallyInitialized` in this scope
   --> src/values/global_value.rs:203:18
    |
203 |         unsafe { LLVMSetExternallyInitialized(self.as_value_ref(), externally_initialized as i32) }
    |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `externally_initialized`

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMSetVisibility` in this scope
   --> src/values/global_value.rs:207:18
    |
207 |         unsafe { LLVMSetVisibility(self.as_value_ref(), visibility.into()) }
    |                  ^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMGetVisibility` in this scope
   --> src/values/global_value.rs:211:35
    |
211 |         let visibility = unsafe { LLVMGetVisibility(self.as_value_ref()) };
    |                                   ^^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMDeleteGlobal` in this scope
   --> src/values/global_value.rs:227:9
    |
227 |         LLVMDeleteGlobal(self.as_value_ref())
    |         ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMGetAlignment` in this scope
   --> src/values/global_value.rs:235:18
    |
235 |         unsafe { LLVMGetAlignment(self.as_value_ref()) }
    |                  ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMSetAlignment` in this scope
   --> src/values/global_value.rs:239:18
    |
239 |         unsafe { LLVMSetAlignment(self.as_value_ref(), alignment) }
    |                  ^^^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMGetLinkage` in this scope
   --> src/values/global_value.rs:287:18
    |
287 |         unsafe { LLVMGetLinkage(self.as_value_ref()).into() }
    |                  ^^^^^^^^^^^^^^ not found in this scope

error[E0425]: cannot find function, tuple struct or tuple variant `LLVMSetLinkage` in this scope
   --> src/values/global_value.rs:291:18
    |
291 |         unsafe { LLVMSetLinkage(self.as_value_ref(), linkage.into()) }
    |                  ^^^^^^^^^^^^^^ not found in this scope

error[E0599]: no method named `get_type` found for struct `fn_value::FunctionValue` in the current scope
   --> src/values/callable_value.rs:100:40
    |
100 |             Left(function) => function.get_type().as_type_ref(),
    |                                        ^^^^^^^^ method not found in `FunctionValue<'_>`
    |
   ::: src/values/fn_value.rs:33:1
    |
33  | pub struct FunctionValue<'ctx> {
    | ------------------------------ method `get_type` not found for this struct

error[E0599]: no method named `get_element_type` found for struct `ptr_type::PointerType` in the current scope
   --> src/values/callable_value.rs:101:50
    |
101 |             Right(pointer) => pointer.get_type().get_element_type().as_type_ref(),
    |                                                  ^^^^^^^^^^^^^^^^ method not found in `PointerType<'_>`
    |
   ::: src/types/ptr_type.rs:18:1
    |
18  | pub struct PointerType<'ctx> {
    | ---------------------------- method `get_element_type` not found for this struct

Some errors have detailed explanations: E0046, E0412, E0425, E0432, E0433, E0599.
For more information about an error, try `rustc --explain E0046`.
warning: `inkwell` (lib) generated 11 warnings
error: could not compile `inkwell` due to 220 previous errors; 11 warnings emitted
Daniel-Boll commented 1 year ago

Hello, @Larsouille25. The issue you encountered is primarily related to the inability of llvm_sys to dynamically link with LLVM 15. It appears that Arch Linux only provides dynamically linked LLVM packages.

To address this problem and make your project work, you can make use of the following configuration:

inkwell = { version = "0.2", features = ["llvm15-0"] }
llvm-sys-150 = { package = "llvm-sys", version = "150.1.0", features = ["prefer-dynamic"] }

These configurations should help you resolve the issue and enable a new project to work smoothly with LLVM 15 on Arch Linux. As of the example execution I don't know how one would change the feature to be added automatically in the main cargo.toml from inkwell.

Best Regards, Daniel Boll. 🎴

thi8v commented 1 year ago

Hello, @Daniel-Boll, thanks for the solution but, when in my crate I have inkwell = { version = "0.2.0", features = ["llvm15-0"] } in the Cargo.toml file, that's just working fine. But when I try to compile inkwell (on the same PC), that's not working

TheDan64 commented 1 year ago

@Larsouille25 Did you specify --features llvm15-0 via the cli?

thi8v commented 1 year ago

The error is solved (forgot to close), it's specific to arch linux and LLVM 15.0.7, to solve the issue you need to download headers of llvm and create an env var that points to the llvm headers

thi8v commented 1 year ago

See issue #405