Skip to content

Commit cb9ebcf

Browse files
authored
Stop adding link-native-libraries flag by default in Emscripten platform in latest Rust (#2991)
The problem with rust trying to link libc was fixed in rust-lang/libc#4002, and this flag is not needed anymore for recent rust versions. Always adding this flag is preventing from using the stable Rust toolchain as `-Z` flag can only be used with the nightly toolchains. From Rust 1.93.0, it is possible to use stable toolchain to build to Emscripten target, so this PR removes this flag for Rust >= 1.93.0 cc: @hoodmane
1 parent a5a85f0 commit cb9ebcf

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

src/compile.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#[cfg(feature = "zig")]
22
use crate::PlatformTag;
3-
use crate::target::RUST_1_64_0;
3+
use crate::target::{RUST_1_64_0, RUST_1_93_0};
44
use crate::{BridgeModel, BuildContext, PythonInterpreter, Target};
55
use anyhow::{Context, Result, anyhow, bail};
66
use cargo_metadata::CrateType;
@@ -245,13 +245,18 @@ fn cargo_build_command(
245245
cargo_rustc.args.extend(mac_args);
246246
}
247247
} else if target.is_emscripten() {
248-
// Allow user to override these default flags
249-
if !rustflags
250-
.flags
251-
.iter()
252-
.any(|f| f.contains("link-native-libraries"))
248+
// The -Z link-native-libraries=no flag is needed for older Rust versions
249+
// where Emscripten builds fail without it due to the behavior that it links
250+
// libc automatically.
251+
// From Rust 1.93.0, it is possible to build Emscripten with stable toolchain
252+
// and this flag can be and should be removed.
253+
if target.rustc_version.semver < RUST_1_93_0
254+
&& !rustflags
255+
.flags
256+
.iter()
257+
.any(|f| f.contains("link-native-libraries"))
253258
{
254-
debug!("Setting `-Z link-native-libraries=no` for Emscripten");
259+
debug!("Setting `-Z link-native-libraries=no` for Emscripten (rust < 1.93.0)");
255260
rustflags.push("-Z");
256261
rustflags.push("link-native-libraries=no");
257262
}

src/target/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod pypi_tags;
2323
pub use pypi_tags::{is_arch_supported_by_pypi, validate_wheel_filename_for_pypi};
2424

2525
pub(crate) const RUST_1_64_0: semver::Version = semver::Version::new(1, 64, 0);
26+
pub(crate) const RUST_1_93_0: semver::Version = semver::Version::new(1, 93, 0);
2627

2728
/// All supported operating system
2829
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]

0 commit comments

Comments
 (0)