Skip to content

[bazel] Use rules_cc everywhere and reformat #149584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2025
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
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/bolt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load(":targets.bzl", "bolt_targets")

package(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library")

package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//llvm:lit_test.bzl", "lit_test", "package_path")

package(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

package(
default_visibility = ["//visibility:public"],
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/clang/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load(
"//:vars.bzl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")

package(default_visibility = ["//visibility:public"])

licenses(["notice"])
Expand Down
2 changes: 2 additions & 0 deletions utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library")

package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_test")

package(
default_visibility = ["//visibility:public"],
features = ["layering_check"],
Expand Down
13 changes: 6 additions & 7 deletions utils/bazel/llvm-project-overlay/libc/libc_build_rules.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@bazel_skylib//lib:selects.bzl", "selects")
load("@rules_cc//cc:defs.bzl", "cc_library")
load(":libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")
load(":libc_namespace.bzl", "LIBC_NAMESPACE")
load(":platforms.bzl", "PLATFORM_CPU_X86_64")
Expand Down Expand Up @@ -52,7 +53,7 @@ def _libc_library(name, **kwargs):
for attr in ["copts", "local_defines"]:
if attr in kwargs:
fail("disallowed attribute: '{}' in rule: '{}'".format(attr, name))
native.cc_library(
cc_library(
name = name,
copts = libc_common_copts(),
local_defines = LIBC_CONFIGURE_OPTIONS,
Expand Down Expand Up @@ -188,7 +189,7 @@ def libc_release_library(
name = name + "_textual_hdrs",
libs = libc_functions,
)
native.cc_library(
cc_library(
name = name + "_textual_hdr_library",
textual_hdrs = [":" + name + "_textual_hdrs"],
)
Expand All @@ -197,8 +198,7 @@ def libc_release_library(
"LLVM_LIBC_FUNCTION_ATTR_" + name + "='LLVM_LIBC_EMPTY, [[gnu::weak]]'"
for name in weak_symbols
]

native.cc_library(
cc_library(
name = name,
srcs = [":" + name + "_srcs"],
copts = libc_common_copts() + libc_release_copts(),
Expand Down Expand Up @@ -229,12 +229,11 @@ def libc_header_library(name, hdrs, deps = [], **kwargs):
name = name + "_textual_hdrs",
libs = deps,
)
native.cc_library(
cc_library(
name = name + "_textual_hdr_library",
textual_hdrs = [":" + name + "_textual_hdrs"],
)

native.cc_library(
cc_library(
name = name,
hdrs = hdrs,
# We put _hdr_deps in srcs, as they are not a part of this cc_library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ They come in two flavors:
When performing tests we make sure to always use the internal version.
"""

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//libc:libc_build_rules.bzl", "libc_common_copts")
load("//libc:libc_configure_options.bzl", "LIBC_CONFIGURE_OPTIONS")

Expand Down Expand Up @@ -58,8 +59,7 @@ def libc_test(

if full_build:
copts = copts + _FULL_BUILD_COPTS

native.cc_test(
cc_test(
name = name,
local_defines = local_defines + LIBC_CONFIGURE_OPTIONS,
deps = deps,
Expand All @@ -77,7 +77,7 @@ def libc_test_library(name, copts = [], local_defines = [], **kwargs):
local_defines: See cc_library.local_defines.
**kwargs: Other attributes relevant to cc_library (e.g. "deps").
"""
native.cc_library(
cc_library(
name = name,
testonly = True,
copts = copts + libc_common_copts(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ libc_test(
],
)


libc_test(
name = "wcslcat_test",
srcs = ["wcslcat_test.cpp"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# A wrapper library over MPC for use with LLVM libc math unittests.

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//libc/test:libc_test_rules.bzl", "libc_test_library")

package(default_visibility = ["//visibility:public"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# A wrapper library over MPFR for use with LLVM libc math unittests.

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//libc/test:libc_test_rules.bzl", "libc_test_library")

package(default_visibility = ["//visibility:public"])
Expand Down
2 changes: 2 additions & 0 deletions utils/bazel/llvm-project-overlay/libunwind/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library")

package(
default_visibility = ["//visibility:public"],
)
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/lld/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library")
load(
"//:vars.bzl",
"LLVM_VERSION",
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/lldb/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ 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("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH", "LLVM_VERSION_SUFFIX", "PACKAGE_VERSION")
load("//lldb/source/Plugins:plugin_config.bzl", "DEFAULT_PLUGINS", "DEFAULT_SCRIPT_PLUGINS", "OBJCPP_COPTS")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//mlir:tblgen.bzl", "gentbl_cc_library")
load(":plugin_config.bzl", "DEFAULT_PLUGINS", "DEFAULT_SCRIPT_PLUGINS", "OBJCPP_COPTS")

Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@rules_python//python:defs.bzl", "py_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "gentbl_filegroup", "td_library")
load(":binary_alias.bzl", "binary_alias")
Expand Down
3 changes: 2 additions & 1 deletion utils/bazel/llvm-project-overlay/llvm/driver.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

load("@bazel_skylib//rules:common_settings.bzl", "BuildSettingInfo")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary")

# Mapping from every tool to the cc_library that implements the tool's entrypoint.
_TOOLS = {
Expand Down Expand Up @@ -175,7 +176,7 @@ def llvm_driver_cc_binary(
template = "//llvm:cmake/modules/llvm-driver-template.cpp.in",
)
deps = deps or []
native.cc_binary(
cc_binary(
name = name,
srcs = [name + "-driver.cpp"],
deps = deps + ["//llvm:Support"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("//mlir:tblgen.bzl", "gentbl_cc_library")

package(
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load(
":build_defs.bzl",
"cc_headers_only",
Expand Down
8 changes: 5 additions & 3 deletions utils/bazel/llvm-project-overlay/mlir/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

"""Rules and macros for MLIR"""

load("@rules_cc//cc:defs.bzl", "cc_library")

def if_cuda_available(if_true, if_false = []):
return select({
# CUDA auto-detection is not yet supported.
Expand Down Expand Up @@ -49,20 +51,20 @@ def mlir_c_api_cc_library(
"""
capi_header_deps = ["%sHeaders" % d for d in capi_deps]
capi_object_deps = ["%sObjects" % d for d in capi_deps]
native.cc_library(
cc_library(
name = name,
srcs = srcs,
hdrs = hdrs,
deps = deps + capi_deps + header_deps,
**kwargs
)
native.cc_library(
cc_library(
name = name + "Headers",
hdrs = hdrs,
deps = header_deps + capi_header_deps,
**kwargs
)
native.cc_library(
cc_library(
name = name + "Objects",
srcs = srcs,
hdrs = hdrs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Description:
# MLIR Tutorial

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])
Expand Down
4 changes: 3 additions & 1 deletion utils/bazel/llvm-project-overlay/mlir/linalggen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

"""BUILD extensions for MLIR linalg generation."""

load("@rules_cc//cc:defs.bzl", "cc_library")

def genlinalg(name, linalggen, src, linalg_outs):
"""genlinalg() generates code from a tc spec file.

Expand Down Expand Up @@ -35,7 +37,7 @@ def genlinalg(name, linalggen, src, linalg_outs):
)

hdrs = [f for (opts, f) in linalg_outs]
native.cc_library(
cc_library(
name = name,
hdrs = hdrs,
textual_hdrs = hdrs,
Expand Down
3 changes: 2 additions & 1 deletion utils/bazel/llvm-project-overlay/mlir/tblgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""BUILD extensions for MLIR table generation."""

load("@bazel_skylib//lib:paths.bzl", "paths")
load("@rules_cc//cc:defs.bzl", "cc_library")

TdInfo = provider(
"Holds TableGen files and the dependencies and include paths necessary to" +
Expand Down Expand Up @@ -424,7 +425,7 @@ def gentbl_cc_library(
skip_opts = ["-gen-op-doc"],
**kwargs
)
native.cc_library(
cc_library(
name = name,
# strip_include_prefix does not apply to textual_hdrs.
# https://github.com/bazelbuild/bazel/issues/12424
Expand Down
1 change: 1 addition & 0 deletions utils/bazel/llvm-project-overlay/mlir/test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
load("@rules_cc//cc:defs.bzl", "cc_library")
load("//llvm:lit_test.bzl", "package_path")
load("//mlir:tblgen.bzl", "gentbl_cc_library", "gentbl_sharded_ops", "td_library")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

load("@rules_cc//cc:defs.bzl", "cc_test")
load("//mlir:tblgen.bzl", "gentbl_cc_library")

package(
Expand Down
Loading
Loading