blob: 7b4c7a81003b16159d2de19fc22ec1da6fb7d8ef [file]
# instantiated by ci.yml
name: build-template
on:
workflow_call:
inputs:
config:
type: string
required: true
nightly:
type: string
required: true
LEAN_SPECIAL_VERSION_DESC:
type: string
required: true
RELEASE_TAG:
type: string
required: true
jobs:
build:
if: github.event_name != 'schedule' || github.repository == 'leanprover/lean4'
strategy:
matrix:
include: ${{fromJson(inputs.config)}}
# complete all jobs
fail-fast: false
runs-on: ${{ matrix.os }}
defaults:
run:
shell: ${{ matrix.shell || 'nix develop -c bash -euxo pipefail {0}' }}
name: ${{ matrix.name }}
env:
# must be inside workspace
CCACHE_DIR: ${{ github.workspace }}/.ccache
CCACHE_COMPRESS: true
# current cache limit
CCACHE_MAXSIZE: 400M
# squelch error message about missing nixpkgs channel
NIX_BUILD_SHELL: bash
LSAN_OPTIONS: max_leaks=10
# somehow MinGW clang64 (or cmake?) defaults to `g++` even though it doesn't exist
CXX: c++
MACOSX_DEPLOYMENT_TARGET: 11.0
# OpenSSL built from source on Intel macOS; sync with `opensslForDist` in flake.nix
OPENSSL_SRC_VERSION: 4.1.0
OPENSSL_SRC_SHA256: 50c17baf54cb008f6ce42d50deb4b28050a1aad711636cabd4b241c7e90cc2fd
# libuv built from source on Intel macOS; sync with `libuvPinned` in flake.nix
LIBUV_SRC_VERSION: 1.53.0
LIBUV_SRC_SHA256: 21425fa398be98b51181a1885df31428092d5435c4373a396351e427322e5f1b
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@ef8a148080ab6020fd15196c2084a2eea5ff2d25 # v22
if: runner.os == 'Linux' && !matrix.cmultilib
with:
summarize: false
- name: Install MSYS2
uses: msys2/setup-msys2@66cd2cce69caa17b53920067426061ca1de3a884 # v2.32.0
with:
msystem: clang64
# without the update, packages are installed in the versions of the possibly outdated MSYS2
# installer tarball's package database
update: true
# `:` means do not prefix with msystem
pacboy: "make: python: cmake clang ccache gmp libuv openssl: git: zip: unzip: diffutils: binutils: tree: zstd tar:"
if: runner.os == 'Windows'
- name: Install Brew Packages
# without the update, the runner image's possibly outdated formula data considers its
# preinstalled versions up to date; skip it on Intel, where Homebrew no longer builds
# bottles, so updated formulae (and their dependency trees) would be built from source
run: |
PACKAGES=(ccache tree zstd coreutils gmp)
if [[ "$(uname -m)" == arm64 ]]; then
brew update
PACKAGES+=(libuv openssl@4)
fi
brew install "${PACKAGES[@]}"
if: runner.os == 'macOS'
- name: Restore OpenSSL
id: restore-openssl
uses: actions/cache/restore@v6
with:
path: ${{ runner.temp }}/openssl
key: openssl-${{ env.OPENSSL_SRC_VERSION }}-${{ matrix.os }}-macos${{ env.MACOSX_DEPLOYMENT_TARGET }}-v1
if: runner.os == 'macOS' && runner.arch == 'X64'
- name: Build OpenSSL
run: |
cd "$RUNNER_TEMP"
curl -fsSL -o openssl.tar.gz "https://github.com/openssl/openssl/releases/download/openssl-$OPENSSL_SRC_VERSION/openssl-$OPENSSL_SRC_VERSION.tar.gz"
echo "$OPENSSL_SRC_SHA256 openssl.tar.gz" | shasum -a 256 -c
tar xf openssl.tar.gz
cd "openssl-$OPENSSL_SRC_VERSION"
./Configure --prefix="$RUNNER_TEMP/openssl" no-shared no-tests
make -j"$(sysctl -n hw.logicalcpu)" build_sw
make install_sw
if: runner.os == 'macOS' && runner.arch == 'X64' && steps.restore-openssl.outputs.cache-hit != 'true'
- name: Save OpenSSL
uses: actions/cache/save@v6
with:
path: ${{ runner.temp }}/openssl
key: ${{ steps.restore-openssl.outputs.cache-primary-key }}
if: runner.os == 'macOS' && runner.arch == 'X64' && steps.restore-openssl.outputs.cache-hit != 'true'
- name: Use OpenSSL
run: |
"$RUNNER_TEMP/openssl/bin/openssl" version
# picked up by script/prepare-llvm-macos.sh
echo "OPENSSL=$RUNNER_TEMP/openssl" >> "$GITHUB_ENV"
if: runner.os == 'macOS' && runner.arch == 'X64'
- name: Restore libuv
id: restore-libuv
uses: actions/cache/restore@v6
with:
path: ${{ runner.temp }}/libuv
key: libuv-${{ env.LIBUV_SRC_VERSION }}-${{ matrix.os }}-macos${{ env.MACOSX_DEPLOYMENT_TARGET }}-v1
if: runner.os == 'macOS' && runner.arch == 'X64'
- name: Build libuv
run: |
cd "$RUNNER_TEMP"
# the `-dist` tarball ships a generated `configure`, so no autotools are needed
curl -fsSL -o libuv.tar.gz "https://dist.libuv.org/dist/v$LIBUV_SRC_VERSION/libuv-v$LIBUV_SRC_VERSION-dist.tar.gz"
echo "$LIBUV_SRC_SHA256 libuv.tar.gz" | shasum -a 256 -c
tar xf libuv.tar.gz
cd "libuv-$LIBUV_SRC_VERSION"
./configure --prefix="$RUNNER_TEMP/libuv" --disable-shared --enable-static
make -j"$(sysctl -n hw.logicalcpu)"
make install
if: runner.os == 'macOS' && runner.arch == 'X64' && steps.restore-libuv.outputs.cache-hit != 'true'
- name: Save libuv
uses: actions/cache/save@v6
with:
path: ${{ runner.temp }}/libuv
key: ${{ steps.restore-libuv.outputs.cache-primary-key }}
if: runner.os == 'macOS' && runner.arch == 'X64' && steps.restore-libuv.outputs.cache-hit != 'true'
- name: Use libuv
run: |
# found by `find_package(LibUV)` in every stage
echo "PKG_CONFIG_PATH=$RUNNER_TEMP/libuv/lib/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}" >> "$GITHUB_ENV"
# picked up by script/prepare-llvm-macos.sh
echo "LIBUV=$RUNNER_TEMP/libuv" >> "$GITHUB_ENV"
if: runner.os == 'macOS' && runner.arch == 'X64'
- name: Checkout
uses: actions/checkout@v6
with:
# the default is to use a virtual merge commit between the PR and master: just use the PR
ref: ${{ github.event.pull_request.head.sha }}
# `lake cache get` walks git history to resolve a cached ancestor revision, so on
# push/merge_group it needs more than the default single commit. (PRs instead get depth
# from the "CI Merge Checkout" step below.)
fetch-depth: ${{ (matrix.lake-cache && github.event_name != 'pull_request') && 10 || 1 }}
- name: Open Nix shell once
run: true
if: runner.os == 'Linux'
# Do check out some CI-relevant files from virtual merge commit to accommodate CI changes on
# master (as the workflow files themselves are always taken from the merge)
# (needs to be after "Install *" to use the right shell)
- name: CI Merge Checkout
run: |
git fetch --depth=${{ matrix.lake-cache && '10' || '1' }} origin ${{ github.sha }}
git checkout FETCH_HEAD flake.nix flake.lock script/prepare-* tests/elab/importStructure.lean
if: github.event_name == 'pull_request'
# (needs to be after "Checkout" so files don't get overridden)
- name: Setup emsdk
uses: emscripten-core/setup-emsdk@4528d102f7230f0e7b276855c01ea1159be0e984 # v16
with:
version: 3.1.44
actions-cache-folder: emsdk
if: matrix.wasm
- name: Install 32bit c libs
run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y gcc-multilib g++-multilib ccache libuv1-dev:i386 libssl-dev:i386 pkgconf:i386
if: matrix.cmultilib
- name: Restore CCache
id: restore-ccache
uses: actions/cache/restore@v6
with:
# NOTE: must be in sync with `save` below and with "Restore CCache" in `update-stage0.yml`
path: .ccache
key: ${{ matrix.name }}-build-v5-${{ github.sha }}
# fall back to (latest) previous cache
restore-keys: |
${{ matrix.name }}-build-v5
# open nix-shell once for initial setup
- name: Setup
run: |
ccache --zero-stats
if: runner.os == 'Linux'
- name: Set up env
run: |
echo "NPROC=$(nproc 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || echo 4)" >> $GITHUB_ENV
echo "TARGET_STAGE=stage${{ matrix.target-stage || 1 }}" >> $GITHUB_ENV
- name: Configure Build
run: |
ulimit -c unlimited # coredumps
[ -d build ] || mkdir build
cd build
# arguments passed to `cmake`
# opt into `LEAN_HEADER_SNAPSHOTS` as suspected issue with incremental builds does not
# affect CI
OPTIONS=(-DWFAIL=ON -DLEAN_HEADER_SNAPSHOTS=ON)
if [[ '${{ matrix.release }}' == true ]]; then
# Embeds the githash into stage 1 library and checks it.
# This prohibits reusing `.olean`s from any build not so stamped,
# so we don't do it in the fast non-release CI.
OPTIONS+=(-DCHECK_OLEAN_VERSION=ON)
# Replace the system-wide cache with a job-level one to avoid ingesting mismatched
# oleans from other builds on self-hosted runners.
echo "LAKE_CACHE_DIR=" >> "$GITHUB_ENV"
fi
if [[ -n '${{ matrix.cross_target }}' ]]; then
# used by `prepare-llvm`
export EXTRA_FLAGS=--target=${{ matrix.cross_target }}
OPTIONS+=(-DLEAN_PLATFORM_TARGET=${{ matrix.cross_target }})
fi
if [[ -n '${{ matrix.prepare-llvm }}' ]]; then
wget -q ${{ matrix.llvm-url }}
PREPARE="$(${{ matrix.prepare-llvm }})"
cp -r stage1 stage2
cp -r stage1 stage3
eval "OPTIONS+=($PREPARE)"
fi
if [[ '${{ matrix.release }}' == true && -n '${{ inputs.nightly }}' ]]; then
OPTIONS+=(-DLEAN_SPECIAL_VERSION_DESC=${{ inputs.nightly }})
fi
if [[ '${{ matrix.release }}' == true && -n '${{ inputs.RELEASE_TAG }}' ]]; then
OPTIONS+=(-DLEAN_VERSION_IS_RELEASE=1)
OPTIONS+=(-DLEAN_SPECIAL_VERSION_DESC=${{ inputs.LEAN_SPECIAL_VERSION_DESC }})
fi
# contortion to support empty OPTIONS with old macOS bash
cmake .. --preset ${{ matrix.CMAKE_PRESET || 'release' }} -B . ${{ matrix.CMAKE_OPTIONS }} ${OPTIONS[@]+"${OPTIONS[@]}"} -DLEAN_INSTALL_PREFIX=$PWD/..
- name: Build Stage 0 & Configure Stage 1
run: |
ulimit -c unlimited # coredumps
time make -C build stage1-configure -j$NPROC
# Key every subsequent Lake invocation's cache trace the same way as the CMake-driven
# stdlib build, using the githash the stage1 configure emitted (see `src/CMakeLists.txt`).
echo "LEAN_GITHASH=$(cat build/stage1/lake-githash)" >> "$GITHUB_ENV"
- name: Check for stage0 update
id: check-stage0
# A stage0 update replaces the bootstrap compiler, which invalidates every Lake artifact
# (Lake does not track stage0), so there is nothing reusable in the cache to download.
# `github.sha` is the pushed commit (push/merge_group) or the virtual merge commit (PRs),
# so `github.sha^1` is the parent / PR base to diff `stage0` against in both cases.
if: matrix.lake-cache
run: |
sha='${{ github.sha }}'
if git rev-parse --verify --quiet "$sha^1" >/dev/null && ! git diff --quiet "$sha^1" "$sha" -- stage0; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "changed=false" >> "$GITHUB_OUTPUT"
fi
- name: Download Lake Cache
if: matrix.lake-cache && steps.check-stage0.outputs.changed != 'true'
run: |
cd src
../build/stage0/bin/lake cache get --repo=${{ github.repository }}
timeout-minutes: 20 # prevent excessive hanging from network issues
continue-on-error: true
- name: Build Target Stage
run: |
ulimit -c unlimited # coredumps
time make -C build $TARGET_STAGE -j$NPROC
# Should be done as early as possible, and the Lake cache upload below in particular *before*
# "Check rebootstrap" which changes the state of stage1/
- name: Save CCache
# Caching on cancellation created some mysterious issues perhaps related to improper build
# shutdown
if: steps.restore-ccache.outputs.cache-hit != 'true' && !cancelled()
uses: actions/cache/save@v6
with:
# NOTE: must be in sync with `restore` above
path: .ccache
key: ${{ steps.restore-ccache.outputs.cache-primary-key }}
- id: upload-lake-cache
name: Upload Lake Cache
# Caching on cancellation created some mysterious issues perhaps related to improper build
# shutdown. Also, since this needs access to secrets, it cannot be run on forks.
if: matrix.lake-cache && !cancelled() && (github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository)
run: |
curl --version
cd src
time ../build/stage0/bin/lake build -o ../build/lake-mappings.jsonl
time ../build/stage0/bin/lake cache put ../build/lake-mappings.jsonl --repo=${{ github.repository }}
env:
LAKE_CACHE_KEY: ${{ secrets.LAKE_CACHE_KEY }}
LAKE_CACHE_ARTIFACT_ENDPOINT: ${{ vars.LAKE_CACHE_ENDPOINT }}/a1
LAKE_CACHE_REVISION_ENDPOINT: ${{ vars.LAKE_CACHE_ENDPOINT }}/r1
timeout-minutes: 20 # prevent excessive hanging from network issues
- name: Verify Lake Cache
if: steps.upload-lake-cache.outcome == 'success'
# `lake cache clean` deletes the entire configured cache directory, which for a build using
# the system-wide cache would be the one shared with every other job on the runner, so give
# the round trip a throwaway directory of its own.
env:
LAKE_CACHE_DIR: ${{ github.workspace }}/build/verify-lake-cache
run: |
cp -r build/stage1 build/stage1.bak
rm -rf build/stage1/lib
cd src
../build/stage0/bin/lake cache clean
../build/stage0/bin/lake cache get --repo=${{ github.repository }}
../build/stage0/bin/lake build --no-build
continue-on-error: true
- name: Restore Build
if: steps.upload-lake-cache.outcome == 'success'
env:
LAKE_CACHE_DIR: ${{ github.workspace }}/build/verify-lake-cache
run: |
rm -rf build/stage1
mv build/stage1.bak build/stage1
cd src
../build/stage0/bin/lake cache clean
- name: Check libuv version
# Homebrew and MSYS2 provide whatever libuv they currently ship, so check the linked one.
# This is not an elab test, because most distributions ship a slightly older LibUV, and having
# a red test for almost everyone building Lean from source is just noise.
run: |
min=$((1 << 16 | 53 << 8 | 0))
v=$(echo $'import Lean.Runtime\n#eval Lean.libUVVersion' | build/$TARGET_STAGE/bin/lean --stdin)
fmt() { echo "$(($1 >> 16)).$(($1 >> 8 & 255)).$(($1 & 255))"; }
echo "libuv $(fmt "$v")"
(( v >= min )) || { echo "::error::libuv $(fmt "$v") is linked, expected at least $(fmt "$min")"; exit 1; }
if: ${{ !matrix.cross }}
# Not part of the default targets because it is big
- name: Build leanchecker-paranoid
if: matrix.release && !matrix.wasm
run: |
make -C build/$TARGET_STAGE leanchecker-paranoid -j$NPROC
# For the external checkers pinned to their own toolchains (`lean4lean`, `con-leche`) and the
# `lean-beam` package test
- name: Install elan
if: (matrix.release && !matrix.wasm) || matrix.lean-beam
run: |
if ! command -v elan > /dev/null; then
# Use consistent `ELAN_HOME` across platforms
(cd build && export ELAN_HOME=elan &&
curl https://elan.lean-lang.org/elan-init.sh -sSf |
sh -s -- -y --default-toolchain none --no-modify-path)
if command -v cygpath > /dev/null; then
# msys2 drops `GITHUB_PATH`, but each step is a login shell
echo "export PATH=\"$PWD/build/elan/bin:\$PATH\"" > /etc/profile.d/elan.sh
else
echo "$PWD/build/elan/bin" >> "$GITHUB_PATH"
fi
fi
- name: Build lean4lean and con-leche
if: matrix.release && !matrix.wasm
run: |
elan --version # fails step if not found
make -C build/$TARGET_STAGE lean4lean con-leche
- name: Build lean-beam
if: (matrix.release || matrix.lean-beam) && !matrix.wasm && runner.os != 'Windows'
run: |
# Require Beam in the package test only when this job explicitly builds it.
echo 'LEAN_BEAM_REQUIRED=1' >> "$GITHUB_ENV"
# Beam's C sources need libc headers, which the toolchain does not bundle; use those of the
# glibc we link against instead of the runner's `/usr/include`, which NixOS runners lack
if [[ -n "${GLIBC_DEV:-}" ]]; then
export C_INCLUDE_PATH="$GLIBC_DEV/include"
fi
make -C build/$TARGET_STAGE lean-beam
- name: Build nanoda and con-ron
if: matrix.release && !matrix.wasm
run: |
# msys2 hides the runner's preinstalled cargo by trimming the Windows `PATH`
if command -v cygpath > /dev/null && [ -n "${USERPROFILE:-}" ]; then
export PATH="$(cygpath -u "$USERPROFILE")/.cargo/bin:$PATH"
# That cargo targets MSVC, so the `cc` crate has to find `cl.exe` itself rather than
# take the job's msys2 `CXX`
unset CC CXX
fi
cargo --version # fails step if not found
make -C build/$TARGET_STAGE nanoda con-ron
- name: Install
run: |
make -C build/$TARGET_STAGE install
- name: Check Binaries
run: ${{ matrix.binary-check }} lean-*/bin/* || true
- name: Count binary symbols
run: |
for f in lean-*/bin/*; do
echo "$f: $(nm $f | grep " T " | wc -l) exported symbols"
done
if: matrix.name == 'Windows'
- name: List Install Tree
run: |
# omit contents of Init/, ...
tree --du -h lean-*-* | grep -E ' (Init|Lean|Lake|LICENSE|[a-z])'
- name: Pack
run: |
dir=$(echo lean-*-*)
mkdir pack
# high-compression tar.zst + zip for release, fast tar.zst otherwise
if [[ '${{ startsWith(github.ref, 'refs/tags/') && matrix.release }}' == true || -n '${{ inputs.nightly }}' || -n '${{ inputs.RELEASE_TAG }}' ]]; then
${{ matrix.tar || 'tar' }} cf - $dir | zstd -T0 --no-progress -19 -o pack/$dir.tar.zst
zip -rq pack/$dir.zip $dir
else
${{ matrix.tar || 'tar' }} cf - $dir | zstd -T0 --no-progress -o pack/$dir.tar.zst
fi
- uses: actions/upload-artifact@v7
if: matrix.release || matrix.upload
with:
name: build-${{ matrix.name }}
path: pack/*
- name: Lean stats
run: |
build/$TARGET_STAGE/bin/lean --stats src/Lean.lean
if: ${{ !matrix.cross }}
# Tests must not write into the checked-in source tree; scratch output belongs in an
# ignored path. Making tracked files read-only catches a test that edits one even if it
# restores the file afterwards, which the tree comparison below cannot see.
- name: Protect Source Tree
run: |
git status --porcelain -unormal | sort > "$RUNNER_TEMP/tree-before"
git ls-files -z | xargs -0 chmod a-w
if: matrix.test
- name: Lower perf_event_paranoid for samply
# Best-effort: some runners lack sudo or won't allow this. The `lake samply`
# recording test skips if perf permissions are unavailable.
run: command -v sudo && sudo -n sysctl -w kernel.perf_event_paranoid=1 || true
if: runner.os == 'Linux' && matrix.test
- name: Test
id: test
run: |
ulimit -c unlimited # coredumps
time ctest --preset ${{ matrix.CMAKE_PRESET || 'release' }} --test-dir build/$TARGET_STAGE -j$NPROC --output-junit test-results.xml ${{ matrix.CTEST_OPTIONS }}
if: matrix.test
# restore write access before any later step (stage 2, benchmarks, `update-stage0`) runs
- name: Unprotect Source Tree
run: git ls-files -z | xargs -0 chmod u+w
if: always() && matrix.test
- name: Check Source Tree Clean
run: |
git status --porcelain -unormal | sort > "$RUNNER_TEMP/tree-after"
diff -u "$RUNNER_TEMP/tree-before" "$RUNNER_TEMP/tree-after" && exit 0
echo "::error::the test suite left files in the checked-in source tree; write them to an ignored path instead"
exit 1
if: matrix.test && steps.test.conclusion != 'skipped'
# copy failed tests' output into the `<failure>` elements shown by the test summary
- name: Embed Test Output
run: |
python3 script/junit_embed_output.py build/$TARGET_STAGE/test-results.xml
if: always() && steps.test.conclusion == 'failure'
- name: Test Summary
uses: test-summary/action@37b508cfee6d4d080eedd00b5bb240a6a784a6a5 # v2.6
with:
paths: build/${{ env.TARGET_STAGE }}/test-results.xml
# prefix `if` above with `always` so it's run even if tests failed
if: always() && steps.test.conclusion != 'skipped'
- name: Check Test Binary
run: ${{ matrix.binary-check }} tests/compile/534.lean.out
if: (!matrix.cross) && steps.test.conclusion != 'skipped'
- name: Build Stage 2
run: |
make -C build -j$NPROC stage2
if: matrix.test-bench
- name: Check Stage 3
run: |
make -C build -j$NPROC check-stage3
if: matrix.check-stage3
- name: Test Benchmarks
run: |
cd tests
nix develop -c make -C ../build -j$NPROC bench
if: matrix.test-bench
- name: Check rebootstrap
run: |
set -e
git config user.email "stage0@lean-fro.org"
git config user.name "update-stage0"
make -C build update-stage0
# An empty commit changes `Lean.githash` without changing the stage0 tree hash that keys
# Lake's traces, leaving stage 1 `.olean`s stale with respect to the rebuilt binaries. If
# stage0 is unchanged, there is nothing to rebootstrap anyway, so exit early.
git diff --cached --quiet -- stage0 && exit 0 || git commit -m "chore: update-stage0"
time make -C build -j$NPROC
# The tests below require Beam ("Build lean-beam" set `LEAN_BEAM_REQUIRED`), and Beam refuses
# to run under a compiler other than the one it was built with
C_INCLUDE_PATH="$GLIBC_DEV/include" make -C build/stage1 lean-beam
# Set Lake's githash to the new stage0 hash used during the build (for the tests).
# Updating `GITHUB_ENV` would only apply to future steps (which do not need it).
export LEAN_GITHASH=$(cat build/stage1/lake-githash)
time ctest --preset ${{ matrix.CMAKE_PRESET || 'release' }} --test-dir build/stage1 -j$NPROC
if: matrix.check-rebootstrap && !matrix.release
- name: CCache stats
if: always()
run: ccache -s
- name: Show stacktrace for coredumps
if: failure() && runner.os == 'Linux'
run: |
for c in $(find . -name core); do
progbin="$(file $c | sed "s/.*execfn: '\([^']*\)'.*/\1/")"
echo bt | $GDB/bin/gdb -q $progbin $c || true
done