From 597a1433b3632fe979f57cb57f5623c1725dc2fd Mon Sep 17 00:00:00 2001 From: Alex Zenla Date: Thu, 21 Mar 2024 18:16:04 -0700 Subject: [PATCH] krata: build kratactl for darwin --- .github/workflows/check.yml | 8 +++---- .github/workflows/client.yml | 39 +++++++++++++++++++++++++++++++ crates/krata/src/lib.rs | 4 +++- hack/build/cross-compile.sh | 16 ++++++++++++- hack/build/target.sh | 45 ++++++++++++++++++++++++++++-------- 5 files changed, 97 insertions(+), 15 deletions(-) create mode 100644 .github/workflows/client.yml diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ddd3b5f..1598d52 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -10,7 +10,7 @@ jobs: - aarch64 env: TARGET_ARCH: "${{ matrix.arch }}" - name: cargo build ${{ matrix.arch }} + name: build ${{ matrix.arch }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -25,7 +25,7 @@ jobs: - aarch64 env: TARGET_ARCH: "${{ matrix.arch }}" - name: cargo test ${{ matrix.arch }} + name: test ${{ matrix.arch }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -40,7 +40,7 @@ jobs: - aarch64 env: TARGET_ARCH: "${{ matrix.arch }}" - name: cargo clippy ${{ matrix.arch }} + name: clippy ${{ matrix.arch }} steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@stable @@ -66,7 +66,7 @@ jobs: - run: ./hack/ci/install-deps.sh - run: ./hack/initrd/build.sh fmt: - name: cargo fmt + name: fmt runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/client.yml b/.github/workflows/client.yml new file mode 100644 index 0000000..e610e62 --- /dev/null +++ b/.github/workflows/client.yml @@ -0,0 +1,39 @@ +name: client +on: [push, pull_request] +jobs: + build: + strategy: + matrix: + os: + - { name: linux, on: ubuntu-latest } + - { name: darwin, on: macos-latest } + arch: + - x86_64 + - aarch64 + env: + TARGET_ARCH: "${{ matrix.arch }}" + runs-on: "${{ matrix.os.on }}" + name: build ${{ matrix.os.name }}-${{ matrix.arch }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh build --bin kratactl + test: + runs-on: ubuntu-latest + strategy: + matrix: + os: + - { name: linux, on: ubuntu-latest } + - { name: darwin, on: macos-latest } + arch: + - x86_64 + - aarch64 + env: + TARGET_ARCH: "${{ matrix.arch }}" + name: test ${{ matrix.os.name }}-${{ matrix.arch }} + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: ./hack/ci/install-deps.sh + - run: ./hack/build/cargo.sh test --bin kratactl diff --git a/crates/krata/src/lib.rs b/crates/krata/src/lib.rs index ed74a4c..3ba3599 100644 --- a/crates/krata/src/lib.rs +++ b/crates/krata/src/lib.rs @@ -1,5 +1,7 @@ pub mod common; pub mod control; pub mod dial; -pub mod ethtool; pub mod launchcfg; + +#[cfg(target_os = "linux")] +pub mod ethtool; diff --git a/hack/build/cross-compile.sh b/hack/build/cross-compile.sh index e8cdbae..a839201 100755 --- a/hack/build/cross-compile.sh +++ b/hack/build/cross-compile.sh @@ -5,9 +5,23 @@ TOOLS_DIR="$(dirname "${0}")" RUST_TARGET="$("${TOOLS_DIR}/target.sh")" TARGET_ARCH="$(echo "${RUST_TARGET}" | awk -F '-' '{print $1}')" + HOST_ARCH="$(uname -m)" -if [ "${HOST_ARCH}" != "${TARGET_ARCH}" ] +if [ "${HOST_ARCH}" = "arm64" ] +then + HOST_ARCH="aarch64" +fi + +HOST_OS="$(uname -s)" +HOST_OS="$(echo "${HOST_OS}" | tr '[:upper:]' '[:lower:]')" + +if [ -z "${TARGET_OS}" ] +then + TARGET_OS="${HOST_OS}" +fi + +if [ "${HOST_ARCH}" != "${TARGET_ARCH}" ] || [ "${HOST_OS}" != "${TARGET_OS}" ] then echo "1" else diff --git a/hack/build/target.sh b/hack/build/target.sh index d21840e..51c4aed 100755 --- a/hack/build/target.sh +++ b/hack/build/target.sh @@ -11,16 +11,43 @@ then TARGET_ARCH="$(uname -m)" fi -if [ -z "${RUST_TARGET}" ] +if [ "${TARGET_ARCH}" = "arm64" ] then - if [ "${TARGET_ARCH}" = "x86_64" ] - then - RUST_TARGET="x86_64-unknown-linux-${TARGET_LIBC}" - fi + TARGET_ARCH="aarch64" +fi - if [ "${TARGET_ARCH}" = "aarch64" ] +if [ -z "${TARGET_OS}" ] +then + TARGET_OS="$(uname -s)" + TARGET_OS="$(echo "${TARGET_OS}" | tr '[:upper:]' '[:lower:]')" +fi + +if [ "${TARGET_OS}" = "darwin" ] +then + if [ -z "${RUST_TARGET}" ] then - RUST_TARGET="aarch64-unknown-linux-${TARGET_LIBC}" + if [ "${TARGET_ARCH}" = "x86_64" ] + then + RUST_TARGET="x86_64-apple-darwin" + fi + + if [ "${TARGET_ARCH}" = "aarch64" ] + then + RUST_TARGET="aarch64-apple-darwin" + fi + fi +else + if [ -z "${RUST_TARGET}" ] + then + if [ "${TARGET_ARCH}" = "x86_64" ] + then + RUST_TARGET="x86_64-unknown-linux-${TARGET_LIBC}" + fi + + if [ "${TARGET_ARCH}" = "aarch64" ] + then + RUST_TARGET="aarch64-unknown-linux-${TARGET_LIBC}" + fi fi fi @@ -41,7 +68,7 @@ if [ "${KRATA_TARGET_C_MODE}" = "1" ] then if [ -z "${C_TARGET}" ] then - echo "ERROR: Unable to determine C_TARGET, your architecture may not be supported by krata." > /dev/stderr + echo "ERROR: Unable to determine C_TARGET, your os or architecture may not be supported by krata." > /dev/stderr exit 1 fi @@ -49,7 +76,7 @@ then else if [ -z "${RUST_TARGET}" ] then - echo "ERROR: Unable to determine RUST_TARGET, your architecture may not be supported by krata." > /dev/stderr + echo "ERROR: Unable to determine RUST_TARGET, your os or architecture may not be supported by krata." > /dev/stderr exit 1 fi