1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
# buildifier: disable=module-docstring
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
def rust_cxx_bridge(name, src, deps = [], **kwargs):
"""A macro defining a cxx bridge library
Args:
name (string): The name of the new target
src (string): The rust source file to generate a bridge for
deps (list, optional): A list of dependencies for the underlying cc_library. Defaults to [].
**kwargs: Common arguments to pass through to underlying rules.
"""
native.alias(
name = "%s/header" % name,
actual = src + ".h",
**kwargs
)
native.alias(
name = "%s/source" % name,
actual = src + ".cc",
**kwargs
)
run_binary(
name = "%s/generated" % name,
srcs = [src],
outs = [
src + ".h",
src + ".cc",
],
args = [
"$(location %s)" % src,
"-o",
"$(location %s.h)" % src,
"-o",
"$(location %s.cc)" % src,
],
tool = "@cxx.rs//:codegen",
**kwargs
)
cc_library(
name = name,
srcs = [src + ".cc"],
deps = deps + [":%s/include" % name],
**kwargs
)
cc_library(
name = "%s/include" % name,
hdrs = [src + ".h"],
**kwargs
)
|