Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ repeatable_string_flag(
visibility = ["//visibility:public"],
)

repeatable_string_flag(
name = "mojo_package_copt",
build_setting_default = [],
visibility = ["//visibility:public"],
)

toolchain_type(
name = "toolchain_type",
visibility = ["//visibility:public"],
Expand Down
14 changes: 14 additions & 0 deletions mojo/mojo_library.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Compile Mojo files into a mojopkg that can be consumed by other Mojo targets."""

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("//mojo:providers.bzl", "MojoInfo")
load("//mojo/private:utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo")

Expand All @@ -14,6 +15,10 @@ def _mojo_library_implementation(ctx):
args.add("package")
args.add("-strip-file-prefix=.")
args.add("-o", mojo_package)

args.add_all(mojo_toolchain.package_copts)
if "-exec-" not in ctx.bin_dir.path:
args.add_all(ctx.attr._mojo_package_copts[BuildSettingInfo].value)
args.add_all([
ctx.expand_location(copt, targets = ctx.attr.additional_compiler_inputs)
for copt in ctx.attr.copts
Expand Down Expand Up @@ -78,6 +83,12 @@ then be used in copts with the $(location) function.
doc = """\
Additional compiler options to pass to the Mojo compiler.

Order of options:
1. copts from mojo_toolchain.package_copts
2. copts from //:mojo_package_copt (if not building in exec config)
3. copts from this attribute, with $(location) expanded for files in
additional_compiler_inputs.

NOTE: copts from --mojocopt and mojo_toolchain.copts are not passed to 'mojo
package' since it does not accept many flags.
""",
Expand All @@ -90,6 +101,9 @@ package' since it does not accept many flags.
providers = [MojoInfo],
),
"data": attr.label_list(),
"_mojo_package_copts": attr.label(
default = Label("//:mojo_package_copt"),
),
},
toolchains = ["//:toolchain_type"],
)
1 change: 1 addition & 0 deletions mojo/providers.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ MojoToolchainInfo = provider(
fields = {
"all_tools": "All the files that must be available in actions in order for the toolchain to work.",
"copts": "Additional compiler options to pass to the Mojo compiler.",
"package_copts": "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.",
"lld": "The lld compiler executable to link with",
"mojo": "The mojo compiler executable to build with",
"implicit_deps": "Implicit dependencies that every target should depend on, providing either CcInfo, or MojoInfo",
Expand Down
5 changes: 5 additions & 0 deletions mojo/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _mojo_toolchain_impl(ctx):
mojo_toolchain_info = MojoToolchainInfo(
all_tools = tool_files,
copts = copts,
package_copts = ctx.attr.package_copts,
lld = ctx.executable.lld,
mojo = ctx.executable.mojo,
implicit_deps = ctx.attr.implicit_deps,
Expand All @@ -41,6 +42,10 @@ mojo_toolchain = rule(
mandatory = False,
doc = "Additional compiler options to pass to the Mojo compiler.",
),
"package_copts": attr.string_list(
mandatory = False,
doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.",
),
"extra_tools": attr.label_list(
providers = [DefaultInfo],
allow_files = True,
Expand Down