build: add universal2-apple-darwin target with lipo

This commit is contained in:
edouardparis 2025-01-06 12:45:27 +01:00
parent 71a110bb8d
commit 5d30ea24fb
3 changed files with 103 additions and 10 deletions

View File

@ -13,8 +13,6 @@ LINUX_DIR_NAME="$LIANA_PREFIX-x86_64-linux-gnu"
LINUX_ARCHIVE="$LINUX_DIR_NAME.tar.gz"
WINDOWS_DIR_NAME="$LIANA_PREFIX-x86_64-windows-gnu"
WINDOWS_ARCHIVE="$WINDOWS_DIR_NAME.zip"
MAC_DIR_NAME="$LIANA_PREFIX-x86_64-apple-darwin"
MAC_ARCHIVE="$MAC_DIR_NAME.tar.gz"
create_dir() {
if [ -d "$1" ]; then
@ -79,14 +77,19 @@ NIX_BUILD_DIR="$(nix path-info .#release)"
# Create the MacOS archive and a zipped application bundle of liana-gui.
(
cd "$BUILD_DIR"
create_dir "$MAC_DIR_NAME"
cp "$NIX_BUILD_DIR/x86_64-apple-darwin/lianad" "$NIX_BUILD_DIR/x86_64-apple-darwin/liana-cli" "$NIX_BUILD_DIR/x86_64-apple-darwin/liana-gui" ../README.md "$MAC_DIR_NAME"
tar --mtime="@${SOURCE_DATE_EPOCH}" -czf "$MAC_ARCHIVE" "$MAC_DIR_NAME"
mv "$MAC_ARCHIVE" "$RELEASE_DIR"
create_dir "$LIANA_PREFIX-x86_64-apple-darwin"
cp "$NIX_BUILD_DIR/x86_64-apple-darwin/lianad" "$NIX_BUILD_DIR/x86_64-apple-darwin/liana-cli" "$NIX_BUILD_DIR/x86_64-apple-darwin/liana-gui" ../README.md "$LIANA_PREFIX-x86_64-apple-darwin"
tar --mtime="@${SOURCE_DATE_EPOCH}" -czf "$LIANA_PREFIX-x86_64-apple-darwin.tar.gz" "$LIANA_PREFIX-x86_64-apple-darwin"
mv "$LIANA_PREFIX-x86_64-apple-darwin.tar.gz" "$RELEASE_DIR"
create_dir "$LIANA_PREFIX-aarch64-apple-darwin"
cp "$NIX_BUILD_DIR/aarch64-apple-darwin/lianad" "$NIX_BUILD_DIR/aarch64-apple-darwin/liana-cli" "$NIX_BUILD_DIR/aarch64-apple-darwin/liana-gui" ../README.md "$LIANA_PREFIX-aarch64-apple-darwin"
tar --mtime="@${SOURCE_DATE_EPOCH}" -czf "$LIANA_PREFIX-aarch64-apple-darwin.tar.gz" "$LIANA_PREFIX-aarch64-apple-darwin"
mv "$LIANA_PREFIX-aarch64-apple-darwin.tar.gz" "$RELEASE_DIR"
unzip ../contrib/release/macos/Liana.app.zip
sed -i "s/VERSION_PLACEHOLDER/$VERSION/g" ./Liana.app/Contents/Info.plist
cp "$NIX_BUILD_DIR/x86_64-apple-darwin/liana-gui" ./Liana.app/Contents/MacOS/Liana
cp "$NIX_BUILD_DIR/universal2-apple-darwin/liana-gui" ./Liana.app/Contents/MacOS/Liana
zip_archive "Liana-$VERSION-noncodesigned.zip" Liana.app
mv "Liana-$VERSION-noncodesigned.zip" "$RELEASE_DIR/"
)

71
flake.lock generated
View File

@ -54,7 +54,60 @@
"type": "github"
}
},
"flake-utils_2": {
"inputs": {
"systems": "systems_2"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"lipo": {
"inputs": {
"flake-utils": "flake-utils_2",
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1736156946,
"narHash": "sha256-gECnGXorKVnloXisX3YWvgOI0Ly5McJ0Dt9Cjwck8os=",
"owner": "edouardparis",
"repo": "lipo-flake",
"rev": "7f4b5727fe0110c9d2c103a0ef3a02adcef535b9",
"type": "github"
},
"original": {
"owner": "edouardparis",
"repo": "lipo-flake",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1736012469,
"narHash": "sha256-/qlNWm/IEVVH7GfgAIyP6EsVZI6zjAx1cV5zNyrs+rI=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "8f3e1f807051e32d8c95cd12b9b421623850a34d",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs_2": {
"locked": {
"lastModified": 1732014248,
"narHash": "sha256-y/MEyuJ5oBWrWAic/14LaIr/u5E0wRVzyYsouYY3W6w=",
@ -75,7 +128,8 @@
"crane": "crane",
"fenix": "fenix",
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs"
"lipo": "lipo",
"nixpkgs": "nixpkgs_2"
}
},
"rust-analyzer-src": {
@ -109,6 +163,21 @@
"repo": "default",
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},
"root": "root",

View File

@ -9,9 +9,10 @@
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
lipo.url = "github:edouardparis/lipo-flake";
};
outputs = { self, nixpkgs, flake-utils, crane, fenix, ... }:
outputs = { self, nixpkgs, flake-utils, crane, fenix, lipo, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; config = { allowUnfree = true; };};
@ -125,6 +126,20 @@
'';
};
universal2-apple-darwin = pkgs.runCommand "universal2-apple-darwin" {
buildInputs = [ lipo.packages.${system}.lipo ];
# Declare dependencies by referencing them in the command
# No need to include x86_64-apple-darwin and aarch64-apple-darwin in buildInputs
# because they are referenced directly
} ''
mkdir -p $out/universal2-apple-darwin
# Combine liana-gui binaries
lipo -output $out/universal2-apple-darwin/liana-gui -create \
${x86_64-apple-darwin}/x86_64-apple-darwin/liana-gui \
${aarch64-apple-darwin}/aarch64-apple-darwin/liana-gui
'';
devShell = pkgs.mkShell rec {
buildInputs = with pkgs; [
expat
@ -161,9 +176,15 @@
x86_64-pc-windows-gnu = x86_64-pc-windows-gnu;
x86_64-apple-darwin = x86_64-apple-darwin;
aarch64-apple-darwin = aarch64-apple-darwin;
universal2-apple-darwin = universal2-apple-darwin;
release = pkgs.buildEnv {
name = "release";
paths = [ x86_64-pc-windows-gnu x86_64-apple-darwin aarch64-apple-darwin ];
paths = [
x86_64-pc-windows-gnu
x86_64-apple-darwin
aarch64-apple-darwin
universal2-apple-darwin
];
};
};