Skip to content

Commit

Permalink
Register CC toolchain from rules_cc (#1163)
Browse files Browse the repository at this point in the history
This reworks my previous PR #1156 [1], which was to make Windows bazel
build compatible with

  --noincompatible_enable_cc_toolchain_resolution

option (#1102) (#1112).

The difference from the previous approach is that this commit uses
CC toolchains defined by 'rules_cc' rather than the ones implicitly
defined by the Bazel itself.

Given that 'rules_cc' becomes the new home of CC-related rules and
configurations, hopefully this change will reduce the likelihood of
future troubles.

There must be no observable behavior change in the final artifacts.

 [1]: 4aad25e

PiperOrigin-RevId: 717738755
  • Loading branch information
yukawa authored Jan 21, 2025
1 parent cd7d25c commit b878663
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 0 additions & 12 deletions src/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ test:macos_env --test_tag_filters=-nomac
build:windows_env --build_tag_filters=-nowin
test:windows_env --test_tag_filters=-nowin

# Bazel does not register cc toolchains for Windows by default.
# We need to explicitly specify them to be compatible with the new behavior
# introduced by --incompatible_enable_cc_toolchain_resolution
# https://github.com/google/mozc/issues/1112
# https://bazel.build/extending/toolchains#registering-building-toolchains
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
build:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-arm64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_windows
test:windows_env --extra_toolchains=@@rules_cc++cc_configure_extension+local_config_cc//:cc-toolchain-x64_x86_windows

# Android specific options
build:android_env --copt "-DOS_ANDROID"
build:android_env --build_tag_filters=-noandroid
Expand Down
17 changes: 17 additions & 0 deletions src/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,29 @@ bazel_dep(
)

# Apple Support for Bazel (1.16.0 2024-07-10)
## this must come above 'rules_cc'
## https://github.com/bazelbuild/apple_support/blob/d87e8b07f3345e750834dbb6ce38c7c7d3b8b44b/README.md#bazel-7-setup
bazel_dep(
name = "apple_support",
version = "1.16.0",
repo_name = "build_bazel_apple_support",
)

# rules_cc: 0.0.17 2024-11-19
# https://github.com/bazelbuild/rules_cc/
bazel_dep(
name = "rules_cc",
version = "0.0.17",
)

cc_configure = use_extension(
"@rules_cc//cc:extensions.bzl",
"cc_configure_extension",
)
use_repo(cc_configure, "local_config_cc")

register_toolchains("@local_config_cc//:all")

# Android NDK rules (0.1.2 2024-07-23)
# https://github.com/bazelbuild/rules_android_ndk
bazel_dep(
Expand Down

0 comments on commit b878663

Please sign in to comment.