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