Skip to content

Commit

Permalink
deep rework (mostly ci and build system)
Browse files Browse the repository at this point in the history
# Fix
* Fix `absl::monostate` support against C++14
* Fix `MSVC C2466` compilation error
  ref: https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2466
* Fix `bazel test -c opt` run

# CMake
* Bump CMake minimal version to 3.18 to align with pybind11_protobuf and needed to work with pypa/manylinux image (ed need `Development.Module` option in `FindPython3`)
* rename `status` as `status_py_extension_stub` target to avoid conflict with abseil-cpp when fetched (ed cmake target are NOT scoped)<br>
  note: still provide the `pybind11_abseil::status` target alias.
* Disable C++ gnu extension.
* Rework third party management
  * disable test for dependencies BUT still allow to enable them for pybind11_abseil
  * Bump abseil-cpp from `20230802.0` to `20240722.0`
  * Bump pybind11 from master(floating) to `v2.13.6`
* Fix XCode build using `MODULE` in `pybind_extension`
* Fix Python support by not linking against the python library as manylinux images and PEP-513 require<br>
  ref: https://peps.python.org/pep-0513/#libpythonx-y-so-1

# Bazel
* Update dependencies in `MODULE.bazel` and `WORKSPACE`
  * Bump Protobuf to `v29.2`
* Add a `.bazelignore` to avoid to parse cmake's usual `build` directory
* Add a `.bazelrc` with default options (similar to the one in `pybind11_protobuf`)

# Update CI workflows
* Split CMake and Bazel workflows to get independent badges
* Split MacOS (amd64 and M1) and Windows (amd64) and Linux (amd64) jobs
* import ubuntu-build.yml from pybind11_protobuf

## Bazel
* Add C++14, c++17 and c++20 flavours
* Add `-c opt` and `-c dbg` variants
* only test against the default python3.11

## CMake
* Test Python 3.9, 3.10. 3.11, 3.12
* cmake(linux): Test Unix Makefile and Ninja Build generators
* cmake(macOS): Test XCode and Makefile generators
* cmake(windows): Test MSVC (VC 2022) generator

PiperOrigin-RevId: 715743424
  • Loading branch information
Mizux authored and copybara-github committed Jan 20, 2025
1 parent 2420efd commit 2c6dc06
Show file tree
Hide file tree
Showing 28 changed files with 1,009 additions and 176 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
29 changes: 29 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Enable logging rc options.
common --announce_rc

# Enable verbose failures for testing only.
build --verbose_failures

# Set the default Apple platform to macOS.
build --apple_platform_type=macos

# Abseil requires C++14 at minimum.
build --enable_platform_specific_config
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:macos --cxxopt=-mmacos-version-min=10.15 --host_cxxopt=-mmacos-version-min=10.15
build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17

# Enable the runfiles symlink tree on Windows. This makes it possible to build
# the pip package on Windows without an intermediate data-file archive, as the
# build_pip_package script in its current form (as of Aug 2023) uses the
# runfiles symlink tree to decide what to put into the Python wheel.
startup --windows_enable_symlinks
build:windows --enable_runfiles

# Enable logging error output.
test --test_output=errors
test --test_summary=detailed

# https://bazel.build/configure/best-practices#bazelrc-file
try-import %workspace%/user.bazelrc
34 changes: 10 additions & 24 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -1,57 +1,43 @@
# ref: https://github.com/actions/runner-images
name: build_and_test

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
on: [push, pull_request, workflow_dispatch]

env:
PIP_BREAK_SYSTEM_PACKAGES: 1

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:

unix:
strategy:
fail-fast: false
matrix:
runs-on: [ubuntu-latest]
build_tool: [bazel, cmake]

name: "${{matrix.runs-on}} ${{matrix.build_tool}}"
name: "script ${{matrix.build_tool}}"
runs-on: ${{matrix.runs-on}}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Show env
run: env

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install bazel
- name: Setup bazel
if: matrix.build_tool == 'bazel'
# Install Bazel, see https://docs.bazel.build/versions/master/install-ubuntu.html#step-1-install-required-packages
run: |
sudo apt install curl gnupg
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
sudo mv bazel.gpg /etc/apt/trusted.gpg.d/
echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
sudo apt update && sudo apt install bazel -y
uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true

- name: Show bazel version
if: matrix.build_tool == 'bazel'
run: bazel --version

- name: Update cmake
if: matrix.build_tool == 'cmake'
uses: jwlawson/[email protected]

- name: Show cmake version
if: matrix.build_tool == 'cmake'
run: cmake --version
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/amd64_linux_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ref: https://github.com/actions/runner-images
name: amd64 Linux Bazel

on: [push, pull_request, workflow_dispatch]

# Building using the github runner environement directly.
jobs:
native:
strategy:
matrix:
bazel: [
{compilation_mode: opt},
{compilation_mode: dbg},
]
cpp: [
{version: 14, flags: "-std=c++14"},
{version: 17, flags: "-std=c++17"},
{version: 20, flags: "-std=c++20"},
]
python: [
{version: '3.11'},
]
exclude:
# only test `-c dbg` build with C++17
- cpp: {version: 14}
bazel: {compilation_mode: dbg}
- cpp: {version: 20}
bazel: {compilation_mode: dbg}
fail-fast: false
name: Linux•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check Java
run: java -version
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
run: |
python --version
python -m platform
- uses: bazel-contrib/[email protected]
with:
bazelisk-cache: true
disk-cache: ${{ github.workflow }}
repository-cache: true
- name: Check Bazel
run: bazel version
- name: Build
run: >
bazel build
-c ${{ matrix.bazel.compilation_mode }}
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
--subcommands=pretty_print
--enable_bzlmod
//...
- name: Test
run: >
bazel test
-c ${{ matrix.bazel.compilation_mode }}
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
--subcommands=pretty_print
--enable_bzlmod
//...
amd64_linux_bazel:
runs-on: ubuntu-latest
needs: native
steps:
- uses: actions/checkout@v4
74 changes: 74 additions & 0 deletions .github/workflows/amd64_linux_cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ref: https://github.com/actions/runner-images
name: amd64 Linux CMake

