Merge branch 'main' of github.com:cstrainge/sorth #240
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: C/C++ CI | |
on: | |
push: | |
branches: [ "main", "ffi" ] | |
tags: ["v*"] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
strategy: | |
matrix: | |
target: | |
- arm-unknown-linux-gnu | |
- x86_64-unknown-linux-gnu | |
- aarch64-apple-darwin | |
- x86_64-apple-darwin | |
- x86_64-pc-windows-msvc | |
os: | |
- ubuntu-latest | |
- macos-latest | |
- windows-latest | |
exclude: | |
- target: aarch64-apple-darwin | |
os: windows-latest | |
- target: x86_64-apple-darwin | |
os: windows-latest | |
- target: arm-unknown-linux-gnu | |
os: windows-latest | |
- target: x86_64-unknown-linux-gnu | |
os: windows-latest | |
- target: x86_64-pc-windows-msvc | |
os: macos-latest | |
- target: arm-unknown-linux-gnu | |
os: macos-latest | |
- target: x86_64-unknown-linux-gnu | |
os: macos-latest | |
- target: x86_64-pc-windows-msvc | |
os: ubuntu-latest | |
- target: aarch64-apple-darwin | |
os: ubuntu-latest | |
- target: x86_64-apple-darwin | |
os: ubuntu-latest | |
runs-on: ${{ matrix.os }} | |
env: | |
CXXTARGET: ${{ matrix.target }} | |
steps: | |
- uses: actions/checkout@v4.2.1 | |
# https://github.com/taiki-e/setup-cross-toolchain-action | |
# Install VCPKG on Windows | |
- name: Install VCPKG (Windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: | | |
git clone https://github.com/microsoft/vcpkg.git | |
./vcpkg/bootstrap-vcpkg.bat | |
env: | |
VCPKG_ROOT: ${{ github.workspace }}/vcpkg | |
# Set VCPKG_ROOT environment variable (Windows) | |
- name: Set VCPKG_ROOT (Windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: echo "VCPKG_ROOT=${{ github.workspace }}\\vcpkg" >> $GITHUB_ENV | |
# Install libffi for Linux and macOS | |
- name: Install libffi (Linux/macOS) | |
if: ${{ runner.os != 'Windows' }} | |
run: | | |
if [ $(uname) = "Linux" ]; then | |
sudo apt-get update | |
sudo apt-get install -y libffi-dev | |
elif [ $(uname) = "Darwin" ]; then | |
brew install libffi | |
fi | |
# Install cross-compilation tools | |
- name: Install cross-compilation tools | |
uses: taiki-e/setup-cross-toolchain-action@v1 | |
with: | |
target: ${{ matrix.target }} | |
# Optionally install libatomic for cross-compilation | |
- name: Optionally install libatomic for cross-compilation | |
if: ${{ matrix.target == 'arm-unknown-linux-gnu' }} | |
run: sudo apt-get install -y libatomic1-arm64-cross | |
# Install Ninja build system | |
- name: Install Ninja (Linux/macOS) | |
if: ${{ runner.os != 'Windows' }} | |
run: | | |
if [ $(uname) = "Linux" ]; then | |
sudo apt-get install -y ninja-build | |
elif [ $(uname) = "Darwin" ]; then | |
brew install ninja | |
fi | |
- name: Install Ninja (Windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: choco install ninja | |
shell: cmd | |
# Ensure Ninja is available (Windows) | |
- name: Add Ninja to PATH (Windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: | | |
$env:Path += ";C:\ProgramData\chocolatey\bin" | |
shell: pwsh | |
# targets and version debug | |
- name: targets and version debug | |
run: clang++ -print-targets && clang++ --version | |
# Create build directory | |
- name: Create build directory | |
run: mkdir -p build | |
# Configure CMake (Windows) | |
- name: Configure CMake (Windows) | |
if: ${{ runner.os == 'Windows' }} | |
run: cmake -DCMAKE_MAKE_PROGRAM=C:\ProgramData\chocolatey\bin\ninja.exe -DCMAKE_TOOLCHAIN_FILE=${{ github.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ --preset=cibuild .. -G Ninja | |
working-directory: build | |
# Configure CMake (Linux/macOS) | |
- name: Configure CMake (Linux/macOS) | |
if: ${{ runner.os != 'Windows' }} | |
run: cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. -G Ninja | |
working-directory: build | |
# Build with make | |
- name: Build with Ninja. | |
run: ninja | |
working-directory: build | |
# List files in build directory | |
- name: List files in dist directory | |
run: ls dist | |
# Add the build artifacts to the action. | |
- name: Get Git Commit ID | |
run: echo "COMMIT_ID=$(git rev-parse --short HEAD)" >> $GITHUB_ENV | |
- name: Upload Build Artifacts | |
uses: actions/upload-artifact@v4.4.3 | |
with: | |
name: 'sorth-${{ matrix.target }}-build-${{ env.COMMIT_ID }}' | |
path: "dist/*" | |
retention-days: 5 | |
# Zip up the build. | |
- name: Archive Release | |
uses: thedoctor0/zip-release@0.7.1 | |
with: | |
type: 'zip' | |
filename: 'sorth-${{ matrix.target }}' | |
directory: 'dist' | |
# Make sure to upload the build. | |
- name: List files again. | |
run: ls dist | |
# Create a draft release for a tag. | |
- name: Release | |
uses: xresloader/upload-to-github-release@v1.6.0 | |
env: | |
GITHUB_TOKEN: ${{ secrets.SORTH_PERSONAL_ACCESS_TOKEN }} | |
with: | |
file: "dist/sorth-${{ matrix.target }}.zip" | |
draft: true | |
tags: true | |
overwrite: true |