Skip to content

Commit f140bf7

Browse files
authored
Merge pull request #4 from Karrq/multi-system
feat: multi system
2 parents 0df46fa + d25d43c commit f140bf7

File tree

16 files changed

+762
-466
lines changed

16 files changed

+762
-466
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
test:
12+
name: Test Solana & Anchor CLI
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
# https://docs.github.com/en/actions/using-github-hosted-runners/using-github-hosted-runners/about-github-hosted-runners#standard-github-hosted-runners-for-public-repositories
18+
os: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest, windows-11-arm, macos-13, macos-latest]
19+
steps:
20+
- uses: actions/checkout@v4
21+
22+
- name: Install Nix
23+
uses: DeterminateSystems/nix-installer-action@main
24+
25+
- name: Enable Nix Flakes
26+
run: |
27+
echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf
28+
sudo systemctl restart nix-daemon || true
29+
30+
- name: Test Solana CLI
31+
run: |
32+
nix run .#solana-cli -- --version
33+
34+
- name: Test Anchor CLI
35+
run: |
36+
nix run .#anchor-cli -- --version

anchor-cli.nix

Lines changed: 88 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,105 @@
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",
1314
}:
1415
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 {
2416
pname = "anchor-cli";
25-
version = "0.31.0";
2617

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};
2833

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;
3635

37-
src = fetchFromGitHub {
36+
originalSrc = fetchFromGitHub {
3837
owner = "coral-xyz";
3938
repo = "anchor";
4039
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+
'';
4262
};
4363

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 ];
4779
};
4880

49-
patches = [
50-
./anchor-cli.patch
51-
];
81+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
82+
in
83+
craneLib.buildPackage (
84+
commonArgs
85+
// {
86+
inherit cargoArtifacts;
5287

5388
# 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+
'';
5994

60-
buildAndTestSubdir = "cli";
95+
cargoExtraArgs = "-p ${pname}";
6196

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+
)

criterion.nix

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
{ lib
2-
, fetchFromGitHub
3-
, cmake
4-
, pkg-config
5-
, criterion
1+
{
2+
lib,
3+
fetchFromGitHub,
4+
cmake,
5+
pkg-config,
6+
criterion,
67
}:
78
criterion.overrideAttrs rec {
89
version = "2.3.3";
@@ -17,7 +18,10 @@ criterion.overrideAttrs rec {
1718

1819
# Remove attrs for v2.4.1
1920
# https://github.com/NixOS/nixpkgs/commit/bff379e9ed908e737009038c24d548ba17e81ee2
20-
nativeBuildInputs = [ cmake pkg-config ];
21+
nativeBuildInputs = [
22+
cmake
23+
pkg-config
24+
];
2125
checkTarget = "criterion_tests test";
2226
cmakeFlags = [ "-DCTESTS=ON" ];
2327
# Disable this phase

default.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(import (
2+
let
3+
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
4+
nodeName = lock.nodes.root.inputs.flake-compat;
5+
in
6+
fetchTarball {
7+
url =
8+
lock.nodes.${nodeName}.locked.url
9+
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
10+
sha256 = lock.nodes.${nodeName}.locked.narHash;
11+
}
12+
) { src = ./.; }).defaultNix

flake.lock

Lines changed: 115 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)