|
| 1 | +diff --git a/cli/src/lib.rs b/cli/src/lib.rs |
| 2 | +index 3404b032..34b08dac 100644 |
| 3 | +--- a/cli/src/lib.rs |
| 4 | ++++ b/cli/src/lib.rs |
| 5 | +@@ -11,7 +11,6 @@ use anchor_lang_idl::types::{Idl, IdlArrayLen, IdlDefinedFields, IdlType, IdlTyp |
| 6 | + use anyhow::{anyhow, Context, Result}; |
| 7 | + use checks::{check_anchor_version, check_deps, check_idl_build_feature, check_overflow}; |
| 8 | + use clap::{CommandFactory, Parser}; |
| 9 | +-use dirs::home_dir; |
| 10 | + use flate2::read::GzDecoder; |
| 11 | + use flate2::read::ZlibDecoder; |
| 12 | + use flate2::write::{GzEncoder, ZlibEncoder}; |
| 13 | +@@ -552,7 +551,7 @@ type RestoreToolchainCallbacks = Vec<Box<dyn FnOnce() -> Result<()>>>; |
| 14 | + /// |
| 15 | + /// Returns the previous versions to restore back to. |
| 16 | + fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainCallbacks> { |
| 17 | +- let mut restore_cbs: RestoreToolchainCallbacks = vec![]; |
| 18 | ++ let restore_cbs: RestoreToolchainCallbacks = vec![]; |
| 19 | + |
| 20 | + let cfg = Config::discover(cfg_override)?; |
| 21 | + if let Some(cfg) = cfg { |
| 22 | +@@ -584,88 +583,7 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC |
| 23 | + if let Some(solana_version) = &cfg.toolchain.solana_version { |
| 24 | + let current_version = get_current_version("solana")?; |
| 25 | + if solana_version != ¤t_version { |
| 26 | +- // We are overriding with `solana-install` command instead of using the binaries |
| 27 | +- // from `~/.local/share/solana/install/releases` because we use multiple Solana |
| 28 | +- // binaries in various commands. |
| 29 | +- fn override_solana_version(version: String) -> Result<bool> { |
| 30 | +- // There is a deprecation warning message starting with `1.18.19` which causes |
| 31 | +- // parsing problems https://github.com/coral-xyz/anchor/issues/3147 |
| 32 | +- let (cmd_name, domain) = |
| 33 | +- if Version::parse(&version)? < Version::parse("1.18.19")? { |
| 34 | +- ("solana-install", "solana.com") |
| 35 | +- } else { |
| 36 | +- ("agave-install", "anza.xyz") |
| 37 | +- }; |
| 38 | +- |
| 39 | +- // Install the command if it's not installed |
| 40 | +- if get_current_version(cmd_name).is_err() { |
| 41 | +- // `solana-install` and `agave-install` are not usable at the same time i.e. |
| 42 | +- // using one of them makes the other unusable with the default installation, |
| 43 | +- // causing the installation process to run each time users switch between |
| 44 | +- // `agave` supported versions. For example, if the user's active Solana |
| 45 | +- // version is `1.18.17`, and he specifies `solana_version = "2.0.6"`, this |
| 46 | +- // code path will run each time an Anchor command gets executed. |
| 47 | +- eprintln!( |
| 48 | +- "Command not installed: `{cmd_name}`. \ |
| 49 | +- See https://github.com/anza-xyz/agave/wiki/Agave-Transition, \ |
| 50 | +- installing..." |
| 51 | +- ); |
| 52 | +- let install_script = std::process::Command::new("curl") |
| 53 | +- .args([ |
| 54 | +- "-sSfL", |
| 55 | +- &format!("https://release.{domain}/v{version}/install"), |
| 56 | +- ]) |
| 57 | +- .output()?; |
| 58 | +- let is_successful = std::process::Command::new("sh") |
| 59 | +- .args(["-c", std::str::from_utf8(&install_script.stdout)?]) |
| 60 | +- .spawn()? |
| 61 | +- .wait_with_output()? |
| 62 | +- .status |
| 63 | +- .success(); |
| 64 | +- if !is_successful { |
| 65 | +- return Err(anyhow!("Failed to install `{cmd_name}`")); |
| 66 | +- } |
| 67 | +- } |
| 68 | +- |
| 69 | +- let output = std::process::Command::new(cmd_name).arg("list").output()?; |
| 70 | +- if !output.status.success() { |
| 71 | +- return Err(anyhow!("Failed to list installed `solana` versions")); |
| 72 | +- } |
| 73 | +- |
| 74 | +- // Hide the installation progress if the version is already installed |
| 75 | +- let is_installed = std::str::from_utf8(&output.stdout)? |
| 76 | +- .lines() |
| 77 | +- .filter_map(parse_version) |
| 78 | +- .any(|line_version| line_version == version); |
| 79 | +- let (stderr, stdout) = if is_installed { |
| 80 | +- (Stdio::null(), Stdio::null()) |
| 81 | +- } else { |
| 82 | +- (Stdio::inherit(), Stdio::inherit()) |
| 83 | +- }; |
| 84 | +- |
| 85 | +- std::process::Command::new(cmd_name) |
| 86 | +- .arg("init") |
| 87 | +- .arg(&version) |
| 88 | +- .stderr(stderr) |
| 89 | +- .stdout(stdout) |
| 90 | +- .spawn()? |
| 91 | +- .wait() |
| 92 | +- .map(|status| status.success()) |
| 93 | +- .map_err(|err| anyhow!("Failed to run `{cmd_name}` command: {err}")) |
| 94 | +- } |
| 95 | +- |
| 96 | +- match override_solana_version(solana_version.to_owned())? { |
| 97 | +- true => restore_cbs.push(Box::new(|| { |
| 98 | +- match override_solana_version(current_version)? { |
| 99 | +- true => Ok(()), |
| 100 | +- false => Err(anyhow!("Failed to restore `solana` version")), |
| 101 | +- } |
| 102 | +- })), |
| 103 | +- false => eprintln!( |
| 104 | +- "Failed to override `solana` version to {solana_version}, \ |
| 105 | +- using {current_version} instead" |
| 106 | +- ), |
| 107 | +- } |
| 108 | ++ return Err(anyhow!("Current Solana version `{current_version}` does not match configured version `{solana_version}`")); |
| 109 | + } |
| 110 | + } |
| 111 | + |
| 112 | +@@ -688,40 +606,7 @@ fn override_toolchain(cfg_override: &ConfigOverride) -> Result<RestoreToolchainC |
| 113 | + .unwrap_or(VERSION) |
| 114 | + .to_owned(); |
| 115 | + if anchor_version != ¤t_version { |
| 116 | +- let binary_path = home_dir() |
| 117 | +- .unwrap() |
| 118 | +- .join(".avm") |
| 119 | +- .join("bin") |
| 120 | +- .join(format!("{ANCHOR_BINARY_PREFIX}{anchor_version}")); |
| 121 | +- |
| 122 | +- if !binary_path.exists() { |
| 123 | +- eprintln!( |
| 124 | +- "`anchor` {anchor_version} is not installed with `avm`. Installing...\n" |
| 125 | +- ); |
| 126 | +- |
| 127 | +- let exit_status = std::process::Command::new("avm") |
| 128 | +- .arg("install") |
| 129 | +- .arg(anchor_version) |
| 130 | +- .spawn()? |
| 131 | +- .wait()?; |
| 132 | +- if !exit_status.success() { |
| 133 | +- eprintln!( |
| 134 | +- "Failed to install `anchor` {anchor_version}, \ |
| 135 | +- using {current_version} instead" |
| 136 | +- ); |
| 137 | +- |
| 138 | +- return Ok(restore_cbs); |
| 139 | +- } |
| 140 | +- } |
| 141 | +- |
| 142 | +- let exit_code = std::process::Command::new(binary_path) |
| 143 | +- .args(std::env::args_os().skip(1)) |
| 144 | +- .spawn()? |
| 145 | +- .wait()? |
| 146 | +- .code() |
| 147 | +- .unwrap_or(1); |
| 148 | +- restore_toolchain(restore_cbs)?; |
| 149 | +- std::process::exit(exit_code); |
| 150 | ++ return Err(anyhow!("Current Anchor version `{current_version}` does not match configured version `{anchor_version}`")); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | +diff --git a/idl/src/build.rs b/idl/src/build.rs |
| 155 | +index ccd89745..3c958377 100644 |
| 156 | +--- a/idl/src/build.rs |
| 157 | ++++ b/idl/src/build.rs |
| 158 | +@@ -139,14 +139,18 @@ fn build( |
| 159 | + cargo_args: &[String], |
| 160 | + ) -> Result<Idl> { |
| 161 | + // `nightly` toolchain is currently required for building the IDL. |
| 162 | +- let toolchain = std::env::var("RUSTUP_TOOLCHAIN") |
| 163 | +- .map(|toolchain| format!("+{}", toolchain)) |
| 164 | +- .unwrap_or_else(|_| "+nightly".to_string()); |
| 165 | ++ let cargo_path = std::env::var("RUST_NIGHTLY_BIN") |
| 166 | ++ .map(|bin| format!("{}/cargo", bin)) |
| 167 | ++ .unwrap_or_else(|_| "cargo".to_string()); |
| 168 | + |
| 169 | +- install_toolchain_if_needed(&toolchain)?; |
| 170 | +- let output = Command::new("cargo") |
| 171 | ++ eprintln!("Cargo at {}", cargo_path); |
| 172 | ++ |
| 173 | ++ let mut command = Command::new(cargo_path); |
| 174 | ++ if let Ok(toolchain) = std::env::var("RUSTUP_TOOLCHAIN") { |
| 175 | ++ command.arg(&format!("+{}", toolchain)); |
| 176 | ++ } |
| 177 | ++ let output = command |
| 178 | + .args([ |
| 179 | +- &toolchain, |
| 180 | + "test", |
| 181 | + "__anchor_private_print_idl", |
| 182 | + "--features", |
| 183 | +@@ -283,23 +287,6 @@ fn build( |
| 184 | + idl.ok_or_else(|| anyhow!("IDL doesn't exist")) |
| 185 | + } |
| 186 | + |
| 187 | +-/// Install the given toolchain if it's not already installed. |
| 188 | +-fn install_toolchain_if_needed(toolchain: &str) -> Result<()> { |
| 189 | +- let is_installed = Command::new("cargo") |
| 190 | +- .arg(toolchain) |
| 191 | +- .output()? |
| 192 | +- .status |
| 193 | +- .success(); |
| 194 | +- if !is_installed { |
| 195 | +- Command::new("rustup") |
| 196 | +- .args(["toolchain", "install", toolchain.trim_start_matches('+')]) |
| 197 | +- .spawn()? |
| 198 | +- .wait()?; |
| 199 | +- } |
| 200 | +- |
| 201 | +- Ok(()) |
| 202 | +-} |
| 203 | +- |
| 204 | + /// Convert paths to name if there are no conflicts. |
| 205 | + fn convert_module_paths(idl: Idl) -> Idl { |
| 206 | + let idl = serde_json::to_string(&idl).unwrap(); |
0 commit comments