Skip to content

Commit

Permalink
Windows: Fix Precondition check for addDynamicInputLinkOptions
Browse files Browse the repository at this point in the history
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 #6171
Fixes #6292
Fixes #6169

RELNOTES: None
PiperOrigin-RevId: 216258674
  • Loading branch information
meteorcloudy authored and Copybara-Service committed Oct 8, 2018
1 parent 9b117ac commit 914b4ce
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ private void addDynamicInputLinkOptions(
Preconditions.checkState(
!Link.useStartEndLib(
input, CppHelper.getArchiveType(cppConfiguration, ccToolchainProvider)));
if (featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)) {
// On Windows, dynamic library (dll) cannot be linked directly.
if (featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)
&& ccToolchainProvider.supportsInterfaceSharedObjects()) {
// On Windows, dynamic library (dll) cannot be linked directly when using toolchains that
// support interface library (eg. MSVC).
Preconditions.checkState(
!CppFileTypes.SHARED_LIBRARY.matches(input.getArtifact().getFilename()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ private static class Impl {
depsBuilder.addAll(ruleContext.getPrerequisites("deps", TARGET));
ImmutableList<TransitiveInfoCollection> deps = depsBuilder.build();
CcLinkingHelper ccLinkingHelper = initializeLinkingHelper(featureConfiguration, deps);
if (ccToolchain(ruleContext).supportsInterfaceSharedObjects()) {
ccLinkingHelper.emitInterfaceSharedObjects(true);
}
CcLinkingOutputs ccLinkingOutputs = CcLinkingOutputs.EMPTY;
if (!ccCompilationOutputs.isEmpty()) {
ccLinkingOutputs = ccLinkingHelper.link(ccCompilationOutputs);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,8 @@ toolchain {
tool_path { name: "strip" path: "C:/tools/msys64/usr/bin/strip" }
tool_path { name: "llvm-profdata" path: "C:/tools/msys64/usr/bin/llvm-profdata" }
linking_mode_flags { mode: DYNAMIC }

supports_interface_shared_objects: true
}

toolchain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public void basic() throws Exception {
"cc_proto_library(name = 'foo_cc_proto', deps = ['foo_proto'])",
"proto_library(name = 'foo_proto', srcs = ['foo.proto'])");
assertThat(prettyArtifactNames(getFilesToBuild(getConfiguredTarget("//x:foo_cc_proto"))))
.containsExactly("x/foo.pb.h", "x/foo.pb.cc", "x/libfoo_proto.a", "x/libfoo_proto.so");
.containsExactly("x/foo.pb.h", "x/foo.pb.cc", "x/libfoo_proto.a",
"x/libfoo_proto.ifso", "x/libfoo_proto.so");
}

@Test
Expand Down Expand Up @@ -207,7 +208,7 @@ public void commandLineControlsOutputFileSuffixes() throws Exception {

assertThat(prettyArtifactNames(getFilesToBuild(getConfiguredTarget("//x:foo_cc_proto"))))
.containsExactly("x/foo.pb.cc", "x/foo.pb.h", "x/foo.pb.cc.meta", "x/foo.proto.h",
"x/libfoo_proto.a", "x/libfoo_proto.so");
"x/libfoo_proto.a", "x/libfoo_proto.ifso", "x/libfoo_proto.so");
}

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

0 comments on commit 914b4ce

Please sign in to comment.