Skip to content

fixup

fixup #76

name: ClangSharp.Pathogen
on:
push:
# This prevents tag pushes from triggering this workflow
branches: ['*']
pull_request:
release:
types: [published]
workflow_dispatch:
inputs:
version:
description: "Version"
default: ""
will_publish_packages:
description: "Publish packages?"
default: "false"
env:
DOTNET_NOLOGO: true
DOTNET_CLI_TELEMETRY_OPTOUT: true
DOTNET_GENERATE_ASPNET_CERTIFICATE: false
ContinuousIntegrationBuild: true
jobs:
# =====================================================================================================================================================================
# Build LLVM
# =====================================================================================================================================================================
build-llvm:
strategy:
fail-fast: false
matrix:
include:
- os: windows-2022
name: Windows x64
rid: win-x64
libclang-subpath: bin/libclang.dll
build-command: ./build-native.cmd
# We use the oldest Ubuntu available so that the binary is usable on systems using older glibc
# If we want to support even older versions we should explore building libclang with https://github.com/wheybags/glibc_version_header
- os: ubuntu-22.04
name: Linux x64
rid: linux-x64
libclang-subpath: lib/libclang.so
build-command: ./build-native.sh
- os: ubuntu-22.04-arm
name: Linux ARM64
rid: linux-arm64
libclang-subpath: lib/libclang.so
build-command: ./build-native.sh
skip-python-install: true
- os: macos-13
name: macOS x64
rid: osx-x64
libclang-subpath: lib/libclang.dylib
build-command: ./build-native.sh
name: Build LLVM - ${{matrix.name}}
runs-on: ${{matrix.os}}
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
# We intentionally don't checkout submodules here
# They will be restored as needed only if we need to build LLVM.
uses: actions/checkout@v4
# ----------------------------------------------------------------------- Setup Python
- name: Setup Python
if: matrix.skip-python-install != true
uses: actions/setup-python@v5
with:
python-version: '3.11'
# ----------------------------------------------------------------------- Get LLVM Revision
- name: Get LLVM Revision
id: llvm
run: python .github/workflows/get-llvm-revision.py
# ----------------------------------------------------------------------- Build LLVM
- name: Load cached LLVM build outputs
id: cached-llvm
uses: actions/cache@v4
# If you change this configuration make sure to update keep-cache-warm.yml as well.
with:
key: llvm-output-${{matrix.rid}}-${{steps.llvm.outputs.revision}}
# These are the paths of the files required by ClangSharp.Pathogen.Native and ClangSharp.Pathogen.ClangResources
# (Make sure this is syncronized with "Archive LLVM Outputs" below)
path: |
bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
bin/llvm/${{matrix.rid}}/lib/clang/
external/llvm-project/clang/LICENSE.TXT
external/llvm-project/clang/tools/libclang/libClangSharp/LICENSE.md
- name: Checkout LLVM
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: git submodule update --init --recursive --depth=1
- name: Install sccache
id: sccache
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: python .github/workflows/install-sccache.py
- name: Load LLVM sccache
id: cached-sccache
# Always save the (potentially partial) sccache database so it can be used to accelerate subsequent builds when an intermittent failure occurs
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
uses: actions/cache@v4
# If you change this configuration make sure to update keep-cache-warm.yml as well.
with:
# Note that this implicitly includes the sccache log
# sccache writes a startup message to the log so you'll be able to tell which section of the log is the current run
# (and see any logs from previous runs which affected this cache)
path: ${{steps.sccache.outputs.root-directory}}
key: sccache-cache-${{matrix.rid}}-${{steps.llvm.outputs.revision}}
restore-keys: sccache-cache-${{matrix.rid}}-
- name: Start sccache server
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: sccache --start-server
# The GitHub hosted runners do not have Ninja installed by default
# This is not necessary on Windows since Visual Studio comes with a copy of Ninja and we end up picking that one up for Windows
- name: Install Ninja on Linux
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: sudo apt-get install --yes ninja-build
- name: Install Ninja on macOS
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'macOS'
run: brew install ninja
- name: Build LLVM
if: steps.cached-llvm.outputs.cache-hit != 'true'
run: ${{matrix.build-command}}
- name: Show sccache statistics
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
run: |
sccache --show-stats 2>&1 | tee ${{steps.sccache.outputs.root-directory}}/sccache-stats.txt
# Stop the server so it releases the lock on the log on Windows
# (Without this the sccache cache fails to save.)
sccache --stop-server
- name: Save sccache logs
uses: actions/upload-artifact@v4
if: steps.cached-llvm.outputs.cache-hit != 'true' && always()
with:
name: llvm-${{matrix.rid}}-sccache-logs
path: |
${{steps.sccache.outputs.log-file-path}}
${{steps.sccache.outputs.root-directory}}/sccache-stats.txt
# ----------------------------------------------------------------------- Pack Runtime Packages
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
- name: Configure versioning
run: python .github/workflows/configure-build.py
env:
github_event_name: ${{github.event_name}}
github_run_number: ${{github.run_number}}
release_version: ${{github.event.release.tag_name}}
workflow_dispatch_version: ${{github.event.inputs.version}}
# SourceLink will complain about the LLVM submodule missing even though it doesn't need it
# If we didn't clone the LLVM submodule we need to delete .gitmodules so it can chill
# (Workaround for https://github.com/dotnet/sourcelink/issues/675)
- name: Clear .gitmodules
if: steps.cached-llvm.outputs.cache-hit == 'true'
run: rm .gitmodules
- name: Restore ClangSharp.Pathogen.Native
run: dotnet restore ClangSharp.Pathogen.Native
- name: Pack ClangSharp.Pathogen.Native.${{matrix.rid}}
run: dotnet pack ClangSharp.Pathogen.Native --no-build --configuration Release /p:RuntimeIdentifier=${{matrix.rid}}
# The Clang resources are the same across all platforms so we only publish a single package based on the linux-x64 build
- name: Pack ClangSharp.Pathogen.ClangResources
if: matrix.rid == 'linux-x64'
run: |
dotnet restore ClangSharp.Pathogen.ClangResources
dotnet pack ClangSharp.Pathogen.ClangResources --no-build --configuration Release
# ----------------------------------------------------------------------- Upload Artifacts
# The GitHub Actions cache gets confused by the symlink so we need to remove it
- name: Unsymlink libclang
if: steps.cached-llvm.outputs.cache-hit != 'true' && runner.os == 'Linux'
run: |
cp bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}} bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}-nosymlink
rm bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
mv bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}-nosymlink bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
- name: Collect Build Outputs
uses: actions/upload-artifact@v4
# We always want to collect any build outputs that were created even if building failed
if: always()
with:
name: llvm-${{matrix.rid}}
if-no-files-found: error
# The paths listed here must match "Load cached LLVM build outputs" above
path: |
bin/llvm/${{matrix.rid}}/${{matrix.libclang-subpath}}
bin/llvm/${{matrix.rid}}/lib/clang/
external/llvm-project/clang/LICENSE.TXT
external/llvm-project/clang/tools/libclang/libClangSharp/LICENSE.md
- name: Collect NuGet Packages
uses: actions/upload-artifact@v4
# We always want to collect any packages that were created even if building failed
if: always()
with:
name: llvm-${{matrix.rid}}-packages
if-no-files-found: error
path: packages/**
# =====================================================================================================================================================================
# Build ClangSharp.Pathogen
# =====================================================================================================================================================================
build-dotnet:
name: Build ClangSharp.Pathogen
runs-on: ubuntu-latest
steps:
# ----------------------------------------------------------------------- Checkout
- name: Checkout
uses: actions/checkout@v4
# SourceLink will complain about the LLVM submodule missing even though it doesn't need it
# If we didn't clone the LLVM submodule we need to delete .gitmodules so it can chill
# (Workaround for https://github.com/dotnet/sourcelink/issues/675)
- name: Clear .gitmodules
run: rm .gitmodules
# ----------------------------------------------------------------------- Setup Python
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
# ----------------------------------------------------------------------- Configure Versioning
- name: Configure build
run: python .github/workflows/configure-build.py
env:
github_event_name: ${{github.event_name}}
github_run_number: ${{github.run_number}}
release_version: ${{github.event.release.tag_name}}
workflow_dispatch_version: ${{github.event.inputs.version}}
# ----------------------------------------------------------------------- Build and Pack ClangSharp.Pathogen
- name: Restore
run: dotnet restore ClangSharp.Pathogen
- name: Build
run: dotnet build ClangSharp.Pathogen --no-restore --configuration Release
- name: Pack
id: pack
run: dotnet pack ClangSharp.Pathogen --no-build --configuration Release
# ----------------------------------------------------------------------- Collect Artifacts
- name: Collect Build Outputs
uses: actions/upload-artifact@v4
# We always want to collect any build outputs that were created even if building failed
if: always()
with:
name: ClangSharp.Pathogen-build-output
path: |
bin/**
obj/**
- name: Collect NuGet Packages
uses: actions/upload-artifact@v4
# We always want to collect packages when they were produced
if: steps.pack.outcome == 'success' && always()
with:
name: ClangSharp.Pathogen-packages
if-no-files-found: error
path: packages/**
# =====================================================================================================================================================================
# Coalesce Packages
# =====================================================================================================================================================================
coalesce-packages:
name: Coalesce Packages
runs-on: ubuntu-latest
needs: [build-llvm, build-dotnet]
steps:
# ----------------------------------------------------------------------- Download Packages
- name: Download LLVM Windows x64 packages
uses: actions/download-artifact@v4
with:
name: llvm-win-x64-packages
- name: Download LLVM Linux x64 packages
uses: actions/download-artifact@v4
with:
name: llvm-linux-x64-packages
- name: Download LLVM Linux ARM64 packages
uses: actions/download-artifact@v4
with:
name: llvm-linux-arm64-packages
- name: Download LLVM macOS x64 packages
uses: actions/download-artifact@v4
with:
name: llvm-osx-x64-packages
- name: Download ClangSharp.Pathogen packages
uses: actions/download-artifact@v4
with:
name: ClangSharp.Pathogen-packages
# ----------------------------------------------------------------------- Upload Combined Packages Artifact
- name: Collect NuGet Packages
uses: actions/upload-artifact@v4
with:
name: Packages
if-no-files-found: error
path: '**'
# =====================================================================================================================================================================
# Verify Clang Resources Match
# =====================================================================================================================================================================
# We only use the linux-x64 build to publish ClangSharp.Pathogen.ClangResources, so we want to ensure they match across all builds
verify-clang-resources:
name: Verify Clang Resources
runs-on: ubuntu-latest
needs: build-llvm
steps:
# ----------------------------------------------------------------------- Download LLVM Build Outputs
- name: Download LLVM Windows x64 build output
if: always()
uses: actions/download-artifact@v4
with:
name: llvm-win-x64
- name: Download LLVM Linux x64 build output
if: always()
uses: actions/download-artifact@v4
with:
name: llvm-linux-x64
- name: Download LLVM Linux ARM64 build output
if: always()
uses: actions/download-artifact@v4
with:
name: llvm-linux-arm64
- name: Download LLVM macOS x64 build output
if: always()
uses: actions/download-artifact@v4
with:
name: llvm-osx-x64
# ----------------------------------------------------------------------- Verify
- name: Verify Windows x64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/win-x64/lib/clang/
- name: Verify Linux ARM64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/linux-arm64/lib/clang/
- name: Verify macOS x64 matches Linux x64
if: always()
run: diff --unified --strip-trailing-cr --recursive bin/llvm/linux-x64/lib/clang/ bin/llvm/osx-x64/lib/clang/
# =====================================================================================================================================================================
# Publish NuGet Packages to GitHub
# =====================================================================================================================================================================
publish-packages-github:
name: Publish to GitHub
runs-on: ubuntu-latest
needs: [coalesce-packages, verify-clang-resources]
# Pushes to main always publish CI packages
# Published releases always publish packages
# A manual workflow only publishes packages if explicitly enabled
if: (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true')
steps:
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
# ----------------------------------------------------------------------- Download built packages
- name: Download built packages
uses: actions/download-artifact@v4
with:
name: Packages
# ----------------------------------------------------------------------- Upload release assets
- name: Upload release assets
if: github.event_name == 'release'
run: gh release upload ${{github.event.release.tag_name}} *.nupkg *.snupkg --clobber
# ----------------------------------------------------------------------- Push to GitHub Packages
- name: Push to GitHub Packages
run: dotnet nuget push "*.nupkg" --skip-duplicate --no-symbols --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/${{github.repository_owner}}
env:
# This is a workaround for https://github.com/NuGet/Home/issues/9775
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0
# =====================================================================================================================================================================
# Publish NuGet Packages to NuGet.org
# =====================================================================================================================================================================
publish-packages-nuget-org:
name: Publish to NuGet.org
runs-on: ubuntu-latest
needs: [coalesce-packages, verify-clang-resources]
environment: NuGet.org
# Release builds always publish packages to NuGet.org
# Workflow dispatch builds will only publish packages if enabled and an explicit version number is given
if: github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true' && github.event.inputs.version != '')
steps:
# ----------------------------------------------------------------------- Setup .NET
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.x
# ----------------------------------------------------------------------- Download built packages
- name: Download built packages
uses: actions/download-artifact@v4
with:
name: Packages
# ----------------------------------------------------------------------- Push to NuGet.org
- name: Push to NuGet.org
run: dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{vars.NUGET_API_URL}}
env:
# This is a workaround for https://github.com/NuGet/Home/issues/9775
DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER: 0