Skip to content

Commit 6a966a7

Browse files
authored
Add Cargo Feature for zlib-rs (#619)
* Switched to Using zlib-rs Signed-off-by: Redfire <[email protected]> * Added Cargo Feature for zlib-rs Signed-off-by: Redfire <[email protected]> * Updated Patches for zlib-rs Signed-off-by: Redfire <[email protected]> --------- Signed-off-by: Redfire <[email protected]>
1 parent af903e0 commit 6a966a7

File tree

14 files changed

+2601
-48
lines changed

14 files changed

+2601
-48
lines changed

mozjs-sys/Cargo.toml

Lines changed: 7 additions & 3 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-1"
5+
version = "0.140.0-2"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
license.workspace = true
@@ -25,19 +25,23 @@ doctest = false
2525
debugmozjs = []
2626
profilemozjs = []
2727
jitspew = []
28+
libz-sys = ["dep:libz-sys"]
29+
libz-rs = ["dep:libz-rs-sys"]
2830
crown = []
2931
oom_with_hook = []
3032

3133
[dependencies]
3234
libc.workspace = true
33-
# SM depends on them and we provide them using cargo
34-
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" }
3838
# keep in sync with intl/icu_capi/Cargo.toml
3939
icu_capi = { version = "=1.5.0", default-features = false, features = ["compiled_data", "icu_calendar", "icu_properties", "icu_segmenter"] }
4040

41+
libz-rs-sys = { version = "0.5.1", features = ["export-symbols"], optional = true }
42+
# SM depends on them and we provide them using cargo
43+
libz-sys = { version = "1.1.19", default-features = false, features = ["libc", "stock-zlib"], optional = true }
44+
4145
[build-dependencies]
4246
bindgen.workspace = true
4347
cc.workspace = true

mozjs-sys/build.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,23 +187,32 @@ fn build_spidermonkey(build_dir: &Path) {
187187
encoding_c_mem_include_dir.replace("\\", "/")
188188
));
189189

