当我使用 bazel 从 midl 文件生成 c++ 头源代码和 winmd 文件时,我发现 MyType.winmd 文件位于输出文件夹中,而 MyType.h 与源代码 MyType.idl 位于同一目录中。我想要的是我生成的头文件与 MyType.winmd 文件位于同一文件夹中。
我的类型.idl:
namespace NS
{
[default_interface]
runtimeclass MyType
{
}
}
建造:
load(":cmd.bzl", "midl")
sh_binary(
name = "midlCmd.bat",
srcs = ["midl.bat"],
)
midl(
name = "midlcc.bat",
idl = "MyType.idl",
winmd = "MyType.winmd",
)
cmd.bzl:
def _impl(ctx):
winmd = ctx.outputs.winmd
idl = ctx.file.idl
ctx.actions.run(
inputs = [idl],
outputs = [winmd],
arguments = [winmd.path, idl.path],
progress_message = "Generate winmd from idl file: %s" % idl,
executable = ctx.executable.code_gen_tool,
)
midl = rule(
implementation = _impl,
output_to_genfiles = True,
attrs = {
"idl": attr.label(allow_single_file = True, mandatory = True),
"winmd": attr.output(mandatory = True),
"code_gen_tool": attr.label(
executable = True,
cfg = "exec",
allow_files = True,
default = Label("//cmd:midlCmd.bat"),
),
},
)
midl.bat:
"C:\Program Files (x86)\Windows Kits\10\bin\10.0.20206.0\x64\midl.exe" ^
/metadata_dir "%WindowsSdkDir%References\%WindowsSDKVersion%Windows.Foundation.FoundationContract\4.0.0.0" ^
/reference "%WindowsSdkDir%References\%WindowsSDKVersion%Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd" ^
/cpp_cmd "C:\PROGRA~2\MICROS~1\2019\Community\VC\Tools\MSVC\14.28.29333\bin\Hostx64\x64\cl.exe" ^
/notlb ^
/winrt ^
/nomidl ^
/nologo ^
/enum_class ^
/ns_prefix ^
/client none ^
/server none ^
/winmd %1 %2
运行命令:
bazel build //cmd:all
在此处生成 MyType.h:
C:\Users\songy\source\repos\tuware\cmd>dir
Directory of C:\Users\songy\source\repos\tuware\cmd
2020-12-02 10:41 PM <DIR> .
2020-12-02 10:40 PM <DIR> ..
2020-12-02 10:41 PM 188 BUILD
2020-12-02 10:33 PM 746 cmd.bzl
2020-12-02 10:30 PM 10,975 midl.bat
2020-12-02 10:41 PM 6,987 MyType.h
2020-11-02 08:41 PM 82 MyType.idl
生成的 MyType.winmd 在这里:
C:\Users\songy\source\repos\tuware\bazel-bin\cmd>dir
2020-12-02 10:30 PM 10,975 midlCmd.bat
2020-12-02 10:40 PM <DIR> midlCmd.bat.runfiles
2020-12-02 10:40 PM 247 midlCmd.bat.runfiles_manifest
2020-12-02 10:41 PM 1,536 MyType.winmd
2020-12-02 10:40 PM <DIR> setupCppDesktopDevEnvironment.bat.runfiles
2020-12-02 10:40 PM 293 setupCppDesktopDevEnvironment.bat.runfiles_manifest
有什么我想念的吗?