Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 16 additions & 34 deletions anchor-cli.nix
Original file line number Diff line number Diff line change
@@ -1,64 +1,46 @@
{ stdenv
, darwin
, fetchFromGitHub
, lib
, libgcc
, pkg-config
, protobuf
, makeRustPlatform
, makeWrapper
, solana-platform-tools
, rust-bin
, udev
}:
{ stdenv, darwin, fetchFromGitHub, lib, libgcc, pkg-config, protobuf
, makeRustPlatform, makeWrapper, solana-platform-tools, rust-bin, udev }:
let
# Anchor does not declare a rust-toolchain, so we have to do it here -- the
# old dependency on the `time` crate doesn't support Rust versions >= 1.80.
# nixpkgs 24.11 defaults to Rust v1.82.0
# Anchor does not declare a rust-toolchain, so we do it here -- the code
# mentions Rust 1.85.0 at https://github.com/coral-xyz/anchor/blob/c509618412e004415c7b090e469a9e4d5177f642/docs/content/docs/installation.mdx?plain=1#L31
rustPlatform = makeRustPlatform {
cargo = rust-bin.stable."1.79.0".default;
rustc = rust-bin.stable."1.79.0".default;
cargo = rust-bin.stable."1.85.0".default;
rustc = rust-bin.stable."1.85.0".default;
};
in
rustPlatform.buildRustPackage rec {
in rustPlatform.buildRustPackage rec {
pname = "anchor-cli";
version = "0.30.1";
version = "0.31.0";

doCheck = false;

nativeBuildInputs = [ protobuf pkg-config makeWrapper ];
buildInputs = [ ]
++ lib.optionals stdenv.isLinux [ udev ]
++ lib.optional
stdenv.isDarwin [
darwin.apple_sdk.frameworks.CoreFoundation
];
buildInputs = [ ] ++ lib.optionals stdenv.isLinux [ udev ]
++ lib.optional stdenv.isDarwin
[ darwin.apple_sdk.frameworks.CoreFoundation ];

src = fetchFromGitHub {
owner = "coral-xyz";
repo = "anchor";
rev = "v${version}";
hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw=";
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
};

cargoLock = {
lockFile = "${src.outPath}/Cargo.lock";
allowBuiltinFetchGit = true;
};

patches = [
./anchor-cli.patch
];
patches = [ ./anchor-cli.patch ];

buildAndTestSubdir = "cli";

# Ensure anchor has access to Solana's cargo and rust binaries
postInstall = ''
rust=${solana-platform-tools}/bin/sdk/sbf/dependencies/platform-tools/rust/bin
rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin
wrapProgram $out/bin/anchor \
--prefix PATH : "$rust"
'';

meta = {
description = "Anchor cli";
};
meta = { description = "Anchor cli"; };
}
45 changes: 37 additions & 8 deletions anchor-cli.patch
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
diff --git a/cli/src/lib.rs b/cli/src/lib.rs
index 3404b032..4d87ed96 100644
--- a/cli/src/lib.rs
+++ b/cli/src/lib.rs
@@ -1821,6 +1821,8 @@ fn docker_build_bpf(
container_name,
"cargo",
subcommand,
+ "--skip-tools-install",
+ "--no-rustup-override",
"--manifest-path",
&manifest_path.display().to_string(),
])
@@ -1923,6 +1925,8 @@ fn _build_rust_cwd(
) -> Result<()> {
let exit = std::process::Command::new("cargo")
.arg(arch.build_subcommand())
+ .arg("--skip-tools-install")
+ .arg("--no-rustup-override")
.args(cargo_args.clone())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
diff --git a/idl/src/build.rs b/idl/src/build.rs
index 96dc3db2..1b098718 100644
index ccd89745..2d679123 100644
--- a/idl/src/build.rs
+++ b/idl/src/build.rs
@@ -60,16 +60,8 @@ pub fn build_idl(

/// Build IDL.
fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool) -> Result<Idl> {
@@ -138,15 +138,8 @@ fn build(
no_docs: bool,
cargo_args: &[String],
) -> Result<Idl> {
- // `nightly` toolchain is currently required for building the IDL.
- 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,
"test",
"__anchor_private_print_idl",
"--features",
@@ -202,23 +194,6 @@ fn build(program_path: &Path, resolution: bool, skip_lint: bool, no_docs: bool)
@@ -283,23 +276,6 @@ fn build(
idl.ok_or_else(|| anyhow!("IDL doesn't exist"))
}

-/// Install the given toolchain if it's not already installed.
-fn install_toolchain_if_needed(toolchain: &str) -> Result<()> {
- let is_installed = Command::new("cargo")
Expand All @@ -43,3 +64,11 @@ index 96dc3db2..1b098718 100644
/// Convert paths to name if there are no conflicts.
fn convert_module_paths(idl: Idl) -> Idl {
let idl = serde_json::to_string(&idl).unwrap();
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 00000000..c1bc0a69
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,2 @@
+[toolchain]
+channel = "1.85.0"
131 changes: 0 additions & 131 deletions cargo-build-sbf.patch

This file was deleted.

7 changes: 1 addition & 6 deletions criterion.nix
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
{ lib
, fetchFromGitHub
, cmake
, pkg-config
, criterion
}:
{ lib, fetchFromGitHub, cmake, pkg-config, criterion }:
criterion.overrideAttrs rec {
version = "2.3.3";

Expand Down
98 changes: 98 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading