From 5d30ea24fb947b81a96ef284f56ffe7e3f1fdc36 Mon Sep 17 00:00:00 2001 From: edouardparis Date: Mon, 6 Jan 2025 12:45:27 +0100 Subject: [PATCH] build: add universal2-apple-darwin target with lipo --- contrib/release/release.sh | 17 +++++---- flake.lock | 71 +++++++++++++++++++++++++++++++++++++- flake.nix | 25 ++++++++++++-- 3 files changed, 103 insertions(+), 10 deletions(-) diff --git a/contrib/release/release.sh b/contrib/release/release.sh index 6425f9af..fcf4f71d 100755 --- a/contrib/release/release.sh +++ b/contrib/release/release.sh @@ -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/" ) diff --git a/flake.lock b/flake.lock index ad945ebb..20c180ed 100644 --- a/flake.lock +++ b/flake.lock @@ -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", diff --git a/flake.nix b/flake.nix index 48f98a77..d6a963f6 100644 --- a/flake.nix +++ b/flake.nix @@ -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 + ]; }; };