Skip to content

Commit a8544e2

Browse files
authored
Add copts to mojo_library (#2)
These are a bit special because 'mojo package' doesn't accept target related options like 'mojo build' does. Because of this the options from the command line flag or toolchain aren't passed here since it would most likely just fail as an unrecognized option.
1 parent 5388821 commit a8544e2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mojo/mojo_library.bzl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def _mojo_library_implementation(ctx):
1111
args.add("package")
1212
args.add("-strip-file-prefix=.")
1313
args.add("-o", mojo_package.path)
14+
args.add_all(ctx.attr.copts)
1415

1516
import_paths, transitive_mojopkgs = collect_mojoinfo(ctx.attr.deps + mojo_toolchain.implicit_deps)
1617
root_directory = ctx.files.srcs[0].dirname
@@ -56,6 +57,14 @@ def _mojo_library_implementation(ctx):
5657
mojo_library = rule(
5758
implementation = _mojo_library_implementation,
5859
attrs = {
60+
"copts": attr.string_list(
61+
doc = """\
62+
Additional compiler options to pass to the Mojo compiler.
63+
64+
NOTE: copts from --mojocopt and mojo_toolchain.copts are not passed to 'mojo
65+
package' since it does not accept many flags.
66+
""",
67+
),
5968
"srcs": attr.label_list(
6069
allow_empty = False,
6170
allow_files = MOJO_EXTENSIONS,

tests/package/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@bazel_skylib//rules:build_test.bzl", "build_test")
12
load("//mojo:mojo_library.bzl", "mojo_library")
23

34
mojo_library(
@@ -6,5 +7,15 @@ mojo_library(
67
"__init__.mojo",
78
"package.mojo",
89
],
10+
copts = [
11+
"-Ifoo",
12+
],
913
visibility = ["//tests:__subpackages__"],
1014
)
15+
16+
build_test(
17+
name = "package_build_test",
18+
targets = [
19+
":package",
20+
],
21+
)

0 commit comments

Comments
 (0)