更新 main.yml #94
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: main | |
on: | |
push: | |
branches: | |
- master | |
paths: | |
- .github/workflows/main.yml | |
workflow_dispatch: | |
jobs: | |
build: | |
strategy: | |
matrix: | |
include: | |
- { os: linux, arch: x64 } | |
- { os: linux, arch: x86 } | |
- { os: linux, arch: arm64 } | |
- { os: linux, arch: arm } | |
- { os: win, arch: x64 } | |
- { os: win, arch: x86 } | |
runs-on: ${{ matrix.os == 'linux' && 'ubuntu-latest' || 'ubuntu-latest' }} | |
env: | |
GMP_VERSION: 6.3.0 | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- name: Set environment variables | |
run: | | |
case "${{ matrix.os }}-${{ matrix.arch }}" in | |
"linux-x64") | |
echo "HOST=x86_64-pc-linux-gnu" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp.so.10.5.0" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx.so.4.7.0" >> $GITHUB_ENV | |
echo "STRIP=strip" >> $GITHUB_ENV | |
echo "TEST_CC=gcc" >> $GITHUB_ENV | |
;; | |
"linux-x86") | |
echo "HOST=i686-pc-linux-gnu" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp.so.10.5.0" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx.so.4.7.0" >> $GITHUB_ENV | |
echo "STRIP=strip" >> $GITHUB_ENV | |
echo "TEST_CC=gcc -m32" >> $GITHUB_ENV | |
;; | |
"linux-arm64") | |
echo "HOST=aarch64-linux-gnu" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp.so.10.5.0" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx.so.4.7.0" >> $GITHUB_ENV | |
echo "STRIP=aarch64-linux-gnu-strip" >> $GITHUB_ENV | |
echo "TEST_CC=aarch64-linux-gnu-gcc" >> $GITHUB_ENV | |
;; | |
"linux-arm") | |
echo "HOST=arm-linux-gnueabihf" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp.so.10.5.0" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx.so.4.7.0" >> $GITHUB_ENV | |
echo "STRIP=arm-linux-gnueabihf-strip" >> $GITHUB_ENV | |
echo "TEST_CC=arm-linux-gnueabihf-gcc" >> $GITHUB_ENV | |
;; | |
"win-x64") | |
echo "HOST=x86_64-w64-mingw32" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp-10.dll" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx-4.dll" >> $GITHUB_ENV | |
echo "STRIP=x86_64-w64-mingw32-strip" >> $GITHUB_ENV | |
echo "TEST_CC=x86_64-w64-mingw32-gcc" >> $GITHUB_ENV | |
;; | |
"win-x86") | |
echo "HOST=i686-w64-mingw32" >> $GITHUB_ENV | |
echo "GMP_SO=libgmp-10.dll" >> $GITHUB_ENV | |
echo "GMP_CPP_SO=libgmpxx-4.dll" >> $GITHUB_ENV | |
echo "STRIP=i686-w64-mingw32-strip" >> $GITHUB_ENV | |
echo "TEST_CC=i686-w64-mingw32-gcc" >> $GITHUB_ENV | |
;; | |
*) | |
echo "Error: Unsupported OS-Architecture combination: ${{ matrix.os }}-${{ matrix.arch }}" | |
exit 1 | |
;; | |
esac | |
- name: Install Toolchain (arch-specific) | |
run: | | |
sudo apt-get update | |
TARGET="${{ matrix.os }}-${{ matrix.arch }}" | |
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 | |
sudo apt-get install -y qemu-user | |
;; | |
"linux-arm") | |
sudo apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf | |
sudo apt-get install -y qemu-user | |
;; | |
"win-x86") | |
sudo apt-get install -y mingw-w64 | |
sudo dpkg --add-architecture i386 | |
sudo apt-get update | |
sudo apt-get install wine32:i386 | |
;; | |
"win-x64") | |
sudo apt-get install -y mingw-w64 | |
sudo apt-get install -y wine | |
;; | |
"linux-x64") | |
# 如果有额外需要,可在此处安装 | |
;; | |
*) | |
echo "Error: Unsupported OS-Architecture combination: $TARGET" | |
exit 1 | |
;; | |
esac | |
- name: Download GMP Source | |
run: | | |
wget https://mirrors.nju.edu.cn/gnu/gmp/gmp-${GMP_VERSION}.tar.xz | |
tar -xf gmp-${GMP_VERSION}.tar.xz | |
- name: Configure GMP | |
run: | | |
CONFIGURE_OPTIONS="--enable-shared --disable-static --enable-fat --enable-cxx" | |
cd gmp-${GMP_VERSION} | |
./configure --host=${{ env.HOST }} ${CONFIGURE_OPTIONS} | |
- name: Build GMP | |
run: | | |
cd gmp-${GMP_VERSION} | |
make MAKEINFO=true | |
- name: Check .libs | |
run: | | |
cd gmp-${GMP_VERSION}/.libs | |
ls -l | |
file ${{ env.GMP_SO }} | |
- name: Strip GMP Library | |
run: | | |
cd gmp-${GMP_VERSION}/.libs | |
${{ env.STRIP }} --strip-unneeded ${{ env.GMP_SO }} | |
${{ env.STRIP }} --strip-unneeded ${{ env.GMP_CPP_SO }} | |
- name: Compile C Program | |
run: | | |
COMPILE_OPTIONS=".github/workflows/factorial_gmp.c -I${{ github.workspace }}/gmp-${GMP_VERSION} -L${{ github.workspace }}/gmp-${GMP_VERSION}/.libs -lgmp" | |
${{ env.TEST_CC }} -o factorial_gmp.exe $COMPILE_OPTIONS | |
- name: Run C Program | |
run: | | |
if [ "${{ matrix.arch }}" = "arm64" ]; then | |
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs qemu-aarch64 -L /usr/aarch64-linux-gnu/ ./factorial_gmp.exe | |
elif [ "${{ matrix.arch }}" = "arm" ]; then | |
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs qemu-arm -L /usr/arm-linux-gnueabihf/ ./factorial_gmp.exe | |
elif [ "${{ matrix.os }}" = "win" ]; then | |
cp ${{ github.workspace }}/gmp-${GMP_VERSION}/.libs/${{ env.GMP_SO }} . | |
wine ${GITHUB_WORKSPACE}/factorial_gmp.exe | |
else | |
LD_LIBRARY_PATH=${{ github.workspace }}/gmp-${GMP_VERSION}/.libs ./factorial_gmp.exe | |
fi | |
- name: Upload Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.os }}-${{ matrix.arch }} | |
path: | | |
gmp-${{ env.GMP_VERSION }}/gmp.h | |
gmp-${{ env.GMP_VERSION }}/gmpxx.h | |
gmp-${{ env.GMP_VERSION }}/.libs/${{ env.GMP_SO }} | |
gmp-${{ env.GMP_VERSION }}/.libs/${{ env.GMP_CPP_SO }} |