From fb3f2b0977c13587b714bdfed6818a2093b34322 Mon Sep 17 00:00:00 2001 From: L0STE <125566964+L0STE@users.noreply.github.com> Date: Fri, 27 Mar 2026 17:08:06 +0100 Subject: [PATCH] fix: use real cfg gates instead of faking target_os="solana" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The scaffold template injected `--cfg target_os="solana"` into rustflags for the `bpfel-unknown-none` target, lying about the actual target OS. Newer nightly rustc rejects this with `explicit_builtin_cfgs_in_flags`. Instead, gate on `target_arch = "bpf"` (the real cfg for bpfel-unknown-none) alongside the existing `target_os = "solana"` (real for sbf-solana-solana). This matches the pattern already used in ~30 other cfg sites across the codebase — the entrypoint, sysvar macro, and string accessors were the only stragglers. Closes #95 Closes #96 --- cli/src/init/templates.rs | 1 - derive/src/account/accessors.rs | 8 ++++---- derive/src/program.rs | 2 +- lang/src/sysvars/mod.rs | 4 ++-- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/cli/src/init/templates.rs b/cli/src/init/templates.rs index 0c954fd3..3c3dd3dc 100644 --- a/cli/src/init/templates.rs +++ b/cli/src/init/templates.rs @@ -22,7 +22,6 @@ build-std = ["core", "alloc"] [target.bpfel-unknown-none] rustflags = [ -"--cfg", "target_os=\"solana\"", "--cfg", "feature=\"mem_unaligned\"", "-C", "linker=sbpf-linker", "-C", "panic=abort", diff --git a/derive/src/account/accessors.rs b/derive/src/account/accessors.rs index 428d1741..7fed3654 100644 --- a/derive/src/account/accessors.rs +++ b/derive/src/account/accessors.rs @@ -63,9 +63,9 @@ pub(super) fn generate_accessors( let __len = #read; let __start = __offset + #pb; let __bytes = &__data[__start..__start + __len]; - #[cfg(target_os = "solana")] + #[cfg(any(target_os = "solana", target_arch = "bpf"))] { unsafe { core::str::from_utf8_unchecked(__bytes) } } - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] { core::str::from_utf8(__bytes).expect("account string field contains invalid UTF-8") } } } @@ -93,9 +93,9 @@ pub(super) fn generate_accessors( let __data = unsafe { self.__view.borrow_unchecked() }; let __offset = #off_expr; let __bytes = &__data[__offset..]; - #[cfg(target_os = "solana")] + #[cfg(any(target_os = "solana", target_arch = "bpf"))] { unsafe { core::str::from_utf8_unchecked(__bytes) } } - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] { core::str::from_utf8(__bytes).expect("account tail field contains invalid UTF-8") } } } diff --git a/derive/src/program.rs b/derive/src/program.rs index 216010a2..7a4c27a4 100644 --- a/derive/src/program.rs +++ b/derive/src/program.rs @@ -260,7 +260,7 @@ pub(crate) fn program(_attr: TokenStream, item: TokenStream) -> TokenStream { items.push(syn::parse_quote! { #[unsafe(no_mangle)] - #[cfg(target_os = "solana")] + #[cfg(any(target_os = "solana", target_arch = "bpf"))] #[allow(unexpected_cfgs)] pub unsafe extern "C" fn entrypoint(ptr: *mut u8, instruction_data: *const u8) -> u64 { // SAFETY: Initialize bump allocator cursor. The SVM maps and zero-inits the heap diff --git a/lang/src/sysvars/mod.rs b/lang/src/sysvars/mod.rs index 438639d8..ebd98c88 100644 --- a/lang/src/sysvars/mod.rs +++ b/lang/src/sysvars/mod.rs @@ -46,7 +46,7 @@ macro_rules! impl_sysvar_get { let mut var = core::mem::MaybeUninit::::uninit(); let var_addr = var.as_mut_ptr() as *mut _ as *mut u8; - #[cfg(target_os = "solana")] + #[cfg(any(target_os = "solana", target_arch = "bpf"))] // SAFETY: `var_addr` points to `MaybeUninit` which has // enough space. The syscall writes `length` bytes; we zero the // trailing `$padding` bytes so the full struct is initialized. @@ -61,7 +61,7 @@ macro_rules! impl_sysvar_get { ) }; - #[cfg(not(target_os = "solana"))] + #[cfg(not(any(target_os = "solana", target_arch = "bpf")))] let result = { // SAFETY: Zero-init the full struct for off-chain use. unsafe { var_addr.write_bytes(0, core::mem::size_of::()) };