From 6bca66c0328f379c5ee522f073a121a6069853c6 Mon Sep 17 00:00:00 2001 From: messense Date: Mon, 15 Aug 2022 10:28:00 +0800 Subject: [PATCH] Allow user to override default Emscripten settings --- Changelog.md | 2 ++ src/compile.rs | 29 ++++++++++++++++++++++------- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index 09b47b776..d8bc4f5fe 100644 --- a/Changelog.md +++ b/Changelog.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +* Allow user to override default Emscripten settings in [#1059](https://github.com/PyO3/maturin/pull/1059) + ## [0.13.2] - 2022-08-14 * Deprecate manylinux 2010 support in [#858](https://github.com/PyO3/maturin/pull/858). diff --git a/src/compile.rs b/src/compile.rs index 12ff68171..efb074503 100644 --- a/src/compile.rs +++ b/src/compile.rs @@ -232,13 +232,28 @@ fn compile_target( } } else if target.is_emscripten() { let flags = rust_flags.get_or_insert_with(Default::default); - flags.push(" -Z link-native-libraries=no"); - let emscripten_args = [ - "-C".to_string(), - "link-arg=-sSIDE_MODULE=2".to_string(), - "-C".to_string(), - "link-arg=-sWASM_BIGINT".to_string(), - ]; + // Allow user to override these default flags + if !flags.to_string_lossy().contains("link-native-libraries") { + flags.push(" -Z link-native-libraries=no"); + } + let mut emscripten_args = Vec::new(); + // Allow user to override these default settings + if !cargo_rustc + .args + .iter() + .any(|arg| arg.contains("SIDE_MODULE")) + { + emscripten_args.push("-C".to_string()); + emscripten_args.push("link-arg=-sSIDE_MODULE=2".to_string()); + } + if !cargo_rustc + .args + .iter() + .any(|arg| arg.contains("WASM_BIGINT")) + { + emscripten_args.push("-C".to_string()); + emscripten_args.push("link-arg=-sWASM_BIGINT".to_string()); + } cargo_rustc.args.extend(emscripten_args); }