Skip to content

Commit 9759ea7

Browse files
committed
Emscripten: No extra rustc-cdylib-link-args on Rust >= 1.95
We used to have to pass extra flags to build with Emscripten but 1. Emscripten 4.0.0 made WASM_BIGINT automatic 2. Rust version 1.95 learned how to build cdylibs rust-lang/rust#151704 We use Emscripten 3.1.58 to build for Python 3.12 which would be broken by dropping WASM_BIGINT but for Python 3.12 we also use JS eh which doesn't work at all with Rust version >= 1.93 so there's no added breakage. On the other hand, Python 3.13 uses Emscripten 4.0.9 and doesn't need `-sWASM_BIGINT`.
1 parent 5d0cae5 commit 9759ea7

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

pyo3-build-config/src/lib.rs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,29 @@ pub fn use_pyo3_cfgs() {
5656
///
5757
/// The following link flags are added:
5858
/// - macOS: `-undefined dynamic_lookup`
59-
/// - wasm32-unknown-emscripten: `-sSIDE_MODULE=2 -sWASM_BIGINT`
59+
/// - wasm32-unknown-emscripten: for Rust <= 1.95, `-sSIDE_MODULE=2 -sWASM_BIGINT`
6060
///
6161
/// All other platforms currently are no-ops, however this may change as necessary
6262
/// in future.
6363
pub fn add_extension_module_link_args() {
64-
_add_extension_module_link_args(&impl_::target_triple_from_env(), std::io::stdout())
64+
_add_extension_module_link_args(
65+
&impl_::target_triple_from_env(),
66+
std::io::stdout(),
67+
rustc_minor_version(),
68+
)
6569
}
6670

67-
fn _add_extension_module_link_args(triple: &Triple, mut writer: impl std::io::Write) {
71+
fn _add_extension_module_link_args(
72+
triple: &Triple,
73+
mut writer: impl std::io::Write,
74+
rustc_minor_version: Option<u32>,
75+
) {
6876
if matches!(triple.operating_system, OperatingSystem::Darwin(_)) {
6977
writeln!(writer, "cargo:rustc-cdylib-link-arg=-undefined").unwrap();
7078
writeln!(writer, "cargo:rustc-cdylib-link-arg=dynamic_lookup").unwrap();
71-
} else if triple == &Triple::from_str("wasm32-unknown-emscripten").unwrap() {
79+
} else if triple == &Triple::from_str("wasm32-unknown-emscripten").unwrap()
80+
&& rustc_minor_version.is_some_and(|version| version < 95)
81+
{
7282
writeln!(writer, "cargo:rustc-cdylib-link-arg=-sSIDE_MODULE=2").unwrap();
7383
writeln!(writer, "cargo:rustc-cdylib-link-arg=-sWASM_BIGINT").unwrap();
7484
}
@@ -415,12 +425,14 @@ mod tests {
415425
_add_extension_module_link_args(
416426
&Triple::from_str("x86_64-pc-windows-msvc").unwrap(),
417427
&mut buf,
428+
None,
418429
);
419430
assert_eq!(buf, Vec::new());
420431

421432
_add_extension_module_link_args(
422433
&Triple::from_str("x86_64-apple-darwin").unwrap(),
423434
&mut buf,
435+
None,
424436
);
425437
assert_eq!(
426438
std::str::from_utf8(&buf).unwrap(),
@@ -432,12 +444,20 @@ mod tests {
432444
_add_extension_module_link_args(
433445
&Triple::from_str("wasm32-unknown-emscripten").unwrap(),
434446
&mut buf,
447+
None,
435448
);
436449
assert_eq!(
437450
std::str::from_utf8(&buf).unwrap(),
438451
"cargo:rustc-cdylib-link-arg=-sSIDE_MODULE=2\n\
439452
cargo:rustc-cdylib-link-arg=-sWASM_BIGINT\n"
440453
);
454+
buf.clear();
455+
_add_extension_module_link_args(
456+
&Triple::from_str("wasm32-unknown-emscripten").unwrap(),
457+
&mut buf,
458+
Some(95),
459+
);
460+
assert_eq!(std::str::from_utf8(&buf).unwrap(), "");
441461
}
442462

443463
#[cfg(feature = "resolve-config")]

0 commit comments

Comments
 (0)