clang-rs icon indicating copy to clipboard operation
clang-rs copied to clipboard

Windows 10 Build Failing

Open turnersr opened this issue 5 years ago • 4 comments

Hello,

Thanks for this project. I am trying to use it on windows, but none the test pass because I get the following error:

thread 'test' panicked at 'a `libclang` shared library is not loaded on this thread', src\libcore\option.rs:1038:5

I updated Cargo.toml for clang-sys to use the master branch since those tests pass.

clang-sys = { git="https://github.com/KyleMayes/clang-sys.git", branch="master", features = ["runtime", "clang_6_0"] }

What is extra strange is that clang-sys on its own passes both the tests:

C:\Users\dev\Projects\clang-sys>cargo test
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running target\debug\deps\clang_sys-ae7cfce2797a2aee.exe

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target\debug\deps\lib-fca0a27cb6a671d0.exe

running 2 tests
test test ... ok
test test_support ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests clang-sys

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

Here is my clang version:

C:\Users\dev\Projects\clang-rs>clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

I am using Microsoft Windows 10 Pro.

turnersr avatar Apr 17 '19 22:04 turnersr

I ran cargo test for bindgen and many of tests pass there:

test result: FAILED. 449 passed; 11 failed; 0 ignored; 0 measured; 0 filtered out

turnersr avatar Apr 18 '19 00:04 turnersr

I think the reason the clang-sys tests work but the clang-rs tests do not is because one is using runtime linking and the other is not. I believe running cargo test --features runtime in clang-sys would produce the same issue as dynamic linking at compiletime instead of at runtime is the default when no features are provided.

That being said, I'm not sure why this error is being thrown. Running Clang::new should validate that the instance of libclang is loaded. I will look into why this is happening (it works on my Windows 10 machine with Clang 7.0).

KyleMayes avatar Apr 18 '19 06:04 KyleMayes

Hi Kyle,

I tried the runtime feature is this what I get. Seems to still work. I will try clang 7 for clang-rs.

C:\Users\dev\Projects\clang-sys>cargo test --features runtime
   Compiling winapi v0.3.7
   Compiling cc v1.0.35
   Compiling clang-sys v0.28.0 (C:\Users\dev\Projects\clang-sys)
warning: use of deprecated item 'core::str::<impl str>::trim_right': superseded by `trim_end`
  --> build\static.rs:99:99
   |
99 |     println!("cargo:rustc-link-search=native={}", common::run_llvm_config(&["--libdir"]).unwrap().trim_right());
   |                                                                                                   ^^^^^^^^^^
   |
   = note: #[warn(deprecated)] on by default

   Compiling libloading v0.5.0
    Finished dev [unoptimized + debuginfo] target(s) in 15.02s
     Running target\debug\deps\clang_sys-bd49863444058b70.exe

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target\debug\deps\lib-3a5ce72bf061f5e0.exe

running 2 tests
test test_support ... ok
test test ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

   Doc-tests clang-sys

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

turnersr avatar Apr 18 '19 17:04 turnersr

I installed Clang 7. I still get the same error:

