Skip to content

Commit 3505a15

Browse files
committed
Build lair keystore
1 parent 238e7b7 commit 3505a15

7 files changed

+301
-10
lines changed

.github/workflows/build.yaml

+42-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
- main
77

88
jobs:
9-
build:
9+
build-holochain:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
@@ -32,7 +32,7 @@ jobs:
3232
- name: Build for x86_64-pc-windows-gnu
3333
run: nix build .#holochain_x86_64-windows
3434

35-
build-apple:
35+
build-holochain-apple:
3636
runs-on: macos-latest
3737
steps:
3838
- uses: actions/checkout@v4
@@ -43,4 +43,43 @@ jobs:
4343
install_url: https://releases.nixos.org/nix/nix-2.20.4/install
4444

4545
- name: Build for x86_64-apple-darwin
46-
run: nix build .#holochain_aarch64-apple
46+
run: nix build .#holochain_aarch64-apple
47+
48+
build-lair-keystore:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Maximize build space
54+
uses: AdityaGarg8/remove-unwanted-software@v2
55+
with:
56+
remove-dotnet: 'true'
57+
remove-android: 'true'
58+
remove-codeql: 'true'
59+
remove-docker-images: 'true'
60+
- name: Install nix
61+
uses: cachix/install-nix-action@v26
62+
with:
63+
install_url: https://releases.nixos.org/nix/nix-2.20.4/install
64+
65+
- name: Build for x86_64-unknown-linux-gnu
66+
run: nix build .#lair_keystore_x86_64-linux
67+
68+
- name: Build for aarch64-unknown-linux-gnu
69+
run: nix build .#lair_keystore_aarch64-linux
70+
71+
- name: Build for x86_64-pc-windows-gnu
72+
run: nix build .#lair_keystore_x86_64-windows
73+
74+
build-lair-keystore-apple:
75+
runs-on: macos-latest
76+
steps:
77+
- uses: actions/checkout@v4
78+
79+
- name: Install nix
80+
uses: cachix/install-nix-action@v26
81+
with:
82+
install_url: https://releases.nixos.org/nix/nix-2.20.4/install
83+
84+
- name: Build for x86_64-apple-darwin
85+
run: nix build .#lair_keystore_aarch64-apple

flake.lock

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+31-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
url = "github:holochain/holochain/bump-influxive";
2929
flake = false;
3030
};
31+
32+
lair-keystore = {
33+
url = "github:holochain/lair";
34+
flake = false;
35+
};
3136
};
3237

3338
outputs = inputs @ { nixpkgs, crane, flake-utils, rust-overlay, ... }:
@@ -58,11 +63,36 @@
5863
rustTargetTriple = "aarch64-apple-darwin";
5964
};
6065
} else { });
66+
67+
defineLairKeystorePackages = {}: {
68+
lair_keystore_aarch64-linux = import ./modules/lair-keystore-cross.nix {
69+
inherit localSystem inputs;
70+
crossSystem = "aarch64-linux";
71+
rustTargetTriple = "aarch64-unknown-linux-gnu";
72+
};
73+
lair_keystore_x86_64-linux = import ./modules/lair-keystore-cross.nix {
74+
inherit localSystem inputs;
75+
crossSystem = "x86_64-linux";
76+
rustTargetTriple = "x86_64-unknown-linux-gnu";
77+
};
78+
lair_keystore_x86_64-windows = import ./modules/lair-keystore-windows.nix {
79+
inherit localSystem inputs;
80+
};
81+
} // (if localSystem == "aarch64-darwin" then {
82+
# Only define darwin builds if we're on a darwin host because Apple don't like people cross compiling
83+
# from other systems.
84+
lair_keystore_aarch64-apple = import ./modules/lair-keystore-cross.nix {
85+
inherit localSystem inputs;
86+
crossSystem = "aarch64-darwin";
87+
rustTargetTriple = "aarch64-apple-darwin";
88+
};
89+
} else { });
6190
in
6291
(defineHolochainPackages { crate = "holochain"; package = "holochain"; }) //
6392
(defineHolochainPackages { crate = "hc"; package = "holochain_cli"; }) //
6493
(defineHolochainPackages { crate = "hc_run_local_services"; package = "holochain_cli_run_local_services"; }) //
65-
(defineHolochainPackages { crate = "holochain_terminal"; package = "hcterm"; })
94+
(defineHolochainPackages { crate = "holochain_terminal"; package = "hcterm"; }) //
95+
(defineLairKeystorePackages { })
6696
;
6797
}) // {
6898
# Add dev helpers that are not required to be platform agnostic

modules/common.nix

