Skip to content

Commit 0df46fa

Browse files
authored
Merge pull request #3 from joncinque/v2.2
Update to Agave v2.2
2 parents 43f351d + b77a86d commit 0df46fa

File tree

8 files changed

+207
-175
lines changed

8 files changed

+207
-175
lines changed

anchor-cli.nix

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
, udev
1313
}:
1414
let
15-
# Anchor does not declare a rust-toolchain, so we have to do it here -- the
16-
# old dependency on the `time` crate doesn't support Rust versions >= 1.80.
15+
# nixpkgs 24.11 defaults to Rust v1.82.0
16+
# Anchor does not declare a rust-toolchain, so we do it here -- the code
17+
# mentions Rust 1.85.0 at https://github.com/coral-xyz/anchor/blob/c509618412e004415c7b090e469a9e4d5177f642/docs/content/docs/installation.mdx?plain=1#L31
1718
rustPlatform = makeRustPlatform {
18-
cargo = rust-bin.stable."1.79.0".default;
19-
rustc = rust-bin.stable."1.79.0".default;
19+
cargo = rust-bin.stable."1.85.0".default;
20+
rustc = rust-bin.stable."1.85.0".default;
2021
};
2122
in
2223
rustPlatform.buildRustPackage rec {
2324
pname = "anchor-cli";
24-
version = "0.30.1";
25+
version = "0.31.0";
2526

2627
doCheck = false;
2728

@@ -37,7 +38,7 @@ rustPlatform.buildRustPackage rec {
3738
owner = "coral-xyz";
3839
repo = "anchor";
3940
rev = "v${version}";
40-
hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw=";
41+
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
4142
};
4243

4344
cargoLock = {
@@ -49,15 +50,15 @@ rustPlatform.buildRustPackage rec {
4950
./anchor-cli.patch
5051
];
5152

52-
buildAndTestSubdir = "cli";
53-
54-
# Ensure anchor has access to Solana's cargo and rust binaries
53+
# Ensure anchor has access to Solana's cargo and rust binaries
5554
postInstall = ''
56-
rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin
55+
rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin
5756
wrapProgram $out/bin/anchor \
5857
--prefix PATH : "$rust"
5958
'';
6059

60+
buildAndTestSubdir = "cli";
61+
6162
meta = {
6263
description = "Anchor cli";
6364
};

anchor-cli.patch

Lines changed: 166 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,185 @@
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 != &current_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 != &current_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+
}
1154
diff --git a/idl/src/build.rs b/idl/src/build.rs
2-
index 96dc3db2..1b098718 100644
155+
index ccd89745..a4edf8a5 100644
3156
--- a/idl/src/build.rs
4157
+++ b/idl/src/build.rs
5-
@@ -60,16 +60,8 @@ pub fn build_idl(
6-
7-
/// Build IDL.
8-
fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool) -> Result<Idl> {
158+
@@ -138,15 +138,12 @@ fn build(
159+
no_docs: bool,
160+
cargo_args: &[String],
161+
) -> Result<Idl> {
9162
- // `nightly` toolchain is currently required for building the IDL.
10163
- let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
11164
- .map(|toolchain| format!("+{}", toolchain))
12165
- .unwrap_or_else(|_| "+nightly".to_string());
13166
-
14167
- install_toolchain_if_needed(&toolchain)?;
15-
-
16-
let output = Command::new("cargo")
168+
- let output = Command::new("cargo")
169+
+ let mut command = Command::new("cargo");
170+
+ if let Ok(toolchain) = std::env::var("RUSTUP_TOOLCHAIN") {
171+
+ command.arg(&format!("+{}", toolchain));
172+
+ }
173+
+ let output = command
17174
.args([
18175
- &toolchain,
19176
"test",
20177
"__anchor_private_print_idl",
21178
"--features",
22-
@@ -202,23 +194,6 @@ fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool)
179+
@@ -283,23 +280,6 @@ fn build(
23180
idl.ok_or_else(|| anyhow!("IDL doesn't exist"))
24181
}
25-
182+
26183
-/// Install the given toolchain if it's not already installed.
27184
-fn install_toolchain_if_needed(toolchain: &str) -> Result<()> {
28185
- let is_installed = Command::new("cargo")

cargo-build-sbf.patch

Lines changed: 0 additions & 131 deletions
This file was deleted.

0 commit comments

Comments
 (0)