Skip to content

Commit 272712a

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 518ee8d commit 272712a

File tree

7 files changed

+92
-24
lines changed

7 files changed

+92
-24
lines changed

mozjs-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
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-0"
5+
version = "0.140.0-1"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
license.workspace = true
@@ -44,3 +44,4 @@ cc.workspace = true
4444
walkdir = "2"
4545
flate2 = "1"
4646
tar = "0.4"
47+
cargo_metadata = "0.20.0"

mozjs-sys/build.rs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,29 @@ 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
139+
.parent()
140+
.expect("manifest dir?")
141+
.join("bindings/c");
142+
assert!(
143+
c_include_path.exists(),
144+
"ICU_C C include path {c_include_path} does not exist"
145+
);
146+
c_include_path.to_string()
147+
}
148+
126149
fn build_spidermonkey(build_dir: &Path) {
127150
let target = env::var("TARGET").unwrap();
128151
let make;
@@ -188,15 +211,19 @@ fn build_spidermonkey(build_dir: &Path) {
188211
cmd.env("MAKEFLAGS", makeflags);
189212
}
190213

214+
let icu_c_include_path = get_icu_capi_include_path();
215+
let mut cxxflags = vec![];
216+
cxxflags.push(format!("-I{}", &icu_c_include_path));
217+
191218
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);
219+
cxxflags.push(String::from("-stdlib=libc++"));
198220
}
199221

222+
let base_cxxflags = env::var("CXXFLAGS").unwrap_or_default();
223+
let mut cxxflags = cxxflags.join(" ");
224+
cxxflags.push_str(&base_cxxflags);
225+
cmd.env("CXXFLAGS", cxxflags);
226+
200227
let cargo_manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
201228
let result = cmd
202229
.args(&["-R", "-f"])
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
diff --git a/mozjs/intl/components/src/calendar/moz.build b/mozjs/intl/components/src/calendar/moz.build
2+
--- a/mozjs/intl/components/src/calendar/moz.build (revision 518ee8df6f7dcc85bbe184d562cea69c505fc7cc)
3+
+++ b/mozjs/intl/components/src/calendar/moz.build (revision 127481d772791381e4a11122d5866adabe305dfb)
4+
@@ -16,10 +16,6 @@
5+
"MonthCode.h",
6+
]
7+
8+
-LOCAL_INCLUDES += [
9+
- "/intl/icu_capi/bindings/c",
10+
-]
11+
-
12+
UNIFIED_SOURCES += [
13+
"ICU4XCalendar.cpp",
14+
"ICU4XChineseBasedCalendar.cpp",
15+
diff --git a/mozjs/intl/components/moz.build b/mozjs/intl/components/moz.build
16+
--- a/mozjs/intl/components/moz.build (revision 518ee8df6f7dcc85bbe184d562cea69c505fc7cc)
17+
+++ b/mozjs/intl/components/moz.build (revision 127481d772791381e4a11122d5866adabe305dfb)
18+
@@ -73,10 +73,6 @@
19+
if not CONFIG["JS_STANDALONE"]:
20+
TEST_DIRS += ["gtest"]
21+
22+
-LOCAL_INCLUDES += [
23+
- "/intl/icu_capi/bindings/c",
24+
-]
25+
-
26+
if not CONFIG["MOZ_SYSTEM_ICU"]:
27+
DIRS += ["src/calendar"]
28+
29+
diff --git a/mozjs/js/src/builtin/temporal/moz.build b/mozjs/js/src/builtin/temporal/moz.build
30+
--- a/mozjs/js/src/builtin/temporal/moz.build (revision 518ee8df6f7dcc85bbe184d562cea69c505fc7cc)
31+
+++ b/mozjs/js/src/builtin/temporal/moz.build (revision 127481d772791381e4a11122d5866adabe305dfb)
32+
@@ -12,10 +12,6 @@
33+
include("../../js-config.mozbuild")
34+
include("../../js-cxxflags.mozbuild")
35+
36+
-LOCAL_INCLUDES += [
37+
- "/intl/icu_capi/bindings/c",
38+
-]
39+
-
40+
UNIFIED_SOURCES += [
41+
"Calendar.cpp",
42+
"CalendarFields.cpp",
43+
diff --git a/mozjs/js/src/moz.build b/mozjs/js/src/moz.build
44+
--- a/mozjs/js/src/moz.build (revision 518ee8df6f7dcc85bbe184d562cea69c505fc7cc)
45+
+++ b/mozjs/js/src/moz.build (revision 127481d772791381e4a11122d5866adabe305dfb)
46+
@@ -512,11 +512,6 @@
47+
"threading/posix/PosixThread.cpp",
48+
]
49+
50+
-if CONFIG["JS_HAS_INTL_API"]:
51+
- LOCAL_INCLUDES += [
52+
- "/intl/icu_capi/bindings/c",
53+
- ]
54+
-
55+
if CONFIG["JS_HAS_CTYPES"]:
56+
SOURCES += [
57+
"ctypes/CTypes.cpp",

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

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

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

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

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

Lines changed: 0 additions & 4 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: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)