1+ name : Build Zig for OpenHarmony
2+
3+ on :
4+ push :
5+ tags :
6+ - ' v*' # 当推送 tag 时触发
7+ workflow_dispatch : # 允许手动触发
8+
9+ jobs :
10+ build :
11+ runs-on : macos-14 # ARM-based macOS runner
12+
13+ steps :
14+ - name : Checkout repository
15+ uses : actions/checkout@v4
16+ with :
17+ submodules : recursive # 递归检出子模块
18+
19+ - name : Install dependencies
20+ run : |
21+ # 更新 Homebrew
22+ brew update
23+
24+ # 安装最新版本的依赖
25+ brew install llvm cmake
26+
27+ # 确保 lld 可用 (LLVM 包含 lld)
28+ echo "LLVM_DIR=$(brew --prefix llvm)" >> $GITHUB_ENV
29+ echo "$(brew --prefix llvm)/bin" >> $GITHUB_PATH
30+
31+ - name : Verify installations
32+ run : |
33+ # 验证安装的版本
34+ cmake --version
35+ llvm-config --version
36+ ld64.lld --version || lld --version
37+
38+ - name : Apply patches to zig-bootstrap
39+ run : |
40+ # 检查是否存在 patch 文件目录
41+ if [ -d "patch" ]; then
42+ echo "Applying patches to zig-bootstrap submodule..."
43+ cd zig-bootstrap
44+
45+ # 应用所有 patch 文件
46+ for patch in ../patch/*.patch; do
47+ if [ -f "$p" ]; then
48+ echo "Applying patch: $p"
49+ git apply "$p" || {
50+ echo "Failed to apply patch: $p"
51+ exit 1
52+ }
53+ fi
54+ done
55+
56+ cd ..
57+ else
58+ echo "No patches directory found, skipping patch application"
59+ fi
60+
61+ - name : Build Zig
62+ run : |
63+ cd zig-bootstrap
64+
65+ # 设置环境变量
66+ export PATH="$LLVM_DIR/bin:$PATH"
67+
68+ # 执行构建命令
69+ echo "Starting build process..."
70+ ./build aarch64-macos-none baseline
71+
72+ - name : Verify build output
73+ run : |
74+ # 检查构建输出
75+ ls -la zig-bootstrap/out/
76+ if [ -d "zig-bootstrap/out/zig-aarch64-macos-none-baseline" ]; then
77+ echo "Build successful!"
78+ ls -la zig-bootstrap/out/zig-aarch64-macos-none-baseline/
79+ else
80+ echo "Build failed - output directory not found"
81+ exit 1
82+ fi
83+
84+ - name : Create release archive
85+ run : |
86+ cd zig-bootstrap/out
87+
88+ # 创建压缩包
89+ tar -czf zig-aarch64-macos-none-baseline.tar.gz zig-aarch64-macos-none-baseline/
90+
91+ # 验证压缩包
92+ ls -lh zig-aarch64-macos-none-baseline.tar.gz
93+
94+ # 移动到工作目录根目录
95+ mv zig-aarch64-macos-none-baseline.tar.gz ../../
96+
97+ - name : Get tag name
98+ id : get_tag
99+ run : |
100+ if [[ $GITHUB_REF == refs/tags/* ]]; then
101+ echo "tag_name=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
102+ else
103+ echo "tag_name=dev-$(date +%Y%m%d-%H%M%S)" >> $GITHUB_OUTPUT
104+ fi
105+
106+ - name : Create Release
107+ id : create_release
108+ uses : actions/create-release@v1
109+ env :
110+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
111+ with :
112+ tag_name : ${{ steps.get_tag.outputs.tag_name }}
113+ release_name : Zig OpenHarmony Build ${{ steps.get_tag.outputs.tag_name }}
114+ body : |
115+ ## Zig OpenHarmony Build
116+
117+ This release contains a Zig compiler built specifically for OpenHarmony development.
118+
119+ ### Build Information
120+ - Target: aarch64-macos-none-baseline
121+ - Built on: ARM macOS
122+ - Date: ${{ github.event.head_commit.timestamp }}
123+ - Commit: ${{ github.sha }}
124+
125+ ### Usage
126+ 1. Download the `zig-aarch64-macos-none-baseline.tar.gz` file
127+ 2. Extract it: `tar -xzf zig-aarch64-macos-none-baseline.tar.gz`
128+ 3. Add the `bin` directory to your PATH
129+
130+ ### Changes
131+ ${{ github.event.head_commit.message }}
132+ draft : false
133+ prerelease : false
134+
135+ - name : Upload Release Asset
136+ uses : actions/upload-release-asset@v1
137+ env :
138+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
139+ with :
140+ upload_url : ${{ steps.create_release.outputs.upload_url }}
141+ asset_path : ./zig-aarch64-macos-none-baseline.tar.gz
142+ asset_name : zig-aarch64-macos-none-baseline.tar.gz
143+ asset_content_type : application/gzip
144+
145+ - name : Upload build artifacts (backup)
146+ uses : actions/upload-artifact@v4
147+ with :
148+ name : zig-aarch64-macos-none-baseline
149+ path : zig-aarch64-macos-none-baseline.tar.gz
150+ retention-days : 30
0 commit comments