Change in bazel[master]: Generating PDB files on Windows

634 views
Skip to first unread message

Yun Peng (Gerrit)

unread,
Apr 12, 2017, 5:09:58 AM4/12/17
to bazel-de...@googlegroups.com

Yun Peng has uploaded this change for review.

View Change

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.

3. Add an empty feature in CROSSTOOL to tell Bazel when need PDB file

4. Add PDB file artifact as link action output and files to build
when PDB file is needed.

Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
---
M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
M tools/cpp/CROSSTOOL.tpl
M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
4 files changed, 34 insertions(+), 3 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 9b9ae31..1dc378a 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
@@ -33,6 +33,7 @@
import com.google.devtools.build.lib.analysis.actions.ExecutionRequirements;
import com.google.devtools.build.lib.analysis.actions.FileWriteAction;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
+import com.google.devtools.build.lib.analysis.config.CompilationMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
@@ -297,6 +298,15 @@
linkActionBuilder.setLTOIndexing(false);
}

+ // On Windows, if GENERATE_PDB_FILE feature is enabled and it's not optimized compilation mode
+ // then a pdb file will be built along with the executable.
+ Artifact pdbFile = null;
+ if (featureConfiguration.isEnabled(CppRuleClasses.GENERATE_PDB_FILE) &&
+ cppConfiguration.getCompilationMode() != CompilationMode.OPT) {
+ pdbFile = ruleContext.getRelatedArtifact(binary.getRootRelativePath(), ".pdb");
+ linkActionBuilder.addActionOutput(pdbFile);
+ }
+
CppLinkAction linkAction = linkActionBuilder.build();
ruleContext.registerAction(linkAction);
LibraryToLink outputLibrary = linkAction.getOutputLibrary();
@@ -317,7 +327,14 @@
linkingOutputsBuilder.addExecutionDynamicLibrary(symlinkLibrary);
}
CcLinkingOutputs linkingOutputs = linkingOutputsBuilder.build();
- NestedSet<Artifact> filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, executable);
+ // If we need to generated pdb file, add it into filesToBuild
+ NestedSet<Artifact> filesToBuild;
+ if (pdbFile != null) {
+ filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, executable, pdbFile);
+ } else {
+ filesToBuild = NestedSetBuilder.create(Order.STABLE_ORDER, executable);
+ }
+

// Create the stripped binary, but don't add it to filesToBuild; it's only built when requested.
Artifact strippedFile = ruleContext.getImplicitOutputArtifact(
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 698353a..0b25d15 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 static final String THIN_LTO = "thin_lto";

+ /**
+ * A string constant for the PDB file generation feature, should only be used on Windows with
+ * MSVC toolchain.
+ */
+ public static final String GENERATE_PDB_FILE = "generate_pdb_file";
+
/*
* A string constant for the fdo_instrument feature.
*/
diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl
index 60fb955..a7e91ce 100644
--- a/tools/cpp/CROSSTOOL.tpl
+++ b/tools/cpp/CROSSTOOL.tpl
@@ -386,6 +386,7 @@
implies: 'legacy_link_flags'
implies: 'linker_param_file'
implies: 'msvc_env'
+ implies: 'generate_pdb_file'
}

action_config {
@@ -403,6 +404,7 @@
implies: 'legacy_link_flags'
implies: 'linker_param_file'
implies: 'msvc_env'
+ implies: 'generate_pdb_file'
}

action_config {
@@ -463,6 +465,10 @@
}

feature {
+ name: 'generate_pdb_file'
+ }
+
+ feature {
name: 'has_configured_linker_path'
}

@@ -673,6 +679,8 @@
compiler_flag: "-g"
compiler_flag: "/Od"
compiler_flag: "-Xcompilation-mode=dbg"
+ compiler_flag: "/Z7"
+ linker_flag: "/DEBUG:FULL"
linker_flag: "-Xcompilation-mode=dbg"
}

@@ -681,6 +689,8 @@
compiler_flag: "/DNDEBUG"
compiler_flag: "/Od"
compiler_flag: "-Xcompilation-mode=fastbuild"
+ compiler_flag: "/Z7"
+ linker_flag: "/DEBUG:FASTLINK"
linker_flag: "-Xcompilation-mode=fastbuild"
}

diff --git a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
index 0695593..127aa87 100644
--- a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
+++ b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
@@ -263,8 +263,6 @@
if arg.startswith('/Fo') or arg.startswith('/Fa') or arg.startswith(
'/Fi'):
self.output_file = arg[3:]
- self.options.append(
- '/Fd%s.pdb' % self.NormPath(os.path.splitext(self.output_file)[0]))
if num_matched == 0:
# Strip out any .a's that have 0 size, they are header or intermediate
# dependency libraries and don't contain any code. 0-length files are

To view, visit change 10090. To unsubscribe, visit settings.

Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
Gerrit-Change-Number: 10090
Gerrit-PatchSet: 1
Gerrit-Owner: Yun Peng <pcl...@google.com>

Yun Peng (Gerrit)

unread,
Apr 12, 2017, 5:13:57 AM4/12/17
to bazel-de...@googlegroups.com

Yun Peng uploaded patch set #2 to this change.

View Change

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.

3. Add an empty feature in CROSSTOOL to tell Bazel when need PDB file

4. Add PDB file artifact as link action output and files to build
when PDB file is needed.

Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
---
M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
M tools/cpp/CROSSTOOL.tpl
M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
4 files changed, 36 insertions(+), 3 deletions(-)

To view, visit change 10090. To unsubscribe, visit settings.

Gerrit-Project: bazel
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
Gerrit-Change-Number: 10090
Gerrit-PatchSet: 2
Gerrit-Owner: Yun Peng <pcl...@google.com>

Dmitry Lomov (Gerrit)

unread,
Apr 12, 2017, 5:26:27 AM4/12/17
to Yun Peng, Marcel Hlopko

Dmitry Lomov posted comments on this change.

View Change

Patch set 2:Code-Review +1

\o/ but Marcel should take a look :)

    To view, visit change 10090. To unsubscribe, visit settings.

    Gerrit-Project: bazel
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
    Gerrit-Change-Number: 10090
    Gerrit-PatchSet: 2
    Gerrit-Owner: Yun Peng <pcl...@google.com>
    Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
    Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
    Gerrit-Comment-Date: Wed, 12 Apr 2017 09:26:25 +0000
    Gerrit-HasComments: No
    Gerrit-HasLabels: Yes

    Marcel Hlopko (Gerrit)

    unread,
    Apr 12, 2017, 6:42:09 AM4/12/17
    to Yun Peng, Dmitry Lomov

    Marcel Hlopko posted comments on this change.

    View Change

    Patch set 2:Verified +1Code-Review +2

    LGTM

    (1 comment)

    • File tools/cpp/CROSSTOOL.tpl:

      • Patch Set #2, Line 682:

        compiler_flag: "/Z7"
        linker_flag: "/DEBUG:FULL"
        linker_flag: "/INCREMENTAL:NO"

        Just FYI, you can use features named 'gdb', 'fastbuild', 'opt', that get activated on respective modes. In the long term, I'd like to express as much stuff with action_configs and features, and have only the bare minimum of other hooks. Compilation_mode_flags are an example of such a hook that we should be able to get rid of. I'm fine with this change, as it will be trivial to move to features later.

    To view, visit change 10090. To unsubscribe, visit settings.

    Gerrit-Project: bazel
    Gerrit-Branch: master
    Gerrit-MessageType: comment
    Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
    Gerrit-Change-Number: 10090
    Gerrit-PatchSet: 2
    Gerrit-Owner: Yun Peng <pcl...@google.com>
    Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
    Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
    Gerrit-Comment-Date: Wed, 12 Apr 2017 10:42:05 +0000
    Gerrit-HasComments: Yes
    Gerrit-HasLabels: Yes

    Marcel Hlopko (Gerrit)

    unread,
    Apr 12, 2017, 6:42:48 AM4/12/17
    to Yun Peng, Dmitry Lomov

    Marcel Hlopko posted comments on this change.

    View Change

    Patch set 2:

    And of course by gdb I meant dbg :)

      To view, visit change 10090. To unsubscribe, visit settings.

      Gerrit-Project: bazel
      Gerrit-Branch: master
      Gerrit-MessageType: comment
      Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
      Gerrit-Change-Number: 10090
      Gerrit-PatchSet: 2
      Gerrit-Owner: Yun Peng <pcl...@google.com>
      Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
      Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
      Gerrit-Comment-Date: Wed, 12 Apr 2017 10:42:45 +0000
      Gerrit-HasComments: No
      Gerrit-HasLabels: No

      Yun Peng (Gerrit)

      unread,
      Apr 12, 2017, 7:29:35 AM4/12/17
      to Marcel Hlopko, Dmitry Lomov, Bazel CI

      Yun Peng uploaded patch set #3 to this change.

      View Change

      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.

      3. Add an empty feature in CROSSTOOL to tell Bazel when need PDB file

      4. Add PDB file artifact as link action output and files to build
      when PDB file is needed.

      5. Add test for PDB file generation


      Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
      ---
      M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
      M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
      M src/test/shell/bazel/bazel_windows_example_test.sh
      M tools/cpp/CROSSTOOL.tpl
      M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
      5 files changed, 81 insertions(+), 26 deletions(-)

      To view, visit change 10090. To unsubscribe, visit settings.

      Gerrit-Project: bazel
      Gerrit-Branch: master
      Gerrit-MessageType: newpatchset
      Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
      Gerrit-Change-Number: 10090
      Gerrit-PatchSet: 3
      Gerrit-Owner: Yun Peng <pcl...@google.com>
      Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>

      Yun Peng (Gerrit)

      unread,
      Apr 12, 2017, 7:31:48 AM4/12/17
      to Bazel CI, Marcel Hlopko, Dmitry Lomov

      Yun Peng posted comments on this change.

      View Change

      Patch set 2:

      (1 comment)

        • Patch Set #2, Line 682:

          compiler_flag: "/Z7"
          linker_flag: "/DEBUG:FULL"
          linker_flag: "/INCREMENTAL:NO"

          Just FYI, you can use features named 'gdb', 'fastbuild', 'opt', that get ac

        • Thanks for letting me know! I was looking for the same thing!

          Now I switched to feature and removed some useless flags, PTAL!

      To view, visit change 10090. To unsubscribe, visit settings.

      Gerrit-Project: bazel
      Gerrit-Branch: master
      Gerrit-MessageType: comment
      Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
      Gerrit-Change-Number: 10090
      Gerrit-PatchSet: 2
      Gerrit-Owner: Yun Peng <pcl...@google.com>
      Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
      Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
      Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
      Gerrit-Reviewer: Yun Peng <pcl...@google.com>
      Gerrit-Comment-Date: Wed, 12 Apr 2017 11:31:45 +0000
      Gerrit-HasComments: Yes
      Gerrit-HasLabels: No

      Marcel Hlopko (Gerrit)

      unread,
      Apr 12, 2017, 8:53:55 AM4/12/17
      to Yun Peng, Bazel CI, Dmitry Lomov

      Marcel Hlopko posted comments on this change.

      View Change

      Patch set 3:

      LGTM

        To view, visit change 10090. To unsubscribe, visit settings.

        Gerrit-Project: bazel
        Gerrit-Branch: master
        Gerrit-MessageType: comment
        Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
        Gerrit-Change-Number: 10090
        Gerrit-PatchSet: 3
        Gerrit-Owner: Yun Peng <pcl...@google.com>
        Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
        Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
        Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
        Gerrit-Reviewer: Yun Peng <pcl...@google.com>
        Gerrit-Comment-Date: Wed, 12 Apr 2017 12:53:52 +0000
        Gerrit-HasComments: No
        Gerrit-HasLabels: No

        Yun Peng (Gerrit)

        unread,
        Apr 12, 2017, 9:09:37 AM4/12/17
        to Marcel Hlopko, Dmitry Lomov, Bazel CI

        Yun Peng uploaded patch set #4 to this change.

        View Change

        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.

        3. Add an empty feature in CROSSTOOL to tell Bazel when need PDB file

        4. Add PDB file artifact as link action output and files to build
        when PDB file is needed.

        5. Add test for PDB file generation

        6. Modified Bazel BUILD file to adapt this change, because now the
        output of cc_binary is not a single file anymore.

        Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
        ---
        M src/BUILD
        M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
        M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java

        M src/test/shell/bazel/bazel_windows_example_test.sh
        M tools/cpp/CROSSTOOL.tpl
        M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
        6 files changed, 97 insertions(+), 15 deletions(-)

        To view, visit change 10090. To unsubscribe, visit settings.

        Gerrit-Project: bazel
        Gerrit-Branch: master
        Gerrit-MessageType: newpatchset
        Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
        Gerrit-Change-Number: 10090
        Gerrit-PatchSet: 4

        Yun Peng (Gerrit)

        unread,
        Apr 12, 2017, 9:22:43 AM4/12/17
        to Marcel Hlopko, Bazel CI, Dmitry Lomov

        Yun Peng posted comments on this change.

        View Change

        Patch set 4:

        Discussed with Dmitry offline, multiple outputs of cc_binary is not good, need more work here.

          To view, visit change 10090. To unsubscribe, visit settings.

          Gerrit-Project: bazel
          Gerrit-Branch: master
          Gerrit-MessageType: comment
          Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
          Gerrit-Change-Number: 10090
          Gerrit-PatchSet: 4
          Gerrit-Owner: Yun Peng <pcl...@google.com>
          Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
          Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
          Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
          Gerrit-Reviewer: Yun Peng <pcl...@google.com>
          Gerrit-Comment-Date: Wed, 12 Apr 2017 13:22:41 +0000
          Gerrit-HasComments: No
          Gerrit-HasLabels: No

          Dmitry Lomov (Gerrit)

          unread,
          Apr 12, 2017, 9:23:49 AM4/12/17
          to Yun Peng, Marcel Hlopko, Bazel CI

          Dmitry Lomov posted comments on this change.

          View Change

          Patch set 4:

          (1 comment)

          • File src/BUILD:

            • Patch Set #4, Line 240: $(locations //src/main/cpp:client)

              Ouch. I think having two outputs for a cc_binary will break too many things :(
              How to solve that? Some ideas:
              1) .pdb file is an extra output of cc_binary (just like *_deploy.jar for java_binary)
              2) a special output group
              3) something else?

              what is the solution for objc .dsym files?

          To view, visit change 10090. To unsubscribe, visit settings.

          Gerrit-Project: bazel
          Gerrit-Branch: master
          Gerrit-MessageType: comment
          Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
          Gerrit-Change-Number: 10090
          Gerrit-PatchSet: 4
          Gerrit-Owner: Yun Peng <pcl...@google.com>
          Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
          Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
          Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
          Gerrit-Reviewer: Yun Peng <pcl...@google.com>
          Gerrit-Comment-Date: Wed, 12 Apr 2017 13:23:46 +0000
          Gerrit-HasComments: Yes
          Gerrit-HasLabels: No

          Yun Peng (Gerrit)

          unread,
          Apr 12, 2017, 10:17:48 AM4/12/17
          to Marcel Hlopko, Dmitry Lomov, Bazel CI

          Yun Peng uploaded patch set #5 to this change.

          View Change

          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.

          3. Add an empty feature in CROSSTOOL to tell Bazel when need PDB file

          4. Add PDB file artifact as an implicit output of cc_binary,
          then you can do build the pdb file by //foo/bar:bin.pdb


          5. Add test for PDB file generation

          Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
          ---
          M src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
          M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
          M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java

          M src/test/shell/bazel/bazel_windows_example_test.sh
          M tools/cpp/CROSSTOOL.tpl
          M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
          6 files changed, 91 insertions(+), 14 deletions(-)

          To view, visit change 10090. To unsubscribe, visit settings.

          Gerrit-Project: bazel
          Gerrit-Branch: master
          Gerrit-MessageType: newpatchset
          Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
          Gerrit-Change-Number: 10090
          Gerrit-PatchSet: 5

          Yun Peng (Gerrit)

          unread,
          Apr 12, 2017, 10:18:57 AM4/12/17
          to Dmitry Lomov, Marcel Hlopko, Bazel CI

          Yun Peng posted comments on this change.

          View Change

          Patch set 4:

          (1 comment)

          The first solution could easily work, I added ${name}.pdb as an implicit output of cc_binary. Then you can do bazel build :hello-world.pdb

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 4
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-Comment-Date: Wed, 12 Apr 2017 14:18:55 +0000
            Gerrit-HasComments: No
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 12, 2017, 10:32:40 AM4/12/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI

            Yun Peng uploaded patch set #6 to this change.

            View Change

            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.

            3. Add an empty feature in MSVC CROSSTOOL to tell Bazel we need PDB file


            4. Add PDB file artifact as an implicit output of cc_binary,
               then you can build the pdb file by bazel build //foo/bar:bin.pdb


            5. Add test for PDB file generation

            Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            ---
            M src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java

            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            6 files changed, 91 insertions(+), 14 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 6

            Yun Peng (Gerrit)

            unread,
            Apr 12, 2017, 10:51:40 AM4/12/17
            to Dmitry Lomov, Marcel Hlopko, Bazel CI

            Yun Peng posted comments on this change.

            View Change

            Patch set 6:

            (1 comment)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 6
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-Comment-Date: Wed, 12 Apr 2017 14:51:37 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Dmitry Lomov (Gerrit)

            unread,
            Apr 12, 2017, 12:33:00 PM4/12/17
            to Yun Peng, Marcel Hlopko, Bazel CI

            Dmitry Lomov posted comments on this change.

            View Change

            Patch set 6:

            (1 comment)

              • Patch Set #6, Line 309:

                // When the link action doesn't produce the pdb file (no generate_pdb_file feature
                // or in opt mode), we still need an action for this implicit output.
                ruleContext.registerAction(FileWriteAction.create(ruleContext, pdbFile, "", false));

                Similar logic here:

              • Hmm I do not like it very much: we are generating incorrect PDB files... a debuuger might just crash on them.
                Marcel, what do you think?

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 6
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-Comment-Date: Wed, 12 Apr 2017 16:32:57 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 3:45:19 AM4/13/17
            to Dmitry Lomov, Marcel Hlopko, Bazel CI

            Yun Peng posted comments on this change.

            View Change

            Patch set 6:

            (1 comment)

              • Patch Set #6, Line 309:

                // When the link action doesn't produce the pdb file (no generate_pdb_file feature
                // or in opt mode), we still need an action for this implicit output.
                ruleContext.registerAction(FileWriteAction.create(ruleContext, pdbFile, "", false));

              • Hmm I do not like it very much: we are generating incorrect PDB files... a

                I see, that's right. How about we make this action always fails with some error message?

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 6
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 07:45:16 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 4:04:12 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI

            Yun Peng uploaded patch set #7 to this change.

            View Change

            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.

            3. Add an empty feature in MSVC CROSSTOOL to tell Bazel we need PDB file

            4. Add PDB file artifact as an implicit output of cc_binary,
            then you can build the pdb file by bazel build //foo/bar:bin.pdb

            5. Add test for PDB file generation

            Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            ---
            M src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java

            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            6 files changed, 91 insertions(+), 14 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 7

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 4:04:42 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI

            Yun Peng uploaded patch set #8 to this change.

            View Change

            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.

            3. Add an empty feature in MSVC CROSSTOOL to tell Bazel we need PDB file

            4. Add PDB file artifact as an implicit output of cc_binary,
            then you can build the pdb file by bazel build //foo/bar:bin.pdb

            5. Add test for PDB file generation

            Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            ---
            M src/main/java/com/google/devtools/build/lib/bazel/rules/cpp/BazelCppRuleClasses.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java

            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            6 files changed, 96 insertions(+), 14 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 8

            Marcel Hlopko (Gerrit)

            unread,
            Apr 13, 2017, 4:07:33 AM4/13/17
            to Yun Peng, Lukács T. Berki, Dmitry Lomov, Bazel CI

            Marcel Hlopko posted comments on this change.

            View Change

            Patch set 8:

            (1 comment)

              • linkActionBuilder.addActionOutput(pdbFile);
                } else {
                // When the link action doesn't produce the pdb file (no generate_pdb_file feature o

              • Hmm I do not like it very much: we are generating incorrect PDB files... a

              • I don't know the details of output groups based solution, so bear with me :) Does it also share this 'fake action' limitation? Btw, IIRC Dmitry mentioned people do want to generate pdb files for production binaries as well.

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 8
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 08:07:30 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 5:16:01 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

            Yun Peng uploaded patch set #9 to this change.

            View Change

            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.

            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
            ---
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            5 files changed, 84 insertions(+), 13 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 9

            Dmitry Lomov (Gerrit)

            unread,
            Apr 13, 2017, 5:42:52 AM4/13/17
            to Yun Peng, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Dmitry Lomov posted comments on this change.

            View Change

            Patch set 9:

            (1 comment)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 9
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 09:42:46 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 5:44:53 AM4/13/17
            to Dmitry Lomov, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Yun Peng posted comments on this change.

            View Change

            Patch set 6:

            (1 comment)

              • // When the link action doesn't produce the pdb file (no generate_pdb_file feature


              • // or in opt mode), we still need an action for this implicit output.
                ruleContext.registerAction(FileWriteAction.create(ruleContext, pdbFile, "", false));

              • I don't know the details of output groups based solution, so bear with me :

                Discussed with Lukács and Dmitry, we think it's better to use output_group instead of implicit output. And we don't need the `fake action` limitation doing this way. PTAL, again.

                As for pdb files for production binaries, I think it means people should be able to produce pdb file even in OPT mode.
                But pdb file generation is time consuming, so it won't be default in our CROSSTOOL.

                I made some change to not check compilation mode in Java code. So that users can implement their own CROSSTOOL which can produce pdb file in OPT mode.

                For example with following two feature:

                  feature {
                name: 'generate_pdb_file'
                requires: {
                feature: 'opt'
                }
                }
                  feature {
                name: 'opt'
                flag_set {
                action: 'c-compile'
                action: 'c++-compile'
                flag_group {
                flag: "/O2"
                flag: '/MT'
                flag: "/Z7"
                }
                }
                flag_set {
                action: 'c++-link-executable'
                action: 'c++-link-dynamic-library'
                flag_group {
                flag: "/DEBUG:FULL"
                flag: "/INCREMENTAL:NO"
                }
                }
                }

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 6
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 09:44:50 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 5:45:51 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

            Yun Peng uploaded patch set #10 to this change.

            View Change

            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.

            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
            ---
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            5 files changed, 89 insertions(+), 13 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 10

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 5:50:39 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

            Yun Peng uploaded patch set #11 to this change.

            View Change

            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.

            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
            ---
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            5 files changed, 89 insertions(+), 13 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 11

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 5:50:54 AM4/13/17
            to Dmitry Lomov, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Yun Peng posted comments on this change.

            View Change

            Patch set 9:

            (1 comment)

              • Make sense, Done!

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 9
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 09:50:51 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Dmitry Lomov (Gerrit)

            unread,
            Apr 13, 2017, 5:54:14 AM4/13/17
            to Yun Peng, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Dmitry Lomov posted comments on this change.

            View Change

            Patch set 11:

            (2 comments)

              • pLinkAction linkAction = linkActionBuilder.build();
                ruleContext.registerAction(linkAction);
                LibraryToLink outputLibrary = linkAction.getOutputLibrary();

                I think that's cool!

                Some pedantry below:


              • > feature {
                > name: 'opt'
                > flag_set {
                > action: 'c-compile'
                > action: 'c++-compile'
                > flag_group {
                > flag: "/O2"
                > flag: '/MT'
                > flag: "/Z7"

              • They would want to omit this flag...


              • > }
                > }
                > flag_set {
                > action: 'c++-link-executable'
                > action: 'c++-link-dynamic-library'
                > flag_group {
                > flag: "/DEBUG:FULL"

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 11
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 09:54:11 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 7:22:38 AM4/13/17
            to Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

            Yun Peng uploaded patch set #12 to this change.

            View Change

            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
            ---
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
            M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
            M src/test/shell/bazel/bazel_windows_example_test.sh
            M tools/cpp/CROSSTOOL.tpl
            M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
            5 files changed, 91 insertions(+), 13 deletions(-)

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: newpatchset
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 12

            Yun Peng (Gerrit)

            unread,
            Apr 13, 2017, 7:23:02 AM4/13/17
            to Dmitry Lomov, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Yun Peng posted comments on this change.

            View Change

            Patch set 11:

            (1 comment)

              • Patch Set #11, Line 61: assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb -c dbg ${cpp_pkg}:hello-world --output_groups=pdb_file

                Do you want to also assert that '-c opt' does not build a pdb?

              • Done.

            To view, visit change 10090. To unsubscribe, visit settings.

            Gerrit-Project: bazel
            Gerrit-Branch: master
            Gerrit-MessageType: comment
            Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
            Gerrit-Change-Number: 10090
            Gerrit-PatchSet: 11
            Gerrit-Owner: Yun Peng <pcl...@google.com>
            Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
            Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
            Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
            Gerrit-Reviewer: Yun Peng <pcl...@google.com>
            Gerrit-CC: Lukács T. Berki <lbe...@google.com>
            Gerrit-Comment-Date: Thu, 13 Apr 2017 11:22:59 +0000
            Gerrit-HasComments: Yes
            Gerrit-HasLabels: No

            Dmitry Lomov (Gerrit)

            unread,
            Apr 13, 2017, 7:23:50 AM4/13/17
            to Yun Peng, Marcel Hlopko, Lukács T. Berki, Bazel CI

            Dmitry Lomov posted comments on this change.

            View Change

            Patch set 12:Code-Review +1

            Cool!

              To view, visit change 10090. To unsubscribe, visit settings.

              Gerrit-Project: bazel
              Gerrit-Branch: master
              Gerrit-MessageType: comment
              Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
              Gerrit-Change-Number: 10090
              Gerrit-PatchSet: 12
              Gerrit-Owner: Yun Peng <pcl...@google.com>
              Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
              Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
              Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
              Gerrit-Reviewer: Yun Peng <pcl...@google.com>
              Gerrit-CC: Lukács T. Berki <lbe...@google.com>
              Gerrit-Comment-Date: Thu, 13 Apr 2017 11:23:49 +0000
              Gerrit-HasComments: No
              Gerrit-HasLabels: Yes

              Yun Peng (Gerrit)

              unread,
              Apr 13, 2017, 1:13:09 PM4/13/17
              to Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

              Yun Peng uploaded patch set #13 to this change.

              To view, visit change 10090. To unsubscribe, visit settings.

              Gerrit-Project: bazel
              Gerrit-Branch: master
              Gerrit-MessageType: newpatchset
              Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
              Gerrit-Change-Number: 10090
              Gerrit-PatchSet: 13

              Dmitry Lomov (Gerrit)

              unread,
              Apr 13, 2017, 1:37:32 PM4/13/17
              to Yun Peng, Marcel Hlopko, Lukács T. Berki, Bazel CI

              Dmitry Lomov posted comments on this change.

              View Change

              Patch set 13:Code-Review +2

                To view, visit change 10090. To unsubscribe, visit settings.

                Gerrit-Project: bazel
                Gerrit-Branch: master
                Gerrit-MessageType: comment
                Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
                Gerrit-Change-Number: 10090
                Gerrit-PatchSet: 13
                Gerrit-Owner: Yun Peng <pcl...@google.com>
                Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
                Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
                Gerrit-Reviewer: Marcel Hlopko <hlo...@google.com>
                Gerrit-Reviewer: Yun Peng <pcl...@google.com>
                Gerrit-CC: Lukács T. Berki <lbe...@google.com>
                Gerrit-Comment-Date: Thu, 13 Apr 2017 17:37:30 +0000
                Gerrit-HasComments: No
                Gerrit-HasLabels: Yes

                Klaus Aehlig (Gerrit)

                unread,
                Apr 18, 2017, 9:26:44 AM4/18/17
                to Yun Peng, Marcel Hlopko, Dmitry Lomov, Bazel CI, Lukács T. Berki

                Klaus Aehlig uploaded patch set #14 to the change originally created by Yun Peng.

                View Change

                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

                ---
                M src/main/java/com/google/devtools/build/lib/rules/cpp/CcBinary.java
                M src/main/java/com/google/devtools/build/lib/rules/cpp/CppRuleClasses.java
                M src/test/shell/bazel/bazel_windows_example_test.sh
                M tools/cpp/CROSSTOOL.tpl
                M tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
                5 files changed, 90 insertions(+), 13 deletions(-)

                To view, visit change 10090. To unsubscribe, visit settings.

                Gerrit-Project: bazel
                Gerrit-Branch: master
                Gerrit-MessageType: newpatchset
                Gerrit-Change-Id: Ia5096470187ebca72f2c804f32d5b723f40c0b85
                Gerrit-Change-Number: 10090
                Gerrit-PatchSet: 14
                Gerrit-Owner: Yun Peng <pcl...@google.com>
                Gerrit-Reviewer: Bazel CI <ci.b...@gmail.com>
                Gerrit-Reviewer: Dmitry Lomov <dsl...@google.com>
                Gerrit-Reviewer: Klaus Aehlig <aeh...@google.com>

                Klaus Aehlig (Gerrit)

                unread,
                Apr 18, 2017, 9:26:44 AM4/18/17
                to Yun Peng, Dmitry Lomov, Marcel Hlopko, Lukács T. Berki, Bazel CI

                Klaus Aehlig merged this change.

                View Change

                Approvals: Dmitry Lomov: Looks good to me, approved Marcel Hlopko: Looks good to me, approved; Verified Objections: Bazel CI: Fails
                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 9b9ae31..ca98d7b 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 @@
                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 @@
                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 698353a..6cad3de 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 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.
                */
                diff --git a/src/test/shell/bazel/bazel_windows_example_test.sh b/src/test/shell/bazel/bazel_windows_example_test.sh
                index 5f16499..e62dc95 100755
                --- a/src/test/shell/bazel/bazel_windows_example_test.sh
                +++ b/src/test/shell/bazel/bazel_windows_example_test.sh
                @@ -57,6 +57,10 @@
                function test_cpp() {
                local cpp_pkg=examples/cpp
                assert_build_output ./bazel-bin/${cpp_pkg}/libhello-lib.a ${cpp_pkg}:hello-world
                + assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb ${cpp_pkg}:hello-world --output_groups=pdb_file
                + assert_build_output ./bazel-bin/${cpp_pkg}/hello-world.pdb -c dbg ${cpp_pkg}:hello-world --output_groups=pdb_file
                + assert_build -c opt ${cpp_pkg}:hello-world --output_groups=pdb_file
                + test -f ./bazel-bin/${cpp_pkg}/hello-world.pdb && fail "PDB file should not be generated in OPT mode"
                assert_bazel_run "//examples/cpp:hello-world foo" "Hello foo"
                assert_test_ok "//examples/cpp:hello-success_test"
                assert_test_fails "//examples/cpp:hello-fail_test"
                diff --git a/tools/cpp/CROSSTOOL.tpl b/tools/cpp/CROSSTOOL.tpl
                index 60fb955..8bf57e5 100644
                --- a/tools/cpp/CROSSTOOL.tpl
                +++ b/tools/cpp/CROSSTOOL.tpl
                @@ -463,6 +463,16 @@
                }

                feature {
                + name: 'generate_pdb_file'
                + requires: {
                + feature: 'dbg'
                + }
                + requires: {
                + feature: 'fastbuild'
                + }
                + }
                +
                + feature {
                name: 'has_configured_linker_path'
                }

                @@ -641,7 +651,6 @@
                }
                }

                -
                feature {
                name: 'linker_param_file'
                flag_set {
                @@ -664,31 +673,78 @@
                }
                }

                + feature {
                + name: 'dbg'
                + flag_set {
                + action: 'c-compile'
                + action: 'c++-compile'
                + flag_group {
                + flag: "/Od"
                + flag: '/MTd'
                + flag: "/Z7"
                + }
                + }
                + flag_set {
                + action: 'c++-link-executable'
                + action: 'c++-link-dynamic-library'
                + flag_group {
                + flag: "/DEBUG:FULL"
                + flag: "/INCREMENTAL:NO"
                + }
                + }
                + implies: 'generate_pdb_file'
                + }
                +
                + feature {
                + name: 'fastbuild'
                + flag_set {
                + action: 'c-compile'
                + action: 'c++-compile'
                + flag_group {
                + flag: "/Od"
                + flag: '/MT'
                + flag: "/Z7"
                + }
                + }
                + flag_set {
                + action: 'c++-link-executable'
                + action: 'c++-link-dynamic-library'
                + flag_group {
                + flag: "/DEBUG:FASTLINK"
                + flag: "/INCREMENTAL:NO"
                + }
                + }
                + implies: 'generate_pdb_file'
                + }
                +
                + feature {
                + name: 'opt'
                + flag_set {
                + action: 'c-compile'
                + action: 'c++-compile'
                + flag_group {
                + flag: "/O2"
                + flag: '/MT'
                + }
                + }
                + }
                +
                compilation_mode_flags {
                mode: DBG
                - compiler_flag: "/DDEBUG=1"
                - # This will signal the wrapper that we are doing a debug build, which sets
                - # some internal state of the toolchain wrapper. It is intentionally a "-"
                - # flag to make this very obvious.
                - compiler_flag: "-g"
                - compiler_flag: "/Od"
                compiler_flag: "-Xcompilation-mode=dbg"
                linker_flag: "-Xcompilation-mode=dbg"
                }

                compilation_mode_flags {
                mode: FASTBUILD
                - compiler_flag: "/DNDEBUG"
                - compiler_flag: "/Od"
                compiler_flag: "-Xcompilation-mode=fastbuild"
                linker_flag: "-Xcompilation-mode=fastbuild"
                }

                compilation_mode_flags {
                mode: OPT
                - compiler_flag: "/DNDEBUG"
                - compiler_flag: "/O2"
                compiler_flag: "-Xcompilation-mode=opt"
                linker_flag: "-Xcompilation-mode=opt"
                }
                +
                }
                diff --git a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
                index 0695593..127aa87 100644
                --- a/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
                +++ b/tools/cpp/wrapper/bin/pydir/msvc_tools.py.tpl
                @@ -263,8 +263,6 @@
                if arg.startswith('/Fo') or arg.startswith('/Fa') or arg.startswith(
                '/Fi'):
                self.output_file = arg[3:]
                - self.options.append(
                - '/Fd%s.pdb' % self.NormPath(os.path.splitext(self.output_file)[0]))
                if num_matched == 0:
                # Strip out any .a's that have 0 size, they are header or intermediate
                # dependency libraries and don't contain any code. 0-length files are

                To view, visit change 10090. To unsubscribe, visit settings.

                Gerrit-Project: bazel
                Gerrit-Branch: master
                Gerrit-MessageType: merged
                Reply all
                Reply to author
                Forward
                0 new messages