cargo-zigbuild
cargo-zigbuild copied to clipboard
Using target `x86_64-pc-windows-gnu` still tries to link in `msvcrt`
I have had a lot of success targeting Linux and macOS machines with this.
However I'm running into a puzzling issue, it seems that Rust really wants to link msvcrt, even when the command I'm specifying is:
cargo zigbuild --target x86_64-pc-windows-gnu
It complains about not being able to locate the library.
= note: error: unable to find dynamic system library 'msvcrt' using strategy 'paths_first'. searched paths:
/Users/digit/git/Jsonrs/native/jsonrs/target/x86_64-pc-windows-gnu/debug/deps/msvcrt.dll
/Users/digit/git/Jsonrs/native/jsonrs/target/x86_64-pc-windows-gnu/debug/deps/msvcrt.lib
/Users/digit/git/Jsonrs/native/jsonrs/target/x86_64-pc-windows-gnu/debug/deps/libmsvcrt.a
/Users/digit/git/Jsonrs/native/jsonrs/target/debug/deps/msvcrt.dll
/Users/digit/git/Jsonrs/native/jsonrs/target/debug/deps/msvcrt.lib
/Users/digit/git/Jsonrs/native/jsonrs/target/debug/deps/libmsvcrt.a
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/msvcrt.dll
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/msvcrt.lib
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/libmsvcrt.a
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/msvcrt.dll
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/msvcrt.lib
/Users/digit/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-pc-windows-gnu/lib/libmsvcrt.a
Does this flag need to be filtered out in the linker argument processing step?
Re-running the long command that's spat out, and then removing the -lmsvcrt results in the build proceeding further until it hits the temp files that no longer exist post-build.
Can you try filter out it in here? https://github.com/rust-cross/cargo-zigbuild/blob/d420792226cef24e8a718dbef87fec14df77f3d2/src/zig.rs#L105-L132
Thanks
FYI, -lmsvcrt seems to be added by Rust in https://github.com/rust-lang/rust/blob/b5723af3457b9cd3795eeb97e9af2d34964854f2/compiler/rustc_target/src/spec/base/windows_gnu.rs#L33-L44
Thanks for the quick reply. Looking at the CI results there's some other gotchas involved here. I've cloned down your branch and will be playing a bit with it to see if I can resolve any of the linker issues I've seen in CI.
upgrading from version 0.18.4 to 0.19.3 seems to fix it for me. Just thought I'd let others know. It looks like it was fixed here: https://github.com/rust-cross/cargo-zigbuild/pull/274
PS. Thank you for making my life easier! I just sponsored on github.