Browse Source

idl: Allow toolchain overriding in `idl build` command (#2941)

skrrb 1 year ago
parent
commit
645ab6dca7
2 changed files with 7 additions and 3 deletions
  1. 1 0
      CHANGELOG.md
  2. 6 3
      idl/src/build.rs

+ 1 - 0
CHANGELOG.md

@@ -12,6 +12,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 
 ### Features
 
+- idl: Allow overriding the idl build toolchain with the `RUSTUP_TOOLCHAIN` environment variable ([#2941](https://github.com/coral-xyz/anchor/pull/2941]))
 - avm: Support customizing the installation location using `AVM_HOME` environment variable ([#2917](https://github.com/coral-xyz/anchor/pull/2917))
 - idl, ts: Add accounts resolution for associated token accounts ([#2927](https://github.com/coral-xyz/anchor/pull/2927))
 

+ 6 - 3
idl/src/build.rs

@@ -70,12 +70,15 @@ pub fn build_idl(
 /// Build IDL.
 fn build(program_path: &Path, resolution: bool, no_docs: bool) -> Result<Idl> {
     // `nightly` toolchain is currently required for building the IDL.
-    const TOOLCHAIN: &str = "+nightly";
-    install_toolchain_if_needed(TOOLCHAIN)?;
+    let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
+        .map(|toolchain| format!("+{}", toolchain))
+        .unwrap_or_else(|_| "+nightly".to_string());
+
+    install_toolchain_if_needed(&toolchain)?;
 
     let output = Command::new("cargo")
         .args([
-            TOOLCHAIN,
+            &toolchain,
             "test",
             "__anchor_private_print_idl",
             "--features",