Skip to content

Commit

Permalink
Use Nix platform identifiers for release binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
amesgen committed May 6, 2024
1 parent 9265f67 commit 5f214b3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
41 changes: 30 additions & 11 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,35 @@ jobs:
matrix:
include:
- os: ubuntu-latest
targetOs: Linux
system: x86_64-linux
attr: native
- os: macOS-latest
targetOs: macOS
system: aarch64-darwin
attr: native
- os: macOS-latest
system: x86_64-darwin
attr: native
- os: ubuntu-latest
targetOs: Windows
name: Build binary for ${{ matrix.targetOs }}
system: x86_64-linux
attr: windows
name: Build ${{ matrix.attr }} binary on ${{ matrix.system }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v26
with:
extra_nix_config: |
accept-flake-config = true
- name: Get target system
id: system
run: |
( echo -n "SYSTEM="
nix eval -L --system ${{ matrix.system }} .#binaries/${{ matrix.attr }} \
--apply 'd: d.stdenv.hostPlatform.system'
echo ) >> "$GITHUB_OUTPUT"
- name: Build binary
run: nix build -L .#binaries/${{ matrix.targetOS }}
run: |
nix build -L --system ${{ matrix.system }} .#binaries/${{ matrix.attr }}
- name: Prepare upload
run: |
cd result/bin
Expand All @@ -35,22 +49,27 @@ jobs:
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ormolu.zip
asset_name: ormolu-${{ matrix.targetOs }}.zip
asset_name: ormolu-${{ steps.system.outputs.SYSTEM }}.zip
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
include:
- os: ubuntu-latest
system: x86_64-linux
- os: macOS-latest
system: aarch64-darwin
- os: macOS-latest
system: x86_64-darwin
- os: windows-latest
system: x86_64-windows
name: Test built binaries
runs-on: ${{ matrix.os }}
needs: build
steps:
- name: Download and extract binary
run: |
curl -sL https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/ormolu-${{ runner.os }}.zip > ormolu.zip
curl -sL https://github.com/${{ github.repository }}/releases/download/${{ github.event.release.tag_name }}/ormolu-${{ matrix.system }}.zip > ormolu.zip
7z e ormolu.zip
- name: Basic functionality tests
run: |
Expand Down
16 changes: 10 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,29 @@
};
ormoluExe = hsPkgs: hsPkgs.hsPkgs.ormolu.components.exes.ormolu;
linuxWindows = {
Linux = ormoluExe hsPkgs.projectCross.musl64;
Windows = ormoluExe hsPkgs.projectCross.mingwW64;
native = ormoluExe hsPkgs.projectCross.musl64;
windows = ormoluExe hsPkgs.projectCross.mingwW64;
};
macOS = pkgs.runCommand "ormolu-macOS"
macOS.native = pkgs.runCommand "ormolu-macOS"
{
nativeBuildInputs = [ pkgs.macdylibbundler ];
nativeBuildInputs = [
pkgs.macdylibbundler
pkgs.darwin.autoSignDarwinBinariesHook
];
} ''
mkdir -p $out/bin
cp ${ormoluExe hsPkgs}/bin/ormolu $out/bin/ormolu
chmod 755 $out/bin/ormolu
dylibbundler -b \
dylibbundler -b --no-codesign \
-x $out/bin/ormolu \
-d $out/bin \
-p '@executable_path'
signDarwinBinariesInAllOutputs
'';
in
lib.recurseIntoAttrs
(lib.optionalAttrs (system == "x86_64-linux") linuxWindows
// lib.optionalAttrs (system == "x86_64-darwin") { inherit macOS; });
// lib.optionalAttrs pkgs.hostPlatform.isDarwin macOS);

pre-commit-check = inputs.pre-commit-hooks.lib.${system}.run {
src = ./.;
Expand Down

0 comments on commit 5f214b3

Please sign in to comment.