Skip to content

Commit 59fde9b

Browse files
authored
Add additional_compile_inputs + copts expansion to mojo_library (#38)
Enables the same thing in `mojo_library` as `mojo_test`, allowing args to be passed to `mojo package` from Bazel with filepaths expanded to the correct sandbox locations.
1 parent 67ddb44 commit 59fde9b

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

mojo/mojo_library.bzl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def _mojo_library_implementation(ctx):
1414
args.add("package")
1515
args.add("-strip-file-prefix=.")
1616
args.add("-o", mojo_package)
17-
args.add_all(ctx.attr.copts)
17+
args.add_all([
18+
ctx.expand_location(copt, targets = ctx.attr.additional_compiler_inputs)
19+
for copt in ctx.attr.copts
20+
])
1821

1922
import_paths, transitive_mojopkgs = collect_mojoinfo(ctx.attr.deps + mojo_toolchain.implicit_deps)
2023
root_directory = ctx.files.srcs[0].dirname
@@ -28,7 +31,7 @@ def _mojo_library_implementation(ctx):
2831
file_args.add(root_directory)
2932
ctx.actions.run(
3033
executable = mojo_toolchain.mojo,
31-
inputs = depset(ctx.files.srcs, transitive = [transitive_mojopkgs]),
34+
inputs = depset(ctx.files.srcs + ctx.files.additional_compiler_inputs, transitive = [transitive_mojopkgs]),
3235
tools = mojo_toolchain.all_tools,
3336
outputs = [mojo_package],
3437
arguments = [args, file_args],
@@ -63,6 +66,13 @@ def _mojo_library_implementation(ctx):
6366
mojo_library = rule(
6467
implementation = _mojo_library_implementation,
6568
attrs = {
69+
"additional_compiler_inputs": attr.label_list(
70+
allow_files = True,
71+
doc = """\
72+
Additional files to pass to the compiler command line. Files specified here can
73+
then be used in copts with the $(location) function.
74+
""",
75+
),
6676
"copts": attr.string_list(
6777
doc = """\
6878
Additional compiler options to pass to the Mojo compiler.

0 commit comments

Comments
 (0)