Skip to content

Commit

Permalink
Deep CI rework with few fix
Browse files Browse the repository at this point in the history
## CI
* Add few more CI workflows
  * Add CMake and Bazel workflows to get badges
  * Add MacOS (amd64 and M1) and Windows (amd64) jobs
  * Add C++ 14, 17 and 20 setup bor bazel jobs

## Code
* Fix C++14 build:
  * using `absl::optional` and `absl::variant` (#184)
  * use of `absl::string_view` (fix cl/715199813 #185 regression)
* Add pybind_abseil deps for tests/
 note: Protobuf v29 (as well as abseil-cpp 20240722) still support C++14 and will drop it in v30
* Fix Windows MSVC compilation

## Dependencies
* Bump protobuf to v29.2 everywhere
  * previously: 23.1 (bazel module), 25.3 (bazel workspace), 23.3 (cmake)

## Bazel
* bazelrc: Fix windows (MSVC) default build flags
* bazelrc: support user configuration override
* Fix the workspace mode when using bazel 8

## CMake
* declare `pybind_extension` as `MODULE` to fix macOS XCode build jobs
* fix Python3 usage
note: on manylinux images, Python Libraries are NOT available, only
headers since python native modules are loaded by the python interpreter and
must not be linked to python.
ref: https://peps.python.org/pep-0513/#libpythonx-y-so-1
PiperOrigin-RevId: 716347968
  • Loading branch information
Mizux authored and copybara-github committed Jan 17, 2025
1 parent 324672e commit 10b50f0
Show file tree
Hide file tree
Showing 34 changed files with 1,082 additions and 313 deletions.
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
11 changes: 8 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ common --announce_rc
# Enable verbose failures for testing only.
build --verbose_failures

# Compiler options.
build --cxxopt=-std=c++17
build --host_cxxopt=-std=c++17
# 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:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17

# 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
73 changes: 73 additions & 0 deletions .github/workflows/amd64_linux_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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'},
{version: '3.12'},
]
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_protobuf/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
75 changes: 75 additions & 0 deletions .github/workflows/amd64_macos_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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'},
{version: '3.12'},
]
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_protobuf/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
76 changes: 76 additions & 0 deletions .github/workflows/amd64_windows_bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# ref: https://github.com/actions/runner-images
name: amd64 Windows Bazel

on: [push, pull_request, workflow_dispatch]

# Building using the github runner environement directly.
jobs:
native:
strategy:
matrix:
runner: [
windows-2022,
#windows-2019,
]
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'},
{version: '3.12'},
]
exclude:
- runner: windows-2019
cpp: {version: 20}
# only test -c dbg with VS 2022 version 17 to save compute time
- runner: windows-2019
bazel: {compilation_mode: dbg}
- cpp: {version: 14}
bazel: {compilation_mode: dbg}
- cpp: {version: 20}
bazel: {compilation_mode: dbg}
fail-fast: false # Don't cancel all jobs if one fails.
name: ${{ matrix.runner }}•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
runs-on: ${{ matrix.runner }}
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 Bazel
run: choco install bazel
- 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_windows_bazel:
runs-on: ubuntu-latest
needs: native
steps:
- uses: actions/checkout@v4
Loading

0 comments on commit 10b50f0

Please sign in to comment.