Skip to content

Commit cc6ce44

Browse files
committed
Use Cargo provided icu_capi headers
Use the headers provided by cargo, instead of our local checkout. This also revealed that we had been using version 1.5, when we wanted to use 1.4, to be in sync with upstream. Signed-off-by: Jonathan Schwender <[email protected]>
1 parent 6f3dcb9 commit cc6ce44

File tree

4 files changed

+42
-15
lines changed

4 files changed

+42
-15
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.137.0-0"
5+
version = "0.137.0-1"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
license.workspace = true
@@ -35,11 +35,12 @@ libz-sys = "1.1.19"
3535
encoding_c = "0.9.8"
3636
encoding_c_mem = "0.2.6"
3737
# unicode-bidi-ffi = { path = "./mozjs/intl/bidi/rust/unicode-bidi-ffi" }
38-
icu_capi = "1.4.0" # keep in sync with intl/icu_capi/Cargo.toml
38+
icu_capi = "=1.5.0" # keep in sync with intl/icu_capi/Cargo.toml from upstream
3939

4040
[build-dependencies]
4141
bindgen.workspace = true
4242
cc.workspace = true
4343
walkdir = "2"
4444
flate2 = "1"
4545
tar = "0.4"
46+
cargo_metadata = "0.21"

mozjs-sys/build.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ fn main() {
123123
}
124124
}
125125

126+
fn get_icu_capi_include_path() -> String {
127+
// Using cargo metadata is the official recommendation from the icu4x documentation.
128+
// See <https://icu4x.unicode.org/2_0/cppdoc/>. In the future we should try to upstream a
129+
// patch that allows us to use DEP_ syntax, like we do with libz.
130+
let metadata = cargo_metadata::MetadataCommand::new().exec().unwrap();
131+
let packages = metadata.packages;
132+
let icu_capi_info = packages
133+
.iter()
134+
.find(|pkg| pkg.name.contains("icu_capi"))
135+
.expect("icu_capi not found");
136+
let icu_cpath = &icu_capi_info.manifest_path;
137+
// Include path for icu_capi 1.5:
138+
let c_include_path = icu_cpath.parent().expect("manifest dir?").join("bindings/c");
139+
assert!(
140+
c_include_path.exists(),
141+
"ICU_C C include path {c_include_path} does not exist"
142+
);
143+
c_include_path.to_string()
144+
}
145+
126146
fn build_spidermonkey(build_dir: &Path) {
127147
let target = env::var("TARGET").unwrap();
128148
let make;
@@ -188,15 +208,19 @@ fn build_spidermonkey(build_dir: &Path) {
188208
cmd.env("MAKEFLAGS", makeflags);
189209
}
190210

211+
let icu_c_include_path = get_icu_capi_include_path();
212+
let mut cxxflags = vec![];
213+
cxxflags.push(format!("-I{}", &icu_c_include_path));
214+
191215
if target.contains("apple") || target.contains("freebsd") || target.contains("ohos") {
192-
let mut cxxflags = OsString::from("-stdlib=libc++");
193-
if let Some(flags) = env::var_os("CXXFLAGS") {
194-
cxxflags.push(" ");
195-
cxxflags.push(flags);
196-
}
197-
cmd.env("CXXFLAGS", cxxflags);
216+
cxxflags.push(String::from("-stdlib=libc++"));
198217
}
199218

219+
let base_cxxflags = env::var("CXXFLAGS").unwrap_or_default();
220+
let mut cxxflags = cxxflags.join(" ");
221+
cxxflags.push_str(&base_cxxflags);
222+
cmd.env("CXXFLAGS", cxxflags);
223+
200224
let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
201225
let result = cmd
202226
.args(&["-R", "-f"])

mozjs-sys/mozjs/intl/components/moz.build

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mozjs-sys/mozjs/js/src/moz.build

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)