Skip to content

Commit f6d963d

Browse files
committed
ci: enhance build workflow with multi-platform support
Add macOS build target and implement matrix-based builds for all platforms. Refactor GitHub Actions workflow to separate build and release jobs, with proper artifact handling. Update documentation with platform-specific build requirements and extend build script to support macOS compilation using Zig.
1 parent 68d7ee1 commit f6d963d

File tree

3 files changed

+86
-19
lines changed

3 files changed

+86
-19
lines changed

.github/workflows/go.yml

Lines changed: 55 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# This workflow will build a golang project
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3-
4-
name: Go
1+
name: Build and Release
52

63
on:
74
push:
@@ -13,9 +10,21 @@ on:
1310

1411
jobs:
1512
build:
16-
runs-on: ubuntu-latest
17-
permissions:
18-
contents: write
13+
name: Build on ${{ matrix.os }}
14+
runs-on: ${{ matrix.os }}
15+
strategy:
16+
matrix:
17+
include:
18+
- os: ubuntu-latest
19+
output_name: dback-linux
20+
asset_name: dback-linux
21+
- os: macos-latest
22+
output_name: dback-macos
23+
asset_name: dback-macos
24+
- os: windows-latest
25+
output_name: dback-windows.exe
26+
asset_name: dback-windows.exe
27+
1928
steps:
2029
- uses: actions/checkout@v4
2130

@@ -24,25 +33,54 @@ jobs:
2433
with:
2534
go-version: "1.21"
2635

27-
- name: Install Dependencies (Linux & Windows Cross-Compile)
36+
# Install dependencies only on Linux
37+
- name: Install Linux Dependencies
38+
if: runner.os == 'Linux'
2839
run: |
2940
sudo apt-get update
30-
sudo apt-get install -y libgl1-mesa-dev xorg-dev gcc-mingw-w64
41+
sudo apt-get install -y libgl1-mesa-dev xorg-dev
3142
32-
- name: Build Linux
33-
run: go build -v -o dback-linux main.go
34-
35-
- name: Build Windows
36-
run: |
37-
CC=x86_64-w64-mingw32-gcc CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build -v -o dback-windows.exe main.go
43+
# Build
44+
- name: Build
45+
run: go build -v -o ${{ matrix.output_name }} main.go
3846

47+
# Test (Skip on Windows if problematic with CGO, but usually fine)
3948
- name: Test
4049
run: go test -v ./...
4150

42-
- name: Release
51+
# Upload Artifact
52+
- name: Upload Artifact
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: ${{ matrix.asset_name }}
56+
path: ${{ matrix.output_name }}
57+
58+
release:
59+
needs: build
60+
if: startsWith(github.ref, 'refs/tags/')
61+
runs-on: ubuntu-latest
62+
permissions:
63+
contents: write
64+
steps:
65+
- name: Download Linux Artifact
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: dback-linux
69+
70+
- name: Download macOS Artifact
71+
uses: actions/download-artifact@v3
72+
with:
73+
name: dback-macos
74+
75+
- name: Download Windows Artifact
76+
uses: actions/download-artifact@v3
77+
with:
78+
name: dback-windows.exe
79+
80+
- name: Create Release
4381
uses: softprops/action-gh-release@v1
44-
if: startsWith(github.ref, 'refs/tags/')
4582
with:
4683
files: |
4784
dback-linux
85+
dback-macos
4886
dback-windows.exe

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,24 @@ This script handles dependency checks and runs the application.
3939
*Note: You may need to install `gcc`, `libgl1-mesa-dev`, and `xorg-dev` if prompted.*
4040

4141
### Build Binaries
42-
To generate standalone executables for Linux and Windows:
42+
To generate standalone executables for Linux, Windows, and macOS:
4343

4444
```bash
4545
./build.sh
4646
```
47-
*Artifacts will be created as `dback-linux` and `dback-windows.exe`.*
47+
*Artifacts will be created as `dback-linux`, `dback-windows.exe`, and `dback-macos`.*
48+
49+
## Build Requirements
50+
51+
To build the application from source, you need **Go 1.21+** and the following platform-specific dependencies:
52+
53+
| Platform | Requirements |
54+
| :--- | :--- |
55+
| **Linux** | `gcc`, `libgl1-mesa-dev`, `xorg-dev` |
56+
| **Windows** | `gcc` (MinGW-w64 or TDM-GCC) |
57+
| **macOS** | Xcode Command Line Tools (`xcode-select --install`) |
58+
| **Cross-Compile (Linux -> Windows)** | `mingw-w64` (`gcc-mingw-w64`) |
59+
| **Cross-Compile (Linux -> macOS)** | `zig` or `osxcross` |
4860

4961
### Docker Alternative
5062
If you have issues with system dependencies, you can run the app in a container:

build.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,20 @@ else
2424
echo "To build for Windows on Linux, install 'mingw-w64':"
2525
echo " sudo apt-get install mingw-w64"
2626
fi
27+
28+
echo ""
29+
echo "Building for macOS..."
30+
# Check for cross-compiler (Zig is best for macOS CGO cross-compilation)
31+
if command -v zig &> /dev/null; then
32+
echo "Using Zig for macOS cross-compilation..."
33+
CC="zig cc -target x86_64-macos" CXX="zig c++ -target x86_64-macos" CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 go build -o dback-macos main.go
34+
if [ $? -eq 0 ]; then
35+
echo "macOS build successful: ./dback-macos"
36+
else
37+
echo "macOS build failed."
38+
fi
39+
else
40+
echo "Cross-compiler for macOS not found (Zig recommended)."
41+
echo "To build for macOS on Linux, install 'zig' or 'osxcross'."
42+
echo "Example with Zig: snap install zig --classic"
43+
fi

0 commit comments

Comments
 (0)