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

Support C++/CX MSVC language extensions #11199

Closed
kjteske opened this issue Apr 22, 2020 · 3 comments
Closed

Support C++/CX MSVC language extensions #11199

kjteske opened this issue Apr 22, 2020 · 3 comments
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) platform: windows stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request

Comments

@kjteske
Copy link
Contributor

kjteske commented Apr 22, 2020

Description of the problem / feature request:

Support for Windows C++/CX MS extensions for C++ files, i.e. with the /ZW compilation flag passed to MSVC's cl.exe.

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

Enable building C++ libraries using C++/CX and producing .winmd files.

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

Add the '/ZW' flag and attempt to build with Bazel's built-in MSVC
toolchain.

Example repo at https://github.com/kjteske/bazel_cppcx_example.

What operating system are you running Bazel on?

Windows 10.

What's the output of bazel info release?

release 3.1.0

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

N/A

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

N/A

Have you found anything relevant by searching the web?

No.

Any other information, logs, or outputs that you want to share?

I've got a few notes on what Compiling/Linking would look like in
a solution.

Compiling

Adding the /ZW flag to MSVC enables Microsoft extensions for interop with C#, and requires #using .winmd files provided by Visual Studio (or at least implicit #using commands done by the compiler). This is similar to #include for a regular header files.
Example common required winmd files:

  • C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.25.28610/lib/x86/store/references/platform.winmd
  • C:/Program Files (x86)/Windows Kits/10/UnionMetadata/10.0.18362.0/windows.winmd

When compiling with /ZW, the first error is that platform.winmd and windows.winmd files cannot be found. This can be resolved with either /AI compile flags, or by setting up the LIBPATH environment variable and using --action_env=LIBPATH. In my prototyping, I set up LIBPATH (by calling vcvarsall.bat), which gets us a little further along. Now, we can successfully finish compiling, but get caught by Bazel's dependency checks that parse 'including file' outputs due to MSVC's /showIncludes flag that Bazel turns on (and can't be disabled). MSVC will output something like this at the end of the compilation:

Note: including file: c:\program files (x86)\microsoft visual studio\2019\professional\vc\tools\msvc\14.24.28314\lib\x86\store\references\platform.winmd
Note: including file: c:\program files (x86)\windows kits\10\unionmetadata\10.0.17763.0\windows.winmd
Note: including file: C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Professional\\VC\\Tools\\MSVC\\14.24.28314\\include\vccorlib.h

Bazel parses these files, and HeaderDiscovery.java does some inclusion checks, and errors:

ERROR: C:/users/kyle/dev/bazel_cppcx_example/BUILD:1:1: undeclared inclusion(s) in rule '//:cppcx_example':
this rule is missing dependency declarations for the following files included by 'Example.cpp':
  'C:/program files (x86)/microsoft visual studio/2019/professional/vc/tools/msvc/14.25.28610/lib/x86/store/references/platform.winmd'
  'C:/program files (x86)/windows kits/10/unionmetadata/10.0.18362.0/windows.winmd'

To avoid this error, I think we would want to permit the directories containing the winmd files, similar to how system include prefixes are permitted and Bazel doesn't error on seeing vccorlib.h here. This doesn't sound too hard to create a patch for.

Ideally, we wouldn't have to set up LIBPATH either. Maybe this could be implemented with features to pass appropriate /AI flags?

Linking & Output

We would also want to support the /WINMDFILE linker option so we can produce a .winmd file from the library, and include this in the Bazel outputs.

Interest?

Is there any interest in this feature, or would maintainers be willing to take a look at a PR or give some recommendations on how to implement support? Does this make sense to go into Bazel/rules_cc proper, or a separate toolchain outside of Bazel? Since this would re-use so much of the existing MSVC toolchain support in Bazel, I think this would be much easier to maintain if in Bazel/rules_cc.

@aiuto aiuto added team-Rules-CPP Issues for C++ rules untriaged labels Apr 23, 2020
@oquenchil oquenchil added P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) platform: windows type: feature request and removed untriaged labels May 11, 2020
@ianier
Copy link

ianier commented Nov 7, 2020

Compiling for WinRT with Bazel is currently possible with workarounds (e.g. see what we've done for tensorflow-cc at microsoft/vcpkg#14252).

As mentioned there, Bazel calls VCVARSALL.BAT in windows_cc_configure.bzl to set the INCLUDE/LIB environment vars. While VCVARSALL.BAT supports specifying the environment type (e.g. VCVARSALL.BAT amd64 store), it looks like this is not foreseen in the current implementation of windows_cc_configure.bzl, by looking at the code.

BTW, it would also be great to support arm64 as a cross-compilation target.

@github-actions
Copy link

github-actions bot commented Apr 7, 2023

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 2+ 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 Apr 7, 2023
@github-actions
Copy link

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4 This is either out of scope or we don't have bandwidth to review a PR. (No assignee) platform: windows stale Issues or PRs that are stale (no activity for 30 days) team-Rules-CPP Issues for C++ rules type: feature request
Projects
None yet
Development

No branches or pull requests

4 participants