Anki/pylib/anki/_backend/BUILD.bazel
Damien Elmes 5df684fa6b rework backend codegen to support multiple services; split out sched
Rust requires all methods of impl Trait to be in a single file, which
means we had a giant backend/mod.rs covering all exposed methods. By
using separate service definitions for the separate areas, and updating
the code generation, we can split it into more manageable chunks -
this commit starts with the scheduling code.

In the long run, we'll probably want to split up the protobuf file into
multiple files as well.

Also dropped want_release_gil() from rsbridge, and the associated method
enum. While it allows us to skip the thread save/restore and mutex unlock/
lock, it looks to only be buying about 2.5% extra performance in the
best case (tested with timeit+format_timespan), and the majority of
the backend methods deal with I/O, and thus were already releasing the
GIL.
2021-03-11 14:51:29 +10:00

90 lines
1.7 KiB
Text

load("@rules_python//python:defs.bzl", "py_binary")
load("@py_deps//:requirements.bzl", "requirement")
load("//pylib:protobuf.bzl", "py_proto_library_typed")
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//lib:selects.bzl", "selects")
py_proto_library_typed(
name = "backend_pb2",
src = "//rslib:backend.proto",
visibility = [
"//visibility:public",
],
)
py_proto_library_typed(
name = "fluent_pb2",
src = "//rslib:fluent.proto",
visibility = [
"//visibility:public",
],
)
py_binary(
name = "genbackend",
srcs = [
"backend_pb2",
"genbackend.py",
],
deps = [
requirement("black"),
requirement("stringcase"),
requirement("protobuf"),
],
)
genrule(
name = "rsbackend_gen",
outs = ["generated.py"],
cmd = "$(location genbackend) $@",
tools = ["genbackend"],
)
copy_file(
name = "rsbridge_unix",
src = "//pylib/rsbridge",
out = "rsbridge.so",
)
copy_file(
name = "rsbridge_win",
src = "//pylib/rsbridge",
out = "rsbridge.pyd",
)
alias(
name = "rsbridge",
actual = selects.with_or({
(
"@io_bazel_rules_rust//rust/platform:x86_64-pc-windows-msvc",
): ":rsbridge_win",
"//conditions:default": ":rsbridge_unix",
}),
)
_py_srcs = [
"genbackend.py",
"__init__.py",
]
# for format check
filegroup(
name = "py_source_files",
srcs = _py_srcs,
visibility = [
"//pylib:__subpackages__",
],
)
filegroup(
name = "_backend",
srcs = [
"__init__.py",
"rsbridge.pyi",
":backend_pb2",
":fluent_pb2",
":rsbackend_gen",
":rsbridge",
],
visibility = ["//pylib:__subpackages__"],
)