summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2021-10-16 00:46:19 -0700
committerChandler Carruth <chandlerc@gmail.com>2021-10-28 16:04:47 +0000
commit112dc16014f19ad68f54c59ad1170d71554c42f2 (patch)
tree573c41cb995928b2500eb8a7fc8d4674602c5ec2
parent947e14be98796b5e680cc7bcae262d4256c8e05c (diff)
downloadllvm-112dc16014f19ad68f54c59ad1170d71554c42f2.tar.gz
Add support for Bazel builds on Windows with `clang-cl`.
Adds basic `--config=clang-cl` to set up the basic options needed, and then fix a number of issues that surface in Windows builds for me. With these fixes, `//llvm/...` builds cleanly. One unittest still fails, but its just due to running out of stack space due to creating a large number of short-lived stack variables. The test should probably be decomposed into a set of tests (`LegalizerInfoTest::RuleSets`), but that seemed like too invasive of a change here and with everything building cleanly this isn't disrupting me experimenting with Windows builds. Some parts of `//clang/...` builds, but that will require more work.
-rw-r--r--utils/bazel/.bazelrc37
-rw-r--r--utils/bazel/llvm-project-overlay/clang/BUILD.bazel1
-rw-r--r--utils/bazel/llvm-project-overlay/llvm/BUILD.bazel2
-rw-r--r--utils/bazel/llvm-project-overlay/llvm/config.bzl12
-rw-r--r--utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h4
-rw-r--r--utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel15
6 files changed, 53 insertions, 18 deletions
diff --git a/utils/bazel/.bazelrc b/utils/bazel/.bazelrc
index ce1d654b94ba..ed2a41dfb46f 100644
--- a/utils/bazel/.bazelrc
+++ b/utils/bazel/.bazelrc
@@ -69,9 +69,18 @@ build:generic_gcc --copt=-Wno-misleading-indentation --host_copt=-Wno-misleading
build:generic_gcc --copt=-Werror --host_copt=-Werror
###############################################################################
-# Windows specific flags for building with VC.
+# Generic Windows flags common to both MSVC and Clang.
###############################################################################
+# Yay for security warnings. Boo for non-standard.
+build:windows --copt=/D_CRT_SECURE_NO_WARNINGS --host_copt=/D_CRT_SECURE_NO_WARNINGS
+
+###############################################################################
+# Windows specific flags for building with MSVC.
+###############################################################################
+
+build:msvc --config=windows
+
build:msvc --copt=/WX --host_copt=/WX # Treat warnings as errors...
# ...but disable the ones that are violated
build:msvc --copt=/wd4141 --host_copt=/wd4141 # inline used more than once
@@ -87,8 +96,30 @@ build:msvc --linkopt=/WX --host_linkopt=/WX # Treat warnings as errors...
# ...but disable the ones that are violated.
build:msvc --linkopt=/IGNORE:4001 --host_linkopt=/IGNORE:4001 # no object files
-# Yay for security warnings. Boo for non-standard.
-build:msvc --copt=/D_CRT_SECURE_NO_WARNINGS --host_copt=/D_CRT_SECURE_NO_WARNINGS
+###############################################################################
+# Options for Windows `clang-cl` builds.
+###############################################################################
+
+# We just start with the baseline Windows config as `clang-cl` doesn't accept
+# some of the generic Clang flags.
+build:clang-cl --config=windows
+
+# Switch from MSVC to the `clang-cl` compiler.
+build:clang-cl --compiler=clang-cl
+
+# C++14 standard version is required.
+build:clang-cl --cxxopt=/std:c++14 --host_cxxopt=/std:c++14
+
+# Use Clang's internal warning flags instead of the ones that sometimes map
+# through to MSVC's flags.
+build:clang-cl --copt=/clang:-Wall --host_copt=/clang:-Wall
+build:clang-cl --copt=/clang:-Werror --host_copt=/clang:-Werror
+
+# This doesn't appear to be enforced by any upstream bot.
+build:clang-cl --copt=/clang:-Wno-unused --host_copt=/clang:-Wno-unused
+
+# There appears to be an unused constant in GoogleTest on Windows.
+build:clang-cl --copt=/clang:-Wno-unused-const-variable --host_copt=/clang:-Wno-unused-const-variable
###############################################################################
diff --git a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
index e4ae5067cf8e..488c23ba8fb6 100644
--- a/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/clang/BUILD.bazel
@@ -29,7 +29,6 @@ cc_binary(
copts = [
"$(STACK_FRAME_UNLIMITED)",
],
- linkopts = ["-ldl"],
stamp = 0,
deps = [
"//llvm:Support",
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index 7afd39139935..39751be589b6 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -3102,7 +3102,9 @@ cc_binary(
name = "llvm-mca",
srcs = glob([
"tools/llvm-mca/*.cpp",
+ "tools/llvm-mca/*.h",
"tools/llvm-mca/Views/*.cpp",
+ "tools/llvm-mca/Views/*.h",
]),
copts = llvm_copts,
stamp = 0,
diff --git a/utils/bazel/llvm-project-overlay/llvm/config.bzl b/utils/bazel/llvm-project-overlay/llvm/config.bzl
index ff64df694048..f4e4bdeaf3c9 100644
--- a/utils/bazel/llvm-project-overlay/llvm/config.bzl
+++ b/utils/bazel/llvm-project-overlay/llvm/config.bzl
@@ -25,15 +25,17 @@ posix_defines = [
r'LTDL_SHLIB_EXT=\".so\"',
r'LLVM_PLUGIN_EXT=\".so\"',
"LLVM_ENABLE_THREADS=1",
- "HAVE_SYSEXITS_H=1",
- "HAVE_UNISTD_H=1",
- "HAVE_STRERROR_R=1",
+ "HAVE_DEREGISTER_FRAME=1",
"HAVE_LIBPTHREAD=1",
"HAVE_PTHREAD_GETNAME_NP=1",
- "HAVE_PTHREAD_SETNAME_NP=1",
"HAVE_PTHREAD_GETSPECIFIC=1",
+ "HAVE_PTHREAD_H=1",
+ "HAVE_PTHREAD_SETNAME_NP=1",
"HAVE_REGISTER_FRAME=1",
- "HAVE_DEREGISTER_FRAME=1",
+ "HAVE_SETENV_R=1",
+ "HAVE_STRERROR_R=1",
+ "HAVE_SYSEXITS_H=1",
+ "HAVE_UNISTD_H=1",
]
linux_defines = posix_defines + [
diff --git a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
index 3fead191388f..1f640e91cc56 100644
--- a/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
+++ b/utils/bazel/llvm-project-overlay/llvm/include/llvm/Config/config.h
@@ -174,7 +174,7 @@
#define HAVE_PTHREAD_GETSPECIFIC 1
/* Define to 1 if you have the <pthread.h> header file. */
-#define HAVE_PTHREAD_H 1
+/* HAVE_PTHREAD_H defined in Bazel */
/* Have pthread_mutex_lock */
#define HAVE_PTHREAD_MUTEX_LOCK 1
@@ -186,7 +186,7 @@
/* HAVE_SBRK defined in Bazel */
/* Define to 1 if you have the `setenv' function. */
-#define HAVE_SETENV 1
+/* HAVE_SETENV defined in Bazel */
/* Define to 1 if you have the `setrlimit' function. */
#define HAVE_SETRLIMIT 1
diff --git a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
index ea90b1bac7ad..dcac33b0311e 100644
--- a/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/unittests/BUILD.bazel
@@ -112,7 +112,7 @@ cc_library(
cc_test(
name = "codegen_tests",
- size = "small",
+ size = "medium",
srcs = glob(
[
"CodeGen/*.cpp",
@@ -167,7 +167,7 @@ cc_test(
cc_test(
name = "debuginfo_tests",
- size = "small",
+ size = "medium",
srcs = glob(
[
"DebugInfo/DWARF/*.cpp",
@@ -219,7 +219,7 @@ cc_test(
cc_test(
name = "execution_engine_mcjit_tests",
- size = "small",
+ size = "medium",
srcs = glob(
[
"ExecutionEngine/MCJIT/*.cpp",
@@ -245,7 +245,7 @@ cc_test(
cc_test(
name = "execution_engine_orc_tests",
- size = "small",
+ size = "medium",
srcs = glob(
[
"ExecutionEngine/Orc/*.cpp",
@@ -381,7 +381,7 @@ cc_test(
cc_test(
name = "mi_tests",
- size = "small",
+ size = "medium",
srcs = glob(
["MI/*.cpp"],
allow_empty = False,
@@ -525,9 +525,10 @@ cc_test(
],
)
+# Note that the name of this test is important as it is used in the test itself.
cc_test(
- name = "support_tests",
- size = "small",
+ name = "SupportTests",
+ size = "medium",
srcs = glob(
[
"Support/*.cpp",