Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC toolchain requiring parse_showinclude feature is not documented #13220

Closed
limdor opened this issue Mar 14, 2021 · 18 comments
Closed

MSVC toolchain requiring parse_showinclude feature is not documented #13220

limdor opened this issue Mar 14, 2021 · 18 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)

Comments

@limdor
Copy link
Contributor

limdor commented Mar 14, 2021

Description of the problem:

When trying to build a cc_library using a custom msvc 2019 toolchain that is the same like the autodetected one, but without /showInclude options, it does not build and shows the following error:
ERROR: C:/users/xavib/documents/development/quoniam/src/example/BUILD:3:11: Compiling src/example/library.cpp failed: error while parsing .d file: C:\users\xavib\_bazel_xavib\3r2w35xj\execroot\__main__\bazel-out\x64_windows-fastbuild\bin\src\example\_objs\example\library.d (The system cannot find the file specified)
If I add /showInclude in the manually declared toolchain, then it works.

Feature requests: what underlying problem are you trying to solve with this feature?

I want to have the same toolchain explicitly declared but I want to remove the /showInclude option

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Create toolchain like the autodetected one in Windows with Visual studio 2019, and remove the /showInclude options. Here is the one that I used: limdor/quoniam@8605cd3

What operating system are you running Bazel on?

Windows

What's the output of bazel info release?

4.0.0

Have you found anything relevant by searching the web?

I tried to check where this error about parsing .d files is comming from, and this seems to come from Bazel, and not from Visual Studio: https://github.com/bazelbuild/bazel/search?q=%22error+while+parsing+.d+file%22
The most interesting part is in this part of the code, it seems that the behavior is different if /showInclude is specified or not, maybe someone familiar with the code can say what is the reason for that.

// output of cl.exe caused by /showIncludes option.

@meteorcloudy
Copy link
Member

Enabling the /showincludes feature is required for MSVC toolchain, because Bazel uses the output to check if the headers included are declared as input. So this failure is WAI.

@limdor
Copy link
Contributor Author

limdor commented Mar 15, 2021

https://docs.bazel.build/versions/master/windows.html#build-c-with-msvc does not mention anything about it. Is it mentioned somewhere else? How is supposed the user know about it?
If that is intended, would it be ok if I create a feature request at least to show that this is missing?

@meteorcloudy
Copy link
Member

If that is intended, would it be ok if I create a feature request at least to show that this is missing?

To report this feature is missing, Bazel has to know if you are using MSVC or mingw-gcc/msys-gcc in advance. Because it's only required for MSVC. I don't think Bazel should try to identify what exact compiler the toolchain is using.

But we definitely could use better documentation about this for users who want to write their own custom toolchain. Feel free to open an issue or PR for this! ;)

limdor added a commit to limdor/bazel that referenced this issue Mar 19, 2021
MSVC is not working in Bazel if showIncludes is not declared bazelbuild#13220
@limdor
Copy link
Contributor Author

limdor commented Mar 19, 2021

@meteorcloudy I created this PR to extend the documentation #13247

Could you elaborate a bit more on what is the problem? Is it in the rules_cc or in Bazel itself? I would not expect Bazel the need to know about the compiler. What would happen if I want to add a custom C++ compiler? Would this not be possible or it would only be possible without using the cc_toolchain?
Just asking because if that is the case it would also be good to add something in the documentation stating what compilers are supported for C++ and what should be done in case that someone wants to add another compiler that is not supported.

@meteorcloudy
Copy link
Member

meteorcloudy commented Mar 22, 2021

So with gcc style compilers, Bazel depends on the compiler to output a dependency file that declares what actual header files used for the compiling action, see this.

But this feature is not available in MSVC. Instead, MSVC provides this information by printing out the dependencies in stdout (/showIncludes). So basically, the parse_showinclude feature is an equivalent of the dependency_file feature for the MSVC toolchain.

If the parse_showinclude feature is enabled in the toolchain, Bazel tries to discover dependencies by parsing the stdout of MSVC, otherwise it tries to read the dot d file generated by gcc style compiler.
See

