Skip to content

Commit 914b4ce

Browse files
meteorcloudyCopybara-Service
authored and
Copybara-Service
committed
Windows: Fix Precondition check for addDynamicInputLinkOptions
The MSYS gcc and MINGW gcc toolchains do support linking against shared library. So the precondition check should be disabled for them. CcProtoAspect.java should set emitInterfaceSharedObjects to true when the toolchain supports interface shared library. Fixes bazelbuild#6171 Fixes bazelbuild#6292 Fixes bazelbuild#6169 RELNOTES: None PiperOrigin-RevId: 216258674
1 parent 9b117ac commit 914b4ce

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

src/main/java/com/google/devtools/build/lib/rules/cpp/LibrariesToLinkCollector.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,10 @@ private void addDynamicInputLinkOptions(
285285
Preconditions.checkState(
286286
!Link.useStartEndLib(
287287
input, CppHelper.getArchiveType(cppConfiguration, ccToolchainProvider)));
288-
if (featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)) {
289-
// On Windows, dynamic library (dll) cannot be linked directly.
288+
if (featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)
289+
&& ccToolchainProvider.supportsInterfaceSharedObjects()) {
290+
// On Windows, dynamic library (dll) cannot be linked directly when using toolchains that
291+
// support interface library (eg. MSVC).
290292
Preconditions.checkState(
291293
!CppFileTypes.SHARED_LIBRARY.matches(input.getArtifact().getFilename()));
292294
}

src/main/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoAspect.java

+3
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,9 @@ private static class Impl {
202202
depsBuilder.addAll(ruleContext.getPrerequisites("deps", TARGET));
203203
ImmutableList<TransitiveInfoCollection> deps = depsBuilder.build();
204204
CcLinkingHelper ccLinkingHelper = initializeLinkingHelper(featureConfiguration, deps);
205+
if (ccToolchain(ruleContext).supportsInterfaceSharedObjects()) {
206+
ccLinkingHelper.emitInterfaceSharedObjects(true);
207+
}
205208
CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
206209
if (!ccCompilationOutputs.isEmpty()) {
207210
ccLinkingOutputs = ccLinkingHelper.link(ccCompilationOutputs);

src/test/java/com/google/devtools/build/lib/analysis/mock/MOCK_CROSSTOOL

+2
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,8 @@ toolchain {
584584
tool_path { name: "strip" path: "C:/tools/msys64/usr/bin/strip" }
585585
tool_path { name: "llvm-profdata" path: "C:/tools/msys64/usr/bin/llvm-profdata" }
586586
linking_mode_flags { mode: DYNAMIC }
587+
588+
supports_interface_shared_objects: true
587589
}
588590

589591
toolchain {

src/test/java/com/google/devtools/build/lib/rules/cpp/proto/CcProtoLibraryTest.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ public void basic() throws Exception {
6868
"cc_proto_library(name = 'foo_cc_proto', deps = ['foo_proto'])",
6969
"proto_library(name = 'foo_proto', srcs = ['foo.proto'])");
7070
assertThat(prettyArtifactNames(getFilesToBuild(getConfiguredTarget("//x:foo_cc_proto"))))
71-
.containsExactly("x/foo.pb.h", "x/foo.pb.cc", "x/libfoo_proto.a", "x/libfoo_proto.so");
71+
.containsExactly("x/foo.pb.h", "x/foo.pb.cc", "x/libfoo_proto.a",
72+
"x/libfoo_proto.ifso", "x/libfoo_proto.so");
7273
}
7374

7475
@Test
@@ -207,7 +208,7 @@ public void commandLineControlsOutputFileSuffixes() throws Exception {
207208

208209
assertThat(prettyArtifactNames(getFilesToBuild(getConfiguredTarget("//x:foo_cc_proto"))))
209210
.containsExactly("x/foo.pb.cc", "x/foo.pb.h", "x/foo.pb.cc.meta", "x/foo.proto.h",
210-
"x/libfoo_proto.a", "x/libfoo_proto.so");
211+
"x/libfoo_proto.a", "x/libfoo_proto.ifso", "x/libfoo_proto.so");
211212
}
212213

213214
// TODO(carmi): test blacklisted protos. I don't currently understand what's the wanted behavior.

0 commit comments

Comments
 (0)