diff --git a/aya-build/src/lib.rs b/aya-build/src/lib.rs index 310a30ac..04b94dcd 100644 --- a/aya-build/src/lib.rs +++ b/aya-build/src/lib.rs @@ -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) -> Result<()> { +pub fn build_ebpf(packages: impl IntoIterator, 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) -> 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) -> 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, + } + } +} diff --git a/test/integration-test/build.rs b/test/integration-test/build.rs index 2caea5a4..29e41dda 100644 --- a/test/integration-test/build.rs +++ b/test/integration-test/build.rs @@ -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"); diff --git a/xtask/public-api/aya-build.txt b/xtask/public-api/aya-build.txt index 9a55017f..f5db5050 100644 --- a/xtask/public-api/aya-build.txt +++ b/xtask/public-api/aya-build.txt @@ -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) -> 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 core::convert::Into for aya_build::Toolchain<'a> where U: core::convert::From +pub fn aya_build::Toolchain<'a>::into(self) -> U +impl core::convert::TryFrom for aya_build::Toolchain<'a> where U: core::convert::Into +pub type aya_build::Toolchain<'a>::Error = core::convert::Infallible +pub fn aya_build::Toolchain<'a>::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_build::Toolchain<'a> where U: core::convert::TryFrom +pub type aya_build::Toolchain<'a>::Error = >::Error +pub fn aya_build::Toolchain<'a>::try_into(self) -> core::result::Result>::Error> +impl 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 core::borrow::Borrow for aya_build::Toolchain<'a> where T: ?core::marker::Sized +pub fn aya_build::Toolchain<'a>::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_build::Toolchain<'a> where T: ?core::marker::Sized +pub fn aya_build::Toolchain<'a>::borrow_mut(&mut self) -> &mut T +impl core::convert::From 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, toolchain: aya_build::Toolchain<'_>) -> anyhow::Result<()>