Skip to content

Commit 4cc1402

Browse files
authored
aya-build: honor RUSTC_BOOTSTRAP
Use `RUSTC_BOOTSTRAP` when deciding whether to pass `-Zbuild-std=core`. This keeps eBPF builds working in environments without rustup where a stable toolchain is used with bootstrap enabled to allow unstable features. It also preserves `-1` as an explicit opt-out and accepts crate-scoped bootstrap values.
1 parent b93ee8c commit 4cc1402

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

aya-build/src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ pub fn build_ebpf<'a>(
121121
} = rustc_version::VersionMeta::for_command(cmd("rustc"))
122122
.context("failed to get rustc version meta")?;
123123

124+
let rustc_bootstrap = env::var_os("RUSTC_BOOTSTRAP");
125+
124126
for Package {
125127
name,
126128
root_dir,
@@ -146,7 +148,26 @@ pub fn build_ebpf<'a>(
146148
&target,
147149
]);
148150

149-
if channel == Channel::Nightly {
151+
// RUSTC_BOOTSTRAP controls whether unstable features (-Z flags) are available:
152+
// "1" – enable for all crates
153+
// "<crate>" – enable only for the named crate
154+
// "-1" – force stable behavior even on nightly (explicit opt-out)
155+
// (unset/other) – follow the actual compiler channel
156+
// See: https://doc.rust-lang.org/beta/unstable-book/compiler-environment-variables/RUSTC_BOOTSTRAP.html
157+
let use_build_std = match rustc_bootstrap.as_ref() {
158+
Some(rustc_bootstrap) => {
159+
if rustc_bootstrap == "1" || rustc_bootstrap == name {
160+
true
161+
} else if rustc_bootstrap == "-1" {
162+
false
163+
} else {
164+
channel == Channel::Nightly
165+
}
166+
}
167+
None => channel == Channel::Nightly,
168+
};
169+
170+
if use_build_std {
150171
cmd.args(["-Z", "build-std=core"]);
151172
}
152173

0 commit comments

Comments
 (0)