Skip to content

Commit 586ee89

Browse files
mkruskal-googlecopybara-github
authored andcommitted
Breaking change: prohibit using Bazel+MSVC to build protobuf
An opt-out flag `--define=protobuf_allow_msvc=true` will be available until our 2026 breaking release 34.0. See #20085 for more details. #test-continuous PiperOrigin-RevId: 718525948
1 parent 4b56158 commit 586ee89

File tree

11 files changed

+84
-2
lines changed

11 files changed

+84
-2
lines changed

.bazelrc

+5
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ common --noenable_bzlmod
4040
build --features=layering_check
4141

4242
common --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
43+
44+
common --enable_platform_specific_config
45+
46+
# Use clang-cl by default on Windows (see https://github.com/protocolbuffers/protobuf/issues/20085).
47+
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl --extra_execution_platforms=//build_defs:x64_windows-clang-cl --host_platform=//build_defs:x64_windows-clang-cl

.github/workflows/test_cpp.yml

+11-1
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,17 @@ jobs:
414414
# Current github runners are all Intel based, so just build/compile
415415
# for Apple Silicon to detect issues there.
416416
bazel: build --cpu=darwin_arm64 //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
417-
- name: Windows Bazel
417+
- name: Windows Bazel (failing)
418418
os: windows-2022
419419
cache_key: windows-2022-bazel7
420+
bazel: test //src/... @com_google_protobuf_examples//... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance
421+
- name: Windows Bazel
422+
os: windows-2022
423+
cache_key: windows-2022-msvc-cl
424+
bazel: test //src/... @com_google_protobuf_examples//... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance --define=protobuf_allow_msvc=true
425+
- name: Windows Bazel clang-cl
426+
os: windows-2022
427+
cache_key: windows-2022-clang-cl
420428
bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance
421429
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} ${{ matrix.name }}
422430
runs-on: ${{ matrix.os }}
@@ -528,6 +536,7 @@ jobs:
528536
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
529537
uses: protocolbuffers/protobuf-ci/bash@v4
530538
with:
539+
bazel-version: 7.1.2
531540
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
532541
command: >-
533542
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.install-flags }}
@@ -554,6 +563,7 @@ jobs:
554563
uses: protocolbuffers/protobuf-ci/bash@v4
555564
with:
556565
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
566+
bazel-version: 7.1.2
557567
command: >-
558568
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.flags }}
559569
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON

.github/workflows/test_csharp.yml

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ jobs:
7474
- name: Run tests
7575
uses: protocolbuffers/protobuf-ci/bash@v4
7676
with:
77+
bazel-version: 7.1.2
7778
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
7879
command: |
7980
dotnet build csharp/src/Google.Protobuf.sln

build_defs/BUILD.bazel

+25-1
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,36 @@ create_compiler_config_setting(
1818
value = "msvc-cl",
1919
)
2020

21-
# Caveat: clang-cl support in protobuf is only best-effort / untested for now.
2221
create_compiler_config_setting(
2322
name = "config_clang_cl",
2423
value = "clang-cl",
2524
)
2625