C:\Users\dev\Projects\clang-rs>cargo build
   Compiling clang-sys v0.28.0 (https://github.com/KyleMayes/clang-sys.git#77af41fd)
   Compiling clang v0.21.0 (C:\Users\dev\Projects\clang-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 9.50s

C:\Users\dev\Projects\clang-rs>cargo test
   Compiling clang v0.21.0 (C:\Users\dev\Projects\clang-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 5.22s
     Running target\debug\deps\clang-e970d24690581d13.exe

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

     Running target\debug\deps\tests-911f7d684628f47d.exe

running 1 test
test test ... FAILED

failures:

---- test stdout ----
thread 'test' panicked at 'a `libclang` shared library is not loaded on this thread', src\libcore\option.rs:1038:5
stack backtrace:
   0:     0x7ff6c4bb532d - std::sys::windows::backtrace::set_frames
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys\windows\backtrace\mod.rs:94
   1:     0x7ff6c4bb532d - std::sys::windows::backtrace::unwind_backtrace
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys\windows\backtrace\mod.rs:81
   2:     0x7ff6c4bb532d - std::sys_common::backtrace::_print
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys_common\backtrace.rs:70
   3:     0x7ff6c4bb85ad - std::sys_common::backtrace::print
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys_common\backtrace.rs:58
   4:     0x7ff6c4bb85ad - std::panicking::default_hook::{{closure}}
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\panicking.rs:200
   5:     0x7ff6c4bb81aa - std::panicking::default_hook
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\panicking.rs:209
   6:     0x7ff6c4bb8e3f - std::panicking::rust_panic_with_hook
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\panicking.rs:478
   7:     0x7ff6c4bb8973 - std::panicking::continue_panic_fmt
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\panicking.rs:385
   8:     0x7ff6c4bb8858 - std::panicking::rust_begin_panic
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\panicking.rs:312
   9:     0x7ff6c4bc59eb - core::panicking::panic_fmt
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libcore\panicking.rs:85
  10:     0x7ff6c4bc5a55 - core::option::expect_failed
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libcore\option.rs:1038
  11:     0x7ff6c4b75c3f - core::option::Option<unsafe extern "C" fn() -> clang_sys::CXString>::expect<unsafe extern "C" fn() -> clang_sys::CXString>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libcore\option.rs:312
  12:     0x7ff6c4b6b337 - clang_sys::clang_getClangVersion
                               at C:\Users\dev\.cargo\git\checkouts\clang-sys-3b2b221bd521c743\77af41f\src\link.rs:92
  13:     0x7ff6c4b011b5 - clang::get_version
                               at C:\Users\dev\Projects\clang-rs\src\lib.rs:2902
  14:     0x7ff6c4a118e8 - tests::test
                               at C:\Users\dev\Projects\clang-rs\tests\tests.rs:121
  15:     0x7ff6c4a9000d - tests::test::{{closure}}
                               at C:\Users\dev\Projects\clang-rs\tests\tests.rs:118
  16:     0x7ff6c49c68ea - core::ops::function::FnOnce::call_once<closure,()>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libcore\ops\function.rs:231
  17:     0x7ff6c4ab1e4d - test::run_test::{{closure}}
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libtest\lib.rs:1485
  18:     0x7ff6c4ab1e4d - core::ops::function::FnOnce::call_once
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libcore\ops\function.rs:231
  19:     0x7ff6c4ab1e4d - alloc::boxed::{{impl}}::call_box<(),closure>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\liballoc\boxed.rs:749
  20:     0x7ff6c4bbddf1 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libpanic_unwind\lib.rs:87
  21:     0x7ff6c4ad42ca - std::panicking::try
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panicking.rs:276
  22:     0x7ff6c4ad42ca - std::panic::catch_unwind
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panic.rs:388
  23:     0x7ff6c4ad42ca - test::run_test::run_test_inner::{{closure}}
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libtest\lib.rs:1452
  24:     0x7ff6c4aa80ad - std::sys_common::backtrace::__rust_begin_short_backtrace<closure,()>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\sys_common\backtrace.rs:135
  25:     0x7ff6c4aa88bd - std::thread::{{impl}}::spawn_unchecked::{{closure}}::{{closure}}
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\thread\mod.rs:469
  26:     0x7ff6c4aa88bd - std::panic::{{impl}}::call_once
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panic.rs:309
  27:     0x7ff6c4aa88bd - std::panicking::try::do_call<std::panic::AssertUnwindSafe<closure>,()>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panicking.rs:297
  28:     0x7ff6c4bbddf1 - panic_unwind::__rust_maybe_catch_panic
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libpanic_unwind\lib.rs:87
  29:     0x7ff6c4ab1c01 - std::panicking::try
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panicking.rs:276
  30:     0x7ff6c4ab1c01 - std::panic::catch_unwind
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\panic.rs:388
  31:     0x7ff6c4ab1c01 - std::thread::{{impl}}::spawn_unchecked::{{closure}}
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\libstd\thread\mod.rs:468
  32:     0x7ff6c4ab1c01 - alloc::boxed::{{impl}}::call_box<(),closure>
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\liballoc\boxed.rs:749
  33:     0x7ff6c4bbcd24 - alloc::boxed::{{impl}}::call_once
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\src\liballoc\boxed.rs:759
  34:     0x7ff6c4bbcd24 - std::sys_common::thread::start_thread
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys_common\thread.rs:14
  35:     0x7ff6c4bbcd24 - std::sys::windows::thread::{{impl}}::new::thread_start
                               at /rustc/91856ed52c58aa5ba66a015354d1cc69e9779bdf\/src\libstd\sys\windows\thread.rs:47
  36:     0x7ffbae214033 - BaseThreadInitThunk
  37:     0x7ffbb08d3690 - RtlUserThreadStart


failures:
    test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

error: test failed, to rerun pass '--test tests'

C:\Users\dev\Projects\clang-rs>clang --version
clang version 7.0.0 (tags/RELEASE_700/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

turnersr avatar Apr 18 '19 17:04 turnersr