nix build and nix shells for release

Cross compiling the crates for windows and macos
This commit is contained in:
edouardparis 2024-11-29 17:21:50 +01:00
parent d9e984af43
commit 2c70aba2d5
4 changed files with 258 additions and 6 deletions

View File

@ -1,5 +1,7 @@
# Liana reproducible builds
## Reproducible build of linux binaries with GUIX
Releases of Liana are built in a reproducible manner, providing an assurance the binary a user is
going to run corresponds to the sources published. It enables the possibility for the user, or a
third party, to audit the code being ran.
@ -13,5 +15,55 @@ builds [here](https://bootstrappable.org/).
For instructions on bootstrappable builds of Linux releases, see the [`guix`](./guix) folder.
For instructions on reproducible builds of Windows and MacOS releases, see the [`docker`](./docker)
folder.
## Reproducible build of windows and macos binaries with NIX
You will have to install [Nix](https://nixos.org/download/#download-nix), a package manager.
We rely on nix flakes, so you may need to activate this feature by setting in your `~/.config/nix/nix.conf`:
```
experimental-features = nix-command flakes
```
### Windows
Simply run:
```
nix build .#x86_64-pc-windows-gnu
```
Binary will be present in the `./result` folder.
### MACOS
First you need get the MacOS SDK. It is required to be able to build the MacOS binaries. The `12_2` version is
required (`Xcode_12.2.xip`). You need to download it from Apple's website. An Apple ID and cookies
enabled for the hostname are required. You can create one for free. (Note it is illegal to
distribute the archive.) Once logged in you can use the [direct
link](https://download.developer.apple.com/Developer_Tools/Xcode_12.2/Xcode_12.2.xip) to download
the archive. Alternatively, go to 'Downloads', then 'More' and search for [`Xcode
12.2`](https://developer.apple.com/download/all/?q=Xcode%2012.2).
The `sha256sum` of the downloaded XIP archive should be
`28d352f8c14a43d9b8a082ac6338dc173cb153f964c6e8fb6ba389e5be528bd0`.
Then you have to extract the SDK and add it to the nix store:
```
nix run github:edouardparis/unxip#unxip -- Xcode_12.2.xip Xcode_12.2
cd Xcode_12.2
nix-store --add-fixed --recursive sha256 Xcode.app
```
It may take a long time.
Then to compile binaries for new apple CPUs:
```
nix build .#aarch64-apple-darwin
```
Or for legacy CPUs:
```
nix build .#x86_64-apple-darwin
```
Binaries will be present in the `./result` folder.

View File

@ -44,3 +44,10 @@ This document details the release process.
- Update the package managers with the new version. As of this writing we only update the [AUR
package](https://aur.archlinux.org/packages/liana-bin) ourselves.
- Celebrate.
In order to build the release assets:
```
nix develop .#release
./contrib/release/release.sh
```

55
flake.lock generated
View File

@ -1,5 +1,41 @@
{
"nodes": {
"crane": {
"locked": {
"lastModified": 1732407143,
"narHash": "sha256-qJOGDT6PACoX+GbNH2PPx2ievlmtT1NVeTB80EkRLys=",
"owner": "ipetkov",
"repo": "crane",
"rev": "f2b4b472983817021d9ffb60838b2b36b9376b20",
"type": "github"
},
"original": {
"owner": "ipetkov",
"repo": "crane",
"type": "github"
}
},
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1732689334,
"narHash": "sha256-yKI1KiZ0+bvDvfPTQ1ZT3oP/nIu3jPYm4dnbRd6hYg4=",
"owner": "nix-community",
"repo": "fenix",
"rev": "a8a983027ca02b363dfc82fbe3f7d9548a8d3dce",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@ -36,10 +72,29 @@
},
"root": {
"inputs": {
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1732633904,
"narHash": "sha256-7VKcoLug9nbAN2txqVksWHHJplqK9Ou8dXjIZAIYSGc=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "8d5e91c94f80c257ce6dbdfba7bd63a5e8a03fa6",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,

146
flake.nix
View File

@ -4,13 +4,124 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crane.url = "github:ipetkov/crane";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, ... }:
outputs = { self, nixpkgs, flake-utils, crane, fenix, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
in {
pkgs = import nixpkgs { inherit system; config = { allowUnfree = true; };};
inherit (pkgs) lib;
toolchain = with fenix.packages.${system};
combine [
minimal.rustc
minimal.cargo
targets.x86_64-pc-windows-gnu.latest.rust-std
targets.aarch64-apple-darwin.latest.rust-std
targets.x86_64-apple-darwin.latest.rust-std
];
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
commonBuildSettings = {
src = lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
(craneLib.fileset.commonCargoSources ./.)
(lib.fileset.maybeMissing ./liana-ui/static)
];
};
strictDeps = true;
doCheck = false;
};
x86_64-pc-windows-gnu = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "x86_64-pc-windows-gnu";
CARGO_BUILD_RUSTFLAGS = "-C link-arg=-Wl,--no-insert-timestamp";
TARGET_CC = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/${pkgs.pkgsCross.mingwW64.stdenv.cc.targetPrefix}cc";
pname = "liana-gui";
cargoExtraArgs = "-p liana-gui";
depsBuildBuild = with pkgs; [
pkgsCross.mingwW64.stdenv.cc
pkgsCross.mingwW64.windows.pthreads
];
installPhaseCommand = ''
mkdir -p $out/x86_64-pc-windows-gnu
cp target/x86_64-pc-windows-gnu/release/liana-gui.exe $out/x86_64-pc-windows-gnu
'';
};
x86_64-apple-darwin = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "x86_64-apple-darwin";
buildPhaseCargoCommand = "cargo zigbuild --release --message-format json-render-diagnostics";
depsBuildBuild = [
pkgs.zig
pkgs.cargo-zigbuild
pkgs.darwin.xcode_12_2
];
preBuild = ''
export SDKROOT=${pkgs.darwin.xcode_12_2}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export XDG_CACHE_HOME=$TMPDIR/xdg_cache
mkdir -p $XDG_CACHE_HOME
export CARGO_ZIGBUILD_CACHE_DIR=$TMPDIR/cargo-zigbuild-cache
mkdir -p $CARGO_ZIGBUILD_CACHE_DIR
export CC=zigcc
export CXX=zigc++
'';
installPhaseCommand = ''
mkdir -p $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/liana-gui $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/lianad $out/x86_64-apple-darwin
cp target/x86_64-apple-darwin/release/liana-cli $out/x86_64-apple-darwin
'';
};
aarch64-apple-darwin = craneLib.buildPackage {
inherit (commonBuildSettings) src strictDeps doCheck;
CARGO_BUILD_TARGET = "aarch64-apple-darwin";
buildPhaseCargoCommand = "cargo zigbuild --release --message-format json-render-diagnostics";
depsBuildBuild = [
pkgs.zig
pkgs.cargo-zigbuild
pkgs.darwin.xcode_12_2
];
preBuild = ''
export SDKROOT=${pkgs.darwin.xcode_12_2}/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk
export XDG_CACHE_HOME=$TMPDIR/xdg_cache
mkdir -p $XDG_CACHE_HOME
export CARGO_ZIGBUILD_CACHE_DIR=$TMPDIR/cargo-zigbuild-cache
mkdir -p $CARGO_ZIGBUILD_CACHE_DIR
export CC=zigcc
export CXX=zigc++
'';
installPhaseCommand = ''
mkdir -p $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/liana-gui $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/lianad $out/aarch64-apple-darwin
cp target/aarch64-apple-darwin/release/liana-cli $out/aarch64-apple-darwin
'';
};
devShell = pkgs.mkShell rec {
buildInputs = with pkgs; [
expat
@ -31,7 +142,34 @@
LD_LIBRARY_PATH =
builtins.foldl' (a: b: "${a}:${b}/lib") "${pkgs.vulkan-loader}/lib" buildInputs;
};
releaseShell = pkgs.mkShell {
buildInputs = with pkgs; [
zip
unzip
gnutar
dpkg
rcodesign
];
};
in {
packages = {
x86_64-pc-windows-gnu = x86_64-pc-windows-gnu;
x86_64-apple-darwin = x86_64-apple-darwin;
aarch64-apple-darwin = aarch64-apple-darwin;
release = pkgs.buildEnv {
name = "release";
paths = [ x86_64-pc-windows-gnu x86_64-apple-darwin aarch64-apple-darwin ];
};
};
devShells = {
dev = devShell;
release = releaseShell;
default = devShell;
};
}
);
}