Skip to content

Commit 1565618

Browse files
gyscosclaude
andcommitted
Check the target, not the host, for MSVC
#353 stopped passing -fvisibility=hidden to cl.exe by testing cfg!(target_env = "msvc"), which fixed the reported case. But build scripts are compiled for the machine running them, so that cfg answers for the host: cross-compiling from a non-MSVC host to a *-windows-msvc target still hands the gcc-style flag to cl.exe. Read CARGO_CFG_TARGET_ENV instead, behind a helper shared with the seekable build in the cmake path, which was already doing this. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01TeZDBS4Uw5kdF77tkJ7cAe
1 parent 8315a62 commit 1565618

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

‎zstd-safe/zstd-sys/build.rs‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ fn compile_zstd_cmake() {
8989
.warnings(false)
9090
.cargo_metadata(!cfg!(feature = "non-cargo"));
9191

92-
if env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() != "msvc" {
92+
if !target_is_msvc() {
9393
seekable.flag("-fvisibility=hidden");
9494
}
9595

@@ -366,7 +366,7 @@ fn compile_zstd() {
366366
// Hide symbols from resulting library,
367367
// so we can be used with another zstd-linking lib.
368368
// See https://github.com/gyscos/zstd-rs/issues/58
369-
if ! cfg!(target_env = "msvc") {
369+
if !target_is_msvc() {
370370
config.flag("-fvisibility=hidden");
371371
}
372372
config.define("XXH_PRIVATE_API", Some(""));
@@ -410,6 +410,16 @@ fn compile_zstd() {
410410
cargo_print(&format_args!("root={}", dst.display()));
411411
}
412412

413+
/// Is the *target* toolchain MSVC?
414+
///
415+
/// `cfg!(target_env = ..)` would answer for the host: build scripts are
416+
/// compiled for the machine running them. That gets the answer wrong whenever
417+
/// the two differ - a windows-gnu host building for a windows-msvc target ends
418+
/// up handing gcc-style flags to `cl.exe`, which warns on every file.
419+
fn target_is_msvc() -> bool {
420+
env::var("CARGO_CFG_TARGET_ENV").unwrap_or_default() == "msvc"
421+
}
422+
413423
/// Print a line for cargo.
414424
///
415425
/// If non-cargo is set, do not print anything.

0 commit comments

Comments
 (0)