26+
platform(
27+
name = "x64_windows-clang-cl",
28+
constraint_values = [
29+
"@platforms//cpu:x86_64",
30+
"@platforms//os:windows",
31+
"@bazel_tools//tools/cpp:clang-cl",
32+
],
33+
)
34+
35+
platform(
36+
name = "x64_windows-msvc-cl",
37+
constraint_values = [
38+
"@platforms//cpu:x86_64",
39+
"@platforms//os:windows",
40+
"@bazel_tools//tools/cpp:msvc",
41+
],
42+
)
43+
44+
config_setting(
45+
name = "protobuf_allow_msvc",
46+
values = {
47+
"define": "protobuf_allow_msvc=true",
48+
},
49+
)
50+
2751
selects.config_setting_group(
2852
name = "config_msvc",
2953
match_any = [

ci/Windows.bazelrc

+4
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ build --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
55
startup --output_user_root=C:/tmp --windows_enable_symlinks
66
common --enable_runfiles
77

8+
build --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl
9+
build:clang-cl --extra_execution_platforms=//build_defs:x64_windows-clang-cl --host_platform=//build_defs:x64_windows-clang-cl
10+
build:msvc-cl --extra_execution_platforms=//build_defs:x64_windows-msvc-cl --host_platform=//build_defs:x64_windows-msvc-cl
11+
build --config=clang-cl

examples/.bazelrc

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ common --enable_platform_specific_config
33
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
44
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
55

6+
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl --extra_execution_platforms=//:x64_windows-clang-cl
67
common:windows --cxxopt=/std:c++17 --host_cxxopt=/std:c++17 --enable_runfiles
78

89
build --experimental_remote_cache_eviction_retries=5

examples/BUILD.bazel

+9
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,12 @@ pkg_files(
185185
strip_prefix = strip_prefix.from_root(""),
186186
visibility = ["//visibility:public"],
187187
)
188+
189+
platform(
190+
name = "x64_windows-clang-cl",
191+
constraint_values = [
192+
"@platforms//cpu:x86_64",
193+
"@platforms//os:windows",
194+
"@bazel_tools//tools/cpp:clang-cl",
195+
],
196+
)

examples/MODULE.bazel

+5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ local_path_override(
77
)
88

99
bazel_dep(name = "bazel_skylib", version = "1.0.3")
10+
bazel_dep(name = "platforms", version = "0.0.8")
1011
bazel_dep(name = "rules_cc", version = "0.0.16")
1112
bazel_dep(name = "rules_java", version = "8.3.2")
1213
bazel_dep(name = "rules_pkg", version = "0.7.0")
1314
bazel_dep(name = "rules_python", version = "0.25.0")
15+
16+
# For clang-cl configuration
17+
cc_configure = use_extension("@bazel_tools//tools/cpp:cc_configure.bzl", "cc_configure_extension")
18+
use_repo(cc_configure, "local_config_cc")

examples/WORKSPACE

+10
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ local_repository(
2828
path = "..",
2929
)
3030

31+
# Bazel platform rules, for clang-cl.
32+
http_archive(
33+
name = "platforms",
34+
sha256 = "3a561c99e7bdbe9173aa653fd579fe849f1d8d67395780ab4770b1f381431d51",
35+
urls = [
36+
"https://mirror.bazel.build/github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
37+
"https://github.com/bazelbuild/platforms/releases/download/0.0.7/platforms-0.0.7.tar.gz",
38+
],
39+
)
40+
3141
# Needed because protobuf_deps brings rules_python 0.26.0 which is broken:
3242
# https://github.com/bazelbuild/rules_python/issues/1543
3343
http_archive(

src/google/protobuf/stubs/BUILD.bazel

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ cc_library(
2222
"status_macros.h",
2323
],
2424
copts = COPTS,
25+
defines = ["GOOGLE_PROTOBUF_USING_BAZEL=1"] + select({
26+
"//build_defs:protobuf_allow_msvc": [
27+
"GOOGLE_PROTOBUF_MSVC_BAZEL_OVERRIDE=1",
28+
],
29+
"//conditions:default": [],
30+
}),
2531
linkopts = LINK_OPTS,
2632
strip_include_prefix = "/src",
2733
deps = [

src/google/protobuf/stubs/port.h

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@
3131
#include <byteswap.h> // IWYU pragma: export
3232
#endif
3333

34+
#if defined(_MSC_VER) && !defined(__clang__) && \
35+
defined(GOOGLE_PROTOBUF_USING_BAZEL) && \
36+
!defined(GOOGLE_PROTOBUF_MSVC_BAZEL_OVERRIDE)
37+
#error \
38+
"Protobuf will be dropping support for MSVC + Bazel in 34.0. To continue using it until then, use the flag --define=protobuf_allow_msvc=true. See github.com/protocolbuffers/protobuf/issues/20085 for more information."
39+
#endif
40+
3441
// Legacy: some users reference these (internal-only) macros even though we
3542
// don't need them any more.
3643
#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)

0 commit comments

Comments
 (0)