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
7 changes: 7 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//mojo:build_settings.bzl", "repeatable_string_flag")

repeatable_string_flag(
Expand All @@ -21,3 +22,9 @@ toolchain_type(
name = "gpu_toolchain_type",
visibility = ["//visibility:public"],
)

bool_flag(
name = "experimental_export_fixits",
build_setting_default = False,
visibility = ["//visibility:public"],
)
14 changes: 13 additions & 1 deletion mojo/mojo_library.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,21 @@ def _mojo_library_implementation(ctx):
if not file.dirname.startswith(root_directory):
args.add_all([file], map_each = _format_include)

output_group_kwargs = {}
package_outputs = [mojo_package]
if ctx.attr._export_fixits[BuildSettingInfo].value:
fixits_file = ctx.actions.declare_file(ctx.label.name + ".mojo_fixits.yaml")
package_outputs.append(fixits_file)
output_group_kwargs["mojo_fixits"] = depset([fixits_file])
args.add("--experimental-export-fixit", fixits_file)

file_args.add_all(transitive_mojopkgs, map_each = _format_include)
file_args.add(root_directory)
ctx.actions.run(
executable = mojo_toolchain.mojo,
inputs = depset(ctx.files.srcs + ctx.files.additional_compiler_inputs, transitive = [transitive_mojopkgs]),
tools = mojo_toolchain.all_tools,
outputs = [mojo_package],
outputs = package_outputs,
arguments = [args, file_args],
mnemonic = "MojoPackage",
progress_message = "%{label} building mojo package",
Expand Down Expand Up @@ -67,6 +75,7 @@ def _mojo_library_implementation(ctx):
import_paths = depset([mojo_package.dirname], transitive = [import_paths]),
mojopkgs = depset([mojo_package], transitive = [transitive_mojopkgs]),
),
OutputGroupInfo(**output_group_kwargs),
]

mojo_library = rule(
Expand Down Expand Up @@ -104,6 +113,9 @@ package' since it does not accept many flags.
"_mojo_package_copts": attr.label(
default = Label("//:mojo_package_copt"),
),
"_export_fixits": attr.label(
default = Label("@rules_mojo//:experimental_export_fixits"),
),
},
toolchains = ["//:toolchain_type"],
)
15 changes: 14 additions & 1 deletion mojo/private/mojo_binary_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ This is useful for shared sanitizer libraries which need to have rpaths added
by bazel.
""",
),
"_export_fixits": attr.label(
default = Label("@rules_mojo//:experimental_export_fixits"),
),
}

_TOOLCHAINS = use_cpp_toolchain() + [
Expand Down Expand Up @@ -128,11 +131,19 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
if ctx.attr.enable_assertions:
args.add("-D", "ASSERT=all")

output_group_kwargs = {}
compile_outputs = [object_file]
if ctx.attr._export_fixits[BuildSettingInfo].value:
fixits_file = ctx.actions.declare_file(ctx.label.name + ".mojo_fixits.yaml")
compile_outputs.append(fixits_file)
output_group_kwargs["mojo_fixits"] = depset([fixits_file])
args.add("--experimental-export-fixit", fixits_file)

ctx.actions.run(
executable = mojo_toolchain.mojo,
tools = mojo_toolchain.all_tools,
inputs = depset(ctx.files.srcs + ctx.files.additional_compiler_inputs, transitive = [transitive_mojopkgs]),
outputs = [object_file],
outputs = compile_outputs,
arguments = [args],
mnemonic = "MojoCompile",
progress_message = "%{label} compiling mojo object",
Expand Down Expand Up @@ -267,6 +278,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
]),
),
),
OutputGroupInfo(**output_group_kwargs),
]
else:
return [
Expand All @@ -277,6 +289,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
RunEnvironmentInfo(
environment = runtime_env,
),
OutputGroupInfo(**output_group_kwargs),
]

mojo_binary = rule(
Expand Down
19 changes: 19 additions & 0 deletions tests/fixits/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("//mojo:mojo_binary.bzl", "mojo_binary")
load("//mojo:mojo_library.bzl", "mojo_library")

# TODO: Find a fixit that doesn't fail the build, verify the output file

mojo_binary(
name = "fixits",
srcs = ["fixits.mojo"],
tags = ["manual"],
)

mojo_library(
name = "package",
srcs = [
"package/__init__.mojo",
"package/package.mojo",
],
tags = ["manual"],
)
5 changes: 5 additions & 0 deletions tests/fixits/fixits.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fn old_origin_of[T: AnyType](b: T):
_ = __origin_of(b)

fn main():
pass
Empty file.
2 changes: 2 additions & 0 deletions tests/fixits/package/package.mojo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn old_origin_of[T: AnyType](b: T):
_ = __origin_of(b)