Skip to content

Commit 504f074

Browse files
Mizuxcopybara-github
authored andcommitted
deep CI rework
## 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) * 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: ## Bazel * bazelrc: support user configuration override * Fix the workspace mode when using bazel 8 ## CMake * define pybind_extension as MODULE to fix macOS XCode build * 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.<br> ref: https://peps.python.org/pep-0513/#libpythonx-y-so-1 PiperOrigin-RevId: 716347968
1 parent 324672e commit 504f074

33 files changed

+1025
-312
lines changed

.bazelignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

.bazelrc

+8-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ common --announce_rc
44
# Enable verbose failures for testing only.
55
build --verbose_failures
66

7-
# Compiler options.
8-
build --cxxopt=-std=c++17
9-
build --host_cxxopt=-std=c++17
7+
# Abseil requires C++14 at minimum.
8+
build --enable_platform_specific_config
9+
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
10+
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
11+
build:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
1012

1113
# Enable logging error output.
1214
test --test_output=errors
1315
test --test_summary=detailed
16+
17+
# https://bazel.build/configure/best-practices#bazelrc-file
18+
try-import %workspace%/user.bazelrc
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ref: https://github.com/actions/runner-images
2+
name: amd64 Linux Bazel
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Building using the github runner environement directly.
7+
jobs:
8+
native:
9+
strategy:
10+
matrix:
11+
bazel: [
12+
{compilation_mode: opt},
13+
{compilation_mode: dbg},
14+
]
15+
cpp: [
16+
{version: 14, flags: "-std=c++14"},
17+
{version: 17, flags: "-std=c++17"},
18+
{version: 20, flags: "-std=c++20"},
19+
]
20+
python: [
21+
{version: '3.11'},
22+
{version: '3.12'},
23+
]
24+
exclude:
25+
# only test `-c dbg` build with C++17
26+
- cpp: {version: 14}
27+
bazel: {compilation_mode: dbg}
28+
- cpp: {version: 20}
29+
bazel: {compilation_mode: dbg}
30+
fail-fast: false
31+
name: Linux•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Check Java
36+
run: java -version
37+
- name: Setup Python
38+
uses: actions/setup-python@v5
39+
with:
40+
python-version: ${{ matrix.python.version }}
41+
- name: Check Python
42+
run: |
43+
python --version
44+
python -m platform
45+
- uses: bazel-contrib/[email protected]
46+
with:
47+
bazelisk-cache: true
48+
disk-cache: ${{ github.workflow }}
49+
repository-cache: true
50+
- name: Check Bazel
51+
run: bazel version
52+
- name: Build
53+
run: >
54+
bazel build
55+
-c ${{ matrix.bazel.compilation_mode }}
56+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
57+
--subcommands=pretty_print
58+
--enable_bzlmod
59+
//...
60+
- name: Test
61+
run: >
62+
bazel test
63+
-c ${{ matrix.bazel.compilation_mode }}
64+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
65+
--subcommands=pretty_print
66+
--enable_bzlmod
67+
//...
+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# ref: https://github.com/actions/runner-images
2+
name: amd64 Linux CMake
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Building using the github runner environement directly.
7+
jobs:
8+
native:
9+
strategy:
10+
matrix:
11+
python: [
12+
{version: '3.9'},
13+
{version: '3.10'},
14+
{version: '3.11'},
15+
{version: '3.12'},
16+
#{version: '3.13'},
17+
]
18+
cmake: [
19+
{generator: "Unix Makefiles", config: "Release"},
20+
{generator: "Ninja", config: "Release"},
21+
#{generator: "Ninja Multi-Config", config: "Release"},
22+
]
23+
fail-fast: false
24+
name: Linux•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }}
25+
runs-on: ubuntu-latest
26+
steps:
27+
- uses: actions/checkout@v4
28+
- name: Setup Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python.version }}
32+
- name: Check Python
33+
run: |
34+
python --version
35+
python -m platform
36+
- name: Install Python requirements
37+
run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))')
38+
- name: Install Ninja
39+
run: |
40+
sudo apt-get update
41+
sudo apt-get install ninja-build
42+
- name: Check CMake
43+
run: cmake --version
44+
- name: Configure
45+
run: >
46+
cmake -S. -Bbuild
47+
-G "${{ matrix.cmake.generator }}"
48+
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }}
49+
-DCMAKE_INSTALL_PREFIX=install
50+
- name: Build
51+
run: >
52+
cmake --build build
53+
--config ${{ matrix.cmake.config }}
54+
--target all
55+
-v -j2
56+
- name: Test
57+
run: >
58+
CTEST_OUTPUT_ON_FAILURE=1
59+
cmake --build build
60+
--config ${{ matrix.cmake.config }}
61+
--target test
62+
-v
63+
- name: Install
64+
run: >
65+
cmake --build build
66+
--config ${{ matrix.cmake.config }}
67+
--target install
68+
-v
+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ref: https://github.com/actions/runner-images
2+
name: amd64 MacOS Bazel
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Building using the github runner environement directly.
7+
jobs:
8+
native:
9+
strategy:
10+
matrix:
11+
bazel: [
12+
{compilation_mode: opt},
13+
{compilation_mode: dbg},
14+
]
15+
cpp: [
16+
#{version: 14, flags: "-std=c++14"},
17+
{version: 17, flags: "-std=c++17"},
18+
#{version: 20, flags: "-std=c++20"},
19+
]
20+
python: [
21+
{version: '3.11'},
22+
{version: '3.12'},
23+
]
24+
exclude:
25+
# only test `-c dbg` build with C++17
26+
- cpp: {version: 14}
27+
bazel: {compilation_mode: dbg}
28+
- cpp: {version: 20}
29+
bazel: {compilation_mode: dbg}
30+
fail-fast: false
31+
name: MacOS•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
32+
runs-on: macos-13 # last macos intel based runner
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Set Java to OpenJDK 17 (Temurin)
36+
uses: actions/setup-java@v3
37+
with:
38+
distribution: 'temurin'
39+
java-version: '17'
40+
- name: Setup Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python.version }}
44+
- name: Check Python
45+
run: |
46+
python --version
47+
python -m platform
48+
- name: Check Bazel
49+
run: bazel version
50+
- name: Change Python in MODULE.bazel
51+
run: |
52+
sed -i '' -e 's/\(DEFAULT_PYTHON =\) "3.[0-9]*"/\1 "${{ matrix.python.version }}"/g' MODULE.bazel
53+
cat MODULE.bazel
54+
- name: Build
55+
run: >
56+
bazel build
57+
-c ${{ matrix.bazel.compilation_mode }}
58+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
59+
--subcommands=pretty_print
60+
--enable_bzlmod
61+
//...
62+
- name: Test
63+
run: >
64+
bazel test
65+
-c ${{ matrix.bazel.compilation_mode }}
66+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
67+
--subcommands=pretty_print
68+
--enable_bzlmod
69+
//...
+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# ref: https://github.com/actions/runner-images
2+
name: amd64 MacOS CMake
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Building using the github runner environement directly.
7+
jobs:
8+
native:
9+
strategy:
10+
matrix:
11+
python: [
12+
{version: '3.9'},
13+
{version: '3.10'},
14+
{version: '3.11'},
15+
{version: '3.12'},
16+
#{version: '3.13'},
17+
]
18+
cmake: [
19+
{generator: "Xcode", config: Release, build_target: ALL_BUILD, test_target: RUN_TESTS, install_target: install},
20+
{generator: "Unix Makefiles", config: Release, build_target: all, test_target: test, install_target: install},
21+
]
22+
fail-fast: false
23+
name: MacOS•CMake(${{ matrix.cmake.generator }})•Python${{ matrix.python.version }}
24+
runs-on: macos-13 # last macos intel based runner
25+
steps:
26+
- uses: actions/checkout@v4
27+
- name: Setup Python
28+
uses: actions/setup-python@v5
29+
with:
30+
python-version: ${{ matrix.python.version }}
31+
- name: Update Path
32+
run: |
33+
echo "$HOME/Library/Python/${{ matrix.python.version }}/bin" >> $GITHUB_PATH
34+
echo "$HOME/.local/bin" >> $GITHUB_PATH
35+
- name: Check Python
36+
run: python --version
37+
- name: Install Python requirements
38+
run: python -m pip install --upgrade -r $(python -c 'import sys; print("./pybind11_protobuf/requirements/requirements_lock_%d_%d.txt" % (sys.version_info[:2]))')
39+
- name: Check CMake
40+
run: cmake --version
41+
- name: Configure
42+
run: >
43+
cmake -S. -Bbuild
44+
-G "${{ matrix.cmake.generator }}"
45+
-DCMAKE_BUILD_TYPE=${{ matrix.cmake.config }}
46+
-DCMAKE_INSTALL_PREFIX=install
47+
- name: Build
48+
run: >
49+
cmake --build build
50+
--config ${{ matrix.cmake.config }}
51+
--target ${{ matrix.cmake.build_target }}
52+
-v -j2
53+
- name: Test
54+
run: >
55+
CTEST_OUTPUT_ON_FAILURE=1
56+
cmake --build build
57+
--config ${{ matrix.cmake.config }}
58+
--target ${{ matrix.cmake.test_target }}
59+
-v
60+
- name: Install
61+
run: >
62+
cmake --build build
63+
--config ${{ matrix.cmake.config }}
64+
--target ${{ matrix.cmake.install_target }}
65+
-v
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# ref: https://github.com/actions/runner-images
2+
name: amd64 Windows Bazel
3+
4+
on: [push, pull_request, workflow_dispatch]
5+
6+
# Building using the github runner environement directly.
7+
jobs:
8+
native:
9+
strategy:
10+
matrix:
11+
runner: [windows-2022, windows-2019]
12+
bazel: [
13+
{compilation_mode: opt},
14+
{compilation_mode: dbg},
15+
]
16+
cpp: [
17+
{version: 14, flags: "/std:c++14"},
18+
{version: 17, flags: "/std:c++17"},
19+
{version: 20, flags: "/std:c++20"},
20+
]
21+
python: [
22+
{version: '3.11'},
23+
{version: '3.12'},
24+
]
25+
exclude:
26+
- runner: windows-2019
27+
cpp: {version: 20}
28+
# only test -c dbg with VS 2022 version 17 to save compute time
29+
- runner: windows-2019
30+
bazel: {compilation_mode: dbg}
31+
- cpp: {version: 14}
32+
bazel: {compilation_mode: dbg}
33+
- cpp: {version: 20}
34+
bazel: {compilation_mode: dbg}
35+
fail-fast: false # Don't cancel all jobs if one fails.
36+
name: ${{ matrix.runner }}•Bazel(${{ matrix.bazel.compilation_mode }})•C++${{ matrix.cpp.version }}•Python${{ matrix.python.version }}
37+
runs-on: ${{ matrix.runner }}
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Setup Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: ${{ matrix.python.version }}
44+
- name: Check Python
45+
run: |
46+
python --version
47+
python -m platform
48+
- name: Install Bazel
49+
run: choco install bazel
50+
- name: Check Bazel
51+
run: bazel version
52+
- name: Build
53+
run: >
54+
bazel build
55+
-c ${{ matrix.bazel.compilation_mode }}
56+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
57+
--subcommands=pretty_print
58+
--enable_bzlmod
59+
//...
60+
- name: Test
61+
run: >
62+
bazel test
63+
-c ${{ matrix.bazel.compilation_mode }}
64+
--cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }}
65+
--subcommands=pretty_print
66+
--enable_bzlmod
67+
//...

0 commit comments

Comments
 (0)