Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish and test debugmozjs artifacts #544

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 22 additions & 24 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -40,21 +40,20 @@ jobs:
uses: mozilla-actions/[email protected]
- 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:
Expand All @@ -65,7 +64,7 @@ jobs:
strategy:
fail-fast: false
matrix:
features: ["debugmozjs", '""']
features: ["debugmozjs", ""]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
Expand All @@ -76,8 +75,8 @@ jobs:
uses: mozilla-actions/[email protected]
- 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' }}
Expand All @@ -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"
Expand All @@ -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
Expand Down
13 changes: 7 additions & 6 deletions .github/workflows/release-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -33,21 +34,21 @@ 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
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"
Expand Down
2 changes: 1 addition & 1 deletion mozjs-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
50 changes: 30 additions & 20 deletions mozjs-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -891,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(
Expand Down Expand Up @@ -1046,13 +1045,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<PathBuf, std::io::Error> {
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());
Comment on lines -1055 to +1064
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should allow on/off debugmozjs.

if !archive_path.exists() {
eprintln!("Trying to download prebuilt mozjs static library from Github Releases");
let curl_start = Instant::now();
Expand All @@ -1063,7 +1072,8 @@ fn download_archive(base: Option<&str>) -> Result<PathBuf, std::io::Error> {
.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()
Expand Down
Loading