Skip to content

Commit d3607e9

Browse files
committed
examples: add embed/
1 parent c15f7a5 commit d3607e9

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

examples/embed/.bazelrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Enable logging rc options.
2+
common --announce_rc
3+
4+
###############################################################################
5+
# Options for continuous integration.
6+
###############################################################################
7+
8+
# All build options also apply to test as described by the "Option precedence"
9+
# section in https://bazel.build/run/bazelrc#bazelrc-syntax-semantics.
10+
11+
# Note for anybody considering using --compilation_mode=opt in CI, it builds
12+
# most files twice, one PIC version for shared libraries in tests, and one
13+
# non-PIC version for binaries.
14+
build:ci --copt=-O1
15+
16+
# Show as many errors as possible.
17+
build:ci --keep_going
18+
19+
# Show test errors.
20+
test:ci --test_output=all
21+
22+
# Only show failing tests to reduce output
23+
#test:ci --test_summary=terse
24+
25+
###############################################################################
26+
# Put user-specific options in user.bazelrc
27+
# See https://bazel.build/configure/best-practices#bazelrc-file
28+
################################################################################
29+
try-import %workspace%/user.bazelrc

examples/embed/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@pybind11_bazel//:build_defs.bzl", "pybind_library", "pybind_library_test")
2+
3+
pybind_library(
4+
name = "embed",
5+
srcs = ["embed.cc"],
6+
)
7+
8+
pybind_library_test(
9+
name = "embed_test",
10+
size= "small",
11+
deps = [":embed"],
12+
)

examples/embed/MODULE.bazel

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
bazel_dep(name = "platforms", version = "1.0.0")
2+
bazel_dep(name = "rules_python", version = "1.5.1")
3+
bazel_dep(name = "pybind11_bazel")
4+
local_path_override(
5+
module_name = "pybind11_bazel",
6+
path = "../..",
7+
)

examples/embed/embed.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include <pybind11/embed.h>
2+
namespace py = pybind11;
3+
using namespace py::literals;
4+
5+
int main() {
6+
py::scoped_interpreter guard{};
7+
8+
auto kwargs = py::dict("name"_a="World", "number"_a=42);
9+
auto message = "Hello, {name}! The answer is {number}"_s.format(**kwargs);
10+
py::print(message);
11+
}

0 commit comments

Comments
 (0)