aya-build: Allow setting Rust nightly version

At present, `aya_build` will always use `+nightly` to build the
eBPF kernel. This is problematic in environments such as CI, where
tools always need to be installed first. Installing the current
nightly Rust toolchain gives you a new toolchain every day. This
poisones caches and makes CI jobs non-deterministic.

Resolves: #1226
reviewable/pr1236/r1
Thomas Eizinger 3 weeks ago committed by Tamir Duberstein
parent 816f6d8a25
commit 6d36fe13d3

@ -22,7 +22,7 @@ use cargo_metadata::{Artifact, CompilerMessage, Message, Package, Target};
/// prevent their use for the time being.
///
/// [bindeps]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html?highlight=feature#artifact-dependencies
pub fn build_ebpf(packages: impl IntoIterator<Item = Package>) -> Result<()> {
pub fn build_ebpf(packages: impl IntoIterator<Item = Package>, toolchain: Toolchain) -> Result<()> {
let out_dir = env::var_os("OUT_DIR").ok_or(anyhow!("OUT_DIR not set"))?;
let out_dir = PathBuf::from(out_dir);
@ -57,9 +57,11 @@ pub fn build_ebpf(packages: impl IntoIterator<Item = Package>) -> Result<()> {
// changes to the binaries too, which gets us the rest of the way.
println!("cargo:rerun-if-changed={dir}");
let mut cmd = Command::new("cargo");
let mut cmd = Command::new("rustup");
cmd.args([
"+nightly",
"run",
toolchain.as_str(),
"cargo",
"build",
"--package",
&name,
@ -147,3 +149,24 @@ pub fn build_ebpf(packages: impl IntoIterator<Item = Package>) -> Result<()> {
}
Ok(())
}
/// The toolchain to use for building eBPF programs.
#[derive(Default)]
pub enum Toolchain<'a> {
/// The latest nightly toolchain i.e. `nightly`.
#[default]
Nightly,
/// A custom toolchain e.g. `nightly-2021-01-01`.
///
/// The toolchain specifier is passed to `rustup run` and therefore should _not_ have a preceding `+`.
Custom(&'a str),
}
impl<'a> Toolchain<'a> {
fn as_str(&self) -> &'a str {
match self {
Toolchain::Nightly => "nightly",
Toolchain::Custom(toolchain) => toolchain,
}
}
}

@ -182,7 +182,7 @@ fn main() -> Result<()> {
}
}
aya_build::build_ebpf([integration_ebpf_package])?;
aya_build::build_ebpf([integration_ebpf_package], aya_build::Toolchain::default())?;
} else {
for (src, build_btf) in C_BPF {
let dst = out_dir.join(src).with_extension("o");

@ -1,3 +1,30 @@
pub mod aya_build
pub use aya_build::cargo_metadata
pub fn aya_build::build_ebpf(packages: impl core::iter::traits::collect::IntoIterator<Item = cargo_metadata::Package>) -> anyhow::Result<()>
pub enum aya_build::Toolchain<'a>
pub aya_build::Toolchain::Custom(&'a str)
pub aya_build::Toolchain::Nightly
impl<'a> core::default::Default for aya_build::Toolchain<'a>
pub fn aya_build::Toolchain<'a>::default() -> aya_build::Toolchain<'a>
impl<'a> core::marker::Freeze for aya_build::Toolchain<'a>
impl<'a> core::marker::Send for aya_build::Toolchain<'a>
impl<'a> core::marker::Sync for aya_build::Toolchain<'a>
impl<'a> core::marker::Unpin for aya_build::Toolchain<'a>
impl<'a> core::panic::unwind_safe::RefUnwindSafe for aya_build::Toolchain<'a>
impl<'a> core::panic::unwind_safe::UnwindSafe for aya_build::Toolchain<'a>
impl<T, U> core::convert::Into<U> for aya_build::Toolchain<'a> where U: core::convert::From<T>
pub fn aya_build::Toolchain<'a>::into(self) -> U
impl<T, U> core::convert::TryFrom<U> for aya_build::Toolchain<'a> where U: core::convert::Into<T>
pub type aya_build::Toolchain<'a>::Error = core::convert::Infallible
pub fn aya_build::Toolchain<'a>::try_from(value: U) -> core::result::Result<T, <T as core::convert::TryFrom<U>>::Error>
impl<T, U> core::convert::TryInto<U> for aya_build::Toolchain<'a> where U: core::convert::TryFrom<T>
pub type aya_build::Toolchain<'a>::Error = <U as core::convert::TryFrom<T>>::Error
pub fn aya_build::Toolchain<'a>::try_into(self) -> core::result::Result<U, <U as core::convert::TryFrom<T>>::Error>
impl<T> core::any::Any for aya_build::Toolchain<'a> where T: 'static + ?core::marker::Sized
pub fn aya_build::Toolchain<'a>::type_id(&self) -> core::any::TypeId
impl<T> core::borrow::Borrow<T> for aya_build::Toolchain<'a> where T: ?core::marker::Sized
pub fn aya_build::Toolchain<'a>::borrow(&self) -> &T
impl<T> core::borrow::BorrowMut<T> for aya_build::Toolchain<'a> where T: ?core::marker::Sized
pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T
impl<T> core::convert::From<T> for aya_build::Toolchain<'a>
pub fn aya_build::Toolchain<'a>::from(t: T) -> T
pub fn aya_build::build_ebpf(packages: impl core::iter::traits::collect::IntoIterator<Item = cargo_metadata::Package>, toolchain: aya_build::Toolchain<'_>) -> anyhow::Result<()>

Loading…
Cancel
Save