Add cross-compilation to CI

Updates the README to use cargo target config instead of RUSTFLAGS to
avoid setting the linker for ebpf in cargo-in-cargo.
reviewable/pr132/r1
Tamir Duberstein 3 months ago
parent 89eb550856
commit 27e7867528

@ -21,12 +21,12 @@ concurrency:
jobs: jobs:
build: build:
runs-on: ubuntu-22.04
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
runner:
- ubuntu-latest # x86
rust: rust:
- stable
- 1.80.1 - 1.80.1
program: program:
- kprobe - kprobe
@ -48,6 +48,15 @@ jobs:
- raw_tracepoint - raw_tracepoint
- tp_btf - tp_btf
- tracepoint - tracepoint
include:
- runner: macos-13 # x86
rust: 1.80.1
program: kprobe
- runner: macos-14 # arm64
rust: 1.80.1
program: kprobe
runs-on: ${{ matrix.runner }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -57,6 +66,21 @@ jobs:
components: rust-src,rustfmt components: rust-src,rustfmt
- uses: dtolnay/rust-toolchain@master - uses: dtolnay/rust-toolchain@master
if: runner.os == 'macOS' && runner.arch == 'X64'
with:
toolchain: ${{ matrix.rust }}
targets: x86_64-unknown-linux-musl
components: clippy
- uses: dtolnay/rust-toolchain@master
if: runner.os == 'macOS' && runner.arch == 'ARM64'
with:
toolchain: ${{ matrix.rust }}
targets: aarch64-unknown-linux-musl
components: clippy
- uses: dtolnay/rust-toolchain@master
if: runner.os == 'Linux'
with: with:
toolchain: ${{ matrix.rust }} toolchain: ${{ matrix.rust }}
components: clippy components: clippy
@ -65,8 +89,18 @@ jobs:
- uses: taiki-e/install-action@v2 - uses: taiki-e/install-action@v2
with: with:
tool: bpf-linker,cargo-generate tool: cargo-generate
- run: brew install filosottile/musl-cross/musl-cross llvm
if: runner.os == 'macos'
- run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git --no-default-features
if: runner.os == 'macos'
- run: cargo install bpf-linker --git https://github.com/aya-rs/bpf-linker.git
if: runner.os == 'Linux'
- run: sudo apt update && sudo apt install expect
if: runner.os == 'Linux'
- run: sudo apt update
- run: sudo apt install expect
- run: ./test.sh ${{ github.workspace }} ${{ matrix.program }} - run: ./test.sh ${{ github.workspace }} ${{ matrix.program }}

@ -21,11 +21,10 @@ experience; this compromise necessitates the use of `xtask` to actually build th
Cross compilation should work on both Intel and Apple Silicon Macs. Cross compilation should work on both Intel and Apple Silicon Macs.
```bash ```shell
AYA_BUILD_EBPF=true \ AYA_BUILD_EBPF=true CC=${ARCH}-linux-musl-gcc cargo build --package {{project-name}} --release \
CC=${ARCH}-linux-musl-gcc \ --target=${ARCH}-unknown-linux-musl \
RUSTFLAGS="-C linker=${ARCH}-linux-musl-gcc" \ --config=target.${ARCH}-unknown-linux-musl.linker=\"${ARCH}-linux-musl-gcc\"
cargo build --package {{project-name}} --release --target=${ARCH}-unknown-linux-musl
``` ```
The cross-compiled program `target/${ARCH}-unknown-linux-musl/release/{{project-name}}` can be The cross-compiled program `target/${ARCH}-unknown-linux-musl/release/{{project-name}}` can be
copied to a Linux server or VM and run there. copied to a Linux server or VM and run there.

@ -14,7 +14,7 @@ if [ -z "${PROG_TYPE}" ]; then
fi fi
CRATE_NAME=aya-test-crate CRATE_NAME=aya-test-crate
case "${PROG_TYPE}" in case ${PROG_TYPE} in
"cgroup_sockopt") "cgroup_sockopt")
ADDITIONAL_ARGS=(-d sockopt_target=getsockopt) ADDITIONAL_ARGS=(-d sockopt_target=getsockopt)
;; ;;
@ -61,6 +61,18 @@ pushd "${TMP_DIR}"
cargo generate --path "${TEMPLATE_DIR}" -n "${CRATE_NAME}" -d program_type="${PROG_TYPE}" "${ADDITIONAL_ARGS[@]}" cargo generate --path "${TEMPLATE_DIR}" -n "${CRATE_NAME}" -d program_type="${PROG_TYPE}" "${ADDITIONAL_ARGS[@]}"
pushd "${CRATE_NAME}" pushd "${CRATE_NAME}"
OS=$(uname)
case $OS in
"Darwin")
ARCH=$(uname -m)
if [[ "$ARCH" == "arm64" ]]; then
ARCH="aarch64"
fi
AYA_BUILD_EBPF=true CC=${ARCH}-linux-musl-gcc cargo build --package "${CRATE_NAME}" --release \
--target="${ARCH}"-unknown-linux-musl \
--config=target."${ARCH}"-unknown-linux-musl.linker=\""${ARCH}"-linux-musl-gcc\"
;;
"Linux")
cargo +nightly fmt --all -- --check cargo +nightly fmt --all -- --check
cargo build --package "${CRATE_NAME}" cargo build --package "${CRATE_NAME}"
cargo build --package "${CRATE_NAME}" --release cargo build --package "${CRATE_NAME}" --release
@ -93,3 +105,9 @@ expect <<EOF
eof { } eof { }
} }
EOF EOF
;;
*)
echo "Unsupported OS: ${OS}"
exit 1
;;
esac

@ -205,8 +205,9 @@ async fn main() -> anyhow::Result<()> {
program.attach("{{tracepoint_name}}")?; program.attach("{{tracepoint_name}}")?;
{%- endcase %} {%- endcase %}
let ctrl_c = signal::ctrl_c();
println!("Waiting for Ctrl-C..."); println!("Waiting for Ctrl-C...");
signal::ctrl_c().await?; ctrl_c.await?;
println!("Exiting..."); println!("Exiting...");
Ok(()) Ok(())

Loading…
Cancel
Save