Skip to content

don't need sheel in upload artifacts #70

don't need sheel in upload artifacts

don't need sheel in upload artifacts #70

Workflow file for this run

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

Check failure on line 81 in .github/workflows/main.yml

View workflow run for this annotation

GitHub Actions / main

Invalid workflow file

The workflow is not valid. .github/workflows/main.yml (Line: 81, Col: 9): Unexpected value 'shell'
- 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 }}