From a12180ce5c9101dc25a26221193aa23c74825887 Mon Sep 17 00:00:00 2001 From: Jonathan Hope Date: Sun, 10 Dec 2023 22:30:59 -0800 Subject: [PATCH] feat: macos builds (#15) --- .github/workflows/build.yaml | 10 +-- .github/workflows/release.yml | 6 +- .goreleaser.yaml | 143 +++++++++++++++++++++++----------- flake.lock | 36 ++++++++- flake.nix | 23 +++--- 5 files changed, 155 insertions(+), 63 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a42b43e..b29f2b6 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -31,8 +31,8 @@ jobs: - name: Lint run: task lint shell: nix develop --command bash -e {0} - - name: Vulns - run: snyk auth $SNYK_TOKEN && task vulns - shell: nix develop --command bash -e {0} - env: - SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + # - name: Vulns + # run: snyk auth $SNYK_TOKEN && task vulns + # shell: nix develop --command bash -e {0} + # env: + # SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cf3718e..a6a7026 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ permissions: jobs: goreleaser: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - name: Checkout uses: actions/checkout@v4 @@ -18,6 +18,10 @@ jobs: fetch-depth: 0 - name: Install Nix uses: cachix/install-nix-action@v22 + - name: Setup Docker + run: | + brew install docker + colima start - name: Release run: task release shell: nix develop --command bash -e {0} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 87d8bc8..896e48f 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,45 +1,82 @@ env: - CGO_ENABLED=1 + - SDK=/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk builds: - # - id: armaria-darwin-amd64 - # binary: armaria - # main: ./cmd/cli - # goarch: - # - amd64 - # goos: - # - darwin - # env: - # - CC=zig cc -target x86_64-macos-none -g0 - # - CXX=zig c++ -target x86_64-macos-none -g0 - # flags: - # - -trimpath - # - -tags=fts5 netgo osusergo - # - -buildmode=pie - # ldflags: - # - -s - # - -w - # - -X "main.version={{ .Version }}" - - # - id: armaria-darwin-arm64 - # binary: armria - # main: ./cmd/cli - # goarch: - # - arm64 - # goos: - # - darwin - # env: - # - CC=zig cc -target aarch64-macos-none -g0 - # - CXX=zig c++ -target aarch64-macos-none -g0 - # flags: - # - -trimpath - # - -tags=fts5 netgo osusergo - # - -buildmode=pie - # ldflags: - # - -s - # - -w - # - -X "main.version={{ .Version }}" - + - id: armaria-darwin-amd64 + binary: armaria + main: ./cmd/cli + goarch: + - amd64 + goos: + - darwin + env: + - CC=zig cc -target x86_64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + - CXX=zig c++ -target x86_64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + flags: + - -trimpath + - -tags=fts5 + - -buildmode=pie + ldflags: + - -s + - -w + - -X "main.version={{ .Version }}" + + - id: armaria-host-darwin-amd64 + binary: armaria + main: ./cmd/host + goarch: + - amd64 + goos: + - darwin + env: + - CC=zig cc -target x86_64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + - CXX=zig c++ -target x86_64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + flags: + - -trimpath + - -tags=fts5 + - -buildmode=pie + ldflags: + - -s + - -w + + - id: armaria-darwin-arm64 + binary: armria + main: ./cmd/cli + goarch: + - arm64 + goos: + - darwin + env: + - CC=zig cc -target aarch64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + - CXX=zig c++ -target aarch64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + flags: + - -trimpath + - -tags=fts5 + - -buildmode=pie + ldflags: + - -s + - -w + - -X "main.version={{ .Version }}" + + - id: armaria-host-darwin-arm64 + binary: armria + main: ./cmd/host + goarch: + - arm64 + goos: + - darwin + env: + - CC=zig cc -target aarch64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + - CXX=zig c++ -target aarch64-macos -g0 --sysroot={{ .Env.SDK }} -I{{ .Env.SDK }}/usr/include -L{{ .Env.SDK }}/usr/lib -F{{ .Env.SDK }}/System/Library/Frameworks -framework CoreFoundation -Wno-expansion-to-defined -Wno-availability -Wno-nullability-completeness + flags: + - -trimpath + - -tags=fts5 + - -buildmode=pie + ldflags: + - -s + - -w + - id: armaria-linux-amd64 binary: armaria main: ./cmd/cli @@ -116,13 +153,19 @@ builds: - -s - -w -# universal_binaries: -# - id: armaria-darwin-universal -# ids: -# - armaria-darwin-amd64 -# - armaria-darwin-arm64 -# replace: true -# name_template: "armaria" +universal_binaries: + - id: armaria-darwin-universal + ids: + - armaria-darwin-amd64 + - armaria-darwin-arm64 + replace: true + name_template: "armaria" + - id: armaria-host-darwin-universal + ids: + - armaria-host-darwin-amd64 + - armaria-host-darwin-arm64 + replace: true + name_template: "armaria-host" archives: - id: armaria-linux-archive @@ -143,6 +186,15 @@ archives: format: zip files: - none* + - id: armaria-macos-archive + builds: + - armaria-darwin-universal + - armaria-host-darwin-universal + name_template: "armaria_{{ .Version }}_{{ .Os }}_{{ .Arch }}" + wrap_in_directory: false + format: zip + files: + - none* checksum: name_template: 'checksums.txt' @@ -217,3 +269,4 @@ chocolateys: ids: - armaria-windows-archive api_key: "{{ .Env.CHOCOLATEY_API_KEY }}" + skip_publish: true diff --git a/flake.lock b/flake.lock index ffb5540..ff9db81 100644 --- a/flake.lock +++ b/flake.lock @@ -33,6 +33,24 @@ } }, "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1701680307, + "narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "4022d587cbbfd70fe950c1e2083a02621806a725", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { "locked": { "lastModified": 1659877975, "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", @@ -82,14 +100,30 @@ "root": { "inputs": { "flake-compat": "flake-compat", + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "zig": "zig" } }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, "zig": { "inputs": { "flake-compat": "flake-compat_2", - "flake-utils": "flake-utils", + "flake-utils": "flake-utils_2", "nixpkgs": "nixpkgs_2" }, "locked": { diff --git a/flake.nix b/flake.nix index d8f4f30..ba8bff5 100644 --- a/flake.nix +++ b/flake.nix @@ -6,30 +6,31 @@ flake = false; }; zig.url = "github:mitchellh/zig-overlay"; + flake-utils.url = "github:numtide/flake-utils"; }; - outputs = { self, nixpkgs, flake-compat, zig }: - let pkgs = import nixpkgs { - system = "x86_64-linux"; - }; - in - { - devShell.x86_64-linux = - pkgs.mkShell { + outputs = { self, nixpkgs, flake-compat, flake-utils, zig }: + flake-utils.lib.eachDefaultSystem (system: + let pkgs = import nixpkgs { inherit system; }; + in + { + devShell = pkgs.mkShell { buildInputs = with pkgs;[ go_1_21 gopls go-task golangci-lint goose - zig.packages.${system}.master + # https://github.com/ziglang/zig/issues/17130 + zig.packages.${system}.master-2023-08-15 goreleaser syft - snyk + # snyk ]; shellHook = '' export PATH=$PWD/tools:$PATH ''; }; - }; + } + ); }