Skip to content

Commit 8c807d6

Browse files
committed
fix(build): link proper cxx std libraries on windows-gnu{,llvm}
`*-pc-windows-gnullvm` targets use Clang toolchain, so the std library for it is libc++, pthread is needed to be explicitly linked too. `*-pc-windows-gnu` build also depends on `libatomic`
1 parent 696006d commit 8c807d6

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,7 @@ fn print_link_flags() {
751751
} else if target.contains("apple")
752752
|| target.contains("freebsd")
753753
|| target.contains("openbsd")
754+
|| target.contains("gnullvm")
754755
{
755756
println!("cargo:rustc-link-lib=dylib=c++");
756757
} else if target.contains("android") {
@@ -760,6 +761,7 @@ fn print_link_flags() {
760761
}
761762
}
762763
}
764+
let target = env::var("TARGET").unwrap();
763765
let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap();
764766
let target_env = env::var("CARGO_CFG_TARGET_ENV").unwrap();
765767

@@ -776,6 +778,12 @@ fn print_link_flags() {
776778
} else {
777779
println!("cargo:rustc-link-lib=dylib=msvcprt");
778780
}
781+
} else if target.ends_with("windows-gnu") {
782+
// Clang-based toolchains don't use separate atomic library
783+
println!("cargo:rustc-link-lib=atomic")
784+
} else if target.ends_with("windows-gnullvm") {
785+
// Clang usually works with Win32 threads, so we need to link pthread explicitly
786+
println!("cargo:rustc-link-lib=pthread")
779787
}
780788
}
781789

0 commit comments

Comments
 (0)