diff options
author | 2017-09-28 08:23:57 -0400 | |
---|---|---|
committer | 2017-09-28 08:55:26 -0400 | |
commit | 90a4a18c62778def22641b4df06e58b3cc7dfc3e (patch) | |
tree | fb6fb4ef0d5fa83d18eb0c71a7a487ba58bc74f7 /src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java | |
parent | 6ee36ef239b25f66afa83e2657bd0b529b1ff50e (diff) |
Make windows_export_all_symbols feature work for cc_binary
Now Bazel can also export symbols when building dynamic library from
cc_binary.
The interface library generated can be accessed by interface_library output group.
The DEF file can still be accessed by def_file output group even when
windows_export_all_symbols feature is not specified. This is useful when
users want to filter symbols in DEF file before using it, for example,
working around the 64K symbols number limit.
Change-Id: I5b4dae0840e20037c00d500181c40b5faedfdcd8
PiperOrigin-RevId: 170330409
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java index 742e5dd37c..6b00ae0d69 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java @@ -290,8 +290,40 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { CppLinkAction.symbolCountsFileName(binaryPath))); } + Artifact defFile = null; + Artifact interfaceLibrary = null; if (isLinkShared(ruleContext)) { linkActionBuilder.setLibraryIdentifier(CcLinkingOutputs.libraryIdentifierOf(binary)); + + if (featureConfiguration.isEnabled(CppRuleClasses.TARGETS_WINDOWS)) { + ImmutableList.Builder<Artifact> objectFiles = ImmutableList.builder(); + objectFiles.addAll(ccCompilationOutputs.getObjectFiles(false)); + for (LibraryToLink library : linkParams.getLibraries()) { + if (library.containsObjectFiles() + && library.getArtifactCategory() != ArtifactCategory.DYNAMIC_LIBRARY + && library.getArtifactCategory() != ArtifactCategory.INTERFACE_LIBRARY) { + objectFiles.addAll(library.getObjectFiles()); + } + } + defFile = + CppHelper.createDefFileActions( + ruleContext, + ccToolchain.getDefParserTool(), + objectFiles.build(), + binary.getFilename()); + + if (CppHelper.shouldUseDefFile(featureConfiguration)) { + linkActionBuilder.setDefFile(defFile); + } + + // If we are using a toolchain supporting interface library and targeting Windows, we build + // the interface library with the link action and add it to `interface_output` output group. + if (cppConfiguration.useInterfaceSharedObjects()) { + interfaceLibrary = ruleContext.getRelatedArtifact(binary.getRootRelativePath(), ".ifso"); + linkActionBuilder.setInterfaceOutput(interfaceLibrary); + linkActionBuilder.addActionOutput(interfaceLibrary); + } + } } // Store immutable context for use in other *_binary rules that are implemented by @@ -451,6 +483,14 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { ruleBuilder.addOutputGroup("pdb_file", pdbFile); } + if (defFile != null) { + ruleBuilder.addOutputGroup("def_file", defFile); + } + + if (interfaceLibrary != null) { + ruleBuilder.addOutputGroup("interface_library", interfaceLibrary); + } + return ruleBuilder .addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)) .addProvider( |