From 32a41fa661a0b25a7dfa722b95d2317e5a417785 Mon Sep 17 00:00:00 2001 From: Michal Rostecki Date: Sun, 22 Jan 2023 21:57:33 +0800 Subject: [PATCH] examples: Honor rust-toolchain.toml file in xtask Signed-off-by: Michal Rostecki --- examples/aya-tool/xtask/src/build_ebpf.rs | 7 ++++++- examples/cgroup-skb-egress/xtask/src/build_ebpf.rs | 7 ++++++- examples/kprobetcp/xtask/src/build_ebpf.rs | 7 ++++++- examples/lsm-nice/xtask/src/build_ebpf.rs | 7 ++++++- examples/tc-egress/xtask/src/build_ebpf.rs | 7 ++++++- examples/xdp-drop/xtask/src/build_ebpf.rs | 7 ++++++- examples/xdp-hello/xtask/src/build_ebpf.rs | 7 ++++++- examples/xdp-log/xtask/src/build_ebpf.rs | 7 ++++++- 8 files changed, 48 insertions(+), 8 deletions(-) diff --git a/examples/aya-tool/xtask/src/build_ebpf.rs b/examples/aya-tool/xtask/src/build_ebpf.rs index f541371..e7507cc 100644 --- a/examples/aya-tool/xtask/src/build_ebpf.rs +++ b/examples/aya-tool/xtask/src/build_ebpf.rs @@ -43,7 +43,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("myapp-ebpf"); let target = format!("--target={}", opts.target); let args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -52,8 +51,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { "--profile", opts.profile.as_str(), ]; + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/cgroup-skb-egress/xtask/src/build_ebpf.rs b/examples/cgroup-skb-egress/xtask/src/build_ebpf.rs index 983055a..81de1ee 100644 --- a/examples/cgroup-skb-egress/xtask/src/build_ebpf.rs +++ b/examples/cgroup-skb-egress/xtask/src/build_ebpf.rs @@ -44,7 +44,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("cgroup-skb-egress-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -54,8 +53,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/kprobetcp/xtask/src/build_ebpf.rs b/examples/kprobetcp/xtask/src/build_ebpf.rs index 26fa19d..9b514a2 100644 --- a/examples/kprobetcp/xtask/src/build_ebpf.rs +++ b/examples/kprobetcp/xtask/src/build_ebpf.rs @@ -43,7 +43,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("kprobetcp-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -53,8 +52,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/lsm-nice/xtask/src/build_ebpf.rs b/examples/lsm-nice/xtask/src/build_ebpf.rs index e2e6324..200096a 100644 --- a/examples/lsm-nice/xtask/src/build_ebpf.rs +++ b/examples/lsm-nice/xtask/src/build_ebpf.rs @@ -43,7 +43,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("lsm-nice-ebpf"); let target = format!("--target={}", opts.target); let args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -52,8 +51,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { "--profile", opts.profile.as_str(), ]; + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/tc-egress/xtask/src/build_ebpf.rs b/examples/tc-egress/xtask/src/build_ebpf.rs index 557d0e8..90c2b9b 100644 --- a/examples/tc-egress/xtask/src/build_ebpf.rs +++ b/examples/tc-egress/xtask/src/build_ebpf.rs @@ -44,7 +44,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("tc-egress-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -54,8 +53,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/xdp-drop/xtask/src/build_ebpf.rs b/examples/xdp-drop/xtask/src/build_ebpf.rs index 09decf2..ee527d5 100644 --- a/examples/xdp-drop/xtask/src/build_ebpf.rs +++ b/examples/xdp-drop/xtask/src/build_ebpf.rs @@ -44,7 +44,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("xdp-drop-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -54,8 +53,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/xdp-hello/xtask/src/build_ebpf.rs b/examples/xdp-hello/xtask/src/build_ebpf.rs index e6f157e..3f14eec 100644 --- a/examples/xdp-hello/xtask/src/build_ebpf.rs +++ b/examples/xdp-hello/xtask/src/build_ebpf.rs @@ -44,7 +44,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("xdp-hello-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -54,8 +53,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program"); diff --git a/examples/xdp-log/xtask/src/build_ebpf.rs b/examples/xdp-log/xtask/src/build_ebpf.rs index 9e1f288..c476ade 100644 --- a/examples/xdp-log/xtask/src/build_ebpf.rs +++ b/examples/xdp-log/xtask/src/build_ebpf.rs @@ -44,7 +44,6 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { let dir = PathBuf::from("xdp-log-ebpf"); let target = format!("--target={}", opts.target); let mut args = vec![ - "+nightly", "build", "--verbose", target.as_str(), @@ -54,8 +53,14 @@ pub fn build_ebpf(opts: Options) -> Result<(), anyhow::Error> { if opts.release { args.push("--release") } + + // Command::new creates a child process which inherits all env variables. This means env + // vars set by the cargo xtask command are also inherited. RUSTUP_TOOLCHAIN is removed + // so the rust-toolchain.toml file in the -ebpf folder is honored. + let status = Command::new("cargo") .current_dir(&dir) + .env_remove("RUSTUP_TOOLCHAIN") .args(&args) .status() .expect("failed to build bpf program");