diff --git a/.github/workflows/amd64_linux_bazel.yml b/.github/workflows/amd64_linux_bazel.yml index 133802b..3dddbcb 100644 --- a/.github/workflows/amd64_linux_bazel.yml +++ b/.github/workflows/amd64_linux_bazel.yml @@ -3,31 +3,27 @@ name: amd64 Linux Bazel on: [push, pull_request, workflow_dispatch] +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + # Building using the github runner environement directly. jobs: native: strategy: matrix: - bazel: [ - {compilation_mode: opt}, - {compilation_mode: dbg}, - ] + examples: [{name: basic}, {name: embed}] cpp: [ - {version: 14, flags: "-std=c++14"}, + #{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 }} + name: Linux•Bzl•C++${{matrix.cpp.version}}•Py${{matrix.python.version}}•${{matrix.examples.name}} runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -36,7 +32,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v6 with: - python-version: ${{ matrix.python.version }} + python-version: ${{matrix.python.version}} - name: Check Python run: | python --version @@ -44,27 +40,27 @@ jobs: - uses: bazel-contrib/setup-bazel@0.15.0 with: bazelisk-cache: true - disk-cache: ${{ github.workflow }} + disk-cache: ${{github.workflow}} repository-cache: true - name: Check Bazel run: bazel version - name: Build run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel build - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... - name: Test run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel test - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... amd64_linux_bazel: diff --git a/.github/workflows/amd64_macos_bazel.yml b/.github/workflows/amd64_macos_bazel.yml index b6d2aad..46f2120 100644 --- a/.github/workflows/amd64_macos_bazel.yml +++ b/.github/workflows/amd64_macos_bazel.yml @@ -3,31 +3,30 @@ name: amd64 MacOS Bazel on: [push, pull_request, workflow_dispatch] +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + # Building using the github runner environement directly. jobs: native: strategy: matrix: - bazel: [ - {compilation_mode: opt}, - {compilation_mode: dbg}, + examples: [ + {name: basic}, + # {name: embed}, # see: https://github.com/pybind/pybind11_bazel/issues/76 ] cpp: [ #{version: 14, flags: "-std=c++14"}, {version: 17, flags: "-std=c++17"}, - #{version: 20, flags: "-std=c++20"}, + {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 }} + name: MacOS•Bzl•C++${{matrix.cpp.version}}•Py${{matrix.python.version}}•${{matrix.examples.name}} runs-on: macos-13 # last macos intel based runner steps: - uses: actions/checkout@v5 @@ -39,7 +38,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v6 with: - python-version: ${{ matrix.python.version }} + python-version: ${{matrix.python.version}} - name: Check Python run: | python --version @@ -48,21 +47,21 @@ jobs: run: bazel version - name: Build run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel build - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... - name: Test run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel test - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... amd64_macos_bazel: diff --git a/.github/workflows/amd64_windows_bazel.yml b/.github/workflows/amd64_windows_bazel.yml index 0ae86c1..74adad3 100644 --- a/.github/workflows/amd64_windows_bazel.yml +++ b/.github/workflows/amd64_windows_bazel.yml @@ -3,46 +3,34 @@ name: amd64 Windows Bazel on: [push, pull_request, workflow_dispatch] +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + # Building using the github runner environement directly. jobs: native: strategy: matrix: - runner: [ - windows-2022, - #windows-2019, - ] - bazel: [ - {compilation_mode: opt}, - {compilation_mode: dbg}, - ] + examples: [{name: basic}, {name: embed}] cpp: [ - {version: 14, flags: "/std:c++14"}, + #{version: 14, flags: "/std:c++14"}, {version: 17, flags: "/std:c++17"}, - #{version: 20, flags: "/std:c++20"}, + {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 }} + fail-fast: false + name: Windows•Bzl•C++${{matrix.cpp.version}}•Py${{matrix.python.version}}•${{matrix.examples.name}} + runs-on: windows-2022 steps: - uses: actions/checkout@v5 - name: Setup Python uses: actions/setup-python@v6 with: - python-version: ${{ matrix.python.version }} + python-version: ${{matrix.python.version}} - name: Check Python run: | python --version @@ -53,21 +41,21 @@ jobs: run: bazel version - name: Build run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel build - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... - name: Test run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel test - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... amd64_windows_bazel: diff --git a/.github/workflows/arm64_macos_bazel.yml b/.github/workflows/arm64_macos_bazel.yml index 59494fc..0574b39 100644 --- a/.github/workflows/arm64_macos_bazel.yml +++ b/.github/workflows/arm64_macos_bazel.yml @@ -3,31 +3,30 @@ name: arm64 MacOS Bazel on: [push, pull_request, workflow_dispatch] +concurrency: + group: ${{github.workflow}}-${{github.ref}} + cancel-in-progress: true + # Building using the github runner environement directly. jobs: native: strategy: matrix: - bazel: [ - {compilation_mode: opt}, - {compilation_mode: dbg}, + examples: [ + {name: basic}, + # {name: embed}, # see: https://github.com/pybind/pybind11_bazel/issues/76 ] cpp: [ #{version: 14, flags: "-std=c++14"}, {version: 17, flags: "-std=c++17"}, - #{version: 20, flags: "-std=c++20"}, + {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 }} + name: MacOS•Bzl•C++${{matrix.cpp.version}}•Py${{matrix.python.version}}•${{matrix.examples.name}} runs-on: macos-latest steps: - uses: actions/checkout@v5 @@ -39,7 +38,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v6 with: - python-version: ${{ matrix.python.version }} + python-version: ${{matrix.python.version}} - name: Check Python run: | python --version @@ -48,21 +47,21 @@ jobs: run: bazel version - name: Build run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel build - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... - name: Test run: > - cd examples/basic && + cd examples/${{matrix.examples.name}} && bazel test - -c ${{ matrix.bazel.compilation_mode }} - --cxxopt=${{ matrix.cpp.flags }} --host_cxxopt=${{ matrix.cpp.flags }} + --config=ci + --@rules_python//python/config_settings:python_version=${{matrix.python.version}} + --cxxopt=${{matrix.cpp.flags}} --host_cxxopt=${{ matrix.cpp.flags }} --subcommands=pretty_print - --enable_bzlmod //... arm64_macos_bazel: diff --git a/examples/basic/.bazelrc b/examples/basic/.bazelrc new file mode 100644 index 0000000..dd77c7f --- /dev/null +++ b/examples/basic/.bazelrc @@ -0,0 +1,32 @@ +# Enable logging rc options. +common --announce_rc + +# Enable Bzlmod for every Bazel command +common --enable_bzlmod + +############################################################################### +# Options for continuous integration. +############################################################################### + +# All build options also apply to test as described by the "Option precedence" +# section in https://bazel.build/run/bazelrc#bazelrc-syntax-semantics. + +# Note for anybody considering using --compilation_mode=opt in CI, it builds +# most files twice, one PIC version for shared libraries in tests, and one +# non-PIC version for binaries. +build:ci --copt=-O1 + +# Show as many errors as possible. +build:ci --keep_going + +# Show test errors. +test:ci --test_output=all + +# Only show failing tests to reduce output +#test:ci --test_summary=terse + +############################################################################### +# Put user-specific options in user.bazelrc +# See https://bazel.build/configure/best-practices#bazelrc-file +################################################################################ +try-import %workspace%/user.bazelrc diff --git a/examples/basic/BUILD.bazel b/examples/basic/BUILD.bazel index 2846923..1904c69 100644 --- a/examples/basic/BUILD.bazel +++ b/examples/basic/BUILD.bazel @@ -32,6 +32,7 @@ py_wheel( py_test( name = "basic_test", + size="small", srcs = ["basic_test.py"], deps = [":basic_lib"], ) diff --git a/examples/embed/.bazelrc b/examples/embed/.bazelrc new file mode 100644 index 0000000..dd77c7f --- /dev/null +++ b/examples/embed/.bazelrc @@ -0,0 +1,32 @@ +# Enable logging rc options. +common --announce_rc + +# Enable Bzlmod for every Bazel command +common --enable_bzlmod + +############################################################################### +# Options for continuous integration. +############################################################################### + +# All build options also apply to test as described by the "Option precedence" +# section in https://bazel.build/run/bazelrc#bazelrc-syntax-semantics. + +# Note for anybody considering using --compilation_mode=opt in CI, it builds +# most files twice, one PIC version for shared libraries in tests, and one +# non-PIC version for binaries. +build:ci --copt=-O1 + +# Show as many errors as possible. +build:ci --keep_going + +# Show test errors. +test:ci --test_output=all + +# Only show failing tests to reduce output +#test:ci --test_summary=terse + +############################################################################### +# Put user-specific options in user.bazelrc +# See https://bazel.build/configure/best-practices#bazelrc-file +################################################################################ +try-import %workspace%/user.bazelrc diff --git a/examples/embed/BUILD.bazel b/examples/embed/BUILD.bazel new file mode 100644 index 0000000..9597c5c --- /dev/null +++ b/examples/embed/BUILD.bazel @@ -0,0 +1,12 @@ +load("@pybind11_bazel//:build_defs.bzl", "pybind_library", "pybind_library_test") + +pybind_library( + name = "embed", + srcs = ["embed.cc"], +) + +pybind_library_test( + name = "embed_test", + size= "small", + deps = [":embed"], +) diff --git a/examples/embed/MODULE.bazel b/examples/embed/MODULE.bazel new file mode 100644 index 0000000..3bed1a2 --- /dev/null +++ b/examples/embed/MODULE.bazel @@ -0,0 +1,7 @@ +bazel_dep(name = "platforms", version = "1.0.0") +bazel_dep(name = "rules_python", version = "1.5.1") +bazel_dep(name = "pybind11_bazel") +local_path_override( + module_name = "pybind11_bazel", + path = "../..", +) diff --git a/examples/embed/embed.cc b/examples/embed/embed.cc new file mode 100644 index 0000000..8138e8e --- /dev/null +++ b/examples/embed/embed.cc @@ -0,0 +1,11 @@ +#include +namespace py = pybind11; +using namespace py::literals; + +int main() { + py::scoped_interpreter guard{}; + + auto kwargs = py::dict("name"_a="World", "number"_a=42); + auto message = "Hello, {name}! The answer is {number}"_s.format(**kwargs); + py::print(message); +}