@@ -16,90 +16,68 @@ name: Build
1616
1717on :
1818 push :
19- branches : [ main ]
19+ branches : [main]
2020 pull_request :
21- branches : [ main ]
21+ branches : [main]
2222
2323permissions :
2424 contents : read
2525
2626jobs :
27- build-no-console :
28- name : Build (no console, no CGO)
27+ # Linux + Windows are cross-compiled with zig on a (cheap) Linux runner.
28+ cross-build :
29+ name : Cross-build linux+windows (zig)
2930 runs-on : ubuntu-latest
3031 steps :
3132 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
33+ with :
34+ submodules : true
3235
3336 - name : Set up Go
3437 uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
3538 with :
3639 go-version-file : go.mod
3740
38- - name : Build without console tag
39- env :
40- CGO_ENABLED : " 0"
41- run : go build -o bin/lk ./cmd/lk
42-
43- - name : Verify binary
44- run : bin/lk --help > /dev/null
45-
46- lint-and-test :
47- runs-on : ubuntu-latest
48- steps :
49- - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
41+ - name : Install Zig
42+ uses : mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2
5043 with :
51- submodules : true
44+ version : 0.14.1
5245
53- - name : Set up Go
54- uses : actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
46+ - name : Cache cross-compile inputs
47+ uses : actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
5548 with :
56- go-version-file : go.mod
49+ path : .cross
50+ key : cross-${{ runner.os }}-zig0.14.1-alsa1.2.12-${{ hashFiles('scripts/setup-cross.sh') }}
5751
58- - name : Static Check
59- uses : dominikh/staticcheck -action@288b4e28bae83c59f35f73651aeb5cab746a06fc # v1.4.0
52+ - name : GoReleaser snapshot build
53+ uses : goreleaser/goreleaser -action@ec59f474b9834571250b370d4735c50f8e2d1e29 # v7
6054 with :
61- version : " latest"
62- install-go : false
63-
64- - name : Test
65- run : go test -v ./...
55+ distribution : goreleaser
56+ version : latest
57+ # darwin is excluded here — it can't be cross-compiled from Linux
58+ # (no macOS SDK/CoreAudio); it builds natively in the macos job below.
59+ args : >-
60+ build --snapshot --clean
61+ --id lk-linux-amd64 --id lk-linux-arm64
62+ --id lk-windows-amd64 --id lk-windows-arm64
63+ env :
64+ # goreleaser-action runs goreleaser via a Node wrapper that doesn't
65+ # forward PWD; the .goreleaser.yaml CGO flags template {{ .Env.PWD }}
66+ # to locate .cross/<target>. Provide it explicitly.
67+ PWD : ${{ github.workspace }}
6668
67- build :
68- strategy :
69- fail-fast : false
70- matrix :
71- include :
72- - os : macos-latest
73- suffix : darwin_arm64
74- - os : ubuntu-latest
75- suffix : linux_amd64
76- zig_target : x86_64-linux-gnu.2.28
77- alsa_arch : amd64
78- alsa_triple : x86_64-linux-gnu
79- - os : ubuntu-latest
80- suffix : linux_arm64
81- zig_target : aarch64-linux-gnu.2.28
82- alsa_arch : arm64
83- alsa_triple : aarch64-linux-gnu
84- goarch : arm64
85- - os : ubuntu-latest
86- suffix : linux_arm
87- zig_target : arm-linux-gnueabihf.2.28
88- alsa_arch : armhf
89- alsa_triple : arm-linux-gnueabihf
90- goarch : arm
91- goarm : " 7"
92- - os : ubuntu-latest
93- suffix : windows_amd64
94- zig_target : x86_64-windows-gnu
95- goos : windows
96- goarch : amd64
97- - os : ubuntu-latest
98- suffix : windows_arm64
99- zig_target : aarch64-windows-gnu
100- goos : windows
101- goarch : arm64
102- runs-on : ${{ matrix.os }}
69+ - name : Verify linux binary runs
70+ run : |
71+ binary=$(find dist -type f -name lk -path '*linux*amd64*' | head -n1)
72+ test -n "$binary" || { echo "no linux/amd64 binary in dist/"; exit 1; }
73+ # Static-libgcc/libstdc++ binary should run on glibc 2.28+ Ubuntu runners.
74+ "$binary" --help > /dev/null
75+
76+ # darwin builds natively on macOS — its cgo links the CoreAudio frameworks,
77+ # which only exist on a Mac. No zig needed.
78+ build-darwin :
79+ name : Build darwin (native)
80+ runs-on : macos-latest
10381 steps :
10482 - uses : actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
10583 with :
@@ -110,73 +88,11 @@ jobs:
11088 with :
11189 go-version-file : go.mod
11290
113- - name : Install Zig
114- if : matrix.zig_target
115- uses : mlugg/setup-zig@d1434d08867e3ee9daa34448df10607b98908d29 # v2
116- with :
117- version : 0.14.1
118-
119- - name : Install ALSA headers
120- if : matrix.alsa_arch
121- run : |
122- sudo dpkg --add-architecture ${{ matrix.alsa_arch }}
123- if [ "${{ matrix.alsa_arch }}" != "amd64" ]; then
124- CODENAME=$(lsb_release -cs)
125- # Restrict existing sources to amd64 to avoid 404s for foreign arch
126- for f in /etc/apt/sources.list.d/*.sources; do
127- grep -q '^Architectures:' "$f" || sudo sed -i '/^Types:/a Architectures: amd64 i386' "$f"
128- done
129- # Add ports.ubuntu.com for the foreign architecture
130- printf 'Types: deb\nURIs: http://ports.ubuntu.com/ubuntu-ports\nSuites: %s %s-updates\nComponents: main universe\nArchitectures: %s\nSigned-By: /usr/share/keyrings/ubuntu-archive-keyring.gpg\n' \
131- "$CODENAME" "$CODENAME" "${{ matrix.alsa_arch }}" | sudo tee /etc/apt/sources.list.d/ports.sources
132- fi
133- sudo apt-get update
134- sudo apt-get install -y libasound2-dev:${{ matrix.alsa_arch }}
135-
136- - name : Generate Windows import libraries
137- if : matrix.goos == 'windows' && matrix.zig_target
91+ - name : Build and verify
13892 run : |
139- ZIG_LIB=$(zig env | jq -r '.lib_dir')
140- echo "ZIG_LIB=${ZIG_LIB}" >> "$GITHUB_ENV"
141- LIB_DIR="${ZIG_LIB}/libc/mingw/lib-common"
142- # Zig bundles MinGW .def files but lld needs .a import libraries.
143- # Go's compiled objects embed COFF /DEFAULTLIB directives (e.g. dbghelp,
144- # bcrypt) that lld resolves directly, bypassing Zig's lazy .def→.a
145- # generation. Pre-generate all import libraries so lld can find them.
146- MACHINE=${{ matrix.goarch == 'amd64' && 'i386:x86-64' || 'arm64' }}
147- for def in "${LIB_DIR}"/*.def; do
148- lib=$(basename "$def" .def)
149- [ -f "${LIB_DIR}/lib${lib}.a" ] && continue
150- zig dlltool -d "$def" -l "${LIB_DIR}/lib${lib}.a" -m "$MACHINE" 2>/dev/null || true
151- done
152-
153- - name : Build
154- env :
155- CGO_ENABLED : ${{ (matrix.goos && !matrix.zig_target) && '0' || '1' }}
156- CC : ${{ matrix.zig_target && format('zig cc -target {0}', matrix.zig_target) || '' }}
157- CXX : ${{ matrix.zig_target && format('zig c++ -target {0}', matrix.zig_target) || '' }}
158- # Zig uses its own sysroot; point it at the system ALSA headers and libraries
159- CGO_CFLAGS : ${{ matrix.alsa_triple && format('-isystem /usr/include -isystem /usr/include/{0}', matrix.alsa_triple) || '' }}
160- CGO_LDFLAGS : ${{ matrix.alsa_triple && format('-L/usr/lib/{0}', matrix.alsa_triple) || '' }}
161- # -fms-extensions: enable __try/__except (SEH) used by WebRTC
162- # -DNTDDI_VERSION: target Windows 10 base to skip WinRT includes absent from MinGW
163- CGO_CXXFLAGS : ${{ matrix.goos == 'windows' && '-fms-extensions -DNTDDI_VERSION=0x0A000000' || '' }}
164- GOOS : ${{ matrix.goos || '' }}
165- GOARCH : ${{ matrix.goarch || '' }}
166- GOARM : ${{ matrix.goarm || '' }}
167- shell : bash
168- run : |
169- EXT=""; if [ "${GOOS:-}" = "windows" ]; then EXT=".exe"; fi
170- TAGS=""
171- if [ "$CGO_ENABLED" = "1" ]; then TAGS="-tags console"; fi
172- # Force external linking for Windows so Go uses zig cc (CC) as the linker,
173- # and add Zig's MinGW lib path so lld can find the generated import libraries.
174- EXTLD=""
175- if [ "${GOOS:-}" = "windows" ] && [ "$CGO_ENABLED" = "1" ]; then
176- EXTLD="-linkmode=external -extldflags '-L${ZIG_LIB}/libc/mingw/lib-common'"
177- fi
178- go build $TAGS -ldflags "-w -s $EXTLD" -o "bin/lk${EXT}" ./cmd/lk
179-
180- - name : Verify binary
181- if : " !matrix.goos && !matrix.goarch"
182- run : bin/lk --help > /dev/null
93+ # arm64 native — build and run.
94+ CGO_ENABLED=1 go build -o /tmp/lk ./cmd/lk
95+ /tmp/lk --help > /dev/null
96+ # amd64 (Intel) cross — Apple clang targets x86_64 from arm64; compile
97+ # only (can't run an x86_64 binary on the arm64 runner).
98+ CGO_ENABLED=1 GOARCH=amd64 go build -o /tmp/lk-amd64 ./cmd/lk
0 commit comments