Skip to content

Commit 690a733

Browse files
djwisdomqwencoder
andcommitted
feat: implement cross-platform build system with CI/CD
- Add CMake platform auto-detection (BSD=X11, Linux=Wayland, Windows=Win32) - Create GitHub Actions workflow for FreeBSD/Linux/Windows builds - Add pre-commit hook for build validation - Create 5 platform-specific build scripts - Update README with comprehensive build instructions - Document build system architecture in BUILD_SYSTEM.md Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
1 parent 0741db0 commit 690a733

12 files changed

Lines changed: 1327 additions & 17 deletions

.githooks/pre-commit

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
# ============================================================================
3+
# Pre-commit hook: Validates build compiles successfully before committing
4+
# ============================================================================
5+
#
6+
# Installation:
7+
# cp .githooks/pre-commit .git/hooks/pre-commit
8+
# chmod +x .git/hooks/pre-commit
9+
#
10+
# Or configure git to use the hooks directory:
11+
# git config core.hooksPath .githooks
12+
#
13+
# Skip with: git commit --no-verify
14+
# ============================================================================
15+
16+
set -e
17+
18+
echo "🔍 Running pre-commit build validation..."
19+
20+
# Detect platform
21+
PLATFORM="$(uname -s)"
22+
BUILD_DIR="build-precommit"
23+
24+
# Function to cleanup on exit
25+
cleanup() {
26+
if [ -d "$BUILD_DIR" ]; then
27+
rm -rf "$BUILD_DIR"
28+
fi
29+
}
30+
31+
# Only cleanup if we created the directory
32+
trap cleanup EXIT
33+
34+
case "$PLATFORM" in
35+
FreeBSD|OpenBSD|NetBSD)
36+
echo "📦 Building for BSD (X11)..."
37+
mkdir -p "$BUILD_DIR"
38+
cd "$BUILD_DIR"
39+
cmake .. \
40+
-DCMAKE_BUILD_TYPE=Release \
41+
-DGLFW_BUILD_WAYLAND=OFF \
42+
-DGLFW_BUILD_X11=ON > /dev/null 2>&1
43+
make -j$(sysctl -n hw.ncpu 2>/dev/null || echo 2) > /dev/null 2>&1
44+
;;
45+
Linux)
46+
echo "📦 Building for Linux (Wayland)..."
47+
mkdir -p "$BUILD_DIR"
48+
cd "$BUILD_DIR"
49+
cmake .. \
50+
-DCMAKE_BUILD_TYPE=Release \
51+
-DGLFW_BUILD_WAYLAND=ON \
52+
-DGLFW_BUILD_X11=OFF > /dev/null 2>&1
53+
make -j$(nproc) > /dev/null 2>&1
54+
;;
55+
Darwin)
56+
echo "📦 Building for macOS..."
57+
mkdir -p "$BUILD_DIR"
58+
cd "$BUILD_DIR"
59+
cmake .. -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
60+
make -j$(sysctl -n hw.ncpu) > /dev/null 2>&1
61+
;;
62+
MINGW*|MSYS*|CYGWIN*)
63+
echo "📦 Building for Windows..."
64+
mkdir -p "$BUILD_DIR"
65+
cd "$BUILD_DIR"
66+
cmake .. -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release > /dev/null 2>&1
67+
make -j$(nproc) > /dev/null 2>&1
68+
;;
69+
*)
70+
echo "❌ Unsupported platform: $PLATFORM"
71+
exit 1
72+
;;
73+
esac
74+
75+
# Verify executable exists
76+
if [ -f "pcode-editor" ] || [ -f "pcode-editor.exe" ]; then
77+
echo "✅ Build successful!"
78+
exit 0
79+
else
80+
echo "❌ Build failed - executable not found"
81+
exit 1
82+
fi

