From 44d94be99dd462daa0979230a2a3e0c1e6538221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 24 Nov 2024 23:05:41 +0100 Subject: [PATCH] make target mandatory input --- .github/workflows/pre-release.yml | 17 ++++++++---- cross-systems.nix | 30 -------------------- default.nix | 21 +++++++++----- package.nix | 8 ------ systems.nix | 46 +++++++++++++++++++++++++++++++ 5 files changed, 72 insertions(+), 50 deletions(-) delete mode 100644 cross-systems.nix create mode 100644 systems.nix diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml index e3ea265e..e064bbd6 100644 --- a/.github/workflows/pre-release.yml +++ b/.github/workflows/pre-release.yml @@ -11,23 +11,31 @@ jobs: matrix: include: - target: aarch64-apple-darwin + artifact: macos.aarch64 os: macos-14 - target: aarch64-unknown-linux-musl + artifact: linux.aarch64 os: ubuntu-latest - target: armv6l-unknown-linux-musleabihf + artifact: linux.armv6l os: ubuntu-latest - target: armv7l-unknown-linux-musleabihf + artifact: linux.armv7l os: ubuntu-latest - target: i686-unknown-linux-musl + artifact: linux.i686 + os: ubuntu-latest + - target: i686-w64-mingw32 + artifact: windows.i686 os: ubuntu-latest - # FIXME - # - target: i686-w64-mingw32 - # os: ubuntu-latest - target: x86_64-apple-darwin + artifact: macos.x86_64 os: macos-13 - target: x86_64-unknown-linux-musl + artifact: linux.x86_64 os: ubuntu-latest - target: x86_64-w64-mingw32 + artifact: windows.x86_64 os: ubuntu-latest steps: - name: Checkout code @@ -37,7 +45,6 @@ jobs: with: nix_path: nixpkgs=channel:nixos-24.05 enable_kvm: true - # extra_nix_config: "experimental-features = nix-command flakes" - name: Cache Nix store uses: cachix/cachix-action@v15 with: @@ -50,7 +57,7 @@ jobs: - name: Upload release artifacts uses: actions/upload-artifact@v4 with: - name: "himalaya.${{ matrix.target }}" + name: "himalaya.${{ matrix.artifact }}" path: | result/bin/himalaya* result/bin/share diff --git a/cross-systems.nix b/cross-systems.nix deleted file mode 100644 index 7416a4e3..00000000 --- a/cross-systems.nix +++ /dev/null @@ -1,30 +0,0 @@ -# The first level represents the build platform system, and the second -# level represents the build platform triple config. - -{ - x86_64-linux = { - x86_64-unknown-linux-musl = { }; - - aarch64-unknown-linux-musl = { - runner = { qemu, ... }: "${qemu}/bin/qemu-aarch64 ./himalaya"; - }; - - x86_64-pc-windows-gnu = { - runner = { wine, ... }: - let wine64 = wine.override { wineBuild = "wine64"; }; - in "${wine64}/bin/wine64 ./himalaya.exe"; - }; - }; - - aarch64-linux = { - x86_64-unknown-linux-musl = { }; - }; - - x86_64-darwin = { - x86_64-apple-darwin = { }; - }; - - aarch64-darwin = { - aarch64-apple-darwin = { }; - }; -} diff --git a/default.nix b/default.nix index 07574b2b..0c5620b7 100644 --- a/default.nix +++ b/default.nix @@ -1,11 +1,18 @@ -{ target ? null, defaultFeatures ? true, features ? "" }: +{ target +, defaultFeatures ? true +, features ? "" +}: let - pkgs = import ( - if isNull target then { } else { - crossSystem = { isStatic = true; config = target; }; - } - ); + systems = import ./systems.nix; + inherit (systems.${target}) rustTarget isStatic; + + pkgs = import { + crossSystem = { + inherit isStatic; + config = target; + }; + }; inherit (pkgs) lib hostPlatform; @@ -15,7 +22,7 @@ let rustToolchain = mkToolchain.fromTarget { inherit lib; - targetSystem = hostPlatform.config; + targetSystem = rustTarget; }; rustPlatform = pkgs.makeRustPlatform { diff --git a/package.nix b/package.nix index 5da1ebf9..09af5419 100644 --- a/package.nix +++ b/package.nix @@ -28,19 +28,11 @@ rustPlatform.buildRustPackage rec { cargoHash = "sha256-YS8IamapvmdrOPptQh2Ef9Yold0IK1XIeGs0kDIQ5b8="; - # TARGET_CC = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc"; - # CARGO_BUILD_RUSTFLAGS = [ - # "-Clinker=${TARGET_CC}" - # "-Clink-args=-static -latomic" - # "-Ctarget-feature=+crt-static" - # ]; - # unit tests only doCheck = false; cargoTestFlags = [ "--lib" ]; nativeBuildInputs = [ ] - ++ lib.optional hostPlatform.isDarwin [ darwin.libiconv ] ++ lib.optional (installManPages || installShellCompletions) installShellFiles; buildInputs = [ ] diff --git a/systems.nix b/systems.nix new file mode 100644 index 00000000..5ba672d0 --- /dev/null +++ b/systems.nix @@ -0,0 +1,46 @@ +{ + aarch64-apple-darwin = { + rustTarget = "aarch64-apple-darwin"; + isStatic = false; + }; + + aarch64-unknown-linux-musl = { + rustTarget = "aarch64-unknown-linux-musl"; + isStatic = true; + }; + + armv6l-unknown-linux-musleabihf = { + rustTarget = "arm-unknown-linux-musleabihf"; + isStatic = true; + }; + + armv7l-unknown-linux-musleabihf = { + rustTarget = "armv7-unknown-linux-musleabihf"; + isStatic = true; + }; + + i686-unknown-linux-musl = { + rustTarget = "i686-unknown-linux-musl"; + isStatic = true; + }; + + i686-w64-mingw32 = { + rustTarget = "i686-pc-windows-gnu"; + isStatic = false; + }; + + x86_64-apple-darwin = { + rustTarget = "x86_64-apple-darwin"; + isStatic = false; + }; + + x86_64-unknown-linux-musl = { + rustTarget = "x86_64-unknown-linux-musl"; + isStatic = true; + }; + + x86_64-w64-mingw32 = { + rustTarget = "x86_64-pc-windows-gnu"; + isStatic = false; + }; +}