From 09704c46790f1589596852cc9aeb452e09562bfc Mon Sep 17 00:00:00 2001 From: Fraser Cormack Date: Wed, 13 May 2026 17:04:01 +0100 Subject: [PATCH] Rename 'mojo package' to 'mojo precompile' Now that the mojo toolchain is making the switch to 'precompile' over 'package', update our bazel rules to adjust. --- BUILD.bazel | 2 +- mojo/mojo_library.bzl | 36 ++++++++++++++++++------------------ mojo/providers.bzl | 4 ++-- mojo/toolchain.bzl | 16 ++++++++-------- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 02f5765..e822818 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -8,7 +8,7 @@ repeatable_string_flag( ) repeatable_string_flag( - name = "mojo_package_copt", + name = "mojo_precompile_copt", build_setting_default = [], visibility = ["//visibility:public"], ) diff --git a/mojo/mojo_library.bzl b/mojo/mojo_library.bzl index 883ef74..7393bc7 100644 --- a/mojo/mojo_library.bzl +++ b/mojo/mojo_library.bzl @@ -12,15 +12,15 @@ def _mojo_library_implementation(ctx): mojo_toolchain = ctx.toolchains["//:toolchain_type"].mojo_toolchain_info build_env = getattr(ctx.toolchains["//:toolchain_type"], "build_env", {}) - mojo_package = ctx.actions.declare_file(ctx.label.name + ".mojopkg") + mojo_precmp_file = ctx.actions.declare_file(ctx.label.name + ".mojoc") args = ctx.actions.args() - args.add("package") + args.add("precompile") args.add("-strip-file-prefix=.") - args.add("-o", mojo_package) + args.add("-o", mojo_precmp_file) - args.add_all(mojo_toolchain.package_copts) + args.add_all(mojo_toolchain.precompile_copts) if not is_exec_config(ctx): - args.add_all(ctx.attr._mojo_package_copts[BuildSettingInfo].value) + args.add_all(ctx.attr._mojo_precompile_copts[BuildSettingInfo].value) args.add_all([ ctx.expand_location(copt, targets = ctx.attr.additional_compiler_inputs) for copt in ctx.attr.copts @@ -35,10 +35,10 @@ def _mojo_library_implementation(ctx): args.add_all([file], map_each = _format_include) output_group_kwargs = {} - package_outputs = [mojo_package] + precompile_outputs = [mojo_precmp_file] if ctx.attr._export_fixits[BuildSettingInfo].value: fixits_file = ctx.actions.declare_file(ctx.label.name + ".mojo_fixits.yaml") - package_outputs.append(fixits_file) + precompile_outputs.append(fixits_file) output_group_kwargs["mojo_fixits"] = depset([fixits_file]) args.add("--experimental-export-fixit", fixits_file) @@ -48,10 +48,10 @@ def _mojo_library_implementation(ctx): executable = mojo_toolchain.mojo, inputs = depset(ctx.files.srcs + ctx.files.additional_compiler_inputs, transitive = [transitive_mojodeps]), tools = mojo_toolchain.all_tools, - outputs = package_outputs, + outputs = precompile_outputs, arguments = [args, file_args], - mnemonic = "MojoPackage", - progress_message = "%{label} building mojo package", + mnemonic = "MojoPrecompile", + progress_message = "%{label} precompiling mojo file", env = { "MODULAR_CRASH_REPORTING_ENABLED": "false", "PATH": "/dev/null", # Avoid using the host's PATH @@ -70,12 +70,12 @@ def _mojo_library_implementation(ctx): return [ DefaultInfo( - files = depset([mojo_package]), + files = depset([mojo_precmp_file]), runfiles = ctx.runfiles(ctx.files.data).merge_all(transitive_runfiles), ), MojoInfo( - import_paths = depset([mojo_package.dirname], transitive = [import_paths]), - mojodeps = depset([mojo_package], transitive = [transitive_mojodeps]), + import_paths = depset([mojo_precmp_file.dirname], transitive = [import_paths]), + mojodeps = depset([mojo_precmp_file], transitive = [transitive_mojodeps]), ), OutputGroupInfo(**output_group_kwargs), ] @@ -95,13 +95,13 @@ then be used in copts with the $(location) function. 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) +1. copts from mojo_toolchain.precompile_copts +2. copts from //:mojo_precompile_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. +precompile' since it does not accept many flags. """, ), "srcs": attr.label_list( @@ -112,8 +112,8 @@ package' since it does not accept many flags. providers = [MojoInfo], ), "data": attr.label_list(), - "_mojo_package_copts": attr.label( - default = Label("//:mojo_package_copt"), + "_mojo_precompile_copts": attr.label( + default = Label("//:mojo_precompile_copt"), ), "_export_fixits": attr.label( default = Label("@rules_mojo//:experimental_export_fixits"), diff --git a/mojo/providers.bzl b/mojo/providers.bzl index 1d1a7f0..f7d8927 100644 --- a/mojo/providers.bzl +++ b/mojo/providers.bzl @@ -13,7 +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'.", + "precompile_copts": "Additional compiler options to pass to the Mojo compiler when running 'mojo precompile'.", "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", @@ -24,7 +24,7 @@ MojoCoptsToolchainInfo = provider( doc = "Provider holding additional compiler options for the Mojo compiler.", fields = { "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'.", + "precompile_copts": "Additional compiler options to pass to the Mojo compiler when running 'mojo precompile'.", }, ) diff --git a/mojo/toolchain.bzl b/mojo/toolchain.bzl index 46f0f66..3b85405 100644 --- a/mojo/toolchain.bzl +++ b/mojo/toolchain.bzl @@ -10,7 +10,7 @@ def _mojo_toolchain_impl(ctx): tool_files.append(dep[DefaultInfo].files) copts = list(ctx.attr.copts) - package_copts = list(ctx.attr.package_copts) + precompile_copts = list(ctx.attr.precompile_copts) gpu_toolchain = ctx.toolchains["//:gpu_toolchain_type"] if gpu_toolchain: copts.append("--target-accelerator=" + gpu_toolchain.mojo_gpu_toolchain_info.target_accelerator) @@ -24,14 +24,14 @@ def _mojo_toolchain_impl(ctx): copts_toolchain = ctx.toolchains["//:copts_toolchain_type"] if copts_toolchain: copts.extend(copts_toolchain.copts_toolchain_info.copts) - package_copts = copts_toolchain.copts_toolchain_info.package_copts + precompile_copts = copts_toolchain.copts_toolchain_info.precompile_copts return [ platform_common.ToolchainInfo( mojo_toolchain_info = MojoToolchainInfo( all_tools = tool_files, copts = copts, - package_copts = package_copts, + precompile_copts = precompile_copts, lld = ctx.executable.lld, mojo = ctx.executable.mojo, implicit_deps = ctx.attr.implicit_deps, @@ -46,9 +46,9 @@ mojo_toolchain = rule( mandatory = False, doc = "Additional compiler options to pass to the Mojo compiler.", ), - "package_copts": attr.string_list( + "precompile_copts": attr.string_list( mandatory = False, - doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.", + doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo precompile'.", ), "extra_tools": attr.label_list( providers = [DefaultInfo], @@ -96,7 +96,7 @@ def _mojo_copts_toolchain_impl(ctx): platform_common.ToolchainInfo( copts_toolchain_info = MojoCoptsToolchainInfo( copts = ctx.attr.copts, - package_copts = ctx.attr.package_copts, + precompile_copts = ctx.attr.precompile_copts, ), ), ] @@ -108,9 +108,9 @@ mojo_copts_toolchain = rule( mandatory = True, doc = "Additional compiler options to pass to the Mojo compiler.", ), - "package_copts": attr.string_list( + "precompile_copts": attr.string_list( mandatory = True, - doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo package'.", + doc = "Additional compiler options to pass to the Mojo compiler when running 'mojo precompile'.", ), }, doc = """\