.github/workflows/build.yml

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
name: Cross-Platform Build
2+
3+
on:
4+
push:
5+
branches: [ main, master, develop ]
6+
pull_request:
7+
branches: [ main, master ]
8+
workflow_dispatch:
9+
10+
jobs:
11+
# ========================================================================
12+
# Linux Build (Wayland)
13+
# ========================================================================
14+
build-linux:
15+
name: Linux (Wayland)
16+
runs-on: ubuntu-22.04
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Install dependencies
23+
run: |
24+
sudo apt-get update
25+
sudo apt-get install -y \
26+
build-essential \
27+
cmake \
28+
libwayland-dev \
29+
wayland-protocols \
30+
libxkbcommon-dev \
31+
libgtk-3-dev \
32+
libgl1-mesa-dev \
33+
pkg-config
34+
35+
- name: Configure CMake
36+
run: |
37+
mkdir -p build
38+
cd build
39+
cmake .. \
40+
-DCMAKE_BUILD_TYPE=Release \
41+
-DGLFW_BUILD_WAYLAND=ON \
42+
-DGLFW_BUILD_X11=OFF
43+
44+
- name: Build
45+
run: |
46+
cd build
47+
make -j$(nproc)
48+
49+
- name: Verify executable
50+
run: |
51+
file build/pcode-editor
52+
ls -lh build/pcode-editor
53+
54+
- name: Upload artifact
55+
uses: actions/upload-artifact@v4
56+
with:
57+
name: pcode-editor-linux
58+
path: build/pcode-editor
59+
if-no-files-found: error
60+
61+
# ========================================================================
62+
# Windows Build (Win32)
63+
# ========================================================================
64+
build-windows:
65+
name: Windows (Win32)
66+
runs-on: windows-latest
67+
68+
steps:
69+
- name: Checkout code
70+
uses: actions/checkout@v4
71+
72+
- name: Setup MSVC
73+
uses: ilammy/msvc-dev-cmd@v1
74+
75+
- name: Configure CMake
76+
run: |
77+
mkdir build
78+
cd build
79+
cmake .. `
80+
-G "Visual Studio 17 2022" `
81+
-A x64 `
82+
-DCMAKE_BUILD_TYPE=Release
83+
84+
- name: Build
85+
run: |
86+
cd build
87+
cmake --build . --config Release --parallel $env:NUMBER_OF_PROCESSORS
88+
89+
- name: Verify executable
90+
shell: pwsh
91+
run: |
92+
Get-ChildItem build/Release/pcode-editor.exe
93+
(Get-Item build/Release/pcode-editor.exe).Length
94+
95+
- name: Upload artifact
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: pcode-editor-windows
99+
path: build/Release/pcode-editor.exe
100+
if-no-files-found: error
101+
102+
# ========================================================================
103+
# FreeBSD Build (X11)
104+
# ========================================================================
105+
build-freebsd:
106+
name: FreeBSD (X11)
107+
runs-on: ubuntu-latest
108+
strategy:
109+
matrix:
110+
freebsd-version: ['14.4']
111+
112+
steps:
113+
- name: Checkout code
114+
uses: actions/checkout@v4
115+
116+
- name: Build on FreeBSD
117+
uses: cross-platform-actions/action@v0.25.0
118+
with:
119+
operating_system: freebsd
120+
version: ${{ matrix.freebsd-version }}
121+
shell: bash
122+
run: |
123+
# Install dependencies
124+
sudo pkg update
125+
sudo pkg install -y \
126+
cmake \
127+
xorg-libX11 \
128+
xorgproto \
129+
gtk3 \
130+
mesa-libs \
131+
pkgconf \
132+
llvm19
133+
134+
# Configure and build
135+
mkdir -p build
136+
cd build
137+
cmake .. \
138+
-DCMAKE_BUILD_TYPE=Release \
139+
-DGLFW_BUILD_WAYLAND=OFF \
140+
-DGLFW_BUILD_X11=ON
141+
142+
make -j$(sysctl -n hw.ncpu)
143+
144+
# Verify
145+
file pcode-editor
146+
ls -lh pcode-editor
147+
148+
- name: Upload artifact
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: pcode-editor-freebsd
152+
path: build/pcode-editor
153+
if-no-files-found: error
154+
155+
# ========================================================================
156+
# Summary Job
157+
# ========================================================================
158+
build-summary:
159+
name: Build Summary
160+
needs: [build-linux, build-windows, build-freebsd]
161+
runs-on: ubuntu-latest
162+
if: always()
163+
164+
steps:
165+
- name: Build Status
166+
run: |
167+
echo "## Build Results" >> $GITHUB_STEP_SUMMARY
168+
echo "" >> $GITHUB_STEP_SUMMARY
169+
echo "| Platform | Status |" >> $GITHUB_STEP_SUMMARY
170+
echo "|----------|--------|" >> $GITHUB_STEP_SUMMARY
171+
echo "| Linux (Wayland) | ${{ needs.build-linux.result }} |" >> $GITHUB_STEP_SUMMARY
172+
echo "| Windows (Win32) | ${{ needs.build-windows.result }} |" >> $GITHUB_STEP_SUMMARY
173+
echo "| FreeBSD (X11) | ${{ needs.build-freebsd.result }} |" >> $GITHUB_STEP_SUMMARY

.gitignore

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
# Build directories
12
build/
3+
build-*/
4+
build-precommit/
5+
6+
# Executables
27
*.exe
38
pcode-editor
9+
pcode-editor.exe
10+
11+
# OS files
412
.DS_Store
513
Thumbs.db
14+
15+
# IDE files
16+
.vscode/
17+
.idea/
18+
*.swp
19+
*.swo
20+
*~
21+
22+
# CMake files
23+
CMakeCache.txt
24+
CMakeFiles/
25+
cmake_install.cmake
26+
Makefile
27+
compile_commands.json
28+
29+
# Test builds
30+
test-build/

0 commit comments

Comments
 (0)