Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: CI

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
test:
name: Test Solana & Anchor CLI
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
# 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
os: [ubuntu-24.04, ubuntu-24.04-arm, windows-latest, windows-11-arm, macos-13, macos-latest]
steps:
- uses: actions/checkout@v4

- name: Install Nix
uses: DeterminateSystems/nix-installer-action@main

- name: Enable Nix Flakes
run: |
echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf
sudo systemctl restart nix-daemon || true

- name: Test Solana CLI
run: |
nix run .#solana-cli -- --version

- name: Test Anchor CLI
run: |
nix run .#anchor-cli -- --version
136 changes: 88 additions & 48 deletions anchor-cli.nix
Original file line number Diff line number Diff line change
@@ -1,65 +1,105 @@
{ stdenv
, darwin
, fetchFromGitHub
, lib
, libgcc
, pkg-config
, protobuf
, makeRustPlatform
, makeWrapper
, solana-platform-tools
, rust-bin
, udev
{
stdenv,
darwin,
fetchFromGitHub,
lib,
pkg-config,
protobuf,
makeWrapper,
solana-platform-tools,
rust-bin,
udev,
crane,
version ? "0.31.0",
}:
let
# 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.85.0".default;
rustc = rust-bin.stable."1.85.0".default;
};
in
rustPlatform.buildRustPackage rec {
pname = "anchor-cli";
version = "0.31.0";

doCheck = false;
versionsDeps = {
"0.31.0" = {
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
rust = rust-bin.stable."1.85.0".default;
platform-tools = solana-platform-tools.override { version = "1.45"; };
patches = [ ./patches/anchor-cli/0.31.0.patch ];
};
"0.30.1" = {
hash = "sha256-3fLYTJDVCJdi6o0Zd+hb9jcPDKm4M4NzpZ8EUVW/GVw=";
rust = rust-bin.stable."1.78.0".default;
platform-tools = solana-platform-tools.override { version = "1.43"; };
patches = [ ./patches/anchor-cli/0.30.1.patch ];
};
};
versionDeps = versionsDeps.${version};

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

src = fetchFromGitHub {
originalSrc = fetchFromGitHub {
owner = "coral-xyz";
repo = "anchor";
rev = "v${version}";
hash = "sha256-CaBVdp7RPVmzzEiVazjpDLJxEkIgy1BHCwdH2mYLbGM=";
hash = versionDeps.hash;
};

src = stdenv.mkDerivation {
name = "anchor-cli-patched";
src = originalSrc;

# Apply the patch
phases = [
"unpackPhase"
"patchPhase"
"installPhase"
];
patches = versionDeps.patches;

# Install the patched source as an output
installPhase = ''
runHook preInstall
mkdir -p $out
cp -r ./* $out/
runHook postInstall
'';
};

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

strictDeps = true;
doCheck = false;

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

patches = [
./anchor-cli.patch
];
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
in
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;

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

buildAndTestSubdir = "cli";
cargoExtraArgs = "-p ${pname}";

meta = {
description = "Anchor cli";
};
}
meta = {
description = "Anchor cli";
};

passthru = {
otherVersions = builtins.attrNames versionsDeps;
};
}
)
16 changes: 10 additions & 6 deletions criterion.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{ lib
, fetchFromGitHub
, cmake
, pkg-config
, criterion
{
lib,
fetchFromGitHub,
cmake,
pkg-config,
criterion,
}:
criterion.overrideAttrs rec {
version = "2.3.3";
Expand All @@ -17,7 +18,10 @@ criterion.overrideAttrs rec {

# Remove attrs for v2.4.1
# https://github.com/NixOS/nixpkgs/commit/bff379e9ed908e737009038c24d548ba17e81ee2
nativeBuildInputs = [ cmake pkg-config ];
nativeBuildInputs = [
cmake
pkg-config
];
checkTarget = "criterion_tests test";
cmakeFlags = [ "-DCTESTS=ON" ];
# Disable this phase
Expand Down
12 changes: 12 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
(import (
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url =
lock.nodes.${nodeName}.locked.url
or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
) { src = ./.; }).defaultNix
115 changes: 115 additions & 0 deletions flake.lock

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

Loading