From ff79c54968368554b8aadd99ebf63c578afa8f4e Mon Sep 17 00:00:00 2001 From: Jorge Prendes Date: Thu, 21 Dec 2023 11:50:03 +0000 Subject: [PATCH] (feat) add support for `musl` using `cross-rs` (#2536) * add cross configuration for musl Signed-off-by: Jorge Prendes * use cargo.sh wapper in build.sh Signed-off-by: Jorge Prendes * make tests build with musl Signed-off-by: Jorge Prendes * add targets to run musl tests Signed-off-by: Jorge Prendes * Use cargo.sh wrapper and cross in CI Signed-off-by: Jorge Prendes * Update scripts/cargo.sh Co-Authored-By: adrianalin Signed-off-by: Jorge Prendes * Use glibc as cross default target --------- Signed-off-by: Jorge Prendes Co-authored-by: adrianalin --- .github/workflows/e2e.yaml | 47 +++++++++++----- .github/workflows/main.yml | 62 ++++++++------------- .github/workflows/release.yaml | 24 ++++---- Cross.toml | 6 ++ crates/libcgroups/src/v2/devices/mocks.rs | 13 +++-- cross/Dockerfile.gnu | 9 ++- cross/Dockerfile.musl | 32 +++++++++++ justfile | 24 ++++---- scripts/build.sh | 57 ++++++++++--------- scripts/cargo.sh | 67 +++++++++++++++++++++++ scripts/clean.sh | 6 +- scripts/features_test.sh | 10 ++-- scripts/musl_test.sh | 21 ------- 13 files changed, 240 insertions(+), 138 deletions(-) create mode 100644 cross/Dockerfile.musl create mode 100755 scripts/cargo.sh delete mode 100755 scripts/musl_test.sh diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml index 8a3e1385..720c62c5 100644 --- a/.github/workflows/e2e.yaml +++ b/.github/workflows/e2e.yaml @@ -15,33 +15,38 @@ jobs: strategy: matrix: arch: [ "x86_64", "aarch64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 - name: Setup Rust toolchain and cache uses: actions-rust-lang/setup-rust-toolchain@v1.3.7 env: - RUST_CACHE_KEY_OS: rust-cache-${{ matrix.arch }} + RUST_CACHE_KEY_OS: rust-cache-${{ matrix.arch }}-${{ matrix.libc }} - name: Install just uses: taiki-e/install-action@just - - name: Install requirements - if: ${{ matrix.arch == 'x86_64' }} - run: sudo env PATH=$PATH arch=${{ matrix.arch }} just ci-prepare - - name: Install requirements for aarch64 - if: ${{ matrix.arch == 'aarch64' }} + - name: Install cross-rs run: cargo install cross --git https://github.com/cross-rs/cross + - name: Setup target + run: | + echo "CARGO=cross" >> ${GITHUB_ENV} + echo "TARGET=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}" >> ${GITHUB_ENV} - name: Build youki - run: arch=${{ matrix.arch }} just youki-release + run: just youki-release - name: Upload youki binary if: ${{ matrix.arch == 'x86_64' }} uses: actions/upload-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} path: youki containerd-integration-tests: runs-on: ubuntu-22.04 needs: [youki-build] timeout-minutes: 40 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 with: @@ -60,7 +65,7 @@ jobs: - name: Download youki binary uses: actions/download-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} - name: Replace runc to youki run: | sudo rm -f /usr/bin/runc /usr/local/bin/runc /usr/sbin/runc @@ -74,12 +79,16 @@ jobs: runs-on: ubuntu-22.04 needs: [youki-build] timeout-minutes: 40 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 - name: Download youki binary uses: actions/download-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} - name: Add the permission to run run: chmod +x ./youki - name: Install just @@ -91,6 +100,10 @@ jobs: runs-on: ubuntu-22.04 needs: [youki-build] timeout-minutes: 15 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 with: @@ -107,7 +120,7 @@ jobs: - name: Download youki binary uses: actions/download-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} - name: Add the permission to run run: chmod +x ./youki - name: Run integration tests @@ -117,6 +130,10 @@ jobs: runs-on: ubuntu-22.04 needs: [youki-build] timeout-minutes: 20 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 with: @@ -130,7 +147,7 @@ jobs: - name: Download youki binary uses: actions/download-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} - name: Add the permission to run run: chmod +x ./youki - name: Build @@ -142,6 +159,10 @@ jobs: runs-on: ubuntu-22.04 needs: [youki-build] timeout-minutes: 20 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 with: @@ -155,7 +176,7 @@ jobs: - name: Download youki binary uses: actions/download-artifact@v3 with: - name: youki + name: youki-${{ matrix.arch }}-${{ matrix.libc }} - name: Add the permission to run run: chmod +x ./youki - name: Run tests diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9c786784..d6f1b396 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -35,21 +35,26 @@ jobs: if: needs.changes.outputs.any_modified == 'true' runs-on: ubuntu-22.04 timeout-minutes: 15 + strategy: + matrix: + arch: [ "x86_64", "aarch64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 - name: Setup Rust toolchain and cache uses: actions-rust-lang/setup-rust-toolchain@v1 with: components: rustfmt, clippy - - name: typos-action uses: crate-ci/typos@v1.14.12 - - - uses: taiki-e/install-action@just - - - name: Install requirements - run: sudo env PATH=$PATH just ci-prepare - + - name: Install just + uses: taiki-e/install-action@just + - name: Install cross-rs + run: cargo install cross --git https://github.com/cross-rs/cross + - name: Setup target + run: | + echo "CARGO=cross" >> ${GITHUB_ENV} + echo "TARGET=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}" >> ${GITHUB_ENV} - name: Check formatting and lints run: just lint @@ -58,46 +63,27 @@ jobs: if: needs.changes.outputs.any_modified == 'true' runs-on: ubuntu-22.04 timeout-minutes: 20 + strategy: + matrix: + arch: [ "x86_64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 - name: Setup Rust toolchain and cache uses: actions-rust-lang/setup-rust-toolchain@v1 - - uses: taiki-e/install-action@just - - name: Install requirements - run: sudo env PATH=$PATH just ci-prepare + - name: Install just + uses: taiki-e/install-action@just + - name: Install cross-rs + run: cargo install cross --git https://github.com/cross-rs/cross + - name: Setup target + run: | + echo "CARGO=cross" >> ${GITHUB_ENV} + echo "TARGET=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}" >> ${GITHUB_ENV} - name: Run tests run: just test-basic - name: Run feature tests run: just test-features - # TODO: musl testing is flaky. Turn it back on when we can resolve it. - # # musl target testing is religated to a separate job because our current build - # # for musl requires nightly. It is difficult to mix stable and nightly - # # toolchains in the same job. - # musl: - # needs: [changes] - # if: needs.changes.outputs.any_modified == 'true' - # runs-on: ubuntu-22.04 - # timeout-minutes: 20 - # steps: - # - uses: actions/checkout@v3 - # # We do not use `actions-rust-lang/setup-rust-toolchain` here because we - # # want to override the default toolchain file to use nightly toolchains. - # # The `setup-rust-toolchain` action will always choose toolchain file with - # # no way to override. - # - name: Setup Rust toolchain and cache - # uses: dtolnay/rust-toolchain@v1 - # with: - # toolchain: nightly - # target: x86_64-unknown-linux-musl - # components: rust-src - # - uses: taiki-e/install-action@just - # - name: Install requirements - # run: sudo env PATH=$PATH just ci-musl-prepare - # - name: Run test against musl target - # run: just test-musl - - coverage: needs: [changes] if: needs.changes.outputs.any_modified == 'true' diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 19a6dc63..fbe4cfe6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -24,6 +24,7 @@ jobs: strategy: matrix: arch: [ "x86_64", "aarch64" ] + libc: [ "gnu", "musl" ] steps: - uses: actions/checkout@v3 with: @@ -31,18 +32,17 @@ jobs: - name: Setup Rust toolchain and cache uses: actions-rust-lang/setup-rust-toolchain@v1.3.7 env: - RUST_CACHE_KEY_OS: rust-cache-${{ matrix.arch }} + RUST_CACHE_KEY_OS: rust-cache-${{ matrix.arch }}-${{ matrix.libc }} - name: Install just uses: taiki-e/install-action@just - - name: Install requirements - if: ${{ matrix.arch == 'x86_64' }} - run: | - sudo env PATH=$PATH arch=${{ matrix.arch }} just ci-prepare - - name: Install requirements for aarch64 - if: ${{ matrix.arch == 'aarch64' }} + - name: Install cross-rs run: cargo install cross --git https://github.com/cross-rs/cross + - name: Setup target + run: | + echo "CARGO=cross" >> ${GITHUB_ENV} + echo "TARGET=${{ matrix.arch }}-unknown-linux-${{ matrix.libc }}" >> ${GITHUB_ENV} - name: Release build - run: arch=${{ matrix.arch }} just youki-release + run: just youki-release - name: test # TODO(utam0k): The feature test needs nightly # run: just test-basic featuretest test-oci @@ -51,12 +51,12 @@ jobs: - name: Create output directory run: mkdir output - name: Create artifact - run: tar -zcvf youki-${{ needs.parse.outputs.version }}-${{ matrix.arch }}.tar.gz youki README.md LICENSE + run: tar -zcvf youki-${{ needs.parse.outputs.version }}-${{ matrix.arch }}-${{ matrix.libc }}.tar.gz youki README.md LICENSE - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: youki-${{ matrix.arch }} - path: youki-${{ needs.parse.outputs.version }}-${{ matrix.arch }}.tar.gz + name: youki-${{ matrix.arch }}-${{ matrix.libc }} + path: youki-${{ needs.parse.outputs.version }}-${{ matrix.arch }}-${{ matrix.libc }}.tar.gz release: name: Create Draft Release @@ -74,6 +74,8 @@ jobs: uses: actions/download-artifact@v3 with: path: artifacts + - name: Show artifacts + run: ls -alhR artifacts - name: Create release draft shell: bash run: | diff --git a/Cross.toml b/Cross.toml index 31cdb4a7..18e0f3d5 100644 --- a/Cross.toml +++ b/Cross.toml @@ -6,3 +6,9 @@ dockerfile = "cross/Dockerfile.gnu" [target.x86_64-unknown-linux-gnu] dockerfile = "cross/Dockerfile.gnu" + +[target.aarch64-unknown-linux-musl] +dockerfile = "cross/Dockerfile.musl" + +[target.x86_64-unknown-linux-musl] +dockerfile = "cross/Dockerfile.musl" diff --git a/crates/libcgroups/src/v2/devices/mocks.rs b/crates/libcgroups/src/v2/devices/mocks.rs index 5d7ed910..04b53b47 100644 --- a/crates/libcgroups/src/v2/devices/mocks.rs +++ b/crates/libcgroups/src/v2/devices/mocks.rs @@ -4,10 +4,15 @@ #[cfg_attr(test, automock())] pub mod libc { - pub fn setrlimit( - _resource: libc::__rlimit_resource_t, - _rlim: *const libc::rlimit, - ) -> libc::c_int { + #[cfg(target_env = "musl")] + #[allow(non_camel_case_types)] + pub type __rlimit_resource_t = libc::c_int; + + #[cfg(not(target_env = "musl"))] + #[allow(non_camel_case_types)] + pub type __rlimit_resource_t = libc::__rlimit_resource_t; + + pub fn setrlimit(_resource: __rlimit_resource_t, _rlim: *const libc::rlimit) -> libc::c_int { unimplemented!(); } } diff --git a/cross/Dockerfile.gnu b/cross/Dockerfile.gnu index 54ca2996..100f44a1 100644 --- a/cross/Dockerfile.gnu +++ b/cross/Dockerfile.gnu @@ -5,4 +5,11 @@ FROM $CROSS_BASE_IMAGE ARG CROSS_DEB_ARCH RUN dpkg --add-architecture ${CROSS_DEB_ARCH} && \ apt-get -y update && \ - apt-get install -y pkg-config libseccomp-dev:${CROSS_DEB_ARCH} + apt-get install -y pkg-config \ + # dependencies required to build libsecccomp-rs + libseccomp-dev:${CROSS_DEB_ARCH} \ + # dependencies required to build libbpf-sys + libelf-dev:${CROSS_DEB_ARCH} \ + zlib1g-dev:${CROSS_DEB_ARCH} \ + # dependencies to build wasmedge-sys + libzstd-dev:${CROSS_DEB_ARCH} diff --git a/cross/Dockerfile.musl b/cross/Dockerfile.musl new file mode 100644 index 00000000..81f32084 --- /dev/null +++ b/cross/Dockerfile.musl @@ -0,0 +1,32 @@ +ARG CROSS_BASE_IMAGE +FROM $CROSS_BASE_IMAGE + +COPY --from=jorgeprendes420/apk-anywhere / / +ENV MARCH=${CROSS_CMAKE_SYSTEM_PROCESSOR} +RUN apk-init ${MARCH} ${CROSS_SYSROOT} + +RUN apk-${MARCH} add \ + # dependencies required to build libsecccomp-rs + libseccomp-static libseccomp-dev \ + # dependencies required to build libbpf-sys + libelf-static elfutils-dev \ + zlib-dev zlib-static \ + # dependencies to build wasmedge-sys + g++ zstd-static + +# configure libsecccomp-rs to use static linking +ENV LIBSECCOMP_LINK_TYPE="static" +ENV LIBSECCOMP_LIB_PATH="${CROSS_SYSROOT}/lib" + +# configure wasmedge-sys to link stdc++ statically +ENV WASMEDGE_DEP_STDCXX_LINK_TYPE="static" +ENV WASMEDGE_DEP_STDCXX_LIB_PATH="${CROSS_SYSROOT}/lib" + +# wasmedge-sys (through llvm) needs some symbols defined in libgcc +RUN mkdir /.cargo && cat <<'EOF' > /.cargo/config.toml +[target.'cfg(target_env = "musl")'] +rustflags = ["-Clink-arg=-lgcc"] +EOF + +RUN apt-get -y update && \ + apt-get install -y pkg-config diff --git a/justfile b/justfile index 6eba1dc3..abf514c7 100644 --- a/justfile +++ b/justfile @@ -12,19 +12,19 @@ build-all: youki-release rust-oci-tests-bin runtimetest # build youki in dev mode youki-dev: - {{ cwd }}/scripts/build.sh -o {{ cwd }} -c youki -a ${arch:-x86_64} + {{ cwd }}/scripts/build.sh -o {{ cwd }} -c youki # build youki in release mode youki-release: - {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c youki -a ${arch:-x86_64} + {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c youki # build runtimetest binary runtimetest: - {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c runtimetest -a ${arch:-x86_64} + {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c runtimetest # build rust oci tests binary rust-oci-tests-bin: - {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c integration-test -a ${arch:-x86_64} + {{ cwd }}/scripts/build.sh -o {{ cwd }} -r -c integration-test # Tests @@ -39,20 +39,16 @@ test-basic: test-unit test-doc # run cargo unit tests test-unit: - cargo test --lib --bins --all --all-targets --all-features --no-fail-fast + {{ cwd }}/scripts/cargo.sh test --lib --bins --all --all-targets --all-features --no-fail-fast # run cargo doc tests test-doc: - cargo test --doc + {{ cwd }}/scripts/cargo.sh test --doc # run permutated feature compilation tests test-features: {{ cwd }}/scripts/features_test.sh -# run test against musl target -test-musl: - {{ cwd }}/scripts/musl_test.sh - # run oci integration tests through runtime-tools test-oci: {{ cwd }}/scripts/oci_integration_tests.sh {{ cwd }} @@ -123,8 +119,8 @@ hack-benchmark: # run linting on project lint: - cargo fmt --all -- --check - cargo clippy --all --all-targets --all-features -- -D warnings + {{ cwd }}/scripts/cargo.sh fmt --all -- --check + {{ cwd }}/scripts/cargo.sh clippy --all --all-targets --all-features -- -D warnings # run spellcheck spellcheck: @@ -132,7 +128,7 @@ spellcheck: # run format on project format: - cargo fmt --all + {{ cwd }}/scripts/cargo.sh fmt --all # cleans up generated artifacts clean: @@ -140,7 +136,7 @@ clean: # install tools used in dev dev-prepare: - cargo install typos-cli + {{ cwd }}/scripts/cargo.sh install typos-cli # setup dependencies in CI ci-prepare: diff --git a/scripts/build.sh b/scripts/build.sh index de7c8043..0a5cd330 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,18 +2,19 @@ set -euo pipefail ROOT=$(git rev-parse --show-toplevel) +HOST_TARGET=$(rustc -Vv | grep ^host: | cut -d' ' -f2) usage_exit() { - echo "Usage: $0 [-r] [-o dir] [-c crate] [-a arch] [-f features]" 1>&2 + echo "Usage: $0 [-r] [-o dir] [-c crate] [-f features] [-t target] [-x]" 1>&2 exit 1 } VERSION=debug CRATE="youki" -RUNTIMETEST_TARGET="$ROOT/runtimetest-target" +TARGET=${TARGET:-$HOST_TARGET} +CARGO=${CARGO:-} features="" -ARCH=$(uname -m) -while getopts f:ro:c:ha: OPT; do +while getopts f:ro:c:t:xh OPT; do case $OPT in f) features=${OPTARG} ;; @@ -23,8 +24,10 @@ while getopts f:ro:c:ha: OPT; do ;; c) CRATE=${OPTARG} ;; - a) ARCH=${OPTARG} - ;; + t) TARGET=${OPTARG} + ;; + x) CARGO=cross + ;; h) usage_exit ;; \?) usage_exit @@ -35,45 +38,41 @@ done shift $((OPTIND - 1)) OPTION="" -if [ ${VERSION} = release ]; then - OPTION="--${VERSION}" +if [ "${VERSION}" = release ]; then + OPTION="--release" fi -TARGET="${ARCH}-unknown-linux-gnu" -CARGO="cargo" -if [ "$ARCH" != "$(uname -m)" ]; then - # shellcheck disable=SC2034 - CARGO="cross" -fi - -FEATURES="" +FEATURES=() if [ -n "${features}" ]; then - FEATURES="--features ${features}" + FEATURES=("--features=${features}") fi -echo "* FEATURES: ${FEATURES}" -echo "* features: ${features}" +echo "* FEATURES: ${features:-}" echo "* TARGET: ${TARGET}" OUTPUT=${output:-$ROOT/bin} -[ ! -d $OUTPUT ] && mkdir -p $OUTPUT +mkdir -p "$OUTPUT" +CARGO_SH="$(dirname "$0")/cargo.sh" +export CARGO_BUILD_TARGET="$TARGET" if [ "$CRATE" == "youki" ]; then - rm -f ${OUTPUT}/youki - $CARGO build --target ${TARGET} ${OPTION} ${FEATURES} --bin youki - mv ${ROOT}/target/${TARGET}/${VERSION}/youki ${OUTPUT}/ + rm -f "${OUTPUT}/youki" + "$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin youki + mv "$("$CARGO_SH" --print-target-dir)/${TARGET}/${VERSION}/youki" "${OUTPUT}/" fi if [ "$CRATE" == "integration-test" ]; then - rm -f ${OUTPUT}/integration_test - cargo build --target ${TARGET} ${OPTION} ${FEATURES} --bin integration_test - mv ${ROOT}/target/${TARGET}/${VERSION}/integration_test ${OUTPUT}/ + rm -f "${OUTPUT}/integration_test" + "$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin integration_test + mv "$("$CARGO_SH" --print-target-dir)/${TARGET}/${VERSION}/integration_test" "${OUTPUT}/" fi if [ "$CRATE" == "runtimetest" ]; then - rm -f ${OUTPUT}/runtimetest - CARGO_TARGET_DIR=${RUNTIMETEST_TARGET} RUSTFLAGS="-Ctarget-feature=+crt-static" cargo build --target ${TARGET} ${OPTION} ${FEATURES} --bin runtimetest - mv ${RUNTIMETEST_TARGET}/${TARGET}/${VERSION}/runtimetest ${OUTPUT}/ + rm -f "${OUTPUT}/runtimetest" + export CARGO_TARGET_DIR="$ROOT/runtimetest-target" + export RUSTFLAGS="-Ctarget-feature=+crt-static" + "$CARGO_SH" build ${OPTION} "${FEATURES[@]}" --bin runtimetest + mv "$("$CARGO_SH" --print-target-dir)/${TARGET}/${VERSION}/runtimetest" "${OUTPUT}/" fi exit 0 diff --git a/scripts/cargo.sh b/scripts/cargo.sh new file mode 100755 index 00000000..a5369094 --- /dev/null +++ b/scripts/cargo.sh @@ -0,0 +1,67 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Usage: +# CARGO_BUILD_TARGET= cargo.sh ... +# +# This script wraps `cargo` invocations, and calls either `cargo` +# or `cross`, as appropriate. It checks the value of the +# `CARGO_BUILD_TARGET` environment variable, and calls `cargo` if +# the target matches the host target, and `cross` otherwise. +# +# Use of `cargo`/`cross` can be forced by setting the `CARGO` +# environment variable to `cargo`/`cross`. This is useful for +# instance to force the use of `cross` in CI even for the host +# target. +# +# When cross is used, the target directory will be appended +# `cross-` to avoid libc conflicts in host binaries (e.g., +# build scripts, proc macros). The computed value of the target +# directory can be obtained with `cargo.sh --print-target-dir`. +# +# Lastly, when using `cross` this scrips sets some configuration +# to allow running `youki` tests inside the `cross`` container. +# Please check the comments in this scrips to learm more about that. +# +# Limitations: +# * You **must** use the `CARGO_BUILD_TARGET` environment variable +# to specify the build target instead of using the `--target` CLI +# argument, or a configuration file like `.cargo/config.toml`. +# * If **must** use the `CARGO_TARGET_DIR` environment variable to +# specify the target directory instead of using the `--target-dir` +# CLI argument, or a configuration file like `.cargo/config.toml`. +# + +ROOT=$(git rev-parse --show-toplevel) +HOST_TARGET=$(rustc -Vv | grep ^host: | cut -d' ' -f2) + +export CARGO_BUILD_TARGET="${CARGO_BUILD_TARGET:-$HOST_TARGET}" +export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}" + +if [ "$CARGO_BUILD_TARGET" == "$HOST_TARGET" ]; then + CARGO="${CARGO:-cargo}" +else + CARGO="${CARGO:-cross}" +fi + +if [ "$1" == "fmt" ]; then + # running cargo fmt fails when run through cross + # also cargo fmt is platform independent + CARGO="cargo" +fi + +if [ "$CARGO" == "cross" ]; then + export CROSS_BUILD_OPTS="--quiet" + export CARGO_TARGET_DIR="$CARGO_TARGET_DIR/cross-$CARGO_BUILD_TARGET" + + # mount run to have access to dbus socket. + # mount /tmp so as shared for test_make_parent_mount_private + export CROSS_CONTAINER_OPTS="--privileged -v/run:/run --mount=type=bind,source=/tmp,destination=/tmp,bind-propagation=shared" +fi + +if [ "$1" == "--print-target-dir" ]; then + echo "$CARGO_TARGET_DIR" + exit 0 +fi + +"$CARGO" "$@" diff --git a/scripts/clean.sh b/scripts/clean.sh index 0b7857ee..b8d1eee5 100755 --- a/scripts/clean.sh +++ b/scripts/clean.sh @@ -1,14 +1,14 @@ #!/usr/bin/env bash set -euo pipefail +ROOT=$(git rev-parse --show-toplevel) + for bin in youki integration_test runtimetest test.log; do if [ -f $bin ]; then rm -f ${1}/$bin fi done -rm -rf runtimetest-target - -cargo clean +rm -rf $ROOT/target $ROOT/runtimetest-target exit 0 # unconditionally return zero diff --git a/scripts/features_test.sh b/scripts/features_test.sh index 6f8275fc..1b6b84a7 100755 --- a/scripts/features_test.sh +++ b/scripts/features_test.sh @@ -1,9 +1,11 @@ #!/usr/bin/env bash set -euo pipefail +CARGO_SH="$(dirname "$0")/cargo.sh" + test_package_features() { - echo "[feature test] testing $1 with features $2" - cargo build --no-default-features --package "$1" --features "$2" + echo "[feature test] building $1 with features $2" + "$CARGO_SH" build --no-default-features --package "$1" --features "$2" } test_package_features "libcontainer" "v1" @@ -20,8 +22,8 @@ test_package_features "libcgroups" "systemd cgroupsv2_devices" test_features() { echo "[feature test] testing features $1" - cargo build --no-default-features --features "$1" - cargo test run --no-default-features --features "$1" + "$CARGO_SH" build --no-default-features --features "$1" + "$CARGO_SH" test run --no-default-features --features "$1" } test_features "v1" diff --git a/scripts/musl_test.sh b/scripts/musl_test.sh deleted file mode 100755 index 3007b097..00000000 --- a/scripts/musl_test.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -test_musl() { - echo "[musl test] testing $1 with features $2" - cargo +nightly build \ - -Zbuild-std \ - --target $(uname -m)-unknown-linux-musl \ - --package "$1" \ - --no-default-features -F "$2" - cargo +nightly test \ - -Zbuild-std \ - --target $(uname -m)-unknown-linux-musl \ - --package "$1" \ - --no-default-features -F "$2" -} - -test_musl "libcontainer" "v1" -test_musl "libcontainer" "v2" -test_musl "libcontainer" "v1 v2" -