-
Notifications
You must be signed in to change notification settings - Fork 19
250 lines (228 loc) · 8.68 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
name: main
on:
push:
branches:
- msvc
paths:
- .github/workflows/main.yml
workflow_dispatch:
jobs:
build:
# 将 runs-on 移动到 strategy.matrix 内
runs-on: ${{ matrix.runner }}
strategy:
matrix:
include:
# === Linux部分 ===
- os: linux
arch: x64
host: x86_64-pc-linux-gnu
gmp_so: libgmp.so.10.5.0
gmp_cpp_so: libgmpxx.so.4.7.0
strip: strip
runner: ubuntu-latest
- os: linux
arch: x86
host: i686-pc-linux-gnu
gmp_so: libgmp.so.10.5.0
gmp_cpp_so: libgmpxx.so.4.7.0
strip: strip
runner: ubuntu-latest
- os: linux
arch: arm64
host: aarch64-linux-gnu
gmp_so: libgmp.so.10.5.0
gmp_cpp_so: libgmpxx.so.4.7.0
strip: aarch64-linux-gnu-strip
runner: ubuntu-latest
- os: linux
arch: arm
host: arm-linux-gnueabihf
gmp_so: libgmp.so.10.5.0
gmp_cpp_so: libgmpxx.so.4.7.0
strip: arm-linux-gnueabihf-strip
runner: ubuntu-latest
# === Windows (Mingw 交叉编译, 仍然在 ubuntu-latest 上跑) ===
- os: win
arch: x64
host: x86_64-w64-mingw32
gmp_so: libgmp-10.dll
gmp_cpp_so: libgmpxx-4.dll
strip: x86_64-w64-mingw32-strip
runner: ubuntu-latest
- os: win
arch: x86
host: i686-w64-mingw32
gmp_so: libgmp-10.dll
gmp_cpp_so: libgmpxx-4.dll
strip: i686-w64-mingw32-strip
runner: ubuntu-latest
# === Windows-ARM64 (用 MSVC/cl, 需在 windows-latest 上跑) ===
- os: win
arch: arm64
gmp_so: libgmp-10.dll
gmp_cpp_so: libgmpxx-4.dll
strip: echo
runner: windows-latest
env:
GMP_VERSION: 6.3
steps:
- name: Check out repository
uses: actions/checkout@v3
shell: bash
- name: Install Toolchain (arch-specific)
shell: bash
run: |
TARGET="${{ matrix.os }}-${{ matrix.arch }}"
if [ "${{ matrix.os }}" = "win" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
echo "Windows-ARM64 下使用 MSVC/cl,不需 apt 安装交叉编译工具。"
echo "若需更多动作,可以在此处 source vsvarsall.bat 或使用 actions/setup-msvc。"
else
sudo apt-get update
case "$TARGET" in
"linux-x86")
sudo apt-get install -y gcc-multilib g++-multilib
;;
"linux-arm64")
sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu qemu-user
;;
"linux-arm")
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf qemu-user
;;
"win-x86")
sudo apt-get install -y mingw-w64
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y wine32:i386
;;
"win-x64")
sudo apt-get install -y mingw-w64 wine
;;
"linux-x64")
# 如果有额外需要,可在此处安装
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Download GMP Source
shell: bash
run: |
git clone --depth 1 https://github.com/gmp-mirror/gmp-${GMP_VERSION}.git
- name: Autoreconf
shell: bash
run: |
cd gmp-${GMP_VERSION}
autoreconf -ivf
- name: Configure GMP
shell: bash
run: |
cd gmp-${GMP_VERSION}
# Windows 下不启用 --enable-fat
if [ "${{ matrix.os }}" = "win" ]; then
CONFIGURE_OPTIONS="--enable-shared --disable-static --enable-cxx"
else
CONFIGURE_OPTIONS="--enable-shared --disable-static --enable-cxx --enable-fat"
fi
if [ "${{ matrix.os }}" = "win" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
echo "Setting environment for MSVC/cl (Windows-ARM64)"
# 通常需要 source VS 的 vcvarsall.bat 或使用 actions/setup-msvc
export CC="cl"
export CXX="cl"
echo "MSVC 对 Autotools 支持不佳,可能需要自定义 nmake/makefile 方式编译。"
else
./configure --host="${{ matrix.host || '' }}" $CONFIGURE_OPTIONS
fi
- name: Build GMP
shell: bash
run: |
cd gmp-${GMP_VERSION}
if [ "${{ matrix.os }}" = "win" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
echo "在 MSVC 下可能需要 nmake /f Makefile.msc"
nmake /f Makefile.msc
else
make MAKEINFO=true
fi
- name: Check .libs
shell: bash
run: |
cd gmp-${GMP_VERSION}
if [ -d ".libs" ]; then
cd .libs
ls -l
if [ -f "${{ matrix.gmp_so }}" ]; then
file ${{ matrix.gmp_so }}
fi
else
echo "No .libs directory found (MSVC 或 Makefile.msc 可能输出到别的目录)"
- name: Strip GMP Library
shell: bash
run: |
cd gmp-${GMP_VERSION}
if [ -d ".libs" ]; then
cd .libs
# 在 Windows-ARM64 (MSVC) 下没有 strip, 此处直接跳过
${{ matrix.strip }} --strip-unneeded ${{ matrix.gmp_so }} || echo "Skipping strip on MSVC build"
${{ matrix.strip }} --strip-unneeded ${{ matrix.gmp_cpp_so }} || echo "Skipping strip on MSVC build"
fi
- name: Compile C Program
shell: bash
run: |
cd "${{ github.workspace }}"
COMPILE_OPTIONS=".github/workflows/factorial_gmp.c -I${{ github.workspace }}/gmp-${GMP_VERSION} -L${{ github.workspace }}/gmp-${GMP_VERSION}/.libs -lgmp"
TARGET="${{ matrix.os }}-${{ matrix.arch }}"
case "$TARGET" in
"linux-x86")
gcc -m32 -o factorial_gmp $COMPILE_OPTIONS
;;
"linux-x64")
gcc -o factorial_gmp $COMPILE_OPTIONS
;;
"linux-arm64")
aarch64-linux-gnu-gcc -o factorial_gmp $COMPILE_OPTIONS
;;
"linux-arm")
arm-linux-gnueabihf-gcc -o factorial_gmp $COMPILE_OPTIONS
;;
"win-x86")
i686-w64-mingw32-gcc -o factorial_gmp.exe $COMPILE_OPTIONS
;;
"win-x64")
x86_64-w64-mingw32-gcc -o factorial_gmp.exe $COMPILE_OPTIONS
;;
"win-arm64")
echo "用 cl 编译 Windows-ARM64 下的测试程序(仅示例)"
cl /Fe:factorial_gmp.exe factorial_gmp.c /I gmp-${GMP_VERSION} /link /LIBPATH:gmp-${GMP_VERSION}/.libs
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Run C Program
shell: bash
run: |
cd "${{ github.workspace }}"
if [ "${{ matrix.arch }}" = "arm64" ] && [ "${{ matrix.os }}" = "linux" ]; then
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./factorial_gmp
elif [ "${{ matrix.arch }}" = "arm" ] && [ "${{ matrix.os }}" = "linux" ]; then
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs qemu-arm -L /usr/arm-linux-gnueabihf/ ./factorial_gmp
elif [ "${{ matrix.os }}" = "win" ] && [ "${{ matrix.arch }}" != "arm64" ]; then
# 仅在 ubuntu-latest (wine) 上可执行 Win32/Win64 程序
cp ${{ github.workspace }}/gmp-${GMP_VERSION}/.libs/${{ matrix.gmp_so }} .
wine ./factorial_gmp.exe
elif [ "${{ matrix.os }}" = "win" ] && [ "${{ matrix.arch }}" = "arm64" ]; then
echo "Windows-ARM64 MSVC 编译产物无法直接在 GitHub Windows x64 Runner 上运行,需要 ARM64 环境或模拟器。跳过。"
else
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs ./factorial_gmp
fi
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.os }}-${{ matrix.arch }}
path: |
${{ github.workspace }}/gmp-${{ env.GMP_VERSION }}/gmp.h
${{ github.workspace }}/gmp-${{ env.GMP_VERSION }}/gmpxx.h
${{ github.workspace }}/gmp-${{ env.GMP_VERSION }}/.libs/${{ matrix.gmp_so }}
${{ github.workspace }}/gmp-${{ env.GMP_VERSION }}/.libs/${{ matrix.gmp_cpp_so }}