Skip to content

Commit

Permalink
Build self-contained macOS binary
Browse files Browse the repository at this point in the history
Also add a basic test that the binaries actually work
  • Loading branch information
amesgen committed Sep 23, 2021
1 parent e38a7cd commit eb65577
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
28 changes: 24 additions & 4 deletions .github/workflows/binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ jobs:
matrix:
include:
- os: ubuntu-latest
attr: projectCross.musl64.hsPkgs.ormolu.components.exes.ormolu
targetOs: Linux
- os: macOS-latest
attr: ormoluExe
targetOs: macOS
- os: ubuntu-latest
attr: projectCross.mingwW64.hsPkgs.ormolu.components.exes.ormolu
targetOs: Windows
name: Build binary for ${{ matrix.targetOs }}
runs-on: ${{ matrix.os }}
Expand All @@ -27,7 +24,7 @@ jobs:
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ=
substituters = https://cache.nixos.org https://hydra.iohk.io
- name: Build binary
run: nix-build -A ${{ matrix.attr }}
run: nix-build -A binaries.${{ matrix.targetOS }}
- name: Prepare upload
run: |
cd result/bin
Expand All @@ -40,3 +37,26 @@ jobs:
asset_path: ormolu.zip
asset_name: ormolu-${{ matrix.targetOs }}.zip
asset_content_type: application/zip
test:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macOS-latest
- windows-latest
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
7z e ormolu.zip
chmod +x ormolu
- name: Basic functionality tests
shell: bash
run: |
./ormolu --version
echo "data A = A" > test.hs
./ormolu -m check test.hs
16 changes: 15 additions & 1 deletion default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ let
else null;
}) ormolizablePackages;
in {
projectCross = hsPkgs.projectCross;
ormoluLib = ormolu.components.library;
ormoluTests = ormolu.checks.tests;
ormolu = ormoluExe; # for compatibility
Expand Down Expand Up @@ -176,4 +175,19 @@ in {
find . -name '*.hs' -exec cp --parents {} $out \;
'';
};
binaries = {
Linux = hsPkgs.projectCross.musl64.hsPkgs.ormolu.components.exes.ormolu;
macOS = pkgs.runCommand "ormolu-macOS" {
buildInputs = [ pkgs.macdylibbundler ];
} ''
mkdir -p $out/bin
cp ${ormoluExe}/bin/ormolu $out/bin/ormolu
chmod 755 $out/bin/ormolu
dylibbundler -b \
-x $out/bin/ormolu \
-d $out/bin \
-p '@executable_path'
'';
Windows = hsPkgs.projectCross.mingwW64.hsPkgs.ormolu.components.exes.ormolu;
};
}

0 comments on commit eb65577

Please sign in to comment.