From dbdd39b9e76c453c22a89d1eb7848282a4e4ad52 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:28:54 +0100 Subject: [PATCH 1/3] Generate and test debugmozjs artifacts Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- .github/workflows/build.yml | 46 ++++++++++++++--------------- .github/workflows/release-check.yml | 9 +++--- mozjs-sys/Cargo.toml | 2 +- mozjs-sys/build.rs | 22 +++++++++----- 4 files changed, 43 insertions(+), 36 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f1f6192f9..022bedfe16 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,7 +19,7 @@ jobs: strategy: fail-fast: false matrix: - features: ["debugmozjs", '""'] + features: ["debugmozjs", ""] platform: - { target: aarch64-apple-darwin, os: macos-14 } - { target: x86_64-apple-darwin, os: macos-13 } @@ -40,21 +40,20 @@ jobs: uses: mozilla-actions/sccache-action@v0.0.4 - name: Build run: | - cargo build --verbose --features ${{ matrix.features }} - cargo test --tests --examples --verbose --features ${{ matrix.features }} + cargo build --verbose --features "${{ matrix.features }}" + cargo test --tests --examples --verbose --features "${{ matrix.features }}" - name: Generate artifact attestation uses: actions/attest-build-provenance@v1 - if: ${{ inputs.release && matrix.features != 'debugmozjs' }} + if: ${{ inputs.release }} with: - subject-path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz + subject-path: ./target/libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz - name: Upload artifact - if: ${{ matrix.features != 'debugmozjs' }} uses: actions/upload-artifact@v4 with: - path: ./target/libmozjs-${{ matrix.platform.target }}.tar.gz - name: libmozjs-${{ matrix.platform.target }}.tar.gz + path: ./target/libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz + name: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz linux: env: @@ -65,7 +64,7 @@ jobs: strategy: fail-fast: false matrix: - features: ["debugmozjs", '""'] + features: ["debugmozjs", ""] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -76,8 +75,8 @@ jobs: uses: mozilla-actions/sccache-action@v0.0.4 - name: Build run: | - cargo build --verbose --features ${{ matrix.features }} - cargo test --tests --examples --verbose --features ${{ matrix.features }} + cargo build --verbose --features "${{ matrix.features }}" + cargo test --tests --examples --verbose --features "${{ matrix.features }}" - name: Check wrappers integrity # we generate wrappers only without debugmozjs if: ${{ matrix.features != 'debugmozjs' }} @@ -87,23 +86,22 @@ jobs: - name: Generate artifact attestation uses: actions/attest-build-provenance@v1 - if: ${{ inputs.release && matrix.features != 'debugmozjs' }} + if: ${{ inputs.release }} with: - subject-path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz + subject-path: ./target/libmozjs-x86_64-unknown-linux-gnu${{ matrix.features && '-debugmozjs' || '' }}.tar.gz - name: Upload artifact - if: ${{ matrix.features != 'debugmozjs' }} uses: actions/upload-artifact@v4 with: - path: ./target/libmozjs-x86_64-unknown-linux-gnu.tar.gz - name: libmozjs-x86_64-unknown-linux-gnu.tar.gz + path: ./target/libmozjs-x86_64-unknown-linux-gnu${{ matrix.features && '-debugmozjs' || '' }}.tar.gz + name: libmozjs-x86_64-unknown-linux-gnu${{ matrix.features && '-debugmozjs' || '' }}.tar.gz windows: runs-on: windows-latest strategy: fail-fast: false matrix: - features: ["debugmozjs", '""'] + features: ["debugmozjs", ""] target: ["x86_64-pc-windows-msvc", "aarch64-pc-windows-msvc"] env: LINKER: "lld-link.exe" @@ -126,25 +124,25 @@ jobs: - name: Build Windows shell: cmd run: | - cargo build --verbose --target ${{ matrix.target }} --features ${{ matrix.features }} + cargo build --verbose --target ${{ matrix.target }} --features "${{ matrix.features }}" - name: Test Windows if: ${{ !contains(matrix.target, 'aarch64') }} shell: cmd run: | - cargo test --tests --examples --verbose --target ${{ matrix.target }} --features ${{ matrix.features }} + cargo test --tests --examples --verbose --target ${{ matrix.target }} --features "${{ matrix.features }}" - name: Generate artifact attestation uses: actions/attest-build-provenance@v1 - if: ${{ inputs.release && !contains(matrix.target, 'aarch64') && matrix.features != 'debugmozjs' }} + if: ${{ inputs.release && !contains(matrix.target, 'aarch64') }} with: - subject-path: ./target/${{ matrix.target }}/libmozjs-x86_64-pc-windows-msvc.tar.gz + subject-path: ./target/${{ matrix.target }}/libmozjs-${{ matrix.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz - name: Upload artifact - if: ${{ !contains(matrix.target, 'aarch64') && matrix.features != 'debugmozjs' }} + if: ${{ !contains(matrix.target, 'aarch64') }} uses: actions/upload-artifact@v4 with: - path: ./target/${{ matrix.target }}/libmozjs-x86_64-pc-windows-msvc.tar.gz - name: libmozjs-x86_64-pc-windows-msvc.tar.gz + path: ./target/${{ matrix.target }}/libmozjs-${{ matrix.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz + name: libmozjs-${{ matrix.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz android: runs-on: ubuntu-latest diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index 4a14683419..52e1ed279a 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -19,6 +19,7 @@ jobs: strategy: fail-fast: false matrix: + features: ["debugmozjs", ""] platform: - { target: aarch64-apple-darwin, os: macos-14 } - { target: x86_64-apple-darwin, os: macos-13 } @@ -39,15 +40,15 @@ jobs: env: MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}.tar.gz run: | - cargo build --verbose - cargo test --tests --examples --verbose + cargo build --verbose --features "${{ matrix.features }}" + cargo test --tests --examples --verbose --features "${{ matrix.features }}" - name: Build from auto-download if: ${{ env.RELEASE_TAG != '' }} env: MOZJS_ATTESTATION: strict run: | - cargo build --verbose - cargo test --tests --examples --verbose + cargo build --verbose --features "${{ matrix.features }}" + cargo test --tests --examples --verbose --features "${{ matrix.features }}" verify-archive-ohos: name: "Verify archive OpenHarmony" diff --git a/mozjs-sys/Cargo.toml b/mozjs-sys/Cargo.toml index 43a40af04f..8f615d5263 100644 --- a/mozjs-sys/Cargo.toml +++ b/mozjs-sys/Cargo.toml @@ -2,7 +2,7 @@ name = "mozjs_sys" description = "System crate for the Mozilla SpiderMonkey JavaScript engine." repository.workspace = true -version = "0.128.3-9" +version = "0.128.3-10" authors = ["Mozilla"] links = "mozjs" build = "build.rs" diff --git a/mozjs-sys/build.rs b/mozjs-sys/build.rs index b8abb0555a..0c8ea16dbf 100644 --- a/mozjs-sys/build.rs +++ b/mozjs-sys/build.rs @@ -131,9 +131,6 @@ fn should_build_from_source() -> bool { true } else if env::var_os("MOZJS_ARCHIVE").is_some() { false - } else if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() { - println!("debug-mozjs feature is enabled. Building from source directly."); - true } else { false } @@ -863,7 +860,7 @@ fn get_cargo_target_dir(build_dir: &Path) -> Option<&Path> { fn compress_static_lib(build_dir: &Path) -> Result<(), std::io::Error> { let target = env::var("TARGET").unwrap(); let target_dir = get_cargo_target_dir(build_dir).unwrap().display(); - let tar_gz = File::create(format!("{}/libmozjs-{}.tar.gz", target_dir, target))?; + let tar_gz = File::create(format!("{}/{}", target_dir, archive()))?; let enc = GzEncoder::new(tar_gz, Compression::default()); let mut tar = tar::Builder::new(enc); @@ -1046,13 +1043,23 @@ fn attest_artifact(kind: AttestationType, archive_path: &Path) -> Result<(), std Ok(()) } +/// Returns name of libmozjs archive +fn archive() -> String { + let target = env::var("TARGET").unwrap(); + let features = if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_some() { + "-debugmozjs" + } else { + "" + }; + format!("libmozjs-{target}{features}.tar.gz") +} + /// Download the SpiderMonkey archive with cURL using the provided base URL. If it's None, /// it will use `servo/mozjs`'s release page as the base URL. fn download_archive(base: Option<&str>) -> Result { let base = base.unwrap_or("https://github.com/servo/mozjs/releases"); let version = env::var("CARGO_PKG_VERSION").unwrap(); - let target = env::var("TARGET").unwrap(); - let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("libmozjs.tar.gz"); + let archive_path = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join(&archive()); if !archive_path.exists() { eprintln!("Trying to download prebuilt mozjs static library from Github Releases"); let curl_start = Instant::now(); @@ -1063,7 +1070,8 @@ fn download_archive(base: Option<&str>) -> Result { .arg("-o") .arg(&archive_path) .arg(format!( - "{base}/download/mozjs-sys-v{version}/libmozjs-{target}.tar.gz" + "{base}/download/mozjs-sys-v{version}/{}", + archive() )) .status()? .success() From 8043910610d721f2971316b53d84c8ed93ee40b5 Mon Sep 17 00:00:00 2001 From: sagudev <16504129+sagudev@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:36:32 +0100 Subject: [PATCH 2/3] Do not strip artifacts when DEBUGMOZJS Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- mozjs-sys/build.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/mozjs-sys/build.rs b/mozjs-sys/build.rs index 0c8ea16dbf..2676f6a59a 100644 --- a/mozjs-sys/build.rs +++ b/mozjs-sys/build.rs @@ -888,19 +888,21 @@ fn compress_static_lib(build_dir: &Path) -> Result<(), std::io::Error> { &mut File::open(build_dir.join("gluebindings.rs")).unwrap(), )?; } else { - let strip_bin = get_cc_rs_env_os("STRIP").unwrap_or_else(|| "strip".into()); - // Strip symbols from the static binary since it could bump up to 1.6GB on Linux. - // TODO: Maybe we could separate symbols for thos who still want the debug ability. - // https://github.com/GabrielMajeri/separate-symbols - let mut strip = Command::new(strip_bin); - if !target.contains("apple") { - strip.arg("--strip-debug"); - }; - let status = strip - .arg(build_dir.join("js/src/build/libjs_static.a")) - .status() - .unwrap(); - assert!(status.success()); + if env::var_os("CARGO_FEATURE_DEBUGMOZJS").is_none() { + let strip_bin = get_cc_rs_env_os("STRIP").unwrap_or_else(|| "strip".into()); + // Strip symbols from the static binary since it could bump up to 1.6GB on Linux. + // TODO: Maybe we could separate symbols for thos who still want the debug ability. + // https://github.com/GabrielMajeri/separate-symbols + let mut strip = Command::new(strip_bin); + if !target.contains("apple") { + strip.arg("--strip-debug"); + }; + let status = strip + .arg(build_dir.join("js/src/build/libjs_static.a")) + .status() + .unwrap(); + assert!(status.success()); + } // This is the static library of spidermonkey. tar.append_file( From 809d81cbe3915035337495d2bf78d2c2a3707ea7 Mon Sep 17 00:00:00 2001 From: Samson <16504129+sagudev@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:07:41 +0100 Subject: [PATCH 3/3] Update release-check.yml Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --- .github/workflows/release-check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-check.yml b/.github/workflows/release-check.yml index 52e1ed279a..1c98c68564 100644 --- a/.github/workflows/release-check.yml +++ b/.github/workflows/release-check.yml @@ -34,11 +34,11 @@ jobs: if: ${{ env.RELEASE_TAG == '' }} uses: actions/download-artifact@v4 with: - name: libmozjs-${{ matrix.platform.target }}.tar.gz + name: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz - name: Build from archive if: ${{ env.RELEASE_TAG == '' }} env: - MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}.tar.gz + MOZJS_ARCHIVE: libmozjs-${{ matrix.platform.target }}${{ matrix.features && '-debugmozjs' || '' }}.tar.gz run: | cargo build --verbose --features "${{ matrix.features }}" cargo test --tests --examples --verbose --features "${{ matrix.features }}"