diff --git a/src/compile.rs b/src/compile.rs index 71b7d41e6..47557b875 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -1,6 +1,6 @@ #[cfg(feature = "zig")] use crate::PlatformTag; -use crate::target::RUST_1_64_0; +use crate::target::{RUST_1_64_0, RUST_1_93_0}; use crate::{BridgeModel, BuildContext, PythonInterpreter, Target}; use anyhow::{Context, Result, anyhow, bail}; use cargo_metadata::CrateType; @@ -245,13 +245,18 @@ fn cargo_build_command( cargo_rustc.args.extend(mac_args); } } else if target.is_emscripten() { - // Allow user to override these default flags - if !rustflags - .flags - .iter() - .any(|f| f.contains("link-native-libraries")) + // The -Z link-native-libraries=no flag is needed for older Rust versions + // where Emscripten builds fail without it due to the behavior that it links + // libc automatically. + // From Rust 1.93.0, it is possible to build Emscripten with stable toolchain + // and this flag can be and should be removed. + if target.rustc_version.semver < RUST_1_93_0 + && !rustflags + .flags + .iter() + .any(|f| f.contains("link-native-libraries")) { - debug!("Setting `-Z link-native-libraries=no` for Emscripten"); + debug!("Setting `-Z link-native-libraries=no` for Emscripten (rust < 1.93.0)"); rustflags.push("-Z"); rustflags.push("link-native-libraries=no"); } diff --git a/src/target/mod.rs b/src/target/mod.rs index 8838d84a5..d15a58ec9 100644 --- a/src/target/mod.rs +++ b/src/target/mod.rs @@ -23,6 +23,7 @@ mod pypi_tags; pub use pypi_tags::{is_arch_supported_by_pypi, validate_wheel_filename_for_pypi}; pub(crate) const RUST_1_64_0: semver::Version = semver::Version::new(1, 64, 0); +pub(crate) const RUST_1_93_0: semver::Version = semver::Version::new(1, 93, 0); /// All supported operating system #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, Deserialize)]