mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-19 20:18:43 +00:00
Fix detect-targets
glibc detection (#1421)
* Fix `detect-targets` glibc detection Fixed #1420 Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `detect-targets` glibc detection for Fedora Fedora 37-39 has glibc installed in `/lib64` and `/usr/lib64` instead of `/lib` or `/usr/lib`. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Improve caching in `detect-targets-alpine-test` Make sure it reuses cached artifacts instead of recompiling everything. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Mv `test-detect-targets-musl.sh` into `.github/scripts/` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Refactor `ci.yml`: Extract new job `detect-targets-build` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * FIx `detect-targets-ubuntu-test` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Avoid building the entire workspacein `detect-targets-build` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `detect-targets-*-test`: `chmod +x detect-targets` Also fixed testing on Alpine, to make sure it exits with status 1 on assertion failure. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix typo Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Cache all crates in `detect-targets-build` Since `detect-targets` rarely changes and is quite small, it is also reasonable to cache it. Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add job `detect-targets-more-glibc-test` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Add `detect-targets-nix-test` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix `detect-targets-nix-test` executing `detect-targets` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> * Fix workflow: Add all `detect-targets-*` jobs to be dep of `tests-pass` Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com> --------- Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
86060fadc2
commit
b56a8c3579
3 changed files with 99 additions and 29 deletions
|
@ -1,6 +1,4 @@
|
||||||
#!/bin/ash
|
#!/bin/bash
|
||||||
|
|
||||||
# shellcheck shell=dash
|
|
||||||
|
|
||||||
set -exuo pipefail
|
set -exuo pipefail
|
||||||
|
|
||||||
|
@ -13,7 +11,7 @@ apk add gcompat
|
||||||
|
|
||||||
ls -lsha /lib
|
ls -lsha /lib
|
||||||
|
|
||||||
GNU_TARGET=$(echo "$TARGET" | sed 's/musl/gnu/')
|
GNU_TARGET=${TARGET//musl/gnu}
|
||||||
|
|
||||||
[ "$(detect-targets)" = "$(printf '%s\n%s' "$GNU_TARGET" "$TARGET")" ]
|
[ "$(detect-targets)" = "$(printf '%s\n%s' "$GNU_TARGET" "$TARGET")" ]
|
||||||
|
|
95
.github/workflows/ci.yml
vendored
95
.github/workflows/ci.yml
vendored
|
@ -139,28 +139,50 @@ jobs:
|
||||||
CARGO_PROFILE_RELEASE_LTO: no
|
CARGO_PROFILE_RELEASE_LTO: no
|
||||||
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 4
|
CARGO_PROFILE_RELEASE_CODEGEN_UNITS: 4
|
||||||
|
|
||||||
detect-targets-alpine-test:
|
detect-targets-build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
|
CARGO_BUILD_TARGET: x86_64-unknown-linux-musl
|
||||||
TARGET: x86_64-unknown-linux-musl
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Install x86_64-unknown-linux-musl target
|
- name: Install ${{ env.CARGO_BUILD_TARGET }} target
|
||||||
run: rustup target add $TARGET
|
run: |
|
||||||
|
rustup target add $CARGO_BUILD_TARGET
|
||||||
|
pip3 install -r zigbuild-requirements.txt
|
||||||
- uses: Swatinem/rust-cache@v2
|
- uses: Swatinem/rust-cache@v2
|
||||||
|
with:
|
||||||
|
cache-all-crates: true
|
||||||
- name: Build detect-targets
|
- name: Build detect-targets
|
||||||
run: |
|
run: |
|
||||||
pip3 install -r zigbuild-requirements.txt
|
cargo zigbuild --features cli-logging --target $CARGO_BUILD_TARGET
|
||||||
cargo zigbuild --bin detect-targets --features cli-logging --target $TARGET
|
# Set working directory here, otherwise `cargo-zigbuild` would download
|
||||||
|
# and build quite a few unused dependencies.
|
||||||
|
working-directory: crates/detect-targets
|
||||||
|
- uses: actions/upload-artifact@v3
|
||||||
|
with:
|
||||||
|
name: detect-targets
|
||||||
|
path: target/${{ env.CARGO_BUILD_TARGET }}/debug/detect-targets
|
||||||
|
|
||||||
|
detect-targets-alpine-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: detect-targets-build
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: detect-targets
|
||||||
|
- run: chmod +x detect-targets
|
||||||
|
|
||||||
- name: Run test in alpine
|
- name: Run test in alpine
|
||||||
run: |
|
run: |
|
||||||
docker run --rm \
|
docker run --rm \
|
||||||
--mount src="$PWD/target/$TARGET/debug/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
|
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
|
||||||
--mount src="$PWD/test-detect-targets-musl.sh",dst=/usr/local/bin/test.sh,type=bind \
|
--mount src="$PWD/.github/scripts/test-detect-targets-musl.sh",dst=/usr/local/bin/test.sh,type=bind \
|
||||||
alpine test.sh "$TARGET"
|
alpine /bin/ash -c "apk update && apk add bash && test.sh x86_64-unknown-linux-musl"
|
||||||
|
|
||||||
detect-targets-ubuntu-test:
|
detect-targets-ubuntu-test:
|
||||||
|
needs: detect-targets-build
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
|
@ -169,16 +191,56 @@ jobs:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/download-artifact@v3
|
||||||
- uses: Swatinem/rust-cache@v2
|
|
||||||
with:
|
with:
|
||||||
key: ${{ matrix.os }}
|
name: detect-targets
|
||||||
- name: Build detect-targets
|
- run: chmod +x detect-targets
|
||||||
run: cargo build --bin detect-targets --features cli-logging
|
|
||||||
- name: Run test in ubuntu
|
- name: Run test in ubuntu
|
||||||
run: |
|
run: |
|
||||||
set -exuo pipefail
|
set -exuo pipefail
|
||||||
[ "$(./target/debug/detect-targets)" = "$(printf '%s\n%s' x86_64-unknown-linux-gnu x86_64-unknown-linux-musl)" ]
|
[ "$(./detect-targets)" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
|
||||||
|
|
||||||
|
detect-targets-more-glibc-test:
|
||||||
|
needs: detect-targets-build
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
container:
|
||||||
|
- archlinux
|
||||||
|
- fedora:37
|
||||||
|
- fedora:38
|
||||||
|
- fedora:39
|
||||||
|
- fedora
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: detect-targets
|
||||||
|
- run: chmod +x detect-targets
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: |
|
||||||
|
set -exuo pipefail
|
||||||
|
[ "$(docker run --rm \
|
||||||
|
--mount src="$PWD/detect-targets",dst=/usr/local/bin/detect-targets,type=bind \
|
||||||
|
${{ matrix.container }} detect-targets )" = "$(printf 'x86_64-unknown-linux-gnu\nx86_64-unknown-linux-musl')" ]
|
||||||
|
|
||||||
|
detect-targets-nix-test:
|
||||||
|
needs: detect-targets-build
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/download-artifact@v3
|
||||||
|
with:
|
||||||
|
name: detect-targets
|
||||||
|
- run: chmod +x detect-targets
|
||||||
|
|
||||||
|
- name: Run test
|
||||||
|
run: |
|
||||||
|
set -exuo pipefail
|
||||||
|
[ "$(docker run --rm \
|
||||||
|
--mount src="$PWD/detect-targets",dst=/detect-targets,type=bind \
|
||||||
|
nixos/nix /detect-targets )" = x86_64-unknown-linux-musl ]
|
||||||
|
|
||||||
# Dummy job to have a stable name for the "all tests pass" requirement
|
# Dummy job to have a stable name for the "all tests pass" requirement
|
||||||
tests-pass:
|
tests-pass:
|
||||||
|
@ -188,8 +250,11 @@ jobs:
|
||||||
- cross-check
|
- cross-check
|
||||||
- lint
|
- lint
|
||||||
- release-dry-run
|
- release-dry-run
|
||||||
|
- detect-targets-build
|
||||||
- detect-targets-alpine-test
|
- detect-targets-alpine-test
|
||||||
- detect-targets-ubuntu-test
|
- detect-targets-ubuntu-test
|
||||||
|
- detect-targets-more-glibc-test
|
||||||
|
- detect-targets-nix-test
|
||||||
if: always() # always run even if dependencies fail
|
if: always() # always run even if dependencies fail
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
|
|
@ -38,16 +38,23 @@ pub(super) async fn detect_targets(target: String) -> Vec<String> {
|
||||||
.expect("unwrap: target always has a - for cpu_arch")
|
.expect("unwrap: target always has a - for cpu_arch")
|
||||||
.0;
|
.0;
|
||||||
|
|
||||||
|
let handles: Vec<_> = {
|
||||||
let cpu_arch_suffix = cpu_arch.replace('_', "-");
|
let cpu_arch_suffix = cpu_arch.replace('_', "-");
|
||||||
|
let filename = format!("ld-linux-{cpu_arch_suffix}.so.2");
|
||||||
|
let dirname = format!("{cpu_arch}-linux-gnu");
|
||||||
|
|
||||||
let handles: Vec<_> = [
|
[
|
||||||
format!("/lib/ld-linux-{cpu_arch_suffix}.so.2"),
|
format!("/lib/{filename}"),
|
||||||
format!("/lib/{cpu_arch}-linux-gnu/ld-linux-{cpu_arch_suffix}.so.2"),
|
format!("/lib64/{filename}"),
|
||||||
format!("/usr/lib/{cpu_arch}-linux-gnu/ld-linux-{cpu_arch_suffix}.so.2"),
|
format!("/lib/{dirname}/{filename}"),
|
||||||
|
format!("/lib64/{dirname}/{filename}"),
|
||||||
|
format!("/usr/lib/{dirname}/{filename}"),
|
||||||
|
format!("/usr/lib64/{dirname}/{filename}"),
|
||||||
]
|
]
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|p| AutoAbortHandle(tokio::spawn(is_gnu_ld(p))))
|
.map(|p| AutoAbortHandle(tokio::spawn(is_gnu_ld(p))))
|
||||||
.collect();
|
.collect()
|
||||||
|
};
|
||||||
|
|
||||||
let has_glibc = async move {
|
let has_glibc = async move {
|
||||||
for mut handle in handles {
|
for mut handle in handles {
|
||||||
|
@ -108,7 +115,7 @@ You are not meant to run this directly.
|
||||||
if status.success() {
|
if status.success() {
|
||||||
// Executing glibc ldd or /lib/ld-linux-{cpu_arch}.so.1 will always
|
// Executing glibc ldd or /lib/ld-linux-{cpu_arch}.so.1 will always
|
||||||
// succeeds.
|
// succeeds.
|
||||||
stdout.contains("GLIBC").then_some(Libc::Gnu)
|
(stdout.contains("GLIBC") || stdout.contains("GNU libc")).then_some(Libc::Gnu)
|
||||||
} else if status.code() == Some(1) {
|
} else if status.code() == Some(1) {
|
||||||
// On Alpine, executing both the gcompat glibc and the ldd and
|
// On Alpine, executing both the gcompat glibc and the ldd and
|
||||||
// /lib/ld-musl-{cpu_arch}.so.1 will fail with exit status 1.
|
// /lib/ld-musl-{cpu_arch}.so.1 will fail with exit status 1.
|
||||||
|
|
Loading…
Add table
Reference in a new issue