Skip to content

Commit c47f790

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 b14aebf commit c47f790

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-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.128.13-1"
5+
version = "0.128.13-2"
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.4.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: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,28 @@ 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+
// Include path for icu_capi 1.4:
140+
let c_include_path = icu_cpath.parent().expect("manifest dir?").join("c/include");
141+
assert!(
142+
c_include_path.exists(),
143+
"ICU_C C include path {c_include_path} does not exist"
144+
);
145+
c_include_path.to_string()
146+
}
147+
126148
fn build_spidermonkey(build_dir: &Path) {
127149
let target = env::var("TARGET").unwrap();
128150
let make;
@@ -188,15 +210,19 @@ fn build_spidermonkey(build_dir: &Path) {
188210
cmd.env("MAKEFLAGS", makeflags);
189211
}
190212

213+
let icu_c_include_path = get_icu_capi_include_path();
214+
let mut cxxflags = vec![];
215+
cxxflags.push(format!("-I{}", &icu_c_include_path));
216+
191217
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);
218+
cxxflags.push(String::from("-stdlib=libc++"));
198219
}
199220

221+
let base_cxxflags = env::var("CXXFLAGS").unwrap_or_default();
222+
let mut cxxflags = cxxflags.join(" ");
223+
cxxflags.push_str(&base_cxxflags);
224+
cmd.env("CXXFLAGS", cxxflags);
225+
200226
let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
201227
let result = cmd
202228
.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)