190-
// add zlib.pc into pkg-config's search path
191-
// this is only needed when libz-sys builds zlib from source
192-
if let Ok(zlib_root_dir) = env::var("DEP_Z_ROOT") {
193-
let mut pkg_config_path = OsString::from(format!(
194-
"{}/lib/pkgconfig",
195-
zlib_root_dir.replace("\\", "/")
196-
));
197-
if let Some(env_pkg_config_path) = get_cc_rs_env_os("PKG_CONFIG_PATH") {
198-
pkg_config_path.push(":");
199-
pkg_config_path.push(env_pkg_config_path);
190+
if cfg!(all(feature = "libz-rs", feature = "libz-sys")) {
191+
panic!("Cannot enable both 'libz-rs' and 'libz-sys' features at the same time. Choose only one.");
192+
} else if cfg!(not(any(feature = "libz-rs", feature = "libz-sys"))) {
193+
panic!("Must enable one of the 'libz-rs' or 'libz-sys' features.");
194+
}
195+
196+
if cfg!(feature = "libz-sys") {
197+
// add zlib.pc into pkg-config's search path
198+
// this is only needed when libz-sys builds zlib from source
199+
if let Ok(zlib_root_dir) = env::var("DEP_Z_ROOT") {
200+
let mut pkg_config_path = OsString::from(format!(
201+
"{}/lib/pkgconfig",
202+
zlib_root_dir.replace("\\", "/")
203+
));
204+
if let Some(env_pkg_config_path) = get_cc_rs_env_os("PKG_CONFIG_PATH") {
205+
pkg_config_path.push(":");
206+
pkg_config_path.push(env_pkg_config_path);
207+
}
208+
cmd.env("PKG_CONFIG_PATH", pkg_config_path);
200209
}
201-
cmd.env("PKG_CONFIG_PATH", pkg_config_path);
202-
}
203210

204-
if let Ok(include) = env::var("DEP_Z_INCLUDE") {
205-
write!(cppflags, "-I{} ", include.replace("\\", "/")).unwrap();
211+
if let Ok(include) = env::var("DEP_Z_INCLUDE") {
212+
write!(cppflags, "-I{} ", include.replace("\\", "/")).unwrap();
213+
}
206214
}
215+
207216
cppflags.push(get_cc_rs_env_os("CPPFLAGS").unwrap_or_default());
208217
cmd.env("CPPFLAGS", cppflags);
209218

mozjs-sys/etc/filters.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,12 @@
3434
- /testing/mozbase/rust
3535
- /third_party/rust
3636
- /Cargo.toml
37-
- /modules/zlib
37+
38+
# Keep zlib headers for libz-rs-sys
39+
+ modules/zlib/src/
40+
+ modules/zlib/src/zlib.h
41+
+ modules/zlib/src/zconf.h
42+
- modules/zlib/**
3843

3944
# Remove unused python dependency that also causes problems with case-sensitive filesystems.
4045
- /third_party/python/Jinja2

mozjs-sys/etc/get_latest_mozjs.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
REPO=mozilla-release
44

5-
# get commit and appropriet mozjs tar
5+
# get commit and appropriate mozjs tar
66
jobs=( $(curl "https://treeherder.mozilla.org/api/project/$REPO/push/?full=true&count=20" | jq '.results[].id') )
77
for i in "${jobs[@]}"
88
do

mozjs-sys/etc/get_taskcluster_mozjs.sh

100644100755
File mode changed.
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
diff --git a/config/external/zlib/moz.build b/config/external/zlib/moz.build
2-
index 755400fa7..d1311b9a7 100644
2+
index c2b9847e6..99bd2b121 100644
33
--- a/config/external/zlib/moz.build
44
+++ b/config/external/zlib/moz.build
5-
@@ -6,9 +6,4 @@
5+
@@ -8,7 +8,8 @@ Library("zlib")
66

7-
Library("zlib")
8-
9-
-if CONFIG["MOZ_SYSTEM_ZLIB"]:
10-
- OS_LIBS += CONFIG["MOZ_ZLIB_LIBS"]
11-
-else:
7+
if CONFIG["MOZ_SYSTEM_ZLIB"]:
8+
OS_LIBS += CONFIG["MOZ_ZLIB_LIBS"]
9+
else:
1210
- DIRS += [
1311
- "../../../modules/zlib",
1412
- ]
15-
+OS_LIBS += CONFIG["MOZ_ZLIB_LIBS"]
13+
+ EXPORTS += [
14+
+ "../../../modules/zlib/src/zconf.h",
15+
+ "../../../modules/zlib/src/zlib.h",
16+
+ ]
1617
diff --git a/moz.configure b/moz.configure
17-
index 804b9a375..87ccc508d 100755
18+
index dd419e1cc..8d618342c 100755
1819
--- a/moz.configure
1920
+++ b/moz.configure
20-
@@ -891,50 +891,8 @@ check_prog(
21+
@@ -890,51 +890,23 @@ check_prog(
2122
validate=validate_strip,
2223
)
2324

24-
+pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when=use_pkg_config)
25-
25+
-
2626
-@depends(js_standalone, target)
2727
-def system_zlib_default(js_standalone, target):
2828
- return (
@@ -32,20 +32,29 @@ index 804b9a375..87ccc508d 100755
3232
- )
3333
-
3434
-
35-
-option(
35+
option(
3636
- "--with-system-zlib",
3737
- nargs="?",
3838
- default=system_zlib_default,
3939
- help="{Use|Do not use} system libz",
4040
- when=use_pkg_config,
41-
-)
42-
-
43-
-
41+
+ "--enable-libz-rs",
42+
+ help="Use libz-rs instead of system libz",
43+
)
44+
45+
+@depends("--enable-libz-rs")
46+
+def use_libz_rs(enabled):
47+
+ return enabled
48+
4449
-@depends("--with-system-zlib", when=use_pkg_config)
4550
-def with_system_zlib_option(with_system_zlib):
4651
- return with_system_zlib
47-
-
48-
-
52+
+@depends(use_libz_rs)
53+
+def use_system_zlib(libz_rs):
54+
+ return not libz_rs
55+
56+
+pkg_check_modules("MOZ_ZLIB", "zlib >= 1.2.3", when=use_system_zlib)
57+
4958
-@depends(with_system_zlib_option)
5059
-def deprecated_system_zlib_path(value):
5160
- if value and len(value) == 1:
@@ -67,7 +76,22 @@ index 804b9a375..87ccc508d 100755
6776
-)
6877
-
6978
-set_config("USE_LIBZ_RS", True, when="USE_LIBZ_RS")
70-
+set_config("MOZ_SYSTEM_ZLIB", True)
79+
+set_config("MOZ_SYSTEM_ZLIB", True, when=use_system_zlib)
80+
+set_config("USE_LIBZ_RS", True, when=use_libz_rs)
7181

7282
with only_when(cross_compiling):
73-
option(
83+
option(
84+
diff --git a/modules/zlib/src/zconf.h b/modules/zlib/src/zconf.h
85+
index c6305ec3d..62adc8d84 100644
86+
--- a/modules/zlib/src/zconf.h
87+
+++ b/modules/zlib/src/zconf.h
88+
@@ -8,9 +8,6 @@
89+
#ifndef ZCONF_H
90+
#define ZCONF_H
91+
92+
-/* This header does prefixing as below, but with an updated set of names. */
93+
-#include "mozzconf.h"
94+
-
95+
/*
96+
* If you *really* need a unique prefix for all types and library functions,
97+
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.

mozjs-sys/makefile.cargo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ ifneq (,$(CARGO_FEATURE_PROFILEMOZJS))
2323
CONFIGURE_FLAGS += --enable-profiling
2424
endif
2525

26+
ifneq (,$(CARGO_FEATURE_LIBZ_RS))
27+
CONFIGURE_FLAGS += --enable-libz-rs
28+
endif
29+
2630
ifneq (,$(CCACHE))
2731
CONFIGURE_FLAGS += --with-ccache=$(CCACHE)
2832
endif

mozjs-sys/mozjs/config/external/zlib/moz.build

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

0 commit comments

Comments
 (0)