Skip to content

Commit

Permalink
Breaking change: prohibit using Bazel+MSVC to build protobuf
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mkruskal-google authored and copybara-github committed Jan 23, 2025
1 parent 4b56158 commit 0d4d896
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 2 deletions.
12 changes: 11 additions & 1 deletion .github/workflows/test_cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,17 @@ jobs:
# Current github runners are all Intel based, so just build/compile
# for Apple Silicon to detect issues there.
bazel: build --cpu=darwin_arm64 //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
- name: Windows Bazel
- name: Windows Bazel (failing)
os: windows-2022
cache_key: windows-2022-bazel7
bazel: test //src/... @com_google_protobuf_examples//... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance
- name: Windows Bazel
os: windows-2022
cache_key: windows-2022-msvc-cl
bazel: test //src/... @com_google_protobuf_examples//... --config=msvc-cl --test_tag_filters=-conformance --build_tag_filters=-conformance --define=protobuf_allow_msvc=true
- name: Windows Bazel clang-cl
os: windows-2022
cache_key: windows-2022-clang-cl
bazel: test //src/... @com_google_protobuf_examples//... --test_tag_filters=-conformance --build_tag_filters=-conformance
name: ${{ matrix.continuous-only && inputs.continuous-prefix || '' }} ${{ matrix.name }}
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -528,6 +536,7 @@ jobs:
if: ${{ matrix.install-flags && (!matrix.continuous-only || inputs.continuous-run) }}
uses: protocolbuffers/protobuf-ci/bash@v4
with:
bazel-version: 7.1.2
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: >-
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.install-flags }}
Expand All @@ -554,6 +563,7 @@ jobs:
uses: protocolbuffers/protobuf-ci/bash@v4
with:
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
bazel-version: 7.1.2
command: >-
cmake . -DCMAKE_CXX_STANDARD=17 ${{ matrix.flags }}
${{ env.SCCACHE_CMAKE_FLAGS }} -Dprotobuf_ALLOW_CCACHE=ON
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test_csharp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ jobs:
- name: Run tests
uses: protocolbuffers/protobuf-ci/bash@v4
with:
bazel-version: 7.1.2
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
command: |
dotnet build csharp/src/Google.Protobuf.sln
Expand Down
17 changes: 16 additions & 1 deletion build_defs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,27 @@ create_compiler_config_setting(
value = "msvc-cl",
)

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

platform(
name = "x64_windows-clang-cl",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
],
)

config_setting(
name = "protobuf_allow_msvc",
values = {
"define": "protobuf_allow_msvc=true",
},
)

selects.config_setting_group(
name = "config_msvc",
match_any = [
Expand Down
3 changes: 3 additions & 0 deletions ci/Windows.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ build --cxxopt=/std:c++17 --host_cxxopt=/std:c++17
startup --output_user_root=C:/tmp --windows_enable_symlinks
common --enable_runfiles

build:clang-cl --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
build:msvc-cl --extra_toolchains= --extra_execution_platforms=
build --config=clang-cl
1 change: 1 addition & 0 deletions examples/.bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ common --enable_platform_specific_config
build:linux --cxxopt=-std=c++17 --host_cxxopt=-std=c++17
build:macos --cxxopt=-std=c++17 --host_cxxopt=-std=c++17

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

build --experimental_remote_cache_eviction_retries=5
Expand Down
9 changes: 9 additions & 0 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,12 @@ pkg_files(
strip_prefix = strip_prefix.from_root(""),
visibility = ["//visibility:public"],
)

platform(
name = "x64_windows-clang-cl",
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:windows",
"@bazel_tools//tools/cpp:clang-cl",
],
)
6 changes: 6 additions & 0 deletions src/google/protobuf/stubs/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ cc_library(
"status_macros.h",
],
copts = COPTS,
defines = ["GOOGLE_PROTOBUF_USING_BAZEL=1"] + select({
"//build_defs:protobuf_allow_msvc": [
"GOOGLE_PROTOBUF_MSVC_BAZEL_OVERRIDE=1",
],
"//conditions:default": [],
}),
linkopts = LINK_OPTS,
strip_include_prefix = "/src",
deps = [
Expand Down
7 changes: 7 additions & 0 deletions src/google/protobuf/stubs/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
#include <byteswap.h> // IWYU pragma: export
#endif

#if defined(_MSC_VER) && !defined(__clang__) && \
defined(GOOGLE_PROTOBUF_USING_BAZEL) && \
!defined(GOOGLE_PROTOBUF_MSVC_BAZEL_OVERRIDE)
#error \
"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."
#endif

// Legacy: some users reference these (internal-only) macros even though we
// don't need them any more.
#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
Expand Down

0 comments on commit 0d4d896

Please sign in to comment.