Skip to content

Building on i686-pc-windows-gnu #9

Closed

Description

@CGMossa

It is important that we can build on 32-bit targets, I've tried to follow the instructions in the README.md,
but substituting with the 32-bit variants.

This doesn't work for some reason. And here's the latest error-message/hurdle:

[redacted] MINGW32 /c/Users/tpb398/Documents/GitHub/libR-sys
$ cargo build --target=i686-pc-windows-gnu
   Compiling libR-sys v0.1.9 (C:\Users\tpb398\Documents\GitHub\libR-sys)
error: failed to run custom build command for `libR-sys v0.1.9 (C:\Users\tpb398\Documents\GitHub\libR-sys)`

Caused by:
  process didn't exit successfully: `C:/cargo_target_dir\debug\build\libR-sys-46304186790a078b\build-script-build` (exit code: 101)
  --- stdout
  cargo:rustc-env=R_HOME=C:/R/R-4.0.2
  cargo:rustc-env=R_HOME=C:/R/R-4.0.2/bin/i386
  cargo:r_home=C:/R/R-4.0.2
  cargo:rustc-link-search=C:/R/R-4.0.2/bin/i386
  cargo:rustc-link-lib=dylib=R
  cargo:rerun-if-changed=build.rs
  cargo:rerun-if-changed=wrapper.h

  --- stderr
  thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching: [\'clang.dll\', \'libclang.dll\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [(C:\\Users\\tpb398\\scoop\\apps\\msys2\\current\\mingw32\\bin\\libclang.dll: invalid DLL (32-bit)), (C:\\Users\\tpb398\\scoop\\apps\\msys2\\current\\mingw32\\bin\\libclang.dll: invalid DLL (32-bit))])"', C:\Users\tpb398\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.53.3\src/lib.rs:1956:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I've searched for clang.dll in the mingw folders, and there is nothing named that.

It is the libclang.dll that is problem.

Here's a few more diagnostic things that I see mentioned when trying to troubleshoot this:

Details
$ clang -v
clang version 11.0.0 (https://github.com/msys2/MINGW-packages 20f70d38fae51f89ce3c06d054a77139606df472)
Target: i686-w64-windows-gnu
Thread model: posix
InstalledDir: C:\Users\tpb398\scoop\apps\msys2\current\mingw32\bin

Activity

  1. Ilia-Kosenkov commented on Nov 28, 2020

    @Ilia-Kosenkov
    Member

    Hi @CGMossa,
    Did you have any success building against i686?
    There is one issue with the building process - the library relies heavily on the R executable (present in PATH) to determine R-specific indlude directories. On 64-bit system PATH usually contains x64 folder of R, meaning libR-sys is linking against 64-bit version of R.dll, and ultimately fails.

    Another thing I have no explanation for - my path contains both mingw32 and mingw64, and by default a 64-bit clang is invoked. If I leave only mingw32, I get the exactly same error as you have posted.

    However, with mingw64 and i386 R on the path, the library can be built and tests can be run, but two of them fail (looks like some native integer/pointer size mismatch). I have no experience in bindgen and cannot comment on that, but I attach a detailed stacktrace.
    I do not understand why the pipeline is able to build a 32-bit app and link agains 32-bit version of R.dll while using 64-bit clang and libraries, this is beyond me.

    Below is the result of
    $(echo $env:RUST_BACKTRACE ; cargo test --release --target=i686-pc-windows-gnu ; clang -v ; Rscript.exe -e '.Platform$r_arch') *>&1 > dump.txt

    dump.txt
    full
       Compiling winapi v0.3.9
       Compiling memchr v2.3.4
       Compiling version_check v0.9.2
       Compiling glob v0.3.0
       Compiling cc v1.0.65
       Compiling libc v0.2.80
       Compiling lazy_static v1.4.0
       Compiling proc-macro2 v1.0.24
       Compiling bitflags v1.2.1
       Compiling log v0.4.11
       Compiling cfg-if v0.1.10
       Compiling unicode-xid v0.2.1
       Compiling regex-syntax v0.6.21
       Compiling quick-error v1.2.3
       Compiling unicode-width v0.1.8
       Compiling bindgen v0.53.3
       Compiling vec_map v0.8.2
       Compiling strsim v0.8.0
       Compiling lazycell v1.3.0
       Compiling shlex v0.1.1
       Compiling peeking_take_while v0.1.2
       Compiling rustc-hash v1.1.0
       Compiling nom v5.1.2
       Compiling clang-sys v0.29.3
       Compiling thread_local v1.0.1
       Compiling humantime v1.3.0
       Compiling textwrap v0.11.0
       Compiling libloading v0.5.2
       Compiling aho-corasick v0.7.15
       Compiling which v3.1.1
       Compiling quote v1.0.7
       Compiling regex v1.4.2
       Compiling winapi-util v0.1.5
       Compiling atty v0.2.14
       Compiling termcolor v1.1.2
       Compiling clap v2.33.3
       Compiling cexpr v0.4.0
       Compiling env_logger v0.7.1
       Compiling libR-sys v0.1.10 (C:\Users\[redacted]\OneDrive\Development\Playground\libR-sys)
        Finished release [optimized] target(s) in 1m 35s
         Running target\i686-pc-windows-gnu\release\deps\libR_sys-6c682b6e624d8212.exe
    
    running 19 tests
    test bindgen_test_layout_R_CMethodDef ... ok
    test bindgen_test_layout_R_CallMethodDef ... ok
    test bindgen_test_layout_R_inpstream_st ... ok
    test bindgen_test_layout_R_outpstream_st ... ok
    test bindgen_test_layout_Rcomplex ... ok
    test bindgen_test_layout___mingw_dbl_type_t ... ok
    test bindgen_test_layout___mingw_dbl_type_t__bindgen_ty_1 ... ok
    test bindgen_test_layout___mingw_flt_type_t ... ok
    test bindgen_test_layout___mingw_ldbl_type_t__bindgen_ty_1 ... ok
    test bindgen_test_layout__complex ... ok
    test bindgen_test_layout__exception ... ok
    test bindgen_test_layout__iobuf ... ok
    test bindgen_test_layout_localeinfo_struct ... ok
    test bindgen_test_layout_tagLC_ID ... ok
    test bindgen_test_layout_threadlocaleinfostruct ... ok
    test bindgen_test_layout_threadlocaleinfostruct__bindgen_ty_1 ... ok
    test bindgen_test_layout___mingw_ldbl_type_t ... FAILED
    test bindgen_test_layout_max_align_t ... FAILED
    test tests::test_eval ... ok
    
    failures:
    
    ---- bindgen_test_layout___mingw_ldbl_type_t stdout ----
    thread 'bindgen_test_layout___mingw_ldbl_type_t' panicked at 'assertion failed: `(left == right)`
      left: `8`,
     right: `4`: Alignment of __mingw_ldbl_type_t', C:\Users\[redacted]\OneDrive\Development\Playground\libR-sys\target\i686-pc-windows-gnu\release\build\libR-sys-3b2a1ee2f7fff495\out/bindings.rs:2941:5
    stack backtrace:
       0:   0x4d1d1b - core::fmt::write::h3a9c091b8ca4c7a7
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\fmt/mod.rs:1080
       1:   0x402bb4 - std::io::Write::write_fmt::h55320c7185531d90
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\io/mod.rs:1516
       2:   0x4603fb - std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt::h6f6daa32b1c2a916
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\io/impls.rs:179
       3:   0x474e7a - std::sys_common::backtrace::_print::hc2f2ae8a2de1951b
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:61
       4:   0x474e7a - std::sys_common::backtrace::print::h3766cc9baca05bc8
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:48
       5:   0x474e7a - std::panicking::default_hook::{{closure}}::h46a919c0bf907afe
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:208
       6:   0x474b0e - std::panicking::default_hook::hc08848c5073d9694
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:224
       7:   0x47553b - std::panicking::rust_panic_with_hook::h0cea3fe379539d48
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:577
       8:   0x4751b2 - std::panicking::begin_panic_handler::{{closure}}::h4309871eae5bd138
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:484
       9:   0x471bed - std::sys_common::backtrace::__rust_end_short_backtrace::h81ee9a5814303916
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:153
      10:   0x475173 - rust_begin_unwind
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:483
      11:   0x475122 - std::panicking::begin_panic_fmt::h09febdf1830100f4
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:437
      12:   0x40193e - libR_sys::bindgen_test_layout___mingw_ldbl_type_t::h29799f4b51cd0da4
      13:   0x4018a8 - libR_sys::bindgen_test_layout___mingw_ldbl_type_t::{{closure}}::hbfb7aff559cfe3e0
      14:   0x4017d8 - core::ops::function::FnOnce::call_once::h614c99b5966abcde
      15:   0x4290d6 - core::ops::function::FnOnce::call_once::h83e7561c518a8a48
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227
      16:   0x4290d6 - test::__rust_begin_short_backtrace::h90b11f61009b2e83
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:516
      17:   0x427948 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hf8c86ac279728e24
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      18:   0x427948 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h2c82c02427f67527
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:308
      19:   0x427948 - std::panicking::try::do_call::h6c28e5eff59b27d8
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:381
      20:   0x427948 - std::panicking::try::ha356e80f88bfb021
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:345
      21:   0x427948 - std::panic::catch_unwind::h6382aaa1f9c058d4
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:382
      22:   0x427948 - test::run_test_in_process::h4409fa3820453ce1
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:543
      23:   0x427948 - test::run_test::run_test_inner::{{closure}}::hab3d81435f5f1c26
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:449
      24:   0x402085 - std::sys_common::backtrace::__rust_begin_short_backtrace::hbf6e7f2154633f10
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\sys_common/backtrace.rs:137
      25:   0x407f8a - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::h8ce8ddd14af0ac44
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\thread/mod.rs:464
      26:   0x407f8a - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hc91973fe6d3d7749
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:308
      27:   0x407f8a - std::panicking::try::do_call::hc9a2a154e6245402
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:381
      28:   0x407f8a - std::panicking::try::hccfa1cfc786c6746
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:345
      29:   0x407f8a - std::panic::catch_unwind::h15f4b4dfb90d6aa7
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:382
      30:   0x407f8a - std::thread::Builder::spawn_unchecked::{{closure}}::hd39261c1641a1b8a
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\thread/mod.rs:463
      31:   0x407f8a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0d2c8144d1ade409
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227
      32:   0x481e5b - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h47540c09aa657433
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      33:   0x481e5b - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h23f63b1f1783f38a
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      34:   0x481e5b - std::sys::windows::thread::Thread::new::thread_start::h86e8623cdc9f64d6
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys\windows/thread.rs:56
      35: 0x7736fa29 - <unknown>
      36: 0x775d75f4 - <unknown>
      37: 0x775d75c4 - <unknown>
    
    ---- bindgen_test_layout_max_align_t stdout ----
    thread 'bindgen_test_layout_max_align_t' panicked at 'assertion failed: `(left == right)`
      left: `16`,
     right: `24`: Size of: max_align_t', C:\Users\[redacted]\OneDrive\Development\Playground\libR-sys\target\i686-pc-windows-gnu\release\build\libR-sys-3b2a1ee2f7fff495\out/bindings.rs:2651:5
    stack backtrace:
       0:   0x4d1d1b - core::fmt::write::h3a9c091b8ca4c7a7
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\core\src\fmt/mod.rs:1080
       1:   0x402bb4 - std::io::Write::write_fmt::h55320c7185531d90
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\io/mod.rs:1516
       2:   0x4603fb - std::io::impls::<impl std::io::Write for alloc::boxed::Box<W>>::write_fmt::h6f6daa32b1c2a916
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\io/impls.rs:179
       3:   0x474e7a - std::sys_common::backtrace::_print::hc2f2ae8a2de1951b
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:61
       4:   0x474e7a - std::sys_common::backtrace::print::h3766cc9baca05bc8
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:48
       5:   0x474e7a - std::panicking::default_hook::{{closure}}::h46a919c0bf907afe
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:208
       6:   0x474b0e - std::panicking::default_hook::hc08848c5073d9694
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:224
       7:   0x47553b - std::panicking::rust_panic_with_hook::h0cea3fe379539d48
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:577
       8:   0x4751b2 - std::panicking::begin_panic_handler::{{closure}}::h4309871eae5bd138
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:484
       9:   0x471bed - std::sys_common::backtrace::__rust_end_short_backtrace::h81ee9a5814303916
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys_common/backtrace.rs:153
      10:   0x475173 - rust_begin_unwind
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:483
      11:   0x475122 - std::panicking::begin_panic_fmt::h09febdf1830100f4
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src/panicking.rs:437
      12:   0x40188e - libR_sys::bindgen_test_layout_max_align_t::h374144ebd117569d
      13:   0x4017f8 - libR_sys::bindgen_test_layout_max_align_t::{{closure}}::h8be0742b37d54879
      14:   0x4017c8 - core::ops::function::FnOnce::call_once::h0a57d00c7b916612
      15:   0x4290d6 - core::ops::function::FnOnce::call_once::h83e7561c518a8a48
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227
      16:   0x4290d6 - test::__rust_begin_short_backtrace::h90b11f61009b2e83
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:516
      17:   0x427948 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::hf8c86ac279728e24
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      18:   0x427948 - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h2c82c02427f67527
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:308
      19:   0x427948 - std::panicking::try::do_call::h6c28e5eff59b27d8
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:381
      20:   0x427948 - std::panicking::try::ha356e80f88bfb021
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:345
      21:   0x427948 - std::panic::catch_unwind::h6382aaa1f9c058d4
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:382
      22:   0x427948 - test::run_test_in_process::h4409fa3820453ce1
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:543
      23:   0x427948 - test::run_test::run_test_inner::{{closure}}::hab3d81435f5f1c26
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\test\src/lib.rs:449
      24:   0x402085 - std::sys_common::backtrace::__rust_begin_short_backtrace::hbf6e7f2154633f10
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\sys_common/backtrace.rs:137
      25:   0x407f8a - std::thread::Builder::spawn_unchecked::{{closure}}::{{closure}}::h8ce8ddd14af0ac44
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\thread/mod.rs:464
      26:   0x407f8a - <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::hc91973fe6d3d7749
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:308
      27:   0x407f8a - std::panicking::try::do_call::hc9a2a154e6245402
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:381
      28:   0x407f8a - std::panicking::try::hccfa1cfc786c6746
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panicking.rs:345
      29:   0x407f8a - std::panic::catch_unwind::h15f4b4dfb90d6aa7
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src/panic.rs:382
      30:   0x407f8a - std::thread::Builder::spawn_unchecked::{{closure}}::hd39261c1641a1b8a
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\std\src\thread/mod.rs:463
      31:   0x407f8a - core::ops::function::FnOnce::call_once{{vtable.shim}}::h0d2c8144d1ade409
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\core\src\ops/function.rs:227
      32:   0x481e5b - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h47540c09aa657433
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      33:   0x481e5b - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h23f63b1f1783f38a
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\library\alloc\src/boxed.rs:1042
      34:   0x481e5b - std::sys::windows::thread::Thread::new::thread_start::h86e8623cdc9f64d6
                           at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4\/library\std\src\sys\windows/thread.rs:56
      35: 0x7736fa29 - <unknown>
      36: 0x775d75f4 - <unknown>
      37: 0x775d75c4 - <unknown>
    
    
    failures:
        bindgen_test_layout___mingw_ldbl_type_t
        bindgen_test_layout_max_align_t
    
    test result: FAILED. 17 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
    
    [1] 1
    error: test failed, to rerun pass '--lib'
    clang version 11.0.0 (https://github.com/msys2/MINGW-packages c0083b9edc111315c868f9c53dd60aaa78d1669b)
    Target: x86_64-w64-windows-gnu
    Thread model: posix
    InstalledDir: C:\tools\msys64\mingw64\bin
    [1] "i386"
    
    
  2. clauswilke commented on Nov 28, 2020

    @clauswilke
    Member

    Using the R executable to find R_HOME is almost certainly the wrong approach and I already have a PR pending to fix this: KyleMayes/clang-sys#12

    It's possible that we need the build script to detect whether it's trying to build a 32bit or a 64bit target and modify the paths accordingly. Could you post the typical path layout on Windows when both 32bit and 64bit versions are installed? Do they use two different R_HOME values or are they nested under one single R_HOME? Where are the include files (e.g. Rinternals.h)? Where are the library files (something like libR.dll)?

  3. Ilia-Kosenkov commented on Nov 28, 2020

    @Ilia-Kosenkov
    Member

    @clauswilke,
    So the layout is typically like this:
    There is a default Program Files\R folder, to where all versions go (unless the user modified it during installation). In my case, it can look like this:

    Details
        Directory: C:\Program Files\R                                                                                                                                                                                                               Mode                 LastWriteTime         Length Name                                                                 
     ----                 -------------         ------ ----                                                                  
    d----          2020-04-06    15:10                R-3.6.3                                                               
    d----          2020-07-09    18:25                R-4.0.2                                                               
    d----          2020-11-05    23:13                R-4.0.3 
    

    Within R-4.0.3

    Details
        Directory: C:\Program Files\R\R-4.0.3                                                                                                                                                                                                       Mode                 LastWriteTime         Length Name                                                                  
    ----                 -------------         ------ ----                                                                  
    d----          2020-11-05    23:12                bin                                                                   
    d----          2020-11-05    23:12                doc                                                                   
    d----          2020-11-05    23:12                etc                                                                   
    d----          2020-11-05    23:12                include                                                               
    d----          2020-11-05    23:13                library                                                              
    d----          2020-11-05    23:13                modules                                                              
    d----          2020-11-05    23:13                share                                                                
    d----          2020-11-05    23:13                src                                                                   
    d----          2020-11-05    23:13                Tcl                                                                   
    d----          2020-11-05    23:13                tests                                                                 
    -a---          2020-10-10    09:24          27421 CHANGES                                                               
    -a---          2018-09-25    09:47          18011 COPYING                                                               
    -a---          2020-10-10    09:33         536651 MD5                                                                   
    -a---          2018-09-25    09:47           4132 README                                                                
    -a---          2020-10-10    09:33           8676 README.R-4.0.3                                                        
    -a---          2020-11-05    23:13        1303256 unins000.dat                                                          
    -a---          2020-11-05    23:12        2594145 unins000.exe     
    
    there are shared \include
    Details
    
        Directory: C:\Program Files\R\R-4.0.3\include                                                                                                                                                                                               Mode                 LastWriteTime         Length Name                                                                 
     ----                 -------------         ------ ----                                                                  
    d----          2020-11-05    23:12                R_ext                                                                 
    -a---          2018-09-25    09:46           8172 ga.h                                                                  
    -a---          2020-03-27    00:02          36322 graphapp.h                                                            
    -a---          2020-10-10    09:14           2027 iconv.h                                                               
    -a---          2020-10-10    09:14          14384 libintl.h                                                             
    -a---          2018-09-25    09:46           3413 R.h                                                                  
    -a---          2020-10-10    09:14            865 Rconfig.h                                                             
    -a---          2018-09-25    09:46           6758 Rdefines.h                                                            
    -a---          2018-09-25    09:46           2075 Rembedded.h                                                         
    -a---          2020-05-27    23:15          62996 Rinternals.h                                                          
    -a---          2020-10-10    09:14          17446 Rmath.h                                                               
    -a---          2020-10-10    09:14            510 Rversion.h                                                            
    -a---          2018-09-25    09:46           2593 S.h         
    

    and platform-specific \bin

    Details
        Directory: C:\Program Files\R\R-4.0.3\bin                                                                                                                                                                                                   Mode                 LastWriteTime         Length Name                                                                  
    ----                 -------------         ------ ----                                                                  
    d----          2020-11-05    23:12                i386                                                                  
    d----          2020-11-05    23:12                x64                                                                   
    -a---          2020-10-10    09:14          11957 config.sh                                                            
    -a---          2020-10-10    09:19         514640 R.exe                                                                
    -a---          2020-10-10    09:19         514640 Rscript.exe     
    

    Here, R.exe is a 64-bit app and I guess this bin folder is added to the PATH.
    Now, both x64 and i386 contain a full set of .exe apps and .dll, which are platform-specific, e.g.

    Details
        Directory: C:\Program Files\R\R-4.0.3\bin\x64                                                                                                                                                                                               Mode                 LastWriteTime         Length Name                                                                  
    ----                 -------------         ------ ----                                                                  
    -a---          2020-10-10    09:19         434550 open.exe                                                              
    -a---          2020-10-10    09:18       51840736 R.dll                                                                 
    -a---          2020-10-10    09:19         625050 R.exe                                                                 
    -a---          2020-10-10    09:18         508902 Rblas.dll                                                             
    -a---          2020-10-10    09:19         621942 Rcmd.exe                                                              
    -a---          2020-10-10    09:19         514640 Rfe.exe                                                               
    -a---          2020-10-10    09:18        2064862 Rgraphapp.dll                                                         
    -a---          2020-10-10    09:19         543177 Rgui.exe                                                              
    -a---          2020-10-10    09:18         437454 Riconv.dll                                                            
    -a---          2020-10-10    09:20        2535936 Rlapack.dll                                                           
    -a---          2020-10-10    09:19         532869 Rscript.exe                                                           
    -a---          2020-10-10    09:19         530053 RSetReg.exe                                                           
    -a---          2020-10-10    09:19         562358 Rterm.exe   
    

    So, to build a 32- or 64- bit project, a correct R.dll should be linked. The current approach invokes 64-bit R and gets an ....\bin\x64\R.dll as include, while the correct one for i686 is ....\bin\i386\R.dll.

    There is yet another way. Default R installation can write values to Registry. Depending on whether the installer was executed as admin (elevated) or not, values can be written to different places, but they can (probably) be tested during the build process. Examples:
    ls HKLM:\SOFTWARE\R-core\ gives

        Hive: HKEY_LOCAL_MACHINE\SOFTWARE\R-core                                                                                                                                                                                                    Name                           Property                                                                                 
    ----                           --------                                                                                 
    R                              InstallPath     : C:\Program Files\R\R-4.0.3                                                                            Current Version : 4.0.3                                                                  
    R64                            InstallPath     : C:\Program Files\R\R-4.0.3                                                                            Current Version : 4.0.3                                                                  
    Rtools                         InstallPath     : C:\rtools40                                                                                           Current Version : 4.0        
    

    and ls HKLM:\SOFTWARE\R-core\R produces all currently active installation of R (32-bit).

        Hive: HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R
    
    Name                           Property
    ----                           --------
    3.6.3                          InstallPath : C:\Program Files\R\R-3.6.3
    4.0.2                          InstallPath : C:\Program Files\R\R-4.0.2
    4.0.3                          InstallPath : C:\Program Files\R\R-4.0.3
    

    So, for instance (using powershell for the sake of example), a query of the form
    "$(Get-ItemProperty HKLM:\SOFTWARE\R-core\R64 | select -expand "InstallPath")\bin\x64"
    results in
    C:\Program Files\R\R-4.0.3\bin\x64

    and "$(Get-ItemProperty HKLM:\SOFTWARE\R-core\R | select -expand "InstallPath")\bin\i386"
    results in
    C:\Program Files\R\R-4.0.3\bin\i386 ,
    which should give correct 64- and 32-bit paths no matter how R is installed.

  4. clauswilke commented on Nov 28, 2020

    @clauswilke
    Member

    So we have the same Rinternals.h but different R.dll. I think when compiling on Windows we need to set the correct library path depending on the target we're compiling for. That should be possible.

  5. clauswilke commented on Nov 28, 2020

    @clauswilke
    Member

    I have amended my PR KyleMayes/clang-sys#12 to set different library paths depending on the target architecture. But I can't test it since I don't have windows. Could you guys test it? Note that you'll have to set the R_HOME environment variable for this code branch to be executed.

  6. clauswilke commented on Dec 8, 2020

    @clauswilke
    Member

    I have merged KyleMayes/clang-sys#12. Does this close this issue?

    Note also the problem described in KyleMayes/clang-rs#82. @CGMossa, do you have this problem?

  7. added this to the 0.1.11 milestone on Dec 10, 2020
  8. yutannihilation commented on Dec 12, 2020

    @yutannihilation
    Contributor

    I have merged KyleMayes/clang-sys#12. Does this close this issue?

    I still see the same error on my MSYS2. The error @Ilia-Kosenkov described in #9 (comment) is solved, but the original one stays the same.

    This error

    thread 'main' panicked at 'Unable to find libclang: "couldn\'t find any valid shared libraries matching:
    [\'clang.dll\', \'libclang.dll\'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found 
    (invalid: [(C:\\...\\msys2\\current\\mingw32\\bin\\libclang.dll: invalid DLL (32-bit)), 
    (C:\\...\\msys2\\current\\mingw32\\bin\\libclang.dll: invalid DLL (32-bit))])"',
    

    comes from clang-sys crate's validation:

            if cfg!(target_pointer_width = "64") && magic != 523 {
                return Err("invalid DLL (32-bit)".into());
            }
    

    I really don't understand why target_pointer_width is 64 when we specify the target of 32bit...

  9. CGMossa commented on Dec 12, 2020

    @CGMossa
    MemberAuthor
  10. yutannihilation commented on Dec 12, 2020

    @yutannihilation
    Contributor

    Try to print out the target

    Here's printed-out bindgen_builder.command_line_flags(). Is this the same on your environment?

    ["wrapper.h", "--rust-target", "1.40", "--blacklist-item", "FP_NAN", "--blacklist-item", "FP_INFINITE", "--blacklist-item", "FP_ZERO", "--blacklist-item", "FP_SUBNORMAL", "--blacklist-item", "FP_NORMAL", "--no-derive-default", "--generate", "functions,types,vars,methods,constructors,destructors", "--", "-IC:\\Program Files\\R\\R-4.0.2\\include", "--target=i686-pc-windows-gnu"]

  11. CGMossa commented on Dec 12, 2020

    @CGMossa
    MemberAuthor
  12. yutannihilation commented on Dec 12, 2020

    @yutannihilation
    Contributor

    Yeah, I think we are stuck in front of the same problem...

    This seems because cargo looks for the default toolchain even when we specify target. If I switch the default toolchain to 32-bit,

    rustup default stable-i686-pc-windows-gnu

    I can pass the validation, but I still get this error (the message says "The specified procedure could not be found." Sorry I don't know how to show English messages...):

    thread 'main' panicked at 'Unable to find libclang: "the libclang shared library at C:\\msys64\\mingw32\\bin\\libclang.dll could not be opened: 指定されたプロシージャが見つかりません。 (os error 127)"', C:\Users\hiroaki-yutani\.cargo\registry\src\github.com-1285ae84e5963aae\bindgen-0.53.3\src/lib.rs:1956:31

  13. clauswilke commented on Dec 12, 2020

    @clauswilke
    Member

    I think what is happening is that cargo uses the default toolchain to compile build.rs, and then runs build.rs with the specific compile target.

    If you switch the default toolchain, you also need a 32-bit clang. Did you install that? The github action does not.

  14. yutannihilation commented on Dec 12, 2020

    @yutannihilation
    Contributor

    Did you install that?

    Yes, I just followed https://github.com/extendr/libR-sys#windows-specific-instructions

    Btw,

    The github action does not.

    it seems GitHub Actions runner already has it installed. I tried to install mingw32/mingw-w64-i686-clang on GitHub Actions CI runner, but it says it's up to date.

       C:\windows\system32\cmd.exe /D /S /C D:\a\_temp\msys\msys2.cmd -c "'pacman' '--noconfirm' '-S' '--needed' '--overwrite' '*' 'mingw32/mingw-w64-i686-clang' 'mingw-w64-i686-toolchain'"
      warning: mingw-w64-i686-clang-11.0.0-4 is up to date -- skipping
      warning: mingw-w64-i686-binutils-2.35.1-3 is up to date -- skipping
      warning: mingw-w64-i686-crt-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-gcc-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gcc-ada-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gcc-fortran-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gcc-libgfortran-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gcc-libs-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gcc-objc-10.2.0-5 is up to date -- skipping
      warning: mingw-w64-i686-gdb-10.1-1 is up to date -- skipping
      warning: mingw-w64-i686-gdb-multiarch-10.1-1 is up to date -- skipping
      warning: mingw-w64-i686-headers-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-libmangle-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-libwinpthread-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-make-4.3-1 is up to date -- skipping
      warning: mingw-w64-i686-pkgconf-1.7.3-5 is up to date -- skipping
      warning: mingw-w64-i686-tools-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-winpthreads-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
      warning: mingw-w64-i686-winstorecompat-git-9.0.0.6029.ecb4ff54-1 is up to date -- skipping
    

    (from my test branch: https://github.com/yutannihilation/libR-sys/runs/1542066028?check_suite_focus=true#step:3:33)

  15. clauswilke commented on Dec 12, 2020

    @clauswilke
    Member

    Side note: I find it so confusing to figure out what is and isn't already installed in the GitHub Actions runner. And if you once install something and then remove the install line it still remains in the cache. I wish there was an easy way to just clear the cache.

  16. 24 remaining items

  17. Ilia-Kosenkov commented on Dec 16, 2020

    @Ilia-Kosenkov
    Member

    @clauswilke,
    --release has no effect - still fails both ways.
    However, I put an example code using c++, in particular, msvc.
    Strangely, it works fine for both x64 and x86, meaning I dynamically load dll, find two functions, invoke them, free resources.
    The only difference so far is that I use simple LoadLibraryW, while rust fails with error at LoadLibraryExW, which has additional flags. I will try playing with LoadLibraryExW to see if it fails under certain conditions.
    I can share a repo which can be reviewed and tested -- if needed.

    Building from source is another step, I think there still maybe some rust-related issue there.

  18. Ilia-Kosenkov commented on Dec 16, 2020

    @Ilia-Kosenkov
    Member

    This is getting weirder and weirder with every step.
    In short, cargo run fails on a sample project, however if cargo build and then just execute the *.exe -- everything works fine.

    If anyone is testing my rust_clang_run, could you please invoke the output .exe manually?

  19. clauswilke commented on Dec 16, 2020

    @clauswilke
    Member

    Interesting! Can you reproduce this in the GH action? Run cargo build, run the *.exe, and then run it again with cargo run?

  20. Ilia-Kosenkov commented on Dec 16, 2020

    @Ilia-Kosenkov
    Member

    Did not try running it with cargo run afterwards, just created separate jobs.
    Here is the last report https://github.com/Ilia-Kosenkov/rust_clang_run/actions/runs/426337151.
    Jobs that are called Run i686 do build and then run executable, other jobs do cargo run only.

  21. removed this from the 0.2.0 milestone on Dec 16, 2020
  22. clauswilke commented on Dec 16, 2020

    @clauswilke
    Member

    I have removed this issue from the milestone for the next libR-sys release. It isn't immediately show-stopping, as I've now a set of manually fixed-up bindings that work for now. We should still try to get the i686 libclang issue resolved, though.

  23. Ilia-Kosenkov commented on Dec 16, 2020

    @Ilia-Kosenkov
    Member

    It feels like we have enough to go and ask 'rust' people about this issue. Clearly it is neither 'msys'/'mingw' nor 'clang' (I called the latter from x86 C++ app with no problem).

  24. clauswilke commented on Dec 16, 2020

    @clauswilke
    Member

    Agreed. We can file an issue with cargo: https://github.com/rust-lang/cargo

    Do you want to do this or do you prefer if I do so?

  25. Ilia-Kosenkov commented on Dec 17, 2020

    @Ilia-Kosenkov
    Member

    @clauswilke,
    If you can do that, please do.
    I will participate and provide clarifications of what I found if needed.

  26. clauswilke commented on Dec 17, 2020

    @clauswilke
    Member

    Issue filed with cargo: rust-lang/cargo#8990

  27. Ilia-Kosenkov commented on Dec 18, 2020

    @Ilia-Kosenkov
    Member

    Following suggestions from rust/cargo people, I was able to build i686 and test* libR-sys without pre-built bindings.

    rustup default stable-i686-pc-windows-msvc
    rustup target add i686-pc-windows-gnu
    LIBCLANG_PATH=path_to_msys\mingw32\bin
    R_HOME=path_to_r
    
    cargo build --release --target=i686-pc-windows-gnu --features use-bindgen
    

    * because of PATH resolution issue (see KyleMayes/clang-rs#91), if PATH is updated to explicitly include only R_HOME\bin\i386, then

    cargo test --release --target=i686-pc-windows-gnu --features use-bindgen -- --nocapture --test-threads=1
    

    also works.

  28. mati865 commented on Dec 19, 2020

    @mati865

    I think cross-compiling from any Windows toolchain, even x86_64-gnu would work here.

  29. Ilia-Kosenkov commented on Dec 22, 2020

    @Ilia-Kosenkov
    Member

    With the answers we got from other teams & the successful deployment of our own GitHub CI, should this issue be closed?
    README contains all the necessary information on how to build on windows, including i686.

  30. clauswilke commented on Dec 22, 2020

    @clauswilke
    Member

    Yes, agreed. If new problems crop up we can open a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions