From 259e544192999988c2ad7e4264e650c0db0524ce Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 27 Jan 2025 23:25:00 +0000 Subject: [PATCH] Switch musl from a script download to a submodule Rather than keeping a script that downloads the tarball, we can just add musl as a submodule and let git handle the synchronizatoin. Do so here. --- .../libm/.github/workflows/main.yaml | 18 +++++++------- library/compiler-builtins/libm/.gitignore | 1 - library/compiler-builtins/libm/.gitmodules | 4 ++++ .../compiler-builtins/libm/CONTRIBUTING.md | 4 ++++ .../libm/ci/download-musl.sh | 24 ------------------- .../libm/crates/musl-math-sys/build.rs | 14 +++-------- .../libm/crates/musl-math-sys/musl | 1 + 7 files changed, 20 insertions(+), 46 deletions(-) create mode 100644 library/compiler-builtins/libm/.gitmodules delete mode 100755 library/compiler-builtins/libm/ci/download-musl.sh create mode 160000 library/compiler-builtins/libm/crates/musl-math-sys/musl diff --git a/library/compiler-builtins/libm/.github/workflows/main.yaml b/library/compiler-builtins/libm/.github/workflows/main.yaml index 59955271170f..e03d7ecd3191 100644 --- a/library/compiler-builtins/libm/.github/workflows/main.yaml +++ b/library/compiler-builtins/libm/.github/workflows/main.yaml @@ -79,6 +79,8 @@ jobs: - name: Print runner information run: uname -a - uses: actions/checkout@v4 + with: + submodules: true - name: Install Rust (rustup) shell: bash run: | @@ -94,10 +96,6 @@ jobs: with: key: ${{ matrix.target }} - - name: Download musl source - run: ./ci/download-musl.sh - shell: bash - - name: Verify API list if: matrix.os == 'ubuntu-24.04' run: python3 etc/update-api-list.py --check @@ -126,14 +124,14 @@ jobs: timeout-minutes: 10 steps: - uses: actions/checkout@master + with: + submodules: true - name: Install Rust run: | rustup update nightly --no-self-update rustup default nightly rustup component add clippy - uses: Swatinem/rust-cache@v2 - - name: Download musl source - run: ./ci/download-musl.sh - run: cargo clippy --all --all-features --all-targets builtins: @@ -153,6 +151,8 @@ jobs: timeout-minutes: 20 steps: - uses: actions/checkout@master + with: + submodules: true - uses: taiki-e/install-action@cargo-binstall - name: Set up dependencies @@ -166,8 +166,6 @@ jobs: sudo apt-get install valgrind - uses: Swatinem/rust-cache@v2 - - name: Download musl source - run: ./ci/download-musl.sh - name: Run icount benchmarks env: @@ -259,13 +257,13 @@ jobs: CHANGED: ${{ matrix.changed }} steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Install Rust run: | rustup update nightly --no-self-update rustup default nightly - uses: Swatinem/rust-cache@v2 - - name: Download musl source - run: ./ci/download-musl.sh - name: Run extensive tests run: | echo "Changed: '$CHANGED'" diff --git a/library/compiler-builtins/libm/.gitignore b/library/compiler-builtins/libm/.gitignore index a447c34cd0f6..d5caba1a0f33 100644 --- a/library/compiler-builtins/libm/.gitignore +++ b/library/compiler-builtins/libm/.gitignore @@ -4,7 +4,6 @@ /math/src target Cargo.lock -musl/ **.tar.gz # Benchmark cache diff --git a/library/compiler-builtins/libm/.gitmodules b/library/compiler-builtins/libm/.gitmodules new file mode 100644 index 000000000000..35b269eadd4e --- /dev/null +++ b/library/compiler-builtins/libm/.gitmodules @@ -0,0 +1,4 @@ +[submodule "musl"] + path = crates/musl-math-sys/musl + url = https://git.musl-libc.org/git/musl + shallow = true diff --git a/library/compiler-builtins/libm/CONTRIBUTING.md b/library/compiler-builtins/libm/CONTRIBUTING.md index ba7f78ca014c..dc40060357c4 100644 --- a/library/compiler-builtins/libm/CONTRIBUTING.md +++ b/library/compiler-builtins/libm/CONTRIBUTING.md @@ -62,6 +62,10 @@ Check [PR #65] for an example. Normal tests can be executed with: ```sh +# Tests against musl require that the submodule is up to date. +git submodule init +git submodule update + # `--release` ables more test cases cargo test --release ``` diff --git a/library/compiler-builtins/libm/ci/download-musl.sh b/library/compiler-builtins/libm/ci/download-musl.sh deleted file mode 100755 index 8a8c58550bb4..000000000000 --- a/library/compiler-builtins/libm/ci/download-musl.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/sh -# Download the expected version of musl to a directory `musl` - -set -eux - -fname=musl-1.2.5.tar.gz -sha=a9a118bbe84d8764da0ea0d28b3ab3fae8477fc7e4085d90102b8596fc7c75e4 - -mkdir musl -curl -L "https://musl.libc.org/releases/$fname" -O --retry 5 - -case "$(uname -s)" in - MINGW*) - # Need to extract the second line because certutil does human output - fsha=$(certutil -hashfile "$fname" SHA256 | sed -n '2p') - [ "$sha" = "$fsha" ] || exit 1 - ;; - *) - echo "$sha $fname" | shasum -a 256 --check || exit 1 - ;; -esac - -tar -xzf "$fname" -C musl --strip-components 1 -rm "$fname" diff --git a/library/compiler-builtins/libm/crates/musl-math-sys/build.rs b/library/compiler-builtins/libm/crates/musl-math-sys/build.rs index d75748159cad..f06d84ee267e 100644 --- a/library/compiler-builtins/libm/crates/musl-math-sys/build.rs +++ b/library/compiler-builtins/libm/crates/musl-math-sys/build.rs @@ -79,17 +79,12 @@ impl Config { let target_features = env::var("CARGO_CFG_TARGET_FEATURE") .map(|feats| feats.split(',').map(ToOwned::to_owned).collect()) .unwrap_or_default(); - - // Default to the `{workspace_root}/musl` if not specified - let musl_dir = env::var("MUSL_SOURCE_DIR") - .map(PathBuf::from) - .unwrap_or_else(|_| manifest_dir.parent().unwrap().parent().unwrap().join("musl")); + let musl_dir = manifest_dir.join("musl"); let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap(); let musl_arch = if target_arch == "x86" { "i386".to_owned() } else { target_arch.clone() }; println!("cargo::rerun-if-changed={}/c_patches", manifest_dir.display()); - println!("cargo::rerun-if-env-changed=MUSL_SOURCE_DIR"); println!("cargo::rerun-if-changed={}", musl_dir.display()); Self { @@ -111,13 +106,10 @@ impl Config { /// Build musl math symbols to a static library fn build_musl_math(cfg: &Config) { let musl_dir = &cfg.musl_dir; - assert!( - musl_dir.exists(), - "musl source is missing. it can be downloaded with ./ci/download-musl.sh" - ); - let math = musl_dir.join("src/math"); let arch_dir = musl_dir.join("arch").join(&cfg.musl_arch); + assert!(math.exists(), "musl source not found. Is the submodule up to date?"); + let source_map = find_math_source(&math, cfg); let out_path = cfg.out_dir.join(format!("lib{LIB_NAME}.a")); diff --git a/library/compiler-builtins/libm/crates/musl-math-sys/musl b/library/compiler-builtins/libm/crates/musl-math-sys/musl new file mode 160000 index 000000000000..0784374d5614 --- /dev/null +++ b/library/compiler-builtins/libm/crates/musl-math-sys/musl @@ -0,0 +1 @@ +Subproject commit 0784374d561435f7c787a555aeab8ede699ed298