Skip to content

Commit 644e97b

Browse files
Support build configurations without Intl API (#623)
* Support build configurations without Intl API The Intl API requires bundling a very large amount of data, and isn't needed in absolutely all environments. This commit introduces an `intl` feature, which is enabled by default on `mozjs`, and builds SpiderMonkey without Intl support if that feature is disabled. On MacOS, a mozjs embedding I'm working on shrinks from 32MB to 12MB, and a wasm32 build from also 32MB to 8.5MB (all stripped). Signed-off-by: Till Schneidereit <[email protected]> * Always build from source if intl feature is disabled Signed-off-by: Till Schneidereit <[email protected]> * Bump `mozjs-sys` version Signed-off-by: Till Schneidereit <[email protected]> --------- Signed-off-by: Till Schneidereit <[email protected]>
1 parent f5d9a37 commit 644e97b

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

mozjs-sys/Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository.workspace = true
5-
version = "0.140.0-4"
5+
version = "0.140.0-5"
66
authors = ["Mozilla", "The Servo Project Developers"]
77
links = "mozjs"
88
license.workspace = true
@@ -26,6 +26,7 @@ profilemozjs = []
2626
jitspew = []
2727
libz-sys = ["dep:libz-sys"]
2828
libz-rs = ["dep:libz-rs-sys"]
29+
intl = ["dep:icu_capi"]
2930
crown = []
3031
oom_with_hook = []
3132

@@ -35,7 +36,7 @@ encoding_c = "0.9.8"
3536
encoding_c_mem = "0.2.6"
3637
# unicode-bidi-ffi = { path = "./mozjs/intl/bidi/rust/unicode-bidi-ffi" }
3738
# keep in sync with intl/icu_capi/Cargo.toml
38-
icu_capi = { version = "=1.5.0", default-features = false, features = ["compiled_data", "icu_calendar", "icu_properties", "icu_segmenter"] }
39+
icu_capi = { version = "=1.5.0", default-features = false, features = ["compiled_data", "icu_calendar", "icu_properties", "icu_segmenter"], optional = true }
3940

4041
libz-rs-sys = { version = "0.5.1", features = ["export-symbols"], optional = true }
4142
# SM depends on them and we provide them using cargo

mozjs-sys/build.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,13 @@ fn build_spidermonkey(build_dir: &Path) {
224224
cmd.env("MAKEFLAGS", makeflags);
225225
}
226226

227-
let icu_c_include_path = get_icu_capi_include_path();
228227
let mut cxxflags = vec![];
229-
cxxflags.push(format!("-I{}", &icu_c_include_path.replace("\\", "/")));
228+
229+
#[cfg(feature = "intl")]
230+
{
231+
let icu_c_include_path = get_icu_capi_include_path();
232+
cxxflags.push(format!("-I{}", &icu_c_include_path.replace("\\", "/")));
233+
}
230234

231235
if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
232236
cxxflags.push(String::from("-stdlib=libc++"));
@@ -460,6 +464,9 @@ fn should_build_from_source() -> bool {
460464
} else if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() {
461465
println!("debug-mozjs feature is enabled. Building from source directly.");
462466
true
467+
} else if env::var_os("CARGO_FEATURE_INTL").is_none() {
468+
println!("intl feature is disabled. Building from source directly.");
469+
true
463470
} else {
464471
false
465472
}

mozjs-sys/makefile.cargo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ ifneq (,$(CARGO_FEATURE_JITSPEW))
1515
CONFIGURE_FLAGS += --enable-jitspew
1616
endif
1717

18+
ifeq (,$(CARGO_FEATURE_INTL))
19+
CONFIGURE_FLAGS += --without-intl-api
20+
endif
21+
1822
ifneq (,$(CARGO_FEATURE_DEBUGMOZJS))
1923
CONFIGURE_FLAGS += --enable-debug --disable-optimize --enable-gczeal
2024
endif

mozjs-sys/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
// These extern crates are needed for linking
1111
extern crate encoding_c;
1212
extern crate encoding_c_mem;
13+
#[cfg(feature = "intl")]
1314
extern crate icu_capi;
1415
#[cfg(feature = "libz-rs")]
1516
extern crate libz_rs_sys;

mozjs/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ edition.workspace = true
1111
doctest = false
1212

1313
[features]
14-
default = ["libz-sys"]
14+
default = ["libz-sys", "intl"]
1515
debugmozjs = ["mozjs_sys/debugmozjs"]
1616
profilemozjs = ["mozjs_sys/profilemozjs"]
1717
jitspew = ["mozjs_sys/jitspew"]
1818
libz-sys = ["mozjs_sys/libz-sys"]
1919
libz-rs = ["mozjs_sys/libz-rs"]
20+
intl = ["mozjs_sys/intl"]
2021
crown = ["mozjs_sys/crown"]
2122

2223

0 commit comments

Comments
 (0)