From 1d06b41e578f41aff8ded77d53a8d1dfb7e250ea Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 15:41:15 +0100 Subject: [PATCH 1/6] ci: Test all architectures Signed-off-by: Dave Tucker --- .github/workflows/build-aya-bpf.yml | 21 +++++++++++++++++++-- .github/workflows/build-aya.yml | 21 ++++++++++++++++++--- bpf/aya-bpf-bindings/build.rs | 4 +++- bpf/aya-bpf-cty/build.rs | 4 +++- bpf/aya-bpf/build.rs | 4 +++- 5 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-aya-bpf.yml b/.github/workflows/build-aya-bpf.yml index 68d85c59..3f16bcf9 100644 --- a/.github/workflows/build-aya-bpf.yml +++ b/.github/workflows/build-aya-bpf.yml @@ -15,6 +15,13 @@ env: jobs: build: + strategy: + matrix: + arch: + - x86_64 + - aarch64 + - arm + - riscv64 runs-on: ubuntu-20.04 steps: @@ -28,7 +35,17 @@ jobs: - uses: Swatinem/rust-cache@v1 - name: Build - run: cargo build --manifest-path bpf/Cargo.toml --verbose + env: + CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }} + run: | + pushd bpf + cargo build --workspace --exclude aya-bpf-macros --verbose + popd - name: Run tests - run: RUST_BACKTRACE=full cargo test --manifest-path bpf/Cargo.toml --verbose + env: + CARGO_CFG_BPF_TARGET_ARCH: ${{ matrix.arch }} + run: | + pushd bpf + cargo test --workspace --exclude aya-bpf-macros --verbose + popd diff --git a/.github/workflows/build-aya.yml b/.github/workflows/build-aya.yml index 82eb94b1..e8dc8582 100644 --- a/.github/workflows/build-aya.yml +++ b/.github/workflows/build-aya.yml @@ -15,16 +15,31 @@ env: jobs: build: + strategy: + matrix: + arch: + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu + - armv7-unknown-linux-gnueabi + - riscv64gc-unknown-none-elf runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v2 - uses: Swatinem/rust-cache@v1 + - name: Prereqs + run: cargo install cross --git https://github.com/cross-rs/cross - name: Build - run: cargo build --verbose + run: cross build --verbose - - name: Run tests - run: RUST_BACKTRACE=full cargo test --verbose + - name: Run test + run: RUST_BACKTRACE=full cross test --verbose + + - name: Build bpf macros + run: cross build --manifest-path ./bpf/Cargo.toml -p aya-bpf-macros --verbose + + - name: Test bpf macros + run: RUST_BACKTRACE=full cross test --manifest-path ./bpf/Cargo.toml -p aya-bpf-macros --verbose test: runs-on: ubuntu-20.04 diff --git a/bpf/aya-bpf-bindings/build.rs b/bpf/aya-bpf-bindings/build.rs index 1f0c9eb1..3029c4b0 100644 --- a/bpf/aya-bpf-bindings/build.rs +++ b/bpf/aya-bpf-bindings/build.rs @@ -1,7 +1,9 @@ use std::env; fn main() { - if env::var("CARGO_CFG_BPF_TARGET_ARCH").is_err() { + if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { + println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); + } else { let arch = env::var("HOST").unwrap(); let arch = arch.split_once('-').map_or(&*arch, |x| x.0); println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); diff --git a/bpf/aya-bpf-cty/build.rs b/bpf/aya-bpf-cty/build.rs index 1f0c9eb1..3029c4b0 100644 --- a/bpf/aya-bpf-cty/build.rs +++ b/bpf/aya-bpf-cty/build.rs @@ -1,7 +1,9 @@ use std::env; fn main() { - if env::var("CARGO_CFG_BPF_TARGET_ARCH").is_err() { + if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { + println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); + } else { let arch = env::var("HOST").unwrap(); let arch = arch.split_once('-').map_or(&*arch, |x| x.0); println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); diff --git a/bpf/aya-bpf/build.rs b/bpf/aya-bpf/build.rs index 1f0c9eb1..3029c4b0 100644 --- a/bpf/aya-bpf/build.rs +++ b/bpf/aya-bpf/build.rs @@ -1,7 +1,9 @@ use std::env; fn main() { - if env::var("CARGO_CFG_BPF_TARGET_ARCH").is_err() { + if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { + println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); + } else { let arch = env::var("HOST").unwrap(); let arch = arch.split_once('-').map_or(&*arch, |x| x.0); println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); From 7f6da53c341bd2fe3be378110cfebf3e18d4b603 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 15:51:45 +0100 Subject: [PATCH 2/6] bpf: Fix pt_regs for aarch64 (again) Signed-off-by: Dave Tucker --- bpf/aya-bpf/src/args.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bpf/aya-bpf/src/args.rs b/bpf/aya-bpf/src/args.rs index 2146e047..db361bc8 100644 --- a/bpf/aya-bpf/src/args.rs +++ b/bpf/aya-bpf/src/args.rs @@ -135,14 +135,14 @@ impl FromPtRegs for *const T { impl FromPtRegs for *const T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 7 { - Some(ctx.regs.regs[n] as *const _) + Some(ctx.regs[n] as *const _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.regs.regs[0] as *const _) + Some(ctx.regs[0] as *const _) } } @@ -184,14 +184,14 @@ impl FromPtRegs for *mut T { impl FromPtRegs for *mut T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 7 { - Some(ctx.regs.regs[n] as *mut _) + Some(ctx.regs[n] as *mut _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.regs.regs[0] as *mut _) + Some(ctx.regs[0] as *mut _) } } @@ -236,14 +236,14 @@ macro_rules! impl_from_pt_regs { impl FromPtRegs for $type { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 7 { - Some(ctx.regs.regs[n] as *const $type as _) + Some(ctx.regs[n] as *const $type as _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.regs.regs[0] as *const $type as _) + Some(ctx.regs[0] as *const $type as _) } } }; From 218d4842d61bd6521d250602ca9a9503c9bbffeb Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 16:21:58 +0100 Subject: [PATCH 3/6] bpf: Be consistent with arm target_arch This is `arm` in bindings but `armv7` in args. Let's use `arm` Signed-off-by: Dave Tucker --- bpf/aya-bpf/src/args.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bpf/aya-bpf/src/args.rs b/bpf/aya-bpf/src/args.rs index db361bc8..a4599b44 100644 --- a/bpf/aya-bpf/src/args.rs +++ b/bpf/aya-bpf/src/args.rs @@ -116,7 +116,7 @@ impl FromPtRegs for *const T { } } -#[cfg(bpf_target_arch = "armv7")] +#[cfg(bpf_target_arch = "arm")] impl FromPtRegs for *const T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { @@ -165,7 +165,7 @@ impl FromPtRegs for *mut T { } } -#[cfg(bpf_target_arch = "armv7")] +#[cfg(bpf_target_arch = "arm")] impl FromPtRegs for *mut T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { @@ -217,7 +217,7 @@ macro_rules! impl_from_pt_regs { } } - #[cfg(bpf_target_arch = "armv7")] + #[cfg(bpf_target_arch = "arm")] impl FromPtRegs for $type { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { From 88834c497d0800048f01154b4a90ea13f79fb2e7 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 16:25:49 +0100 Subject: [PATCH 4/6] ci: Skip riscv64 for bpf There is a missing pt_regs implementation in args.rs Signed-off-by: Dave Tucker --- .github/workflows/build-aya-bpf.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-aya-bpf.yml b/.github/workflows/build-aya-bpf.yml index 3f16bcf9..c196c960 100644 --- a/.github/workflows/build-aya-bpf.yml +++ b/.github/workflows/build-aya-bpf.yml @@ -21,7 +21,8 @@ jobs: - x86_64 - aarch64 - arm - - riscv64 + # Disable riscv64 due to missing pt_regs handling in aya-bpf/args.rs + # - riscv64 runs-on: ubuntu-20.04 steps: From e3c8c659a1d1bce9a1ade60c8761b47893dc5e31 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 16:43:23 +0100 Subject: [PATCH 5/6] bpf: arm fix pt_regs handling Signed-off-by: Dave Tucker --- bpf/aya-bpf/src/args.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bpf/aya-bpf/src/args.rs b/bpf/aya-bpf/src/args.rs index a4599b44..8929c7a3 100644 --- a/bpf/aya-bpf/src/args.rs +++ b/bpf/aya-bpf/src/args.rs @@ -120,14 +120,14 @@ impl FromPtRegs for *const T { impl FromPtRegs for *const T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { - Some(ctx.uregs.regs[n] as *const _) + Some(ctx.uregs[n] as *const _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.uregs.regs[0] as *const _) + Some(ctx.uregs[0] as *const _) } } @@ -169,14 +169,14 @@ impl FromPtRegs for *mut T { impl FromPtRegs for *mut T { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { - Some(ctx.uregs.regs[n] as *mut _) + Some(ctx.uregs[n] as *mut _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.uregs.regs[0] as *mut _) + Some(ctx.uregs[0] as *mut _) } } @@ -221,14 +221,14 @@ macro_rules! impl_from_pt_regs { impl FromPtRegs for $type { fn from_argument(ctx: &pt_regs, n: usize) -> Option { if n <= 6 { - Some(ctx.uregs.regs[n] as *const $type as _) + Some(ctx.uregs[n] as *const $type as _) } else { None } } fn from_retval(ctx: &pt_regs) -> Option { - Some(ctx.uregs.regs[0] as *const $type as _) + Some(ctx.uregs[0] as *const $type as _) } } From c725e72796b3ca845c234416348a6e8ab8cf1b0d Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 7 Jun 2022 17:53:40 +0100 Subject: [PATCH 6/6] bpf: re-reun build.rs if env changed Signed-off-by: Dave Tucker --- bpf/aya-bpf-bindings/build.rs | 1 + bpf/aya-bpf-cty/build.rs | 1 + bpf/aya-bpf/build.rs | 1 + 3 files changed, 3 insertions(+) diff --git a/bpf/aya-bpf-bindings/build.rs b/bpf/aya-bpf-bindings/build.rs index 3029c4b0..a8a2c261 100644 --- a/bpf/aya-bpf-bindings/build.rs +++ b/bpf/aya-bpf-bindings/build.rs @@ -1,6 +1,7 @@ use std::env; fn main() { + println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); } else { diff --git a/bpf/aya-bpf-cty/build.rs b/bpf/aya-bpf-cty/build.rs index 3029c4b0..a8a2c261 100644 --- a/bpf/aya-bpf-cty/build.rs +++ b/bpf/aya-bpf-cty/build.rs @@ -1,6 +1,7 @@ use std::env; fn main() { + println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); } else { diff --git a/bpf/aya-bpf/build.rs b/bpf/aya-bpf/build.rs index 3029c4b0..a8a2c261 100644 --- a/bpf/aya-bpf/build.rs +++ b/bpf/aya-bpf/build.rs @@ -1,6 +1,7 @@ use std::env; fn main() { + println!("cargo:rerun-if-env-changed=CARGO_CFG_BPF_TARGET_ARCH"); if let Ok(arch) = env::var("CARGO_CFG_BPF_TARGET_ARCH") { println!("cargo:rustc-cfg=bpf_target_arch=\"{}\"", arch); } else {