Skip to content

Commit ebf24b3

Browse files
committed
Force compilation with Clang on windows (newer version of bazel enable --incompatible_enable_cc_toolchain_resolution, and now we are trying to compile with MSVC -- bazelbuild/bazel#7260). In addition: improve the run-format.sh script to automatically find the correct clang-format binary if not provided
1 parent bb5f301 commit ebf24b3

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

.bazelrc

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,10 @@ common:macos --config=unix
2828
# https://github.com/bazelbuild/bazel/issues/4341#issuecomment-758361769
2929
common:macos --features=-supports_dynamic_linker --linkopt=-framework --linkopt=CoreFoundation --host_linkopt=-framework --host_linkopt=CoreFoundation
3030

31-
# Force the use clang-cl on Windows instead of MSVC. MSVC has some issues with
32-
# the codebase, so we focus the effort for now is to have a Windows Verible
33-
# compiled with clang-cl before fixing the issues unique to MSVC.
34-
# Since we use designated initializers (C99 ... but >= c++20), compiler really wants the c++20 mode
35-
common:windows --compiler=clang-cl --cxxopt=/std:c++20 --host_cxxopt=/std:c++20 --client_env=BAZEL_CXXOPTS=/std:c++20
36-
# Protobuf will be dropping support for MSVC + Bazel in 34.0. See github.com/protocolbuffers/protobuf/issues/20085
37-
common:windows --define='protobuf_allow_msvc=true'
31+
# Use clang-cl by default on Windows. MSVC has some issues with the codebase,
32+
# so we focus the effort for now is to have a Windows Verible compiled with
33+
# clang-cl before fixing the issues unique to MSVC.
34+
common:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows-clang-cl --extra_execution_platforms=//:x64_windows-clang-cl
3835

3936
# For 3rd party code: Disable warnings entirely.
4037
# They are not actionable and just create noise.

.github/bin/run-format.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,20 @@ done
3131

3232
FORMAT_OUT=${TMPDIR:-/tmp}/clang-format-diff.out
3333

34-
CLANG_FORMAT=${CLANG_FORMAT:-clang-format}
34+
# Use the provided Clang format binary, or try to fallback to clang-format-17
35+
# or clang-format.
36+
if [[ ! -v CLANG_FORMAT ]]; then
37+
if command -v "clang-format-17" 2>&1 >/dev/null
38+
then
39+
CLANG_FORMAT="clang-format-17"
40+
elif command -v "clang-format" 2>&1 >/dev/null
41+
then
42+
CLANG_FORMAT="clang-format"
43+
else
44+
(echo "-- Missing the clang-format binary! --"; exit 1)
45+
fi
46+
fi
47+
3548
BUILDIFIER=${BUILDIFIER:-buildifier}
3649

3750
# Currently, we're using clang-format 17, as newer versions still have some

BUILD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,14 @@ genrule(
5555
"//verible/verilog/tools/lint:verible-verilog-lint",
5656
],
5757
)
58+
59+
# For building with clang-cl on Windows.
60+
# https://bazel.build/configure/windows#clang
61+
platform(
62+
name = "x64_windows-clang-cl",
63+
constraint_values = [
64+
"@platforms//cpu:x86_64",
65+
"@platforms//os:windows",
66+
"@bazel_tools//tools/cpp:clang-cl",
67+
],
68+
)

MODULE.bazel

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,11 @@ bazel_dep(name = "googletest", version = "1.14.0.bcr.1", dev_dependency = True)
2323

2424
# To build compilation DB and run build-cleaning
2525
bazel_dep(name = "bant", version = "0.2.0", dev_dependency = True)
26+
27+
#":x64_windows-clang-cl" Force clang-cl for the Windows builds.
28+
register_execution_platforms(
29+
":x64_windows-clang-cl"
30+
)
31+
register_toolchains(
32+
"@local_config_cc//:cc-toolchain-x64_windows-clang-cl",
33+
)

0 commit comments

Comments
 (0)