Bazel: Windows: support resource compilation

Created on 9 May 2019  路  9Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Support compiling .rc files on Windows. The resource compiler is part of the Windows SDK.

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

To support compiling resources (icons, string tables, version info, etc.) on Windows to object files, and linking them into C++ binaries.

What operating system are you running Bazel on?

Windows

What's the output of bazel info release?

0.25.0

P3 area-Windows team-XProduct feature request

All 9 comments

Important to know: the resource compiler (rc.exe) is in the Windows SDK, not in MSVC.

Useful info from @meteorcloudy : https://github.com/bazelbuild/bazel/commit/a3dd7775d2dbf7e4368712626e11c15be7a23efd#diff-457360df3a98d4f91f49ccc5c8f3b35a has exposed functions we could use to find the Windows SDK and the resource compiler within, and implement a Starlark rule to compile resources.

We could put the Starlark rule into https://github.com/bazelbuild/rules_cc.

@meteorcloudy : could you briefly explain how to fix this? I think you have the most expertise.
I understand windows_cc_configure now knows where the Windows SDK is (https://github.com/bazelbuild/bazel/commit/8167f46ce53201ca3d725b6262c6b9e31dac2f13), but how to go from there? Is the SDK path recorded in the cc toolchain somehow? How would a custom rule find out the SDK path (and thus the rc.exe path)?

This is actually an internal rule we could open source to rules_cc, search for msvc/build_windows.bzl

Status:

Removing 1.0 label because this rule will be out of Bazel core.

Is this meant to be in 2.0.0?

$ bazel query @bazel_tools//src/main/res:win_res.bzl
Loading: 0 packages loaded
ERROR: no such package '@bazel_tools//src/main/res': BUILD file not found in directory 'src/main/res' of external repository @bazel_tools. Add a BUILD file to a directory to mark it as a package.
Loading: 0 packages loaded
Loading: 0 packages loaded

and

$ bazel build //:app_resources
Loading:
Loading: 0 packages loaded
ERROR: Skipping '//:app_resources': error loading package '': Label '@bazel_tools//src/main/res:win_res.bzl' is invalid because 'src/main/res' is not a package; perhaps you meant to put the colon here: '@bazel_tools//src:main/res/win_res.bzl'?
WARNING: Target pattern parsing failed.
ERROR: error loading package '': Label '@bazel_tools//src/main/res:win_res.bzl' is invalid because 'src/main/res' is not a package; perhaps you meant to put the colon here: '@bazel_tools//src:main/res/win_res.bzl'?
INFO: Elapsed time: 0.131s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
FAILED: Build did NOT complete successfully (1 packages loaded)

Looks like ~/_bazel_${USER}/install/*/embedded_tools/src/main contains just cpp, native and protobuf directories. I understand this is meant to go into rules_cc, but until it goes there, can the rule be released anyway? As it is, it's not very useful.

No, it's not meant to be in @bazel_tools in 2.0.0. The rule only exists in Bazel's source tree.

I understand that the rule isn't generally useful in its current state, but due to changed priorities I'm no longer planning to move it to rules_cc, sorry.

@ivucica , I recommend copying the rule to your source tree. It should work. If you (or someone else) wants to move it to rules_cc for everyone's benefit, then please send a PR to rules_cc.

Was this page helpful?
0 / 5 - 0 ratings