on: [push, pull_request, workflow_dispatch]

# Building using the github runner environement directly.
jobs:
native:
strategy:
matrix:
python: [
{version: '3.9'},
{version: '3.10'},
{version: '3.11'},
{version: '3.12'},
#{version: '3.13'},
]
cmake: [
{generator: "Unix Makefiles", config: "Release"},
{generator: "Ninja", config: "Release"},
#{generator: "Ninja Multi-Config", config: "Release"},
]
fail-fast: false
name: Linux•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
run: |
python --version
python -m platform
- name: Install Python requirements
run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_abseil/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))')
- name: Install Ninja
run: |
sudo apt-get update
sudo apt-get install ninja-build
- name: Check CMake
run: cmake --version
- name: Configure
run: >
cmake -S. -Bbuild
-G "${{ matrix.cmake.generator }}"
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }}
-DCMAKE_INSTALL_PREFIX=install
- name: Build
run: >
cmake --build build
--config ${{ matrix.cmake.config }}
--target all
-v -j2
- name: Test
run: >
CTEST_OUTPUT_ON_FAILURE=1
cmake --build build
--config ${{ matrix.cmake.config }}
--target test
-v
- name: Install
run: >
cmake --build build
--config ${{ matrix.cmake.config }}
--target install
-v
amd64_linux_cmake:
runs-on: ubuntu-latest
needs: native
steps:
- uses: actions/checkout@v4
74 changes: 74 additions & 0 deletions .github/workflows/amd64_macos_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# ref: https://github.com/actions/runner-images
name: amd64 MacOS Bazel

on: [push, pull_request, workflow_dispatch]

# Building using the github runner environement directly.
jobs:
native:
strategy:
matrix:
bazel: [
{compilation_mode: opt},
{compilation_mode: dbg},
]
cpp: [
#{version: 14, flags: "-std=c++14"},
{version: 17, flags: "-std=c++17"},
#{version: 20, flags: "-std=c++20"},
]
python: [
{version: '3.11'},
]
exclude:
# only test `-c dbg` build with C++17
- cpp: {version: 14}
bazel: {compilation_mode: dbg}
- cpp: {version: 20}
bazel: {compilation_mode: dbg}
fail-fast: false
name: MacOS•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
runs-on: macos-13 # last macos intel based runner
steps:
- uses: actions/checkout@v4
- name: Set Java to OpenJDK 17 (Temurin)
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Check Python
run: |
python --version
python -m platform
- name: Check Bazel
run: bazel version
- name: Change Python in MODULE.bazel
run: |
sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel
cat MODULE.bazel
- name: Build
run: >
bazel build
-c ${{ matrix.bazel.compilation_mode }}
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
--subcommands=pretty_print
--enable_bzlmod
//...
- name: Test
run: >
bazel test
-c ${{ matrix.bazel.compilation_mode }}
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
--subcommands=pretty_print
--enable_bzlmod
//...
amd64_macos_bazel:
runs-on: ubuntu-latest
needs: native
steps:
- uses: actions/checkout@v4
71 changes: 71 additions & 0 deletions .github/workflows/amd64_macos_cmake.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ref: https://github.com/actions/runner-images
name: amd64 MacOS CMake

on: [push, pull_request, workflow_dispatch]

# Building using the github runner environement directly.
jobs:
native:
strategy:
matrix:
python: [
{version: '3.9'},
{version: '3.10'},
{version: '3.11'},
{version: '3.12'},
#{version: '3.13'},
]
cmake: [
{generator: "Xcode", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: install},
{generator: "Unix Makefiles", config: Release, build_target: all, test_target: test, install_target: install},
]
fail-fast: false
name: MacOS•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }}
runs-on: macos-13 # last macos intel based runner
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python.version }}
- name: Update Path
run: |
echo "$HOME/Library/Python/${{ matrix.python.version }}/bin" >> $GITHUB_PATH
echo "$HOME/.local/bin" >> $GITHUB_PATH
- name: Check Python
run: python --version
- name: Install Python requirements
run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_abseil/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))')
- name: Check CMake
run: cmake --version
- name: Configure
run: >
cmake -S. -Bbuild
-G "${{ matrix.cmake.generator }}"
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }}
-DCMAKE_INSTALL_PREFIX=install
- name: Build
run: >
cmake --build build
--config ${{ matrix.cmake.config }}
--target ${{ matrix.cmake.build_target }}
-v -j2
- name: Test
run: >
CTEST_OUTPUT_ON_FAILURE=1
cmake --build build
--config ${{ matrix.cmake.config }}
--target ${{ matrix.cmake.test_target }}
-v
- name: Install
run: >
cmake --build build
--config ${{ matrix.cmake.config }}
--target ${{ matrix.cmake.install_target }}
-v
amd64_macos_cmake:
runs-on: ubuntu-latest
needs: native
steps:
- uses: actions/checkout@v4
Loading

0 comments on commit 2c6dc06

Please sign in to comment.