Skip to content

Commit 125b5ab

Browse files
authored
Publish and test debugmozjs artifacts (#544)
With this PR we also generate debugmozjs artifacts (for windows, mac and linux; mobile platforms were skipped). Such artifacts are now loaded by same mechanism as normal ones, so for servo developers it's just matter of switching debugmozjs on and this will now avoid SM compilation. Debugmozjs artifacts are not stripped, as it's users will likely need them for debugging. Switching between features works because `target/build/mozjs_sys-hash`, where hash depends on features (so we get different folder for debugmozjs \o/). Fix #541 --------- Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent 48bf97d commit 125b5ab

File tree

6 files changed

+74
-54
lines changed

6 files changed

+74
-54
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
features: ["debugmozjs", '""']
31+
features: ["debugmozjs", ""]
3232
platform:
3333
- { target: aarch64-apple-darwin, os: macos-14 }
3434
- { target: x86_64-apple-darwin, os: macos-15-intel }
@@ -58,14 +58,14 @@ jobs:
5858
version: "v0.12.0"
5959
- name: Build
6060
run: |
61-
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features ${{ matrix.features }}
62-
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features ${{ matrix.features }}
61+
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features "${{ matrix.features }}"
62+
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features "${{ matrix.features }}"
6363
- name: Upload artifact
64-
if: ${{ matrix.features != 'debugmozjs' && env.NEW_RUST_CHECK == 'false' }}
64+
if: ${{ env.NEW_RUST_CHECK == 'false' }}
6565
uses: actions/upload-artifact@v4
6666
with:
67-
path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz
68-
name: libmozjs-${{ matrix.platform.target }}.tar.gz
67+
path: ./target/libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
68+
name: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
6969

7070
linux:
7171
env:
@@ -76,9 +76,15 @@ jobs:
7676
strategy:
7777
fail-fast: false
7878
matrix:
79-
features: ["debugmozjs", '""']
79+
features: ["debugmozjs", ""]
8080
steps:
8181
- uses: actions/checkout@v4
82+
- name: Free Disk Space (Ubuntu)
83+
uses: jlumbroso/free-disk-space@main
84+
with:
85+
tool-cache: false
86+
large-packages: false
87+
swap-storage: false
8288
- uses: dtolnay/rust-toolchain@master
8389
id: toolchain
8490
with:
@@ -93,9 +99,9 @@ jobs:
9399
- name: Build
94100
# doc tests on mozjs_sys fail because they include stuff from SpiderMonkey
95101
run: |
96-
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features ${{ matrix.features }}
97-
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features ${{ matrix.features }}
98-
cargo +${{ steps.toolchain.outputs.name }} test --doc -p mozjs --verbose --features ${{ matrix.features }}
102+
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features "${{ matrix.features }}"
103+
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features "${{ matrix.features }}"
104+
cargo +${{ steps.toolchain.outputs.name }} test --doc -p mozjs --verbose --features "${{ matrix.features }}"
99105
- name: Check wrappers integrity
100106
# we generate wrappers only without debugmozjs
101107
if: ${{ matrix.features != 'debugmozjs' }}
@@ -106,18 +112,18 @@ jobs:
106112
git diff --staged --no-ext-diff --exit-code
107113
108114
- name: Upload artifact
109-
if: ${{ matrix.features != 'debugmozjs' && env.NEW_RUST_CHECK == 'false' }}
115+
if: ${{ env.NEW_RUST_CHECK == 'false' }}
110116
uses: actions/upload-artifact@v4
111117
with:
112-
path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz
113-
name: libmozjs-x86_64-unknown-linux-gnu.tar.gz
118+
path: ./target/libmozjs-x86_64-unknown-linux-gnu${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
119+
name: libmozjs-x86_64-unknown-linux-gnu${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
114120

115121
windows:
116122
runs-on: ${{ matrix.platform.os }}
117123
strategy:
118124
fail-fast: false
119125
matrix:
120-
features: ["debugmozjs", '""']
126+
features: ["debugmozjs", ""]
121127
platform:
122128
- { target: x86_64-pc-windows-msvc, os: windows-latest }
123129
- { target: aarch64-pc-windows-msvc, os: windows-11-arm }
@@ -134,7 +140,7 @@ jobs:
134140
id: toolchain
135141
with:
136142
toolchain: ${{ inputs.rust_version }}
137-
targets: ${{ matrix.target }}
143+
targets: ${{ matrix.platform.target }}
138144
components: "rustfmt"
139145
- name: Install deps
140146
run: |
@@ -145,18 +151,18 @@ jobs:
145151
- name: Build Windows
146152
shell: cmd
147153
run: |
148-
cargo +${{ steps.toolchain.outputs.name }} build --verbose --target ${{ matrix.platform.target }} --features ${{ matrix.features }}
154+
cargo +${{ steps.toolchain.outputs.name }} build --verbose --target ${{ matrix.platform.target }} --features "${{ matrix.features }}"
149155
- name: Test Windows
150156
shell: cmd
151157
run: |
152-
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --target ${{ matrix.platform.target }} --features ${{ matrix.features }}
158+
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --target ${{ matrix.platform.target }} --features "${{ matrix.features }}"
153159
154160
- name: Upload artifact
155-
if: ${{ matrix.features != 'debugmozjs' && env.NEW_RUST_CHECK == 'false' }}
161+
if: ${{ env.NEW_RUST_CHECK == 'false' }}
156162
uses: actions/upload-artifact@v4
157163
with:
158-
path: ./target/${{ matrix.platform.target }}/libmozjs-${{ matrix.platform.target }}.tar.gz
159-
name: libmozjs-${{ matrix.platform.target }}.tar.gz
164+
path: ./target/${{ matrix.platform.target }}/libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
165+
name: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
160166

161167
android:
162168
runs-on: ubuntu-latest
@@ -201,7 +207,7 @@ jobs:
201207
strategy:
202208
matrix:
203209
target: ["aarch64-unknown-linux-ohos", "x86_64-unknown-linux-ohos"]
204-
features: [ "", "--features debugmozjs"]
210+
features: ["", "--features debugmozjs"]
205211
steps:
206212
- uses: actions/checkout@v4
207213
- name: Setup OpenHarmony SDK
@@ -372,7 +378,7 @@ jobs:
372378
if: ${{ inputs.verify_artifacts && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
373379
uses: ./.github/workflows/release-check.yml
374380
with:
375-
release-tag: ''
381+
release-tag: ""
376382
rust_version: ${{ inputs.rust_version }}
377383

378384
build_result:

.github/workflows/publish.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
publish-github-release:
2121
name: Check version and publish release
2222
runs-on: ubuntu-latest
23-
needs: [ "build" ]
23+
needs: ["build"]
2424
permissions:
2525
contents: write
2626
id-token: write
@@ -43,6 +43,7 @@ jobs:
4343
RELEASE_TAG=mozjs-sys-v$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "mozjs_sys") | .version')
4444
git fetch --tags --quiet
4545
if ! git show-ref --tags --verify --quiet "refs/tags/${RELEASE_TAG}" ; then
46+
echo "Making release ${RELEASE_TAG}"
4647
gh release create ${RELEASE_TAG} ./*.tar.gz
4748
fi
4849
echo "RELEASE_TAG=${RELEASE_TAG}" >> ${GITHUB_OUTPUT}
@@ -85,4 +86,4 @@ jobs:
8586
rm -f err.log
8687
cargo publish -p mozjs --no-verify 2> err.log || grep "already exists on crates.io" err.log || ( cat err.log ; exit 1)
8788
env:
88-
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
89+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}

.github/workflows/release-check.yml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
strategy:
2424
fail-fast: false
2525
matrix:
26+
features: ["debugmozjs", ""]
2627
platform:
2728
- { target: aarch64-apple-darwin, os: macos-14 }
2829
- { target: x86_64-apple-darwin, os: macos-15-intel }
@@ -31,7 +32,7 @@ jobs:
3132
- { target: aarch64-pc-windows-msvc, os: windows-11-arm }
3233
runs-on: ${{ matrix.platform.os }}
3334
env:
34-
RELEASE_TAG: ${{ github.event_name == 'release' && github.ref_name || inputs.release-tag }}
35+
RELEASE_TAG: ${{ github.event_name == 'release' && github.ref_name || inputs.release-tag }}
3536
steps:
3637
- uses: actions/checkout@v4
3738
- name: Install Rust
@@ -44,21 +45,21 @@ jobs:
4445
if: ${{ env.RELEASE_TAG == '' }}
4546
uses: actions/download-artifact@v4
4647
with:
47-
name: libmozjs-${{ matrix.platform.target }}.tar.gz
48+
name: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
4849
- name: Build from archive
4950
if: ${{ env.RELEASE_TAG == '' }}
5051
env:
51-
MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}.tar.gz
52+
MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz
5253
run: |
53-
cargo +${{ steps.toolchain.outputs.name }} build --verbose
54-
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose
54+
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features "${{ matrix.features }}"
55+
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features "${{ matrix.features }}"
5556
- name: Build from auto-download
5657
if: ${{ env.RELEASE_TAG != '' }}
5758
env:
5859
MOZJS_ATTESTATION: strict
5960
run: |
60-
cargo +${{ steps.toolchain.outputs.name }} build --verbose
61-
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose
61+
cargo +${{ steps.toolchain.outputs.name }} build --verbose --features "${{ matrix.features }}"
62+
cargo +${{ steps.toolchain.outputs.name }} test --tests --examples --verbose --features "${{ matrix.features }}"
6263
6364
verify-archive-android:
6465
name: "Verify archive Android"

mozjs-sys/Cargo.toml

Lines changed: 1 addition & 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.5-9"
5+
version = "0.140.5-10"
66
authors = ["Mozilla", "The Servo Project Developers"]
77
links = "mozjs"
88
license.workspace = true

mozjs-sys/build.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -459,9 +459,6 @@ fn should_build_from_source() -> bool {
459459
true
460460
} else if env::var_os("MOZJS_ARCHIVE").is_some() {
461461
false
462-
} else if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() {
463-
println!("debug-mozjs feature is enabled. Building from source directly.");
464-
true
465462
} else if env::var_os("CARGO_FEATURE_INTL").is_none() {
466463
println!("intl feature is disabled. Building from source directly.");
467464
true
@@ -959,7 +956,7 @@ mod archive {
959956
pub(crate) fn compress_static_lib(build_dir: &Path) -> Result<(), std::io::Error> {
960957
let target = env::var("TARGET").unwrap();
961958
let target_dir = get_cargo_target_dir(build_dir).unwrap().display();
962-
let tar_gz = File::create(format!("{}/libmozjs-{}.tar.gz", target_dir, target))?;
959+
let tar_gz = File::create(format!("{}/{}", target_dir, archive()))?;
963960
let enc = GzEncoder::new(tar_gz, Compression::default());
964961
let mut tar = tar::Builder::new(enc);
965962

@@ -989,18 +986,20 @@ mod archive {
989986
&mut File::open(join_path(build_dir, "gluebindings.rs"))?,
990987
)?;
991988
} else {
992-
let strip_bin = get_cc_rs_env_os("STRIP").unwrap_or_else(|| "strip".into());
993-
// Strip symbols from the static binary since it could bump up to 1.6GB on Linux.
994-
// TODO: Maybe we could separate symbols for those who still want the debug ability.
995-
// https://github.com/GabrielMajeri/separate-symbols
996-
let mut strip = Command::new(strip_bin);
997-
if !target.contains("apple") {
998-
strip.arg("--strip-debug");
999-
};
1000-
let status = strip
1001-
.arg(join_path(build_dir, "js/src/build/libjs_static.a"))
1002-
.status()?;
1003-
assert!(status.success());
989+
if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_none() {
990+
let strip_bin = get_cc_rs_env_os("STRIP").unwrap_or_else(|| "strip".into());
991+
// Strip symbols from the static binary since it could bump up to 1.6GB on Linux.
992+
// TODO: Maybe we could separate symbols for those who still want the debug ability.
993+
// https://github.com/GabrielMajeri/separate-symbols
994+
let mut strip = Command::new(strip_bin);
995+
if !target.contains("apple") {
996+
strip.arg("--strip-debug");
997+
};
998+
let status = strip
999+
.arg(join_path(build_dir, "js/src/build/libjs_static.a"))
1000+
.status()?;
1001+
assert!(status.success());
1002+
}
10041003

10051004
// This is the static library of spidermonkey.
10061005
tar.append_file(
@@ -1031,6 +1030,17 @@ mod archive {
10311030
Ok(())
10321031
}
10331032

1033+
/// Returns name of libmozjs archive
1034+
pub(crate) fn archive() -> String {
1035+
let target = env::var("TARGET").unwrap();
1036+
let features = if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() {
1037+
"-debugmozjs"
1038+
} else {
1039+
""
1040+
};
1041+
format!("libmozjs-{target}{features}.tar.gz")
1042+
}
1043+
10341044
/// Decompress the archive of spidermonkey build to build directory.
10351045
pub(crate) fn decompress_static_lib(
10361046
archive: &Path,
@@ -1154,8 +1164,7 @@ mod archive {
11541164
pub(crate) fn download_archive(base: Option<&str>) -> Result<PathBuf, std::io::Error> {
11551165
let base = base.unwrap_or("https://github.com/servo/mozjs/releases");
11561166
let version = env::var("CARGO_PKG_VERSION").unwrap();
1157-
let target = env::var("TARGET").unwrap();
1158-
let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("libmozjs.tar.gz");
1167+
let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join(&archive());
11591168

11601169
if !archive_path.exists() {
11611170
eprintln!("Trying to download prebuilt mozjs static library from Github Releases");
@@ -1167,7 +1176,8 @@ mod archive {
11671176
.arg("-o")
11681177
.arg(&archive_path)
11691178
.arg(format!(
1170-
"{base}/download/mozjs-sys-v{version}/libmozjs-{target}.tar.gz"
1179+
"{base}/download/mozjs-sys-v{version}/{}",
1180+
archive()
11711181
))
11721182
.status()?
11731183
.success()

mozjs/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs"
33
description = "Rust bindings to the Mozilla SpiderMonkey JavaScript engine."
44
repository.workspace = true
5-
version = "0.14.7"
5+
version = "0.14.8"
66
authors = ["The Servo Project Developers"]
77
license.workspace = true
88
edition.workspace = true
@@ -26,11 +26,13 @@ crown = ["mozjs_sys/crown"]
2626
encoding_rs = "0.8.35"
2727
libc.workspace = true
2828
log = "0.4"
29-
mozjs_sys = { version = "=0.140.5-9", path = "../mozjs-sys" }
29+
mozjs_sys = { version = "=0.140.5-10", path = "../mozjs-sys" }
3030
num-traits = "0.2"
3131

3232
[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
33-
criterion = { version = "0.6", default-features = false, features = ["html_reports"] }
33+
criterion = { version = "0.6", default-features = false, features = [
34+
"html_reports",
35+
] }
3436

3537
[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
3638
criterion = "0.6"

0 commit comments

Comments
 (0)