if (featureConfiguration.isEnabled(CppRuleClasses.PARSE_SHOWINCLUDES)) {

The problem you encounter here is that when you remove the parse_showinclude feature, Bazel assume the compiler will produce the dot d file, but in fact it still uses MSVC which doesn't generate that file.

@limdor
Copy link
Contributor Author

limdor commented Mar 22, 2021

This java code is part of Bazel, but this is part of rules cpp. Is this part of the code that in the long term should go in rules_cc in starlark? If that is the case, everything start making sense now.

Should I create another ticket for the documentation or what would be your proposal? Seems that it is not obvious where to document it.

@meteorcloudy
Copy link
Member

This java code is part of Bazel, but this is part of rules cpp. Is this part of the code that in the long term should go in rules_cc in starlark? If that is the case, everything start making sense now.

Yes, you're right. The reason it's in Java is because C++ rules are still native rules. In the long term, they will be starlarkified.

Should I create another ticket for the documentation or what would be your proposal? Seems that it is not obvious where to document it.

Yeah, maybe adding it here: https://docs.bazel.build/versions/master/tutorial/cc-toolchain-config.html ?

@meteorcloudy meteorcloudy reopened this Mar 23, 2021
@meteorcloudy meteorcloudy changed the title Cannot build with MSVC 2019 if /showIncludes is not specified MSVC toolchain requiring parse_showinclude feature is not documented Mar 23, 2021
@limdor
Copy link
Contributor Author

limdor commented Mar 29, 2021

@aiuto @meteorcloudy thanks for your feedback. I will continue the discussion here.

As for creating a toolchain for MSVC, maybe https://github.com/meteorcloudy/my_tests/tree/master/preconfigure_msvc_toolchain can help? Instead of writing one entirely from scratch, maybe you can start with the auto generated one?

I will take a look, seems like a good starting point, in the end this is exactly what I was looking for when I created #12767

Perhaps the two of you can pair up to turn that private test into a public
sample in the examples repository.

Fine for me, however I'm doing this during my free time, not sure when I will finish it. At work I am only working on Linux.
My plan was:

  1. Get a manually configured toolchain working on a project (I took a personal project that is small enough to play around but big enough to check if would scale https://github.com/limdor/quoniam/pull/83/files)
  2. Prepare a Bazel example explaining how to create a MSVC toolchain taking as a reference the autodetected one (https://github.com/limdor/bazel-examples)
  3. Check how can I port it in some place of the official Bazel documentation. For the moment I had this private repository because I did not know where to put it and how much Bazel wants to maintain a big set of examples.

If you can tell me a bit more about number 3 would be great, I could event prepare porting some of the ones that I currently have if the community is interested.

@meteorcloudy
Copy link
Member

Maybe https://github.com/bazelbuild/examples is a good place to store those examples?
Tutorials can be put at https://github.com/bazelbuild/bazel/tree/master/site/docs/tutorial

@limdor
Copy link
Contributor Author

limdor commented Apr 4, 2021

Thanks, I will see if I can put them somewhere there, for the moment I will play around in my repo and once I have it ready I will create the PR.
Create the toolchain from the generated one was easy, now the problem is to make use of the toolchain without crosstool_top and making sure that the generated one is not available and not selected.
#7260 (comment)

@meteorcloudy
Copy link
Member

Sounds good!

making sure that the generated one is not available and not selected.

Check the BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN env var.
https://github.com/bazelbuild/bazel/blob/master/tools/cpp/cc_configure.bzl#L49

@gregestren gregestren added the team-Rules-CPP Issues for C++ rules label Apr 15, 2021
@limdor
Copy link
Contributor Author

limdor commented Apr 18, 2021

Thanks for the support @meteorcloudy, I manage to create the example for linux, now I will do the same for Windows also and then we can see where would be the place to put them in the Bazel repo.
https://github.com/limdor/bazel-examples/tree/master/linux_toolchain

@meteorcloudy
Copy link
Member

Wow, that's some really nice documentation! Thank you so much!

@meteorcloudy
Copy link
Member

/cc @oquenchil probably can help with reviewing it.

@oquenchil oquenchil added the P3 We're not considering working on this, but happy to review a PR. (No assignee) label May 31, 2021
@github-actions
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label May 10, 2023
@limdor
Copy link
Contributor Author

limdor commented May 10, 2023

@bazelbuild/triage please keep

@sgowroji sgowroji removed the stale Issues or PRs that are stale (no activity for 30 days) label May 10, 2023
Copy link

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 90 days unless any other activity occurs. If you think this issue is still relevant and should stay open, please post any comment here and the issue will no longer be marked as stale.

@github-actions github-actions bot added the stale Issues or PRs that are stale (no activity for 30 days) label Jul 14, 2024
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please post @bazelbuild/triage in a comment here and we'll take a look. Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: support / not a bug (process)
Projects
None yet
Development

No branches or pull requests

6 participants