-
Notifications
You must be signed in to change notification settings - Fork 19
492 lines (452 loc) · 19.8 KB
/
build.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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
name: Build
on:
workflow_call:
inputs:
os:
description: 'Operating System'
required: true
type: string
arch:
description: 'Architecture'
required: true
type: string
gmp-version:
description: 'GMP version'
required: true
type: string
mpfr-version:
description: 'MPFR version'
required: true
type: string
build-type:
description: 'Build type (shared or static)'
required: true
type: string
default: 'shared'
workflow_dispatch:
inputs:
os:
description: 'Operating System'
required: true
default: linux
arch:
description: 'Architecture'
required: true
default: x64
gmp-version:
description: 'GMP version'
required: true
default: 6.3.0
mpfr-version:
description: 'MPFR version'
required: true
default: 4.2.1
build-type:
description: 'Build type (shared or static)'
required: true
default: 'shared'
jobs:
build:
runs-on: ${{ (inputs.os == 'osx' || inputs.os == 'ios') && (inputs.arch == 'x64' && 'macos-13' || 'macos-latest') || 'ubuntu-latest' }}
env:
GMP_CONFIGURE: ${{ inputs.os == 'browser' && 'emconfigure ./configure' || './configure' }}
BUILD_TYPE: ${{ inputs.build-type }}
steps:
- name: Checkout Repository
uses: actions/checkout@v4
with:
show-progress: false
- name: Set environment variables
run: |
echo "TARGET=${{ inputs.os }}-${{ inputs.arch }}" >> $GITHUB_ENV
GMP_CONFIGURE_ARGS="--enable-cxx --enable-fat"
echo "GMP_SO=libgmp.so.10" >> $GITHUB_ENV
echo "GMP_CPP_SO=libgmpxx.so.4" >> $GITHUB_ENV
echo "MPFR_SO=libmpfr.so.6" >> $GITHUB_ENV
case "${{ inputs.os }}" in
"linux")
case "${{ inputs.arch }}" in
"x64")
echo "HOST=x86_64-pc-linux-gnu" >> $GITHUB_ENV
echo "STRIP=strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=gcc" >> $GITHUB_ENV
;;
"x86")
echo "HOST=i686-pc-linux-gnu" >> $GITHUB_ENV
echo "STRIP=strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=gcc -m32" >> $GITHUB_ENV
;;
"arm64")
echo "HOST=aarch64-linux-gnu" >> $GITHUB_ENV
echo "STRIP=aarch64-linux-gnu-strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV
;;
"arm")
echo "HOST=arm-linux-gnueabihf" >> $GITHUB_ENV
echo "STRIP=arm-linux-gnueabihf-strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV
;;
esac
;;
"linux-musl")
case "${{ inputs.arch }}" in
"x64")
echo "HOST=x86_64-linux-musl" >> $GITHUB_ENV
echo "STRIP=strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=musl-gcc" >> $GITHUB_ENV
;;
"arm64")
echo "HOST=aarch64-unknown-linux-musl" >> $GITHUB_ENV
echo "STRIP=aarch64-unknown-linux-musl-strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=aarch64-unknown-linux-musl-gcc" >> $GITHUB_ENV
;;
esac
;;
"win")
echo "GMP_SO=libgmp-10.dll" >> $GITHUB_ENV
echo "GMP_CPP_SO=libgmpxx-4.dll" >> $GITHUB_ENV
echo "MPFR_SO=libmpfr-6.dll" >> $GITHUB_ENV
echo "CFLAGS=-O2 -static-libgcc" >> $GITHUB_ENV
echo "LDFLAGS=-O2 -static-libgcc" >> $GITHUB_ENV
case "${{ inputs.arch }}" in
"x64")
echo "HOST=x86_64-w64-mingw32" >> $GITHUB_ENV
echo "STRIP=x86_64-w64-mingw32-strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV
;;
"x86")
echo "HOST=i686-w64-mingw32" >> $GITHUB_ENV
echo "STRIP=i686-w64-mingw32-strip --strip-unneeded" >> $GITHUB_ENV
echo "TEST_CC=i686-w64-mingw32-gcc" >> $GITHUB_ENV
;;
esac
;;
"android")
echo "GMP_SO=libgmp.so" >> $GITHUB_ENV
echo "GMP_CPP_SO=libgmpxx.so" >> $GITHUB_ENV
echo "MPFR_SO=libmpfr.so" >> $GITHUB_ENV
echo "STRIP=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip --strip-unneeded" >> $GITHUB_ENV
case "${{ inputs.arch }}" in
"x64")
HOST=x86_64-linux-android
;;
"arm64")
HOST=aarch64-linux-android
;;
"x86")
HOST=i686-linux-android
;;
"arm")
HOST=armv7a-linux-android
;;
esac
echo "HOST=$HOST" >> $GITHUB_ENV
GMP_CONFIGURE_ARGS="${GMP_CONFIGURE_ARGS} --with-pic"
ARGS="--target=${HOST}21 --sysroot=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/sysroot -pie"
echo "TEST_CC=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang ${ARGS} -fPIC" >> $GITHUB_ENV
echo "CC=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang ${ARGS} -fPIC" >> $GITHUB_ENV
echo "CXX=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ ${ARGS} -fPIC" >> $GITHUB_ENV
;;
"osx")
echo "GMP_SO=libgmp.10.dylib" >> $GITHUB_ENV
echo "GMP_CPP_SO=libgmpxx.4.dylib" >> $GITHUB_ENV
echo "MPFR_SO=libmpfr.6.dylib" >> $GITHUB_ENV
echo "STRIP=strip -x" >> $GITHUB_ENV
case "${{ inputs.arch }}" in
"arm64")
echo "HOST=aarch64-apple-darwin" >> $GITHUB_ENV
echo "TEST_CC=clang -arch arm64" >> $GITHUB_ENV
;;
"x64")
echo "HOST=x86_64-apple-darwin" >> $GITHUB_ENV
echo "TEST_CC=clang" >> $GITHUB_ENV
echo "LDFLAGS=-ld_classic" >> $GITHUB_ENV
if [ "${{ env.BUILD_TYPE }}" == "static" ]; then
GMP_CONFIGURE_ARGS="${GMP_CONFIGURE_ARGS//--enable-fat/--disable-assembly}" # macOS static does not support fat binaries & assembly
fi
;;
esac
;;
"ios")
BUILD_TYPE=static # iOS does not support shared libraries
echo "BUILD_TYPE=static" >> $GITHUB_ENV
echo "HOST=aarch64-apple-ios" >> $GITHUB_ENV
echo "STRIP=strip -x" >> $GITHUB_ENV
echo "CFLAGS=-arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=12.0" >> $GITHUB_ENV
echo "LDFLAGS=-arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=12.0" >> $GITHUB_ENV
echo "TEST_CC=xcrun -sdk iphoneos clang -arch arm64 -isysroot \$(xcrun --sdk iphoneos --show-sdk-path)" >> $GITHUB_ENV
GMP_CONFIGURE_ARGS="${GMP_CONFIGURE_ARGS//--enable-fat/--disable-assembly}" # iOS does not support fat binaries & assembly
;;
"browser")
BUILD_TYPE=static # WebAssembly does not support shared libraries
echo "BUILD_TYPE=static" >> $GITHUB_ENV
echo "HOST=none" >> $GITHUB_ENV
echo "STRIP=strip" >> $GITHUB_ENV
echo "TEST_CC=emcc" >> $GITHUB_ENV
GMP_CONFIGURE_ARGS="${GMP_CONFIGURE_ARGS//--enable-fat/--disable-assembly}" # WebAssembly does not support fat binaries & assembly
;;
*)
echo "Error: Unsupported OS-Architecture combination: ${{ inputs.os }}-${{ inputs.arch }}"
exit 1
;;
esac
case "$BUILD_TYPE" in
"shared")
echo "GMP_CONFIGURE_ARGS=${GMP_CONFIGURE_ARGS}" >> $GITHUB_ENV
echo "BUILD_TYPE_ARGS=--enable-shared --disable-static" >> $GITHUB_ENV
;;
"static")
echo "GMP_CONFIGURE_ARGS=${GMP_CONFIGURE_ARGS}" >> $GITHUB_ENV
echo "BUILD_TYPE_ARGS=--enable-static --disable-shared" >> $GITHUB_ENV
echo "GMP_SO=libgmp.a" >> $GITHUB_ENV
echo "GMP_CPP_SO=libgmpxx.a" >> $GITHUB_ENV
echo "MPFR_SO=libmpfr.a" >> $GITHUB_ENV
;;
*)
echo "Error: Unsupported build type: ${{ inputs.build-type }}"
exit 1
;;
esac
- name: Install Toolchain (arch-specific)
run: |
case "$TARGET" in
"linux-x64")
;;
"linux-x86")
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib
;;
"linux-arm64")
sudo apt-get update
sudo apt-get install -y --no-install-recommends qemu-user gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
;;
"linux-arm")
sudo apt-get update
sudo apt-get install -y --no-install-recommends qemu-user gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf
;;
"linux-musl-x64")
sudo apt-get update
sudo apt-get install -y --no-install-recommends musl-tools
;;
"linux-musl-arm64")
sudo apt-get update
sudo apt-get install -y --no-install-recommends musl-tools qemu-user
sudo mkdir -p /opt/x-tools
wget -nv https://github.com/musl-cross/musl-cross/releases/download/20241103/aarch64-unknown-linux-musl.tar.xz
sudo tar -xf aarch64-unknown-linux-musl.tar.xz -C /opt/x-tools
ls -l /opt/x-tools/aarch64-unknown-linux-musl/bin/
/opt/x-tools/aarch64-unknown-linux-musl/bin/aarch64-unknown-linux-musl-gcc --version
echo "/opt/x-tools/aarch64-unknown-linux-musl/bin" >> $GITHUB_PATH
;;
"win-x86")
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y --no-install-recommends mingw-w64
sudo apt-get install -y wine32:i386
;;
"win-x64")
sudo apt-get update
sudo apt-get install -y --no-install-recommends mingw-w64 wine
;;
"android-x64" | "android-arm64" | "android-x86" | "android-arm")
;;
"osx-arm64" | "osx-x64" | "ios-arm64")
echo "No toolchain installation needed on macOS/iOS."
;;
"browser-wasm")
git clone --depth 1 https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
echo "${{ github.workspace }}/emsdk" >> $GITHUB_PATH
echo "${{ github.workspace }}/emsdk/upstream/emscripten" >> $GITHUB_PATH
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Download GMP Source
run: |
wget -nv https://mirrors.nju.edu.cn/gnu/gmp/gmp-${{ inputs.gmp-version }}.tar.xz
tar -xf gmp-${{ inputs.gmp-version }}.tar.xz
- name: Configure GMP
run: |
cd gmp-${{ inputs.gmp-version }}
${{ env.GMP_CONFIGURE }} ${{ env.BUILD_TYPE_ARGS }} ${{ env.GMP_CONFIGURE_ARGS }} --host=${{ env.HOST }}
- name: Build GMP
run: |
cd gmp-${{ inputs.gmp-version }}
make -j4
- name: Download MPFR Source
run: |
wget -nv https://mirrors.nju.edu.cn/gnu/mpfr/mpfr-${{ inputs.mpfr-version }}.tar.xz
tar -xf mpfr-${{ inputs.mpfr-version }}.tar.xz
- name: Configure MPFR
run: |
cd mpfr-${{ inputs.mpfr-version }}
./configure --host=${{ env.HOST }} --enable-thread-safe \
--with-gmp-include=${{ github.workspace }}/gmp-${{ inputs.gmp-version }} \
--with-gmp-lib=${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs \
${{ env.BUILD_TYPE_ARGS }}
- name: Build MPFR
run: |
cd mpfr-${{ inputs.mpfr-version }}
make -j4
- name: Check .libs
run: |
cd ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs
ls -l
file ${{ env.GMP_SO }}
cd ${{ github.workspace }}/mpfr-${{ inputs.mpfr-version }}/src/.libs
ls -l
file ${{ env.MPFR_SO }}
- name: Generate .lib files (Windows shared only)
if: ${{ inputs.os == 'win' && env.BUILD_TYPE == 'shared' }}
run: |
cd gmp-${{ inputs.gmp-version }}/.libs
if [ "$TARGET" = "win-x86" ]; then
HOST_PREFIX=i686-w64-mingw32
elif [ "$TARGET" = "win-x64" ]; then
HOST_PREFIX=x86_64-w64-mingw32
else
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
fi
${HOST_PREFIX}-dlltool \
--input-def libgmp-3.dll.def \
--output-lib libgmp-10.lib \
--dllname ${{ env.GMP_SO }}
${HOST_PREFIX}-dlltool \
--input-def libgmpxx-3.dll.def \
--output-lib libgmpxx-4.lib \
--dllname ${{ env.GMP_SO }}
- name: Dump lib dependencies(Shared Libraries only)
if: ${{ inputs.os != 'win' && env.BUILD_TYPE != 'static' }}
run: |
case "$TARGET" in
osx-*)
otool -L ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs/${{ env.GMP_SO }}
otool -L ${{ github.workspace }}/mpfr-${{ inputs.mpfr-version }}/src/.libs/${{ env.MPFR_SO }}
;;
linux-* | android-*)
objdump -x ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs/${{ env.GMP_SO }} | grep NEEDED
objdump -x ${{ github.workspace }}/mpfr-${{ inputs.mpfr-version }}/src/.libs/${{ env.MPFR_SO }} | grep NEEDED
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Strip GMP Library
run: |
${STRIP} ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs/${GMP_SO}
${STRIP} ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs/${GMP_CPP_SO}
file ${{ github.workspace }}/gmp-${{ inputs.gmp-version }}/.libs/${GMP_SO}
${STRIP} ${{ github.workspace }}/mpfr-${{ inputs.mpfr-version }}/src/.libs/${MPFR_SO}
file ${{ github.workspace }}/mpfr-${{ inputs.mpfr-version }}/src/.libs/${MPFR_SO}
- name: Prepare Artifact folder
run: |
mkdir -p artifacts/bin artifacts/include artifacts/misc artifacts/test
cp gmp-${{ inputs.gmp-version }}/gmp.h artifacts/include
cp gmp-${{ inputs.gmp-version }}/gmpxx.h artifacts/include
cp mpfr-${{ inputs.mpfr-version }}/src/mpfr.h artifacts/include
cp -L gmp-${{ inputs.gmp-version }}/.libs/${{ env.GMP_SO }} artifacts/bin
cp -L gmp-${{ inputs.gmp-version }}/.libs/${{ env.GMP_CPP_SO }} artifacts/bin
cp -L mpfr-${{ inputs.mpfr-version }}/src/.libs/${{ env.MPFR_SO }} artifacts/bin
cp gmp-${{ inputs.gmp-version }}/.libs/*.lib artifacts/misc || true
cp gmp-${{ inputs.gmp-version }}/.libs/*.def artifacts/misc || true
cp gmp-${{ inputs.gmp-version }}/.libs/*.lai artifacts/misc
cp mpfr-${{ inputs.mpfr-version }}/src/.libs/*.lai artifacts/misc
ls -l artifacts/bin
- name: Compile Test C GMP Program
run: |
${{ env.TEST_CC }} -o factorial_gmp.exe \
.github/workflows/factorial_gmp.c \
-Iartifacts/include \
-Lgmp-${{ inputs.gmp-version }}/.libs \
-lgmp
ls -l
file factorial_gmp.exe
- name: Run Test C GMP Program
if: ${{ inputs.os != 'android' && inputs.os != 'ios' && !(inputs.os == 'linux-musl' && inputs.arch == 'arm64') }}
run: |
case "$TARGET" in
win-*)
cp ${{ github.workspace }}/artifacts/bin/${GMP_SO} .
wine ${GITHUB_WORKSPACE}/factorial_gmp.exe
;;
"linux-x64" | "linux-x86")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./factorial_gmp.exe
;;
"linux-arm64")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./factorial_gmp.exe
;;
"linux-arm")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin qemu-arm -L /usr/arm-linux-gnueabihf/ ./factorial_gmp.exe
;;
"linux-musl-x64")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./factorial_gmp.exe
;;
osx-*)
DYLD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./factorial_gmp.exe
;;
browser-wasm)
node ./factorial_gmp.exe
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Compile Test C MPFR Program
run: |
${{ env.TEST_CC }} -o pi_mpfr.exe \
.github/workflows/pi_mpfr.c \
-Iartifacts/include \
-Lgmp-${{ inputs.gmp-version }}/.libs \
-Lmpfr-${{ inputs.mpfr-version }}/src/.libs \
-lmpfr -lgmp
ls -l
file pi_mpfr.exe
- name: Run Test C MPFR Program
if: ${{ inputs.os != 'android' && inputs.os != 'ios' && !(inputs.os == 'linux-musl' && inputs.arch == 'arm64') }}
run: |
case "$TARGET" in
win-*)
cp ${{ github.workspace }}/artifacts/bin/${GMP_SO} .
cp ${{ github.workspace }}/artifacts/bin/${MPFR_SO} .
wine ${GITHUB_WORKSPACE}/pi_mpfr.exe
;;
"linux-x64" | "linux-x86")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./pi_mpfr.exe
;;
"linux-arm64")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./pi_mpfr.exe
;;
"linux-arm")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin qemu-arm -L /usr/arm-linux-gnueabihf/ ./pi_mpfr.exe
;;
"linux-musl-x64")
LD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./pi_mpfr.exe
;;
osx-*)
DYLD_LIBRARY_PATH=${{ github.workspace }}/artifacts/bin ./pi_mpfr.exe
;;
browser-wasm)
node ./pi_mpfr.exe
;;
*)
echo "Error: Unsupported OS-Architecture combination: $TARGET"
exit 1
;;
esac
- name: Prepare test artifacts
run: |
cp factorial_gmp.* ./artifacts/test
cp pi_mpfr.* ./artifacts/test
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.BUILD_TYPE }}-${{ inputs.os }}-${{ inputs.arch }}
path: artifacts