blob: 4147096f9ff639c6935b8d4ede9cf020c493d6e3 [file] [edit]
# Part of the Crubit project, under the Apache License v2.0 with LLVM
# Exceptions. See /LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
name: CI
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
# Supersede in-flight runs for the same PR instead of running both to
# completion. Pushes to main are left alone: a cancelled run reports as a
# failed check, which would confuse the Copybara export gating on it.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
CARGO_TERM_COLOR: always
# Incremental compilation only pays off across repeated builds in one
# checkout; on ephemeral runners it is pure overhead.
CARGO_INCREMENTAL: 0
CARGO_NET_RETRY: 10
RUSTUP_MAX_RETRIES: 10
# Single source of truth for the crates Cargo cannot yet build or test
# directly. Expand these with ${{ env.NAME }} rather than $NAME so that the
# quoting around the globs is interpreted by the shell rather than passed
# through to Cargo literally.
CARGO_SKIP_ALL: >-
--exclude '*_sys'
CARGO_SKIP_UNTESTABLE: >-
--exclude=rs_bindings_from_cc
--exclude=rs_bindings_from_cc_cc_api
--exclude=rs_bindings_from_cc_cc_api_ffi
--exclude=rs_bindings_from_cc_ir_matchers
--exclude=rs_bindings_from_cc_ir_testing
--exclude=rs_bindings_from_cc_multiplatform_ir_testing
--exclude=rs_bindings_from_cc_test_generators
permissions:
contents: read
# LINT.IfChange
jobs:
cargo_test:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Setup CI
id: setup
uses: ./.github/actions/setup_ci
with:
gcp_sa_key: ${{ secrets.GCP_SA_KEY }}
sccache: 'true'
protoc: 'true'
- name: Test Cargo project
run: >
cargo test --verbose --locked --workspace --no-fail-fast
${{ env.CARGO_SKIP_ALL }}
--exclude 'rs_bindings_from_cc*'
# Shares target/ with the step above, so these must stay in one job.
- name: Build not-yet-testable Cargo crates
run: >
cargo build --verbose --locked --workspace
${{ env.CARGO_SKIP_ALL }}
${{ env.CARGO_SKIP_UNTESTABLE }}
- name: Show sccache stats
if: steps.setup.outputs.sccache_enabled == 'true' && always()
run: sccache --show-stats
cmake:
runs-on: ubuntu-latest
timeout-minutes: 30
strategy:
# Report both legs independently; one failing example should not mask
# the state of the other.
fail-fast: false
matrix:
project: [cmake, cmake_demo]
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Setup CI
id: setup
uses: ./.github/actions/setup_ci
with:
gcp_sa_key: ${{ secrets.GCP_SA_KEY }}
# Covers both the C++ compiled directly by CMake and the Rust that
# Corrosion builds through Cargo.
sccache: 'true'
- name: Test CMake project
run: |
cd examples/build_systems/${{ matrix.project }}
cmake -B build -S . -G Ninja $LAUNCHER_FLAGS
cmake --build build --parallel
cd build
ctest --output-on-failure --parallel 2
- name: Show sccache stats
if: steps.setup.outputs.sccache_enabled == 'true' && always()
run: sccache --show-stats
# examples/build_systems/bazel is a second Bazel workspace: its own
# MODULE.bazel, its own .bazelrc, its own external dependency fetch and its
# own Bazel server. It shares no state with bazel_bridge, so the two run
# concurrently rather than one after the other in a single job.
bazel_example:
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Setup CI
uses: ./.github/actions/setup_ci
with:
gcp_sa_key: ${{ secrets.GCP_SA_KEY }}
bazel: 'true'
# The example resolves rules_crubit through local_path_override, so it
# builds against the same LLVM as the main workspace.
llvm: 'pinned'
- name: Build Bazel test project (example)
run: |
cd examples/build_systems/bazel
bazelisk build --remote_download_outputs=minimal //:main
bazel_bridge:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
with:
persist-credentials: false
- name: Setup CI
id: setup
uses: ./.github/actions/setup_ci
with:
gcp_sa_key: ${{ secrets.GCP_SA_KEY }}
bazel: 'true'
llvm: 'pinned'
sccache: 'true'
# setup_bazel_env.py's merge_archives() globs *.a files, generated C++
# headers (*.h, *.inc, *.def), and protoc off local disk, so download only
# those artifacts rather than every intermediate .o and .rlib.
- name: "Build rs_bindings_from_cc using Bazel"
run: >
bazelisk build
--lockfile_mode=error
--remote_download_outputs=minimal
--remote_download_regex='.*\.(a|h|inc|def)$|.*/protoc$'
rs_bindings_from_cc:rs_bindings_from_cc_main
@protobuf//:protoc
- name: "Set up Bazel environment for Cargo"
run: python3 cargo/build/setup_bazel_env.py
- name: "Build rs_bindings_from_cc using Cargo"
run: cargo build --verbose --locked -p rs_bindings_from_cc
- name: Show sccache stats
if: steps.setup.outputs.sccache_enabled == 'true' && always()
run: sccache --show-stats
# Single aggregate check for branch protection and for the Copybara export.
# Gating on this rather than on each job individually means jobs above can be
# renamed, split, or given new matrix dimensions without another synchronized
# copy.bara.sky edit.
ci-status:
if: always()
needs: [cargo_test, cmake, bazel_example, bazel_bridge]
runs-on: ubuntu-latest
steps:
- name: Fail if any job did not succeed
if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')
run: exit 1
# LINT.ThenChange(//depot/copy.bara.sky)