-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
In the context of generating Rust bindings for R via bindgen (libR-sys project, https://github.com/extendr/libR-sys), we have encountered a strange problem for the target i686-pc-windows-gnu that seems to trace back to something cargo run does when calling an executable it has just built.
In brief, we noticed that when trying to run our bindgen build script on 32-bit Windows, the program would abort with a linking error in libclang. We first thought it was a packaging problem with the mingw package providing libclang, and we reported it as such: msys2/MINGW-packages#7442. However, further investigation has shown that this is unlikely to be the case. Instead, we now suspect there's a problem with cargo itself.
@Ilia-Kosenkov has created a minimal example of a Rust program calling libclang, to mimic what bindgen does:
https://github.com/Ilia-Kosenkov/rust_clang_run. This program compiles and runs just fine on 64-bit Windows, and it aborts with a linking error on 32-bit Windows, regardless of whether libclang is linked statically or dynamically. But here's the kicker: This happens only when we run the program with cargo run. If we build the program with cargo build and then run the executable by calling it directly, everything works fine. You can see this behavior in the GitHub Actions for the minimal example, e.g. here: https://github.com/Ilia-Kosenkov/rust_clang_run/runs/1565696019?check_suite_focus=true
In the minimal example, we can of course work around the problem by not using cargo run. But in the actual application, libclang is linked into the build script, and thus the compiled executable is always run by cargo and the linking error occurs.
Related libR-sys issue with discussion and background: extendr/libR-sys#9
Note: We're using the i686-pc-windows-gnu target because that's a hard requirement set by the R project. We cannot use i686-pc-windows-msvc as a workaround, and we have not tested whether the problem exists on i686-pc-windows-msvc.