Skip to content

Extract nanobind_example compile commands for CMake and Bazel #11

Extract nanobind_example compile commands for CMake and Bazel

Extract nanobind_example compile commands for CMake and Bazel #11

name: Extract nanobind_example compile commands for CMake and Bazel
on:
workflow_dispatch:
jobs:
nb-compile-commands:
name: Capture nanobind compile commands on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- uses: actions/checkout@v4
with:
repository: wjakob/nanobind_example
path: nanobind_example
fetch-depth: 0
- uses: actions/checkout@v4
with:
path: nanobind-bazel
- name: Set up Python and dependencies
uses: actions/setup-python@v5
with:
python-version: 3.12
- run: python -m pip install --upgrade build
- name: Build and capture CMake compile commands
run: python -m build . --wheel --config-setting="cmake.args=-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
working-directory: nanobind_example
- name: Upload CMake commands and Ninja build artifacts
uses: actions/upload-artifact@v4
with:
name: cmake-compile-commands-${{ matrix.os}}
# the build subfolder name is autogenerated, so just use a glob.
# the build.ninja file has the linker command section.
path: |
nanobind_example/build/cp312-*/build.ninja
nanobind_example/build/cp312-*/CMakeCache.txt
nanobind_example/build/cp312-*/compile_commands.json
if-no-files-found: error
- name: Clean repo and switch to Bazel
run: git clean -xdf && git checkout bazel
working-directory: nanobind_example
- name: Build wheel using Bazel
run: python -m build . --wheel
working-directory: nanobind_example
- name: Extract Bazel compile commands for ${{ matrix.os}}
run: |
bazel run @hedron_compile_commands//:refresh_all \
-- \
--compilation_mode=opt \
--cxxopt=-std=c++17 \
--@rules_python//python/config_settings:python_version=3.12 \
--@nanobind_bazel//:minsize \
--@nanobind_bazel//:py-limited-api=cp312
shell: bash
working-directory: nanobind_example
- name: Rearrange files into a single output directory
run: |
shopt -s globstar
mkdir ${{ matrix.os }}
cp compile_commands.json ${{ matrix.os }}
cp -r bazel-out/*-opt/**/*.params ${{ matrix.os }}
shell: bash
working-directory: nanobind_example
- name: Upload Bazel compile commands and flag files for ${{ matrix.os }}
uses: actions/upload-artifact@v4
with:
name: bazel-compile-commands-${{ matrix.os }}
# there should be two params files - the libnanobind one, and the nanobind_example_ext one.
path: nanobind_example/${{ matrix.os }}
if-no-files-found: error
merge-compile-commands:
name: Stitch together previously collected commands
runs-on: ubuntu-latest
needs: nb-compile-commands
steps:
- name: Merge all CMake Artifacts into one
uses: actions/upload-artifact/merge@v4
with:
name: cmake-compile-commands
pattern: cmake-compile-commands-*
delete-merged: true
- name: Merge all Bazel Artifacts into one
uses: actions/upload-artifact/merge@v4
with:
name: bazel-compile-commands
pattern: bazel-compile-commands-*
delete-merged: true