[llvm] [bazel] Stop forcing PIC on Windows (PR #228454)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 2 07:21:11 PDT 2026
https://github.com/UebelAndre created https://github.com/llvm/llvm-project/pull/228454
CMake's LLVM_ENABLE_PIC defaults ON but is an explicit no-op on Windows: the `elseif( WIN32 OR CYGWIN)` branch in HandleLLVMOptions.cmake is just the comment "On Windows all code is PIC. MinGW warns if -fPIC is used." In Bazel the same flag is fatal. rules_cc's auto-configured Windows toolchain declares the `supports_pic` feature only in its non-MSVC
(mingw) branch. Building with this results in the following failure:
```
$ bazel build --nobuild --force_pic @llvm-project//llvm:Demangle
ERROR: local_config_cc/BUILD:340:13: in cc_toolchain rule @@...local_config_cc//:cc-compiler-x64_windows:
Error in fail: PIC compilation is requested but the toolchain does not support it (feature named 'supports_pic' is not enabled)
ERROR: Analysis of target '@@...local_config_cc//:cc-compiler-x64_windows' failed
ERROR: Analysis of target '@@+llvm_configure+llvm-project//llvm:Demangle' failed; build aborted: Analysis failed
```
Where building without it succeeds
```
$ bazel build --nobuild @llvm-project//llvm:Demangle
INFO: Analyzed target @@+llvm_configure+llvm-project//llvm:Demangle (110 packages loaded, 1760 targets configured).
```
>From 557abafc5dc6b78b662075748c191d3a48aef9ff Mon Sep 17 00:00:00 2001
From: UebelAndre <github at uebelandre.com>
Date: Tue, 29 Sep 2026 06:19:34 -0700
Subject: [PATCH] [bazel] Stop forcing PIC on Windows
---
utils/bazel/.bazelrc | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/utils/bazel/.bazelrc b/utils/bazel/.bazelrc
index a9a61aac6e93f..1aabb032b023b 100644
--- a/utils/bazel/.bazelrc
+++ b/utils/bazel/.bazelrc
@@ -34,9 +34,11 @@ common -- at rules_python//python/config_settings:bootstrap_impl=script
# tests vs binaries. We don't need this feature and it slows down opt builds
# considerably.
# TODO: Remove platform specifics we're on bazel 7.x https://github.com/bazelbuild/bazel/issues/12439
-# Apple platforms always enable pic so this flag is unnecessary anyways
+# Apple platforms always enable pic so this flag is unnecessary anyways.
+# On Windows all code is PIC (CMake's LLVM_ENABLE_PIC is a no-op there), and
+# rules_cc's MSVC toolchain does not declare the `supports_pic` feature, so
+# `--force_pic` makes configure_features() fail before anything is built.
build:linux --force_pic
-build:windows --force_pic
# Shared objects take up more space. With fast linkers and binaries that aren't
# super large, the benefits of shared objects are minimal.
More information about the llvm-commits
mailing list