krata: compile for aarch64 (aarch64 guests are not yet supported)

This commit is contained in:
Alex Zenla
2024-03-05 16:37:36 -08:00
parent f8e2f50c60
commit 0e27b8f228
10 changed files with 62 additions and 16 deletions

View File

@ -7,14 +7,14 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
- run: cargo build --target x86_64-unknown-linux-gnu - run: ./scripts/cargo.sh build
test: test:
name: cargo test name: cargo test
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
- run: cargo test --target x86_64-unknown-linux-gnu - run: ./scripts/cargo.sh test
clippy: clippy:
name: cargo clippy name: cargo clippy
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -23,7 +23,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
with: with:
components: clippy components: clippy
- run: cargo clippy --target x86_64-unknown-linux-gnu - run: ./scripts/cargo.sh clippy
fmt: fmt:
name: cargo fmt name: cargo fmt
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -32,4 +32,4 @@ jobs:
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable
with: with:
components: rustfmt components: rustfmt
- run: cargo fmt - run: ./scripts/cargo.sh fmt --all -- --check

View File

@ -1,14 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
TARGET="x86_64-unknown-linux-gnu" export RUST_LIBC="musl"
RUST_TARGET="$(./scripts/detect-rust-target.sh)"
export RUSTFLAGS="-Ctarget-feature=+crt-static" export RUSTFLAGS="-Ctarget-feature=+crt-static"
cd "$(dirname "${0}")/.." cd "$(dirname "${0}")/.."
KRATA_DIR="${PWD}" KRATA_DIR="${PWD}"
cargo build -q --bin krataguest --release --target "${TARGET}" ./scripts/cargo.sh build -q --release --bin krataguest
INITRD_DIR="$(mktemp -d /tmp/krata-initrd.XXXXXXXXXXXXX)" INITRD_DIR="$(mktemp -d /tmp/krata-initrd.XXXXXXXXXXXXX)"
cp "target/${TARGET}/release/krataguest" "${INITRD_DIR}/init" cp "target/${RUST_TARGET}/release/krataguest" "${INITRD_DIR}/init"
chmod +x "${INITRD_DIR}/init" chmod +x "${INITRD_DIR}/init"
cd "${INITRD_DIR}" cd "${INITRD_DIR}"
mkdir -p "${KRATA_DIR}/initrd/target" mkdir -p "${KRATA_DIR}/initrd/target"

View File

@ -2,13 +2,13 @@
parallel = true parallel = true
[pre-commit.commands.build] [pre-commit.commands.build]
run = "cargo build --target x86_64-unknown-linux-gnu" run = "./scripts/cargo.sh build"
[pre-commit.commands.test] [pre-commit.commands.test]
run = "cargo test --target x86_64-unknown-linux-gnu" run = "./scripts/cargo.sh test"
[pre-commit.commands.fmt] [pre-commit.commands.fmt]
run = "cargo fmt --all -- --check" run = "./scripts/cargo.sh fmt --all -- --check"
[pre-commit.commands.clippy] [pre-commit.commands.clippy]
run = "cargo clippy --target x86_64-unknown-linux-gnu" run = "./scripts/cargo.sh clippy"

View File

@ -234,6 +234,7 @@ macro_rules! mac_impl {
} }
} }
#[cfg(not(target_arch = "aarch64"))]
impl TryFrom<&[core::ffi::c_char]> for $nm { impl TryFrom<&[core::ffi::c_char]> for $nm {
type Error = ParseError; type Error = ParseError;

View File

@ -14,8 +14,9 @@ BUNDLE_DIR="${BUNDLE_DIR}/krata"
mkdir -p "${BUNDLE_DIR}" mkdir -p "${BUNDLE_DIR}"
for X in kratad kratanet kratactl for X in kratad kratanet kratactl
do do
cargo build --release --target x86_64-unknown-linux-gnu --bin "${X}" ./scripts/cargo.sh build --release --bin "${X}"
cp "${KRATA_DIR}/target/x86_64-unknown-linux-gnu/release/${X}" "${BUNDLE_DIR}/${X}" RUST_TARGET="$(./scripts/detect-rust-target.sh)"
cp "${KRATA_DIR}/target/${RUST_TARGET}/release/${X}" "${BUNDLE_DIR}/${X}"
done done
./initrd/build.sh ./initrd/build.sh
if [ "${KRATA_BUNDLE_SKIP_KERNEL_BUILD}" != "1" ] if [ "${KRATA_BUNDLE_SKIP_KERNEL_BUILD}" != "1" ]

8
scripts/cargo.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
set -e
SCRIPTS_DIR="$(dirname "${0}")"
RUST_TARGET="$("${SCRIPTS_DIR}/detect-rust-target.sh")"
export CARGO_BUILD_TARGET="${RUST_TARGET}"
exec cargo "${@}"

30
scripts/detect-rust-target.sh Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
set -e
if [ -z "${RUST_LIBC}" ]
then
RUST_LIBC="gnu"
fi
if [ -z "${RUST_TARGET}" ]
then
HOST_ARCH="$(uname -m)"
if [ "${HOST_ARCH}" = "x86_64" ]
then
RUST_TARGET="x86_64-unknown-linux-${RUST_LIBC}"
fi
if [ "${HOST_ARCH}" = "aarch64" ]
then
RUST_TARGET="aarch64-unknown-linux-${RUST_LIBC}"
fi
fi
if [ -z "${RUST_TARGET}" ]
then
echo "ERROR: Unable to determine RUST_TARGET, your architecture may not be supported by krata." > /dev/stderr
exit 1
fi
echo "${RUST_TARGET}"

View File

@ -2,5 +2,5 @@
set -e set -e
cd "$(dirname "${0}")/.." cd "$(dirname "${0}")/.."
cargo clippy --target x86_64-unknown-linux-gnu --fix --allow-dirty --allow-staged ./scripts/cargo.sh clippy --fix --allow-dirty --allow-staged
cargo fmt --all cargo fmt --all

View File

@ -24,6 +24,7 @@ build_and_run() {
./initrd/build.sh -q ./initrd/build.sh -q
sudo cp "target/initrd/initrd" "/var/lib/krata/default/initrd" sudo cp "target/initrd/initrd" "/var/lib/krata/default/initrd"
fi fi
cargo build ${CARGO_BUILD_FLAGS} --target x86_64-unknown-linux-gnu --bin "${EXE_TARGET}" RUST_TARGET="$(./scripts/detect-rust-target.sh)"
exec sudo RUST_LOG="${RUST_LOG}" "target/x86_64-unknown-linux-gnu/debug/${EXE_TARGET}" "${@}" ./scripts/cargo.sh build ${CARGO_BUILD_FLAGS} --bin "${EXE_TARGET}"
exec sudo RUST_LOG="${RUST_LOG}" "target/${RUST_TARGET}/debug/${EXE_TARGET}" "${@}"
} }

View File

@ -14,7 +14,11 @@ struct EthtoolValue {
const ETHTOOL_SGSO: u32 = 0x00000024; const ETHTOOL_SGSO: u32 = 0x00000024;
const ETHTOOL_STSO: u32 = 0x0000001f; const ETHTOOL_STSO: u32 = 0x0000001f;
#[cfg(not(target_env = "musl"))]
const SIOCETHTOOL: libc::c_ulong = libc::SIOCETHTOOL; const SIOCETHTOOL: libc::c_ulong = libc::SIOCETHTOOL;
#[cfg(target_env = "musl")]
const SIOCETHTOOL: libc::c_int = libc::SIOCETHTOOL as i32;
#[repr(C)] #[repr(C)]
#[derive(Debug)] #[derive(Debug)]