Skip to content

Commit

Permalink
Allow setting the dtrace binary (#2607)
Browse files Browse the repository at this point in the history
Allow setting the dtrace binary in `dtrace_compile`.
  • Loading branch information
stevebarrau authored Dec 2, 2024
1 parent fee0f3b commit b5dc9d1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
12 changes: 11 additions & 1 deletion apple/dtrace.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ def _dtrace_compile_impl(ctx):
output_hdrs = []
include_dir = None

dtrace = "/usr/sbin/dtrace"
if ctx.executable.dtrace:
dtrace = ctx.executable.dtrace

for src in ctx.files.srcs:
owner_relative_path = bundle_paths.owner_relative_path(src)
label_scoped_owner_path = ctx.label.name + "/" + owner_relative_path.lstrip("/")
Expand All @@ -53,7 +57,7 @@ def _dtrace_compile_impl(ctx):
inputs = [src],
outputs = [hdr],
mnemonic = "dtraceCompile",
executable = "/usr/sbin/dtrace",
executable = dtrace,
arguments = ["-h", "-s", src.path, "-o", hdr.path],
progress_message = ("Compiling dtrace probes %s" % (src.basename)),
)
Expand All @@ -77,6 +81,12 @@ def _dtrace_compile_impl(ctx):
dtrace_compile = rule(
implementation = _dtrace_compile_impl,
attrs = dicts.add(apple_support.action_required_attrs(), {
"dtrace": attr.label(
doc = "dtrace binary to use.",
mandatory = False,
executable = True,
cfg = "exec",
),
"srcs": attr.label_list(
allow_files = [".d"],
allow_empty = False,
Expand Down
3 changes: 2 additions & 1 deletion doc/rules-dtrace.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## dtrace_compile

<pre>
dtrace_compile(<a href="#dtrace_compile-name">name</a>, <a href="#dtrace_compile-srcs">srcs</a>)
dtrace_compile(<a href="#dtrace_compile-name">name</a>, <a href="#dtrace_compile-srcs">srcs</a>, <a href="#dtrace_compile-dtrace">dtrace</a>)
</pre>

Compiles
Expand All @@ -32,5 +32,6 @@ and a target named `dtrace_gen` the header path would be
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="dtrace_compile-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="dtrace_compile-srcs"></a>srcs | dtrace(.d) source files to be compiled. | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | `[]` |
| <a id="dtrace_compile-dtrace"></a>dtrace | dtrace binary to use. | <a href="https://bazel.build/concepts/labels">Label</a> | optional | `None` |


0 comments on commit b5dc9d1

Please sign in to comment.