+30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
{}:
22
{
3+
mkLibSodium = pkgs: pkgs.stdenv.mkDerivation {
4+
name = "libsodium";
5+
src = builtins.fetchurl {
6+
url = "https://download.libsodium.org/libsodium/releases/libsodium-1.0.20-mingw.tar.gz";
7+
sha256 = "sha256:09npqqrialraf2v4m6cicvhnj52p8jaya349wnzlklp31b0q3yq1";
8+
};
9+
unpackPhase = "true";
10+
postInstall = ''
11+
tar -xvf $src
12+
mkdir -p $out
13+
cp -r libsodium-win64/* $out
14+
'';
15+
};
16+
317
holochain = { lib, craneLib, holochain }:
418
let
519
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
@@ -15,4 +29,20 @@
1529
filter = includeFilesFilter;
1630
};
1731
};
32+
33+
lair-keystore = { lib, craneLib, lair-keystore }:
34+
let
35+
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
36+
nonCargoBuildFiles = path: _type: builtins.match ".*(sql|md)$" path != null;
37+
includeFilesFilter = path: type:
38+
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
39+
in
40+
{
41+
crateInfo = craneLib.crateNameFromCargoToml { cargoToml = lair-keystore + "/crates/lair_keystore/Cargo.toml"; };
42+
43+
src = lib.cleanSourceWith {
44+
src = lair-keystore;
45+
filter = includeFilesFilter;
46+
};
47+
};
1848
}

modules/holochain-windows.nix

+1-6
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,11 @@ let
2424

2525
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
2626

27-
# Crane filters out all non-cargo related files. Define include filter with files needed for build.
28-
nonCargoBuildFiles = path: _type: builtins.match ".*(json|sql|wasm.gz)$" path != null;
29-
includeFilesFilter = path: type:
30-
(craneLib.filterCargoSources path type) || (nonCargoBuildFiles path type);
27+
holochainCommon = common.holochain { inherit craneLib; lib = pkgs.lib; holochain = inputs.holochain; };
3128

3229
# Crane doesn't know which version to select from a workspace, so we tell it where to look
3330
crateInfo = holochainCommon.crateInfo crate;
3431

35-
holochainCommon = common.holochain { inherit craneLib; lib = pkgs.lib; holochain = inputs.holochain; };
36-
3732
libsodium = pkgs.stdenv.mkDerivation {
3833
name = "libsodium";
3934
src = builtins.fetchurl {

modules/lair-keystore-cross.nix

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
{
2+
# Flake inputs
3+
inputs
4+
# The system that we are compiling on
5+
, localSystem
6+
# The target system that we are cross-compiling for
7+
, crossSystem
8+
# The target that Rust should be configured to use
9+
, rustTargetTriple
10+
, ...
11+
}:
12+
let
13+
inherit (inputs) nixpkgs crane rust-overlay;
14+
15+
common = import ./common.nix { };
16+
17+
pkgs = import nixpkgs {
18+
inherit crossSystem localSystem;
19+
overlays = [ (import rust-overlay) ];
20+
};
21+
22+
rustToolchain = pkgs.pkgsBuildHost.rust-bin.stable.latest.default.override {
23+
targets = [ rustTargetTriple ];
24+
};
25+
26+
craneLib = (crane.mkLib pkgs).overrideToolchain rustToolchain;
27+
28+
# Note: we have to use the `callPackage` approach here so that Nix
29+
# can "splice" the packages in such a way that dependencies are
30+
# compiled for the appropriate targets. If we did not do this, we
31+
# would have to manually specify things like
32+
# `nativeBuildInputs = with pkgs.pkgsBuildHost; [ someDep ];` or
33+
# `buildInputs = with pkgs.pkgsHostHost; [ anotherDep ];`.
34+
#
35+
# Normally you can stick this function into its own file and pass
36+
# its path to `callPackage`.
37+
crateExpression =
38+
{ lib
39+
, pkg-config
40+
, go
41+
, perl
42+
, stdenv
43+
}:
44+
let
45+
lairKeystoreCommon = common.lair-keystore { inherit lib craneLib; lair-keystore = inputs.lair-keystore; };
46+
47+
commonArgs = {
48+
# Just used for building the workspace, will be replaced when building a specific crate
49+
pname = "default";
50+
version = "0.0.0";
51+
52+
# Load source with a custom filter so we can include non-cargo files that get used during the build
53+
src = lairKeystoreCommon.src;
54+
55+
# We don't want to run tests
56+
doCheck = false;
57+
58+
strictDeps = true;
59+
60+
# Dependencies which need to be built for the current platform
61+
# on which we are doing the cross compilation. In this case,
62+
# pkg-config needs to run on the build platform so that the build
63+
# script can find the location of openssl. Note that we don't
64+
# need to specify the rustToolchain here since it was already
65+
# overridden above.
66+
nativeBuildInputs = [
67+
pkg-config
68+
stdenv.cc
69+
perl
70+
];
71+
72+
# Tell cargo about the linker and an optional emulater. So they can be used in `cargo build`
73+
# and `cargo run`.
74+
# Environment variables are in format `CARGO_TARGET_<UPPERCASE_UNDERSCORE_RUST_TRIPLE>_LINKER`.
75+
# They are also be set in `.cargo/config.toml` instead.
76+
# See: https://doc.rust-lang.org/cargo/reference/config.html#target
77+
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
78+
CARGO_TARGET_x86_64_UNKNOWN_LINUX_GNU_LINKER = "${stdenv.cc.targetPrefix}cc";
79+
CARGO_TARGET_AARCH64_UNKNOWN_APPLE_LINKER = "${stdenv.cc.targetPrefix}cc";
80+
81+
# Tell cargo which target we want to build (so it doesn't default to the build system).
82+
cargoExtraArgs = "--target ${rustTargetTriple}";
83+
84+
# These environment variables may be necessary if any of your dependencies use a
85+
# build-script which invokes the `cc` crate to build some other code. The `cc` crate
86+
# should automatically pick up on our target-specific linker above, but this may be
87+
# necessary if the build script needs to compile and run some extra code on the build
88+
# system.
89+
HOST_CC = "${stdenv.cc.nativePrefix}cc";
90+
TARGET_CC = "${stdenv.cc.targetPrefix}cc";
91+
};
92+
93+
# Build *just* the Cargo dependencies (of the entire workspace),
94+
# so we can reuse all of that work (e.g. via cachix) when running in CI
95+
# It is *highly* recommended to use something like cargo-hakari to avoid
96+
# cache misses when building individual top-level-crates
97+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
98+
in
99+
craneLib.buildPackage (commonArgs // {
100+
pname = "lair-keystore";
101+
version = lairKeystoreCommon.crateInfo.version;
102+
103+
inherit cargoArtifacts;
104+
105+
cargoExtraArgs = "${commonArgs.cargoExtraArgs} --package lair_keystore";
106+
});
107+
in
108+
# Dispatch the crate expression to run the cross compile
109+
pkgs.callPackage crateExpression { }

modules/lair-keystore-windows.nix

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
# Flake inputs
3+
inputs
4+
# The system that we are compiling on
5+
, localSystem
6+
}:
7+
let
8+
inherit (inputs) nixpkgs crane fenix;
9+
10+
common = import ./common.nix { };
11+
12+
pkgs = nixpkgs.legacyPackages.${localSystem};
13+
14+
toolchain = with fenix.packages.${localSystem};
15+
combine [
16+
minimal.rustc
17+
minimal.cargo
18+
targets.x86_64-pc-windows-gnu.latest.rust-std
19+
];
20+
21+
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
22+
23+
lairKeystoreCommon = common.lair-keystore { inherit craneLib; lib = pkgs.lib; lair-keystore = inputs.lair-keystore; };
24+
25+
libsodium = common.mkLibSodium pkgs;
26+
27+
commonArgs = {
28+
# Just used for building the workspace, will be replaced when building a specific crate
29+
pname = "default";
30+
version = "0.0.0";
31+
32+
# Load source with a custom filter so we can include non-cargo files that get used during the build
33+
src = lairKeystoreCommon.src;
34+
35+
strictDeps = true;
36+
doCheck = false;
37+
38+
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
39+
40+
# fixes issues related to libring
41+
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
42+
43+
# Otherwise tx5-go-pion-sys picks up the host linker instead of the cross linker
44+
RUSTC_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
45+
46+
SODIUM_LIB_DIR = "${libsodium}/lib";
47+
48+
nativeBuildInputs = with pkgs; [
49+
perl
50+
];
51+
52+
depsBuildBuild = with pkgs; [
53+
pkgsCross.mingwW64.stdenv.cc
54+
pkgsCross.mingwW64.windows.pthreads
55+
];
56+
};
57+
58+
# Build *just* the Cargo dependencies (of the entire workspace),
59+
# so we can reuse all of that work (e.g. via cachix) when running in CI
60+
# It is *highly* recommended to use something like cargo-hakari to avoid
61+
# cache misses when building individual top-level-crates
62+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
63+
in
64+
craneLib.buildPackage (commonArgs // {
65+
pname = "lair_keystore";
66+
version = lairKeystoreCommon.crateInfo.version;
67+
68+
inherit cargoArtifacts;
69+
70+
cargoExtraArgs = "--package lair_keystore";
71+
})

0 commit comments

Comments
 (0)