|
1 | | -{ stdenv |
2 | | -, darwin |
3 | | -, fetchFromGitHub |
4 | | -, lib |
5 | | -, libgcc |
6 | | -, pkg-config |
7 | | -, protobuf |
8 | | -, makeRustPlatform |
9 | | -, makeWrapper |
10 | | -, solana-platform-tools |
11 | | -, rust-bin |
12 | | -, udev |
| 1 | +{ |
| 2 | + stdenv, |
| 3 | + darwin, |
| 4 | + fetchFromGitHub, |
| 5 | + lib, |
| 6 | + pkg-config, |
| 7 | + protobuf, |
| 8 | + makeWrapper, |
| 9 | + solana-platform-tools, |
| 10 | + rust-bin, |
| 11 | + udev, |
| 12 | + crane, |
| 13 | + version ? "0.31.0", |
13 | 14 | }: |
14 | 15 | let |
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 |
18 | | - rustPlatform = makeRustPlatform { |
19 | | - cargo = rust-bin.stable."1.85.0".default; |
20 | | - rustc = rust-bin.stable."1.85.0".default; |
21 | | - }; |
22 | | -in |
23 | | -rustPlatform.buildRustPackage rec { |
24 | 16 | pname = "anchor-cli"; |
25 | | - version = "0.31.0"; |
26 | 17 |
|
27 | | - doCheck = false; |
| 18 | + versionsDeps = { |
| 19 | + "0.31.0" = { |
| 20 | + hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM="; |
| 21 | + rust = rust-bin.stable."1.85.0".default; |
| 22 | + platform-tools = solana-platform-tools.override { version = "1.45"; }; |
| 23 | + patches = [ ./patches/anchor-cli/0.31.0.patch ]; |
| 24 | + }; |
| 25 | + "0.30.1" = { |
| 26 | + hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw="; |
| 27 | + rust = rust-bin.stable."1.78.0".default; |
| 28 | + platform-tools = solana-platform-tools.override { version = "1.43"; }; |
| 29 | + patches = [ ./patches/anchor-cli/0.30.1.patch ]; |
| 30 | + }; |
| 31 | + }; |
| 32 | + versionDeps = versionsDeps.${version}; |
28 | 33 |
|
29 | | - nativeBuildInputs = [ protobuf pkg-config makeWrapper ]; |
30 | | - buildInputs = [ ] |
31 | | - ++ lib.optionals stdenv.isLinux [ udev ] |
32 | | - ++ lib.optional |
33 | | - stdenv.isDarwin [ |
34 | | - darwin.apple_sdk.frameworks.CoreFoundation |
35 | | - ]; |
| 34 | + craneLib = crane.overrideToolchain versionDeps.rust; |
36 | 35 |
|
37 | | - src = fetchFromGitHub { |
| 36 | + originalSrc = fetchFromGitHub { |
38 | 37 | owner = "coral-xyz"; |
39 | 38 | repo = "anchor"; |
40 | 39 | rev = "v${version}"; |
41 | | - hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM="; |
| 40 | + hash = versionDeps.hash; |
| 41 | + }; |
| 42 | + |
| 43 | + src = stdenv.mkDerivation { |
| 44 | + name = "anchor-cli-patched"; |
| 45 | + src = originalSrc; |
| 46 | + |
| 47 | + # Apply the patch |
| 48 | + phases = [ |
| 49 | + "unpackPhase" |
| 50 | + "patchPhase" |
| 51 | + "installPhase" |
| 52 | + ]; |
| 53 | + patches = versionDeps.patches; |
| 54 | + |
| 55 | + # Install the patched source as an output |
| 56 | + installPhase = '' |
| 57 | + runHook preInstall |
| 58 | + mkdir -p $out |
| 59 | + cp -r ./* $out/ |
| 60 | + runHook postInstall |
| 61 | + ''; |
42 | 62 | }; |
43 | 63 |
|
44 | | - cargoLock = { |
45 | | - lockFile = "${src.outPath}/Cargo.lock"; |
46 | | - allowBuiltinFetchGit = true; |
| 64 | + commonArgs = { |
| 65 | + inherit pname version src; |
| 66 | + |
| 67 | + strictDeps = true; |
| 68 | + doCheck = false; |
| 69 | + |
| 70 | + nativeBuildInputs = [ |
| 71 | + protobuf |
| 72 | + pkg-config |
| 73 | + makeWrapper |
| 74 | + ]; |
| 75 | + buildInputs = |
| 76 | + [ ] |
| 77 | + ++ lib.optionals stdenv.isLinux [ udev ] |
| 78 | + ++ lib.optional stdenv.isDarwin [ darwin.apple_sdk.frameworks.CoreFoundation ]; |
47 | 79 | }; |
48 | 80 |
|
49 | | - patches = [ |
50 | | - ./anchor-cli.patch |
51 | | - ]; |
| 81 | + cargoArtifacts = craneLib.buildDepsOnly commonArgs; |
| 82 | +in |
| 83 | +craneLib.buildPackage ( |
| 84 | + commonArgs |
| 85 | + // { |
| 86 | + inherit cargoArtifacts; |
52 | 87 |
|
53 | 88 | # Ensure anchor has access to Solana's cargo and rust binaries |
54 | | - postInstall = '' |
55 | | - rust=${solana-platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin |
56 | | - wrapProgram $out/bin/anchor \ |
57 | | - --prefix PATH : "$rust" |
58 | | - ''; |
| 89 | + postInstall = '' |
| 90 | + rust=${versionDeps.platform-tools}/bin/platform-tools-sdk/sbf/dependencies/platform-tools/rust/bin |
| 91 | + wrapProgram $out/bin/anchor \ |
| 92 | + --prefix PATH : "$rust" |
| 93 | + ''; |
59 | 94 |
|
60 | | - buildAndTestSubdir = "cli"; |
| 95 | + cargoExtraArgs = "-p ${pname}"; |
61 | 96 |
|
62 | | - meta = { |
63 | | - description = "Anchor cli"; |
64 | | - }; |
65 | | -} |
| 97 | + meta = { |
| 98 | + description = "Anchor cli"; |
| 99 | + }; |
| 100 | + |
| 101 | + passthru = { |
| 102 | + otherVersions = builtins.attrNames versionsDeps; |
| 103 | + }; |
| 104 | + } |
| 105 | +) |
0 commit comments