krata: build kratactl for darwin

This commit is contained in:
Alex Zenla
2024-03-21 18:16:04 -07:00
parent ba00889efb
commit 597a1433b3
5 changed files with 97 additions and 15 deletions

View File

@ -10,7 +10,7 @@ jobs:
- aarch64 - aarch64
env: env:
TARGET_ARCH: "${{ matrix.arch }}" TARGET_ARCH: "${{ matrix.arch }}"
name: cargo build ${{ matrix.arch }} name: build ${{ matrix.arch }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
@ -25,7 +25,7 @@ jobs:
- aarch64 - aarch64
env: env:
TARGET_ARCH: "${{ matrix.arch }}" TARGET_ARCH: "${{ matrix.arch }}"
name: cargo test ${{ matrix.arch }} name: test ${{ matrix.arch }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
@ -40,7 +40,7 @@ jobs:
- aarch64 - aarch64
env: env:
TARGET_ARCH: "${{ matrix.arch }}" TARGET_ARCH: "${{ matrix.arch }}"
name: cargo clippy ${{ matrix.arch }} name: clippy ${{ matrix.arch }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
@ -66,7 +66,7 @@ jobs:
- run: ./hack/ci/install-deps.sh - run: ./hack/ci/install-deps.sh
- run: ./hack/initrd/build.sh - run: ./hack/initrd/build.sh
fmt: fmt:
name: cargo fmt name: fmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4

39
.github/workflows/client.yml vendored Normal file
View File

@ -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

View File

@ -1,5 +1,7 @@
pub mod common; pub mod common;
pub mod control; pub mod control;
pub mod dial; pub mod dial;
pub mod ethtool;
pub mod launchcfg; pub mod launchcfg;
#[cfg(target_os = "linux")]
pub mod ethtool;

View File

@ -5,9 +5,23 @@ TOOLS_DIR="$(dirname "${0}")"
RUST_TARGET="$("${TOOLS_DIR}/target.sh")" RUST_TARGET="$("${TOOLS_DIR}/target.sh")"
TARGET_ARCH="$(echo "${RUST_TARGET}" | awk -F '-' '{print $1}')" TARGET_ARCH="$(echo "${RUST_TARGET}" | awk -F '-' '{print $1}')"
HOST_ARCH="$(uname -m)" 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 then
echo "1" echo "1"
else else

View File

@ -11,8 +11,34 @@ then
TARGET_ARCH="$(uname -m)" TARGET_ARCH="$(uname -m)"
fi fi
if [ -z "${RUST_TARGET}" ] if [ "${TARGET_ARCH}" = "arm64" ]
then then
TARGET_ARCH="aarch64"
fi
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
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" ] if [ "${TARGET_ARCH}" = "x86_64" ]
then then
RUST_TARGET="x86_64-unknown-linux-${TARGET_LIBC}" RUST_TARGET="x86_64-unknown-linux-${TARGET_LIBC}"
@ -22,6 +48,7 @@ then
then then
RUST_TARGET="aarch64-unknown-linux-${TARGET_LIBC}" RUST_TARGET="aarch64-unknown-linux-${TARGET_LIBC}"
fi fi
fi
fi fi
if [ -z "${C_TARGET}" ] if [ -z "${C_TARGET}" ]
@ -41,7 +68,7 @@ if [ "${KRATA_TARGET_C_MODE}" = "1" ]
then then
if [ -z "${C_TARGET}" ] if [ -z "${C_TARGET}" ]
then 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 exit 1
fi fi
@ -49,7 +76,7 @@ then
else else
if [ -z "${RUST_TARGET}" ] if [ -z "${RUST_TARGET}" ]
then 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 exit 1
fi fi