Skip to content

Commit 5e1295a

Browse files
committed
Fix exec config check with bazel 9.x
bazelbuild/bazel#29421
1 parent ca33e95 commit 5e1295a

4 files changed

Lines changed: 26 additions & 4 deletions

File tree

MODULE.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ module(
44
bazel_compatibility = [">=8.0.0"],
55
)
66

7+
bazel_dep(name = "bazel_features", version = "1.46.0")
78
bazel_dep(name = "bazel_skylib", version = "1.7.1")
89
bazel_dep(name = "platforms", version = "0.0.11")
910
bazel_dep(name = "rules_cc", version = "0.2.16")

mojo/mojo_library.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
44
load("//mojo:providers.bzl", "MojoInfo")
5-
load("//mojo/private:utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo")
5+
load("//mojo/private:utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo", "is_exec_config")
66

77
def _format_include(arg):
88
return ["-I", arg.dirname]
@@ -18,7 +18,7 @@ def _mojo_library_implementation(ctx):
1818
args.add("-o", mojo_package)
1919

2020
args.add_all(mojo_toolchain.package_copts)
21-
if "-exec-" not in ctx.bin_dir.path:
21+
if not is_exec_config(ctx):
2222
args.add_all(ctx.attr._mojo_package_copts[BuildSettingInfo].value)
2323
args.add_all([
2424
ctx.expand_location(copt, targets = ctx.attr.additional_compiler_inputs)

mojo/private/mojo_binary_test.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
99
load("@rules_python//python:py_info.bzl", "PyInfo")
1010
load("//mojo:providers.bzl", "MojoInfo")
1111
load(":transitions.bzl", "python_version_transition")
12-
load(":utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo")
12+
load(":utils.bzl", "MOJO_EXTENSIONS", "collect_mojoinfo", "is_exec_config")
1313

1414
_PYTHON_TOOLCHAIN_TYPE = "@rules_python//python:toolchain_type"
1515
_ATTRS = {
@@ -125,7 +125,7 @@ def _mojo_binary_test_implementation(ctx, *, shared_library = False):
125125
args.add_all(mojo_toolchain.copts)
126126

127127
# Ignore default mojo flags for exec built binaries
128-
if "-exec-" not in ctx.bin_dir.path:
128+
if not is_exec_config(ctx):
129129
args.add_all(ctx.attr._mojo_copts[BuildSettingInfo].value)
130130
args.add_all([
131131
ctx.expand_location(copt, targets = ctx.attr.additional_compiler_inputs)

mojo/private/utils.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Helpers internal to rules_mojo."""
22

3+
load("@bazel_features//:features.bzl", "bazel_features")
34
load("//mojo:providers.bzl", "MojoInfo")
45

56
MOJO_EXTENSIONS = ("mojo", "🔥")
@@ -22,3 +23,23 @@ def collect_mojoinfo(deps):
2223
import_paths.append(info.import_paths)
2324

2425
return depset(transitive = import_paths), depset(transitive = mojopkgs)
26+
27+
def is_exec_config(ctx):
28+
"""Determines whether the current configuration is an exec configuration.
29+
30+
Args:
31+
ctx: The rule context.
32+
33+
Returns:
34+
Whether the current configuration is an exec configuration.
35+
"""
36+
37+
# TODO: Remove once we drop 9.x
38+
if bazel_features.rules.is_tool_configuration_public and ctx.configuration.is_tool_configuration():
39+
return True
40+
elif ctx.bin_dir.path.endswith("-exec/bin"): # NOTE: 9.0.0 or <8.7.0 with --experimental_platform_in_output_dir
41+
return True
42+
elif "-exec-" in ctx.bin_dir.path:
43+
return True
44+
45+
return False

0 commit comments

Comments
 (0)