Support C++/CX MSVC language extensions #11199
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
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:
When compiling with
/ZW
, the first error is thatplatform.winmd
andwindows.winmd
files cannot be found. This can be resolved with either/AI
compile flags, or by setting up theLIBPATH
environment variable and using--action_env=LIBPATH
. In my prototyping, I set upLIBPATH
(by callingvcvarsall.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:Bazel parses these files, and HeaderDiscovery.java does some inclusion checks, and errors:
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.
The text was updated successfully, but these errors were encountered: