examples: add embed/
diff --git a/examples/embed/.bazelrc b/examples/embed/.bazelrc new file mode 100644 index 0000000..7cf5a21 --- /dev/null +++ b/examples/embed/.bazelrc
@@ -0,0 +1,29 @@ +# Enable logging rc options. +common --announce_rc + +############################################################################### +# 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 <pybind11/embed.h> +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); +}