Skip to content

Commit

Permalink
Clean up Solana derivation (#42)
Browse files Browse the repository at this point in the history
* Clean up Solana derivation

* solana-full now works on darwin

* move solana-full to all os

* old solana doesnt work on darwin

* install nix v26

* don't use rocksdb from nixpkgs if on older solana

* use rocksdb from nixpkgs optionals

* readd libclang path etc for older solana

* remove solana-full old versions

* fix rocksdb dep again
  • Loading branch information
macalinao authored Apr 9, 2024
1 parent d3e2155 commit b6b024f
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 33 deletions.
50 changes: 25 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os: [ubuntu-latest]
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: cachix/install-nix-action@v26
- name: Setup Cachix
uses: cachix/cachix-action@v12
with:
Expand Down Expand Up @@ -59,37 +59,37 @@ jobs:
- anchor-0_28
- anchor-0_29
- anchor
- saber-devenv
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- name: Setup Cachix
uses: cachix/cachix-action@v12
with:
name: saber
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: nix build --show-trace --print-build-logs .#${{ matrix.package }}

build-packages-linux-only:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
package:
- solana-1_8-full
- solana-1_9-full
- solana-1_10-full
- solana-1_11-full
- solana-1_13-full
- solana-1_17-full
- solana-full
- saber-devenv
steps:
- uses: actions/checkout@v3
- uses: cachix/install-nix-action@v20
- uses: cachix/install-nix-action@v26
- name: Setup Cachix
uses: cachix/cachix-action@v12
with:
name: saber
authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
- run: nix build --show-trace --print-build-logs .#${{ matrix.package }}

# build-packages-linux-only:
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os: [ubuntu-latest]
# package:
# - solana-1_8-full
# - solana-1_9-full
# - solana-1_10-full
# - solana-1_11-full
# - solana-1_13-full
# steps:
# - uses: actions/checkout@v3
# - uses: cachix/install-nix-action@v26
# - name: Setup Cachix
# uses: cachix/cachix-action@v12
# with:
# name: saber
# authToken: "${{ secrets.CACHIX_AUTH_TOKEN }}"
# - run: nix build --show-trace --print-build-logs .#${{ matrix.package }}
5 changes: 4 additions & 1 deletion packages/solana/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
}:
let
mkSolana = (
{ rust ? rustStable, cargoOutputHashes ? { }, ... }@args:
{ rust ? rustStable
, cargoOutputHashes ? { }
, ...
}@args:
import ./solana-packages.nix {
inherit pkgs rust darwinPackages cargoOutputHashes;
inherit (args) version githubSha256;
Expand Down
48 changes: 41 additions & 7 deletions packages/solana/solana.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Some of this file is taken from https://github.com/NixOS/nixpkgs/blob/nixpkgs-unstable/pkgs/applications/blockchains/solana/default.nix
{ name ? "solana"
, lib
, validatorOnly ? false
Expand All @@ -12,13 +13,16 @@
, fetchFromGitHub
, stdenv
, darwinPackages
, darwin
, libcxx
, protobuf
, rustfmt
, cargoLockFile
, version
, githubSha256
, perl
, cargoOutputHashes
, rocksdb
, # Taken from https://github.com/solana-labs/solana/blob/master/scripts/cargo-install-all.sh#L84
solanaPkgs ? [
"solana"
Expand Down Expand Up @@ -52,6 +56,10 @@
]
}:

let
inherit (darwin.apple_sdk_11_0) Libsystem;
inherit (darwin.apple_sdk_11_0.frameworks) System IOKit AppKit Security;
in
rustPlatform.buildRustPackage rec {
pname = name;
inherit version;
Expand All @@ -71,20 +79,46 @@ rustPlatform.buildRustPackage rec {

cargoBuildFlags = builtins.map (n: "--bin=${n}") solanaPkgs;

# weird errors. see https://github.com/NixOS/nixpkgs/issues/52447#issuecomment-852079285
LIBCLANG_PATH = "${libclang.lib}/lib";
BINDGEN_EXTRA_CLANG_ARGS =
"-isystem ${libclang.lib}/lib/clang/${lib.getVersion clang}/include";

nativeBuildInputs = [ clang llvm pkg-config protobuf rustfmt perl ];
buildInputs =
([ openssl zlib libclang ] ++ (lib.optionals stdenv.isLinux [ udev ]))
++ darwinPackages;
[
openssl
rustPlatform.bindgenHook
zlib
libclang
rocksdb
]
++ lib.optionals stdenv.isLinux [ udev ]
++ lib.optionals stdenv.isDarwin [
libcxx
IOKit
Security
AppKit
System
Libsystem
];
strictDeps = true;

postInstall = ''
mkdir -p $out/bin/sdk/bpf
cp -a ./sdk/bpf/* $out/bin/sdk/bpf/
'';

# this is too slow
doCheck = false;

# Used by build.rs in the rocksdb-sys crate. If we don't set these, it would
# try to build RocksDB from source.
ROCKSDB_LIB_DIR = "${rocksdb}/lib";

# Require this on darwin otherwise the compiler starts rambling about missing
# cmath functions
CPPFLAGS = lib.optionals stdenv.isDarwin "-isystem ${lib.getDev libcxx}/include/c++/v1";
LDFLAGS = lib.optionals stdenv.isDarwin "-L${lib.getLib libcxx}/lib";

# If set, always finds OpenSSL in the system, even if the vendored feature is enabled.
OPENSSL_NO_VENDOR = 1;

meta = with lib; {
homepage = "https://solana.com/";
description =
Expand Down

0 comments on commit b6b024f

Please sign in to comment.