diff options
author | Yun Peng <pcloudy@google.com> | 2017-04-18 13:33:28 +0200 |
---|---|---|
committer | Klaus Aehlig <aehlig@google.com> | 2017-04-18 15:26:12 +0200 |
commit | 997992d728a6ae5f5b9ee9a4a117d554041e6f45 (patch) | |
tree | 0c5e4538967a1f533e443266859e0567ad89c9f0 /src/main/java/com/google/devtools | |
parent | 1ade2c47f075d981e5c9d23276530778abb3d8ab (diff) |
Generating PDB files on Windows
1. Add /Z7 as compiler flag in CROSSTOOL, this causes full debugging
infomation built into object files, no PDB file is generated.
2. Add /DEBUG as linker flag so that a PDB file will be generated for
executable or dll.
* /DEBUG:FULL for dbg mode. the full PDB can be used to debug the
executable when no other build products are available, such as
when the executable is deployed.
* /DEBUG:FASTLINK for fastbuild mode. object files are still needed
when debugging the executable, but linking speed can be two to four
times faster that full PDB generation.
* No option is added for opt mode.
More detailed info: https://msdn.microsoft.com/en-us/library/xe4t6fc1.aspx
3. Add an empty feature in MSVC CROSSTOOL to tell Bazel we need PDB file
4. Add PDB file artifact in an output named pdb_file of cc_binary,
then you can build the pdb file by bazel build //foo/bar:bin --output_groups=pdb_file
5. Add test for PDB file generation
Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
PiperOrigin-RevId: 153449059
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java | 13 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java | 6 |
2 files changed, 19 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 9b9ae3118f..ca98d7bf61 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 @@ -297,6 +297,14 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { linkActionBuilder.setLTOIndexing(false); } + // On Windows, if GENERATE_PDB_FILE feature is enabled + // then a pdb file will be built along with the executable. + Artifact pdbFile = null; + if (featureConfiguration.isEnabled(CppRuleClasses.GENERATE_PDB_FILE)) { + pdbFile = ruleContext.getRelatedArtifact(binary.getRootRelativePath(), ".pdb"); + linkActionBuilder.addActionOutput(pdbFile); + } + CppLinkAction linkAction = linkActionBuilder.build(); ruleContext.registerAction(linkAction); LibraryToLink outputLibrary = linkAction.getOutputLibrary(); @@ -412,6 +420,11 @@ public abstract class CcBinary implements RuleConfiguredTargetFactory { new ExecutionInfoProvider(ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, ""))); } + // If PDB file is generated by the link action, we add it to pdb_file output group + if (pdbFile != null) { + ruleBuilder.addOutputGroup("pdb_file", pdbFile); + } + return ruleBuilder .addProvider(RunfilesProvider.class, RunfilesProvider.simple(runfiles)) .addProvider( diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java index 698353a105..6cad3decee 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java @@ -283,6 +283,12 @@ public class CppRuleClasses { */ public static final String THIN_LTO = "thin_lto"; + /** + * A string constant for the PDB file generation feature, should only be used for toolchains + * targeting Windows that include a linker producing PDB files + */ + public static final String GENERATE_PDB_FILE = "generate_pdb_file"; + /* * A string constant for the fdo_instrument feature. */ |