Skip to content

Commit 3303dcf

Browse files
committed
Clear RUSTUP_TOOLCHAIN in generate_idl
1 parent 7f32a71 commit 3303dcf

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/anchor_cli_lib/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,12 +339,30 @@ fn generate_idl(
339339
) -> Result<Idl> {
340340
check_idl_build_feature()?;
341341

342-
anchor_lang_idl::build::IdlBuilder::new()
342+
// smoelius: If `RUSTUP_TOOLCHAIN` is not cleared, `Span::unwrap` might not be found in
343+
// `proc-macro2`. The affected code is in `anchor-syn`:
344+
// https://github.com/solana-foundation/anchor/blob/38f2b554b2dc6632376241f94048639eaf33d7bd/lang/syn/src/idl/defined.rs#L498-L502
345+
let rustup_toolchain = std::env::var_os("RUSTUP_TOOLCHAIN");
346+
if rustup_toolchain.is_some() {
347+
unsafe {
348+
std::env::remove_var("RUSTUP_TOOLCHAIN");
349+
}
350+
}
351+
352+
let result = anchor_lang_idl::build::IdlBuilder::new()
343353
.resolution(cfg.features.resolution)
344354
.skip_lint(cfg.features.skip_lint || skip_lint)
345355
.no_docs(no_docs)
346356
.cargo_args(cargo_args.into())
347-
.build()
357+
.build();
358+
359+
if let Some(rustup_toolchain) = rustup_toolchain {
360+
unsafe {
361+
std::env::set_var("RUSTUP_TOOLCHAIN", rustup_toolchain);
362+
}
363+
}
364+
365+
result
348366
}
349367

350368
fn idl_ts(idl: &Idl) -> Result<String> {

0 commit comments

Comments
 (0)