[llvm] [bazel] Replace various genrules with bazel_skylib rules (PR #228170)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 10:55:07 PDT 2026
https://github.com/UebelAndre created https://github.com/llvm/llvm-project/pull/228170
This change replaces a number of `genrule` with rules from `bazel_skylib` which helps avoid the need for Bash on Windows and provides a more consistent experience between Unix and Windows platforms.
>From eaf3bbb9ff64f8b89270c87b9c885791131ac441 Mon Sep 17 00:00:00 2001
From: UebelAndre <github at uebelandre.com>
Date: Thu, 1 Oct 2026 10:52:04 -0700
Subject: [PATCH] [bazel] Avoid bash requirement on windows
---
utils/bazel/MODULE.bazel | 3 ++
.../llvm-project-overlay/bolt/BUILD.bazel | 11 +++++--
.../clang-tools-extra/clang-tidy/BUILD.bazel | 10 ++++--
.../clang-tools-extra/clangd/BUILD.bazel | 25 +++++++-------
.../llvm-project-overlay/clang/BUILD.bazel | 24 +++++++-------
.../clang/tools/clang-fuzzer/BUILD.bazel | 3 +-
.../compiler-rt/BUILD.bazel | 6 ++++
.../llvm-project-overlay/libc/BUILD.bazel | 27 +++++++++------
.../libc/libc_build_rules.bzl | 21 ++++++------
.../llvm-project-overlay/lldb/BUILD.bazel | 26 +++++++++++----
.../llvm-project-overlay/llvm/BUILD.bazel | 3 ++
.../llvm-project-overlay/mlir/linalggen.bzl | 20 +++++------
.../llvm-project-overlay/mlir/tblgen.bzl | 1 +
.../mlir/test/BUILD.bazel | 11 +++++--
.../openmp/runtime/src/BUILD.bazel | 33 +++++++------------
.../openmp/runtime/tools/BUILD.bazel | 20 +++++++----
16 files changed, 143 insertions(+), 101 deletions(-)
diff --git a/utils/bazel/MODULE.bazel b/utils/bazel/MODULE.bazel
index 785e897247b40b0..7ae6e4a29f5a803 100644
--- a/utils/bazel/MODULE.bazel
+++ b/utils/bazel/MODULE.bazel
@@ -13,6 +13,9 @@ bazel_dep(name = "apple_support", version = "2.6.1", repo_name = "build_bazel_ap
bazel_dep(name = "protobuf", version = "35.0", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_android", version = "0.7.2")
bazel_dep(name = "rules_cc", version = "0.2.25")
+
+# Keep below 2.0: from 2.0.0, py_binary on Windows requires symlink privileges
+# (https://github.com/bazel-contrib/rules_python/issues/3792).
bazel_dep(name = "rules_python", version = "1.8.4")
bazel_dep(name = "rules_shell", version = "0.8.0")
diff --git a/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel b/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel
index 6f530a049f3e63a..52e16c1d374fc0d 100644
--- a/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/bolt/BUILD.bazel
@@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load(":targets.bzl", "bolt_targets")
@@ -21,10 +22,14 @@ package(
licenses(["notice"])
-genrule(
+write_file(
name = "generate_vcs_revision",
- outs = ["include/VCSVersion.inc"],
- cmd = "echo '#undef BOLT_REVISION' >> $@\n",
+ out = "include/VCSVersion.inc",
+ content = [
+ "#undef BOLT_REVISION",
+ "",
+ ],
+ newline = "unix",
)
expand_template(
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
index f591a57d5423150..eb8701823beda3d 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clang-tidy/BUILD.bazel
@@ -5,6 +5,7 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@bazel_skylib//rules:native_binary.bzl", "native_binary")
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("defs.bzl", "clang_tidy_library")
@@ -72,12 +73,15 @@ cc_binary(
deps = ["//llvm:Support"],
)
-genrule(
+run_binary(
name = "confusables_inc",
srcs = ["misc/ConfusableTable/confusables.txt"],
outs = ["Confusables.inc"],
- cmd = "$(location :confusable_table_builder) $(SRCS) $(OUTS)",
- tools = [":confusable_table_builder"],
+ args = [
+ "$(execpath misc/ConfusableTable/confusables.txt)",
+ "$(execpath Confusables.inc)",
+ ],
+ tool = ":confusable_table_builder",
visibility = ["//visibility:private"],
)
diff --git a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
index 34d44e8f6351244..39043f70d9ed93f 100644
--- a/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang-tools-extra/clangd/BUILD.bazel
@@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_library")
package(
@@ -13,18 +14,20 @@ licenses(["notice"])
# TODO: this is a shim to provide Features.inc as needed by Feature.h.
# Replace this with something that parses Features.inc.in.
-genrule(
+write_file(
name = "gen_features_inc",
- outs = ["Features.inc"],
- cmd = "\n".join([
- "echo '// IWYU pragma: private, include \"Feature.h\"' >> $@",
- "echo '#define CLANGD_BUILD_XPC 0' >> $@",
- "echo '#define CLANGD_ENABLE_REMOTE 1' >> $@",
- "echo '#define ENABLE_GRPC_REFLECTION 0' >> $@",
- "echo '#define CLANGD_MALLOC_TRIM 0' >> $@",
- "echo '#define CLANGD_TIDY_CHECKS 1' >> $@",
- "echo '#define CLANGD_DECISION_FOREST 1' >> $@",
- ]),
+ out = "Features.inc",
+ content = [
+ "// IWYU pragma: private, include \"Feature.h\"",
+ "#define CLANGD_BUILD_XPC 0",
+ "#define CLANGD_ENABLE_REMOTE 1",
+ "#define ENABLE_GRPC_REFLECTION 0",
+ "#define CLANGD_MALLOC_TRIM 0",
+ "#define CLANGD_TIDY_CHECKS 1",
+ "#define CLANGD_DECISION_FOREST 1",
+ "",
+ ],
+ newline = "unix",
)
# TODO: Pick up other files for more complete functionality, to match
diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index 20a68825086e273..2386464a9916460 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
@@ -1985,19 +1986,18 @@ filegroup(
srcs = builtin_headers,
)
-genrule(
+[
+ copy_file(
+ name = "copy_" + hdr.replace("lib/Headers/", "staging/include/"),
+ src = hdr,
+ out = hdr.replace("lib/Headers/", "staging/include/"),
+ )
+ for hdr in builtin_headers
+]
+
+filegroup(
name = "builtin_headers_gen",
- srcs = builtin_headers,
- outs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers],
- cmd = """
- for src in $(SRCS); do
- relsrc=$${src#*"$(WORKSPACE_ROOT)"/clang/lib/Headers}
- target=$(@D)/staging/include/$$relsrc
- mkdir -p $$(dirname $$target)
- cp $$src $$target
- done""",
- output_to_bindir = 1,
- toolchains = [":workspace_root"],
+ srcs = [hdr.replace("lib/Headers/", "staging/include/") for hdr in builtin_headers],
)
cc_library(
diff --git a/utils/bazel/llvm-project-overlay/clang/tools/clang-fuzzer/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/tools/clang-fuzzer/BUILD.bazel
index bee4f0e143f8988..b16584b848768c6 100644
--- a/utils/bazel/llvm-project-overlay/clang/tools/clang-fuzzer/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/tools/clang-fuzzer/BUILD.bazel
@@ -17,7 +17,8 @@ cc_binary(
genrule(
name = "fuzzer-dictionary",
outs = ["fuzzer-dictionary.txt"],
- cmd = "$(location :clang-fuzzer-dictionary) > $@",
+ cmd = "$(execpath :clang-fuzzer-dictionary) > $@",
+ cmd_bat = ">$@ $(execpath :clang-fuzzer-dictionary)",
tools = [":clang-fuzzer-dictionary"],
)
diff --git a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
index 3b6b4c493d36244..738ad14eda782a0 100644
--- a/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
@@ -411,6 +411,12 @@ AARCH64_OUTLINE_ATOMICS_FMT = "lib/builtins/aarch64/outline_atomic_{0}{1}_{2}.S"
"echo '#define MODEL " + model + "' >> $(OUTS) && " +
"cat $(SRCS) >> $(OUTS)"
),
+ cmd_bat = (
+ ">>$(OUTS) echo #define L_" + pat + "&& " +
+ ">>$(OUTS) echo #define SIZE " + size + "&& " +
+ ">>$(OUTS) echo #define MODEL " + model + "&& " +
+ ">>$(OUTS) type $(SRCS)"
+ ),
)] for (pat, size, model) in AARCH64_OUTLINE_ATOMICS]
# Source files for the AArch64 architecture-specific builtins.
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index 72a3e709e4af422..e5457e002f01547 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -5,6 +5,7 @@
# LLVM libc project.
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
+load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load(
@@ -280,21 +281,27 @@ STATIC_HEADERS = glob(
],
) + ["include/__llvm-libc-common.h"]
-genrule(
+[
+ copy_file(
+ name = "copy_staging/" + f,
+ src = f,
+ out = "staging/" + f,
+ )
+ for f in STATIC_HEADERS
+]
+
+filegroup(
name = "copy_llvm_libc_static_headers",
- srcs = STATIC_HEADERS,
- outs = ["staging/" + f for f in STATIC_HEADERS],
- cmd = """srcs=($(SRCS))\n outs=($(OUTS))\n for i in "$${!srcs[@]}"; do cp "$${srcs[$$i]}" "$${outs[$$i]}"; done""",
+ srcs = ["staging/" + f for f in STATIC_HEADERS],
)
-genrule(
+copy_file(
name = "copy_modular_format_header",
- srcs = select({
- ":modular_format_enable": ["include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF.h"],
- "//conditions:default": ["include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF-disable.h"],
+ src = select({
+ ":modular_format_enable": "include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF.h",
+ "//conditions:default": "include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF-disable.h",
}),
- outs = ["staging/include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF.h"],
- cmd = "cp $< $@",
+ out = "staging/include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF.h",
)
STATIC_AND_CONDITIONAL_HEADERS = STATIC_HEADERS + ["include/llvm-libc-macros/_LIBC_MODULAR_FORMAT_PRINTF.h"]
diff --git a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
index 07cb2b04a5dfd58..68ab3152b79ad31 100644
--- a/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
+++ b/utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
@@ -6,6 +6,7 @@
load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:selects.bzl", "selects")
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
load(":libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
load(":libc_namespace.bzl", "LIBC_NAMESPACE")
@@ -340,18 +341,12 @@ def libc_generated_header(name, hdr, yaml_template, other_srcs = [], proxy = Fal
"""Generates a libc header file from YAML template.
Args:
- name: Name of the genrule target.
+ name: Name of the target.
hdr: Path of the header file to generate.
yaml_template: Path of the YAML template file.
other_srcs: Other files required to generate the header, if any.
proxy: Whether this is a proxy header with slightly different generation results.
"""
- hdrgen = "//libc:hdrgen"
- cmd = "$(location {hdrgen}) $(location {yaml}) -o $@".format(
- hdrgen = hdrgen,
- yaml = yaml_template,
- ) + (" --proxy" if proxy else "")
-
if not hdr.startswith("staging/"):
fail(
"Generated headers should be placed in a 'staging/' directory " +
@@ -359,12 +354,16 @@ def libc_generated_header(name, hdr, yaml_template, other_srcs = [], proxy = Fal
"when bootstrapping builds.",
)
- native.genrule(
+ run_binary(
name = name,
- outs = [hdr],
srcs = [yaml_template] + other_srcs,
- cmd = cmd,
- tools = [hdrgen],
+ outs = [hdr],
+ args = [
+ "$(execpath %s)" % yaml_template,
+ "-o",
+ "$(execpath %s)" % hdr,
+ ] + (["--proxy"] if proxy else []),
+ tool = "//libc:hdrgen",
)
def libc_header_info(
diff --git a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
index f876c28c3d474ae..a830dfba92b694f 100644
--- a/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
@@ -5,6 +5,8 @@
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
+load("@bazel_skylib//rules:write_file.bzl", "write_file")
load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_import", "cc_library", "objc_library")
load("@rules_python//python:defs.bzl", "py_binary")
@@ -79,11 +81,15 @@ _VERSION_SUBSTITUTIONS = {
'#cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"': "/* #undef LLDB_FULL_VERSION_STRING */",
}
-genrule(
+write_file(
name = "vcs_version_gen",
- outs = ["VCSVersion.inc"],
- cmd = "echo '#undef LLDB_REVISION' >> $@\n" +
- "echo '#undef LLDB_REPOSITORY' >> $@\n",
+ out = "VCSVersion.inc",
+ content = [
+ "#undef LLDB_REVISION",
+ "#undef LLDB_REPOSITORY",
+ "",
+ ],
+ newline = "unix",
)
expand_template(
@@ -238,12 +244,16 @@ py_binary(
srcs = ["scripts/generate-sbapi-dwarf-enum.py"],
)
-genrule(
+run_binary(
name = "lldb-sbapi-dwarf-enums",
srcs = ["//llvm:include/llvm/BinaryFormat/Dwarf.def"],
outs = ["include/lldb/API/SBLanguages.h"],
- cmd = "$(location :generate-sbapi-dwarf-enum) $(location //llvm:include/llvm/BinaryFormat/Dwarf.def) --output $@",
- tools = [":generate-sbapi-dwarf-enum"],
+ args = [
+ "$(execpath //llvm:include/llvm/BinaryFormat/Dwarf.def)",
+ "--output",
+ "$(execpath include/lldb/API/SBLanguages.h)",
+ ],
+ tool = ":generate-sbapi-dwarf-enum",
)
cc_library(
@@ -934,6 +944,7 @@ cat > $(OUTS) <<EOF
};
EOF
""",
+ cmd_bat = ">$(OUTS) echo {&& >>$(OUTS) echo global:&& (for /f \"usebackq delims=\" %l in (\"$(SRCS)\") do @>>$(OUTS) echo %l;)&& >>$(OUTS) echo };",
)
genrule(
@@ -941,6 +952,7 @@ genrule(
srcs = ["//lldb:source/API/liblldb-private.exports"],
outs = ["exports_macos.txt"],
cmd = "sed 's/^/_/g' $(SRCS) > $(OUTS)",
+ cmd_bat = "(for /f \"usebackq delims=\" %l in (\"$(SRCS)\") do @>>$(OUTS) echo _%l)",
)
# Create a shared library using linkshared=True for liblldb. This uses
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index c0d95afc4ffa776..1ce335987d5b628 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -2228,6 +2228,9 @@ genrule(
srcs = ["include/llvm/Transforms/IPO/InstrumentorRuntimeHelper.h"],
outs = ["include/llvm/Transforms/IPO/InstrumentorVariables.inc"],
cmd = "printf 'constexpr char InstrumentorRuntimeHelper[] = R\"(' > $@ && cat $(SRCS) >> $@ && echo ')\";' >> $@",
+ # `set /p` writes its prompt without a newline, like printf; it also returns
+ # errorlevel 1 on empty input, hence the single `&` after it.
+ cmd_bat = ">$@ <nul set /p =constexpr char InstrumentorRuntimeHelper[] = R^\"(& >>$@ type $(SRCS)&& >>$@ echo ^)^\";",
)
cc_library(
diff --git a/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl b/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl
index b45a6f675d79eae..4df8da747139bc7 100644
--- a/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl
+++ b/utils/bazel/llvm-project-overlay/mlir/linalggen.bzl
@@ -4,6 +4,7 @@
"""BUILD extensions for MLIR linalg generation."""
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
def genlinalg(name, linalggen, src, linalg_outs):
@@ -19,22 +20,17 @@ def genlinalg(name, linalggen, src, linalg_outs):
"""
for (opts, out) in linalg_outs:
- # All arguments to generate the output except output destination.
- base_args = [
- "$(location %s)" % linalggen,
- "%s" % opts,
- "$(location %s)" % src,
- ]
rule_suffix = "_".join(opts.replace("-", "_").replace("=", "_").split(" "))
-
- # Rule to generate code using generated shell script.
- native.genrule(
+ run_binary(
name = "%s_%s_genrule" % (name, rule_suffix),
srcs = [src],
outs = [out],
- tools = [linalggen],
- output_to_bindir = 1,
- cmd = (" ".join(base_args)),
+ # `$@` in opts names the output, as it would in a genrule.
+ args = [
+ opt.replace("$@", "$(execpath %s)" % out)
+ for opt in opts.split(" ")
+ ] + ["$(execpath %s)" % src],
+ tool = linalggen,
)
hdrs = [f for (opts, f) in linalg_outs]
diff --git a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
index fd395b36579c649..3065ab49733bb4e 100644
--- a/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
+++ b/utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
@@ -587,5 +587,6 @@ def gentbl_sharded_op_defs(name, source_file, shard_count):
srcs = [source_file],
outs = [out_file],
cmd = "echo -e \"#define GET_OP_DEFS_" + str(i) + "\n$$(cat $(SRCS))\" > $(OUTS)",
+ cmd_bat = ">$(OUTS) echo #define GET_OP_DEFS_" + str(i) + "&& >>$(OUTS) type $(SRCS)",
)
return copies
diff --git a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
index d1dbeb5159faa63..929c085caa2daae 100644
--- a/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
@@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//llvm:lit_test.bzl", "lit_expand_template")
load("//llvm:targets.bzl", "llvm_targets")
@@ -275,12 +276,16 @@ cc_library(
],
)
-genrule(
+run_binary(
name = "test_irdl_to_cpp_gen",
srcs = ["lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir"],
outs = ["lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir.cpp.inc"],
- cmd = "$(location %s) $< -o $@" % "//mlir:irdl-to-cpp",
- tools = ["//mlir:irdl-to-cpp"],
+ args = [
+ "$(execpath lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir)",
+ "-o",
+ "$(execpath lib/Dialect/TestIRDLToCpp/test_irdl_to_cpp.irdl.mlir.cpp.inc)",
+ ],
+ tool = "//mlir:irdl-to-cpp",
)
cc_library(
diff --git a/utils/bazel/llvm-project-overlay/openmp/runtime/src/BUILD.bazel b/utils/bazel/llvm-project-overlay/openmp/runtime/src/BUILD.bazel
index be115fff470531a..bea5b7dc817a5f4 100644
--- a/utils/bazel/llvm-project-overlay/openmp/runtime/src/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/openmp/runtime/src/BUILD.bazel
@@ -16,6 +16,7 @@
# runtime without them.
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
+load("@bazel_skylib//rules:run_binary.bzl", "run_binary")
load("@rules_cc//cc:defs.bzl", "cc_library")
package(
@@ -185,35 +186,25 @@ expand_template(
# (see message-converter.py:414: Windows path), so we pass --target-system-override
# on Windows to ensure we get a Windows-formatted catalog even when generating
# the inc files on another host.
-_i18n_target_system_arg = select({
- "@platforms//os:windows": "--target-system-override=Windows ",
- "//conditions:default": "",
+_i18n_target_system_args = select({
+ "@platforms//os:windows": ["--target-system-override=Windows"],
+ "//conditions:default": [],
})
-genrule(
+run_binary(
name = "kmp_i18n_id_inc_gen",
- srcs = [
- "i18n/en_US.txt",
- "//openmp/runtime/tools:message-converter.py",
- "//openmp/runtime/tools:libomputils.py",
- ],
+ srcs = ["i18n/en_US.txt"],
outs = ["kmp_i18n_id.inc"],
- cmd = "PYTHONPATH=$$(dirname $(location //openmp/runtime/tools:libomputils.py)) " +
- "python3 $(location //openmp/runtime/tools:message-converter.py) " +
- "--enum=$@ " + _i18n_target_system_arg + "$(location i18n/en_US.txt)",
+ args = ["--enum=$(execpath kmp_i18n_id.inc)"] + _i18n_target_system_args + ["$(execpath i18n/en_US.txt)"],
+ tool = "//openmp/runtime/tools:message-converter",
)
-genrule(
+run_binary(
name = "kmp_i18n_default_inc_gen",
- srcs = [
- "i18n/en_US.txt",
- "//openmp/runtime/tools:message-converter.py",
- "//openmp/runtime/tools:libomputils.py",
- ],
+ srcs = ["i18n/en_US.txt"],
outs = ["kmp_i18n_default.inc"],
- cmd = "PYTHONPATH=$$(dirname $(location //openmp/runtime/tools:libomputils.py)) " +
- "python3 $(location //openmp/runtime/tools:message-converter.py) " +
- "--default=$@ " + _i18n_target_system_arg + "$(location i18n/en_US.txt)",
+ args = ["--default=$(execpath kmp_i18n_default.inc)"] + _i18n_target_system_args + ["$(execpath i18n/en_US.txt)"],
+ tool = "//openmp/runtime/tools:message-converter",
)
# ---------------------------------------------------------------------------
diff --git a/utils/bazel/llvm-project-overlay/openmp/runtime/tools/BUILD.bazel b/utils/bazel/llvm-project-overlay/openmp/runtime/tools/BUILD.bazel
index b4911c762db3c0f..c78f83dcca5d821 100644
--- a/utils/bazel/llvm-project-overlay/openmp/runtime/tools/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/openmp/runtime/tools/BUILD.bazel
@@ -2,16 +2,22 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+load("@rules_python//python:defs.bzl", "py_binary")
+
package(
default_visibility = ["//visibility:public"],
)
licenses(["notice"])
-# message-converter.py is invoked at build time to generate the
-# kmp_i18n_id.inc and kmp_i18n_default.inc message catalog headers.
-# libomputils.py is imported by message-converter.py.
-exports_files([
- "message-converter.py",
- "libomputils.py",
-])
+# Invoked at build time to generate the kmp_i18n_id.inc and
+# kmp_i18n_default.inc message catalog headers.
+py_binary(
+ name = "message-converter",
+ srcs = [
+ "libomputils.py",
+ "message-converter.py",
+ ],
+ imports = ["."],
+ main = "message-converter.py",
+)
More information about the llvm-commits
mailing list