Skip to content

Commit 147ea5a

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 bba7557 commit 147ea5a

File tree

11 files changed

+82
-2
lines changed

11 files changed

+82
-2
lines changed

.bazelrc

Lines changed: 5 additions & 0 deletions
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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ jobs:
412412
bazel: build --cpu=darwin_arm64 //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
413413
- name: Windows Bazel
414414
os: windows-2022
415-
cache_key: windows-2022-bazel7
415+
cache_key: windows-2022-msvc-cl
416+
bazel: test //src/... @com_google_protobuf_examples//... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance --define=protobuf_allow_msvc=true
417+
- name: Windows Bazel clang-cl
418+
os: windows-2022
419+
cache_key: windows-2022-clang-cl
416420
bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance
417421
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} ${{ matrix.name }}
418422
runs-on: ${{ matrix.os }}
@@ -524,6 +528,7 @@ jobs:
524528
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
525529
uses: protocolbuffers/protobuf-ci/bash@v4
526530
with:
531+
bazel-version: 7.1.2
527532
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
528533
command: >-
529534
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.install-flags }}
@@ -550,6 +555,7 @@ jobs:
550555
uses: protocolbuffers/protobuf-ci/bash@v4
551556
with:
552557
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
558+
bazel-version: 7.1.2
553559
command: >-
554560
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.flags }}
555561
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON

.github/workflows/test_csharp.yml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 25 additions & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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.7.1")
10+
bazel_dep(name = "platforms", version = "0.0.8")
1011
bazel_dep(name = "rules_cc", version = "0.0.17")
1112
bazel_dep(name = "rules_java", version = "8.6.1")
1213
bazel_dep(name = "rules_pkg", version = "1.0.1")
1314
bazel_dep(name = "rules_python", version = "1.0.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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
workspace(name = "com_google_protobuf_examples")
22

3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
35
# This protobuf repository is required for proto_library rule.
46
# It provides the protocol compiler binary (i.e., protoc).
57
#
@@ -26,6 +28,16 @@ local_repository(
2628
path = "..",
2729
)
2830

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+
2941
load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
3042

3143
protobuf_deps()

src/google/protobuf/stubs/BUILD.bazel

Lines changed: 6 additions & 0 deletions
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

Lines changed: 7 additions & 0 deletions
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. For feedback or discussion, see github.com/protocolbuffers/protobuf/issues/20085."
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)