├── .gitattributes ├── WORKSPACE ├── deps_scanner.bat.tpl ├── cmd_helper.tpl ├── BUILD.bazel ├── ewdk_extension.bzl ├── MODULE.bazel ├── LICENSE ├── arm_asm.bat.tpl ├── BUILD.no_ewdk ├── ewdk_command.bzl ├── resource_toolchain.bzl ├── wpp_toolchain.bzl ├── idl_toolchain.bzl ├── c_cpp_properties.tpl ├── README.md ├── BUILD.ewdk.toolchains.tpl └── ewdk_cc_configure.bzl /.gitattributes: -------------------------------------------------------------------------------- 1 | BUILD.ewdk.toolchains.tpl linguist-language=starlark 2 | c_cpp_properties.tpl linguist-language=json 3 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | workspace(name = "ewdk_cc_toolchain") -------------------------------------------------------------------------------- /deps_scanner.bat.tpl: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal 3 | set DEPS_SCANNER_OUTPUT_FILE=%DEPS_SCANNER_OUTPUT_FILE:"=% 4 | "%{cl_path}" /TP /scanDependencies "%DEPS_SCANNER_OUTPUT_FILE%" %* 5 | -------------------------------------------------------------------------------- /cmd_helper.tpl: -------------------------------------------------------------------------------- 1 | @echo off 2 | set EWDK_PATH=%{path} 3 | set EWDK_INCLUDE=%{include} 4 | set EWDK_EXTERNAL_INCLUDE=%{external_include} 5 | set EWDK_LIBPATH=%{libpath} 6 | set EWDK_LIB=%{lib} 7 | -------------------------------------------------------------------------------- /BUILD.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | exports_files( 5 | glob( 6 | ["*"], 7 | exclude = ["BUILD.bazel"], 8 | ), 9 | ) 10 | -------------------------------------------------------------------------------- /ewdk_extension.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | load("//:ewdk_cc_configure.bzl", "ewdk_cc_autoconf_toolchains") 5 | 6 | toolchains = module_extension( 7 | implementation = lambda ctx: ewdk_cc_autoconf_toolchains(name = "ewdk_toolchains") 8 | ) 9 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | module( 5 | name = "ewdk_cc_toolchains", 6 | version = "1.0.12", 7 | compatibility_level = 1, 8 | ) 9 | 10 | bazel_dep(name = "rules_cc", version = "0.1.1") 11 | bazel_dep(name = "platforms", version = "0.0.11") 12 | 13 | toolchains = use_extension("//:ewdk_extension.bzl", "toolchains") 14 | use_repo(toolchains, ewdk_cc = "ewdk_toolchains") 15 | register_toolchains("@ewdk_cc//:all") 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 Ira Strawser 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /arm_asm.bat.tpl: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enableextensions 3 | 4 | set userargs= 5 | set incdirs= 6 | set cl_incdirs= 7 | set state= 8 | set output= 9 | set input= 10 | set cl_arm64ec= 11 | 12 | shift 13 | :parse_args 14 | set arg=%~0 15 | REM This argument forced in cc rules from bazel breaks the following if statement 16 | if "%arg:~0,26%"=="/DBAZEL_CURRENT_REPOSITORY" goto next_arg 17 | if "%0"=="" ( 18 | goto done_args 19 | ) 20 | if "%state%"=="out" ( 21 | set output=%arg% 22 | set state= 23 | goto next_arg 24 | ) 25 | if "%state%"=="in" ( 26 | set input=%arg% 27 | set state= 28 | goto next_arg 29 | ) 30 | if "%arg:~0,2%"=="/I" ( 31 | set cl_incdirs=%cl_incdirs% %0 32 | if "%incdirs%"=="" ( 33 | set incdirs=%arg:~2% 34 | ) else ( 35 | set incdirs=%incdirs%;%arg:~2% 36 | ) 37 | goto next_arg 38 | ) 39 | if "%arg%"=="/Fo" ( 40 | set state=out 41 | goto next_arg 42 | ) 43 | if "%arg%"=="/Ta" ( 44 | set state=in 45 | goto next_arg 46 | ) 47 | if /i "%arg%"=="/nologo" set arg=-nologo 48 | if /i "%arg%"=="/zh:sha_256" set arg=-gh:SHA256 49 | if /i "%arg%"=="/machine:arm64ec" ( 50 | set arg=-machine ARM64EC 51 | set cl_arm64ec=/D_ARM64EC_ /arm64EC 52 | ) 53 | if "%arg:~0,1%"=="-" ( 54 | set userargs=%userargs% %arg% 55 | goto next_arg 56 | ) 57 | if not "%arg:~0,1%"=="/" ( 58 | set input=%arg% 59 | goto next_arg 60 | ) 61 | :next_arg 62 | shift 63 | goto parse_args 64 | :done_args 65 | 66 | if not "%incdirs%"=="" ( 67 | set incdirs=-i "%incdirs%" 68 | ) 69 | 70 | "%{cl_path}" /nologo /c /P %cl_arm64ec% %cl_incdirs% /Fi"%output%.preprocessed.asm" /TC "%input%" && ( 71 | "%{armasm_path}"%userargs% %incdirs% "%output%.preprocessed.asm" "%output%" 72 | ) || ( 73 | exit 1 74 | ) 75 | -------------------------------------------------------------------------------- /BUILD.no_ewdk: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2023 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | # EWDKDIR envvar not set. Toolchains unavailable. 5 | 6 | load(":ewdk_cc_configure.bzl", "ewdk_cc_toolchain_config", "empty") 7 | load(":resource_toolchain.bzl", "resource_script_toolchain_config") 8 | load(":wpp_toolchain.bzl", "wpp_toolchain_config") 9 | load(":idl_toolchain.bzl", "idl_toolchain_config") 10 | load(":ewdk_command.bzl", "ewdk_command_config") 11 | 12 | constraint_setting( 13 | name = "ewdk_toolchain", 14 | visibility = ["//visibility:public"], 15 | ) 16 | 17 | constraint_value( 18 | name = "ewdk_cc", 19 | constraint_setting = ":ewdk_toolchain", 20 | visibility = ["//visibility:public"], 21 | ) 22 | 23 | empty(name = "empty") 24 | 25 | toolchain_type( 26 | name = "resource_script_toolchain_type", 27 | visibility = ["//visibility:public"], 28 | ) 29 | 30 | toolchain_type( 31 | name = "wpp_toolchain_type", 32 | visibility = ["//visibility:public"], 33 | ) 34 | 35 | toolchain_type( 36 | name = "idl_toolchain_type", 37 | visibility = ["//visibility:public"], 38 | ) 39 | 40 | toolchain_type( 41 | name = "ewdk_command_type", 42 | visibility = ["//visibility:public"], 43 | ) 44 | 45 | # bazel 5.x requires toolchains to still be registered before target_compatible_with is checked. 46 | # cc toolchains don't have this issue. 47 | 48 | resource_script_toolchain_config( 49 | name = "resource_script_toolchain", 50 | rcpath = ":empty", 51 | ) 52 | 53 | toolchain( 54 | name = "resource-script-toolchain", 55 | toolchain = ":resource_script_toolchain", 56 | toolchain_type = ":resource_script_toolchain_type", 57 | ) 58 | 59 | wpp_toolchain_config( 60 | name = "wpp_toolchain", 61 | tracewpp_path = ":empty", 62 | cfgdir = "", 63 | ) 64 | 65 | toolchain( 66 | name = "wpp-toolchain", 67 | toolchain = ":wpp_toolchain", 68 | toolchain_type = ":wpp_toolchain_type", 69 | ) 70 | 71 | idl_toolchain_config( 72 | name = "idl_toolchain", 73 | midl_path = ":empty", 74 | ) 75 | 76 | toolchain( 77 | name = "idl-toolchain", 78 | toolchain =":idl_toolchain", 79 | toolchain_type = ":idl_toolchain_type", 80 | ) 81 | 82 | ewdk_command_config( 83 | name = "ewdk_command_toolchain", 84 | command_path = ":empty", 85 | ) 86 | 87 | toolchain( 88 | name = "ewdk-command-toolchain", 89 | toolchain = ":ewdk_command_toolchain", 90 | toolchain_type = ":ewdk_command_type", 91 | ) 92 | -------------------------------------------------------------------------------- /ewdk_command.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2023 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Run an ewdk command with correct environment""" 5 | 6 | EwdkCommandInfo = provider( 7 | doc = "Toolchain for running any ewdk command with correct environment set", 8 | fields = ["command_path", "launch_env"], 9 | ) 10 | 11 | def _ewdk_command_config_impl(ctx): 12 | toolchain_info = platform_common.ToolchainInfo( 13 | idlinfo = EwdkCommandInfo( 14 | command_path = ctx.executable.command_path, 15 | launch_env = ctx.attr.launch_env, 16 | ), 17 | ) 18 | return toolchain_info 19 | 20 | ewdk_command_config = rule( 21 | implementation = _ewdk_command_config_impl, 22 | attrs = { 23 | "command_path": attr.label( 24 | allow_files = True, 25 | executable = True, 26 | cfg = "target", 27 | ), 28 | "launch_env": attr.string_dict(default = {}), 29 | }, 30 | ) 31 | 32 | def _parse_args(cmd): 33 | args = [] 34 | curarg = [] 35 | state = 0 # 0 = between args, 1 = in quoted arg, 2 = in non-quoted arg 36 | prev = '' 37 | 38 | for _ in range(len(cmd)): 39 | c, cmd = cmd[:1], cmd[1:] 40 | if state == 0: 41 | if c == '"': 42 | state = 1 43 | continue 44 | elif c != ' ': 45 | state = 2 46 | else: 47 | prev = c 48 | continue 49 | 50 | if (c == '"' and state == 1) or (c == ' ' and state == 2): 51 | if prev != '`': 52 | args.append(''.join(curarg)) 53 | state, prev, curarg = 0, c, [] 54 | continue 55 | 56 | if c == '`': 57 | if prev != '`': 58 | prev = c 59 | continue 60 | 61 | curarg.append(c) 62 | prev = c 63 | 64 | return args 65 | 66 | def _impl(ctx): 67 | tc = ctx.toolchains["@ewdk_cc//:ewdk_command_type"].idlinfo 68 | 69 | args = [] 70 | for x in _parse_args(ctx.attr.cmd): 71 | nx = ctx.expand_location(x, ctx.attr.srcs) 72 | if nx != x: 73 | nx = nx.replace("/", "\\") 74 | args.append(nx) 75 | 76 | ctx.actions.run( 77 | inputs = ctx.files.srcs, 78 | outputs = ctx.outputs.outs, 79 | env = tc.launch_env, 80 | executable = tc.command_path, 81 | arguments = args, 82 | mnemonic = "EwdkCommand", 83 | ) 84 | 85 | return [ 86 | DefaultInfo(files = depset(ctx.outputs.outs)), 87 | ] 88 | 89 | ewdk_command = rule( 90 | implementation = _impl, 91 | attrs = { 92 | "srcs": attr.label_list( 93 | mandatory = True, 94 | allow_files = True, 95 | ), 96 | "outs": attr.output_list( 97 | mandatory = True, 98 | allow_empty = False, 99 | ), 100 | "cmd": attr.string(mandatory = True), 101 | }, 102 | toolchains = ["@ewdk_cc//:ewdk_command_type"], 103 | ) 104 | -------------------------------------------------------------------------------- /resource_toolchain.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Defines a simple toolchain for windows resource scripts""" 5 | 6 | ResourceScriptCompilerInfo = provider( 7 | doc = "Toolchain for windows resource scripts", 8 | fields = ["rcpath", "env", "defines"], 9 | ) 10 | 11 | def _rc_toolchain_impl(ctx): 12 | toolchain_info = platform_common.ToolchainInfo( 13 | rcinfo = ResourceScriptCompilerInfo( 14 | rcpath = ctx.executable.rcpath, 15 | env = ctx.attr.env, 16 | defines = ctx.attr.defines, 17 | ), 18 | ) 19 | return toolchain_info 20 | 21 | resource_script_toolchain_config = rule( 22 | attrs = { 23 | "rcpath": attr.label( 24 | allow_files = True, 25 | executable = True, 26 | cfg = "target", 27 | ), 28 | "env": attr.string_dict(default = {}), 29 | "defines": attr.string_list(default = []), 30 | }, 31 | implementation = _rc_toolchain_impl, 32 | ) 33 | 34 | def _build_feature_flags(ctx): 35 | features = {} 36 | for feat in ctx.features: 37 | features[feat] = 1 38 | if not features.get("opt") and not features.get("dbg") and not features.get("fastbuild"): 39 | features[ctx.var.get("COMPILATION_MODE")] = 1 40 | 41 | ret = [] 42 | for feature in features.keys(): 43 | if feature == "opt": 44 | ret.append("/DNDEBUG") 45 | elif feature == "dbg" or feature == "fastbuild": 46 | ret += ["/D_DEBUG", "/DDBG=1"] 47 | return ret 48 | 49 | def _compile_rc(ctx, tc): 50 | output = ctx.actions.declare_file(ctx.file.rcfile.basename + ".res") 51 | 52 | inputs = [ctx.file.rcfile] 53 | for x in ctx.attr.deps: 54 | inputs += x.files.to_list() 55 | 56 | feature_flags = _build_feature_flags(ctx) 57 | 58 | # the script must be last on the command line 59 | ctx.actions.run( 60 | inputs = inputs, 61 | outputs = [output], 62 | env = tc.env, 63 | executable = tc.rcpath, 64 | arguments = ["/nologo", "/fo", output.path, "/I."] + tc.defines + ctx.attr.rcopts + feature_flags + [ctx.file.rcfile.path], 65 | mnemonic = "ResourceScript", 66 | ) 67 | return output 68 | 69 | def _resource_script_impl(ctx): 70 | tc = ctx.toolchains["@ewdk_cc//:resource_script_toolchain_type"].rcinfo 71 | 72 | files = [_compile_rc(ctx, tc)] 73 | linker_input = cc_common.create_linker_input( 74 | owner = ctx.label, 75 | additional_inputs = depset(files), 76 | user_link_flags = depset([res.path for res in files]), 77 | ) 78 | linker_ctx = cc_common.create_linking_context(linker_inputs = depset([linker_input])) 79 | return [ 80 | DefaultInfo(files = depset(files)), 81 | CcInfo(linking_context = linker_ctx), 82 | ] 83 | 84 | resource_script = rule( 85 | implementation = _resource_script_impl, 86 | attrs = { 87 | "rcfile": attr.label( 88 | mandatory = True, 89 | allow_single_file = [".rc"], 90 | ), 91 | "rcopts": attr.string_list(default = []), 92 | "deps": attr.label_list(allow_files = True), 93 | }, 94 | fragments = ["cpp"], 95 | toolchains = ["@ewdk_cc//:resource_script_toolchain_type"], 96 | ) 97 | -------------------------------------------------------------------------------- /wpp_toolchain.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2023 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Defines a simple toolchain for windows WPP tracing""" 5 | 6 | WppCompilerInfo = provider( 7 | doc = "Toolchain for windows WPP tracing", 8 | fields = ["tracewpp_path", "env", "cfgdir"], 9 | ) 10 | 11 | def _wpp_toolchain_config_impl(ctx): 12 | toolchain_info = platform_common.ToolchainInfo( 13 | wppinfo = WppCompilerInfo( 14 | tracewpp_path = ctx.executable.tracewpp_path, 15 | env = ctx.attr.env, 16 | cfgdir = ctx.attr.cfgdir, 17 | ), 18 | ) 19 | return toolchain_info 20 | 21 | wpp_toolchain_config = rule( 22 | implementation = _wpp_toolchain_config_impl, 23 | attrs = { 24 | "tracewpp_path": attr.label( 25 | allow_files = True, 26 | executable = True, 27 | cfg = "target", 28 | ), 29 | "env": attr.string_dict(default = {}), 30 | "cfgdir": attr.string(), 31 | }, 32 | ) 33 | 34 | def _compile_wpp(ctx, tc, cfg, input, output): 35 | output_file = ctx.actions.declare_file(output) 36 | raw_path = output_file.path.replace("/", "\\") 37 | args = [ 38 | raw_path[:-len(output_file.extension)], 39 | raw_path, 40 | "-scan:" + cfg.path.replace("/", "\\"), 41 | "-cfgdir:" + tc.cfgdir, 42 | "-odir:" + output_file.dirname.replace("/", "\\") + "\\", 43 | ] 44 | if ctx.attr.kernel: 45 | args.append("-km") 46 | elif ctx.attr.dll: 47 | args.append("-dll") 48 | args.append(input.path.replace("/", "\\")) 49 | 50 | ctx.actions.run( 51 | inputs = [cfg, input], 52 | outputs = [output_file], 53 | env = tc.env, 54 | executable = tc.tracewpp_path, 55 | arguments = args, 56 | mnemonic = "WppTraceHeader", 57 | ) 58 | 59 | return output_file 60 | 61 | def _impl(ctx): 62 | tc = ctx.toolchains["@ewdk_cc//:wpp_toolchain_type"].wppinfo 63 | 64 | inputs = [] 65 | for x in ctx.attr.srcs: 66 | inputs += x.files.to_list() 67 | outputs = [] 68 | for inp in inputs: 69 | name = inp.basename 70 | index = name.rfind(".") 71 | if index != -1: 72 | name = name[:index] 73 | 74 | # tracewpp.exe will only emit .tmh files and cc_binary won't recognize these. 75 | # the wrapper batch file will copy the .tmh to the .h to satisfy bazel 76 | outputs.append(name + ".tmh.h") 77 | 78 | files = [ctx.file.cfghdr] 79 | for i in range(len(inputs)): 80 | files.append(_compile_wpp(ctx, tc, ctx.file.cfghdr, inputs[i], outputs[i])) 81 | 82 | incdirs = {ctx.file.cfghdr.dirname: True} 83 | for file in files: 84 | incdirs[file.dirname] = True 85 | incdirs = incdirs.keys() 86 | 87 | return [ 88 | DefaultInfo(files = depset(files)), 89 | CcInfo(compilation_context = cc_common.create_compilation_context( 90 | quote_includes = depset(incdirs), 91 | headers = depset(files), 92 | )), 93 | ] 94 | 95 | wpp_trace = rule( 96 | implementation = _impl, 97 | attrs = { 98 | "cfghdr": attr.label( 99 | mandatory = True, 100 | allow_single_file = True, 101 | ), 102 | "srcs": attr.label_list( 103 | mandatory = True, 104 | allow_files = True, 105 | ), 106 | "kernel": attr.bool(default = False), 107 | "dll": attr.bool(default = False), 108 | }, 109 | fragments = ["c", "cpp"], 110 | toolchains = ["@ewdk_cc//:wpp_toolchain_type"], 111 | ) 112 | -------------------------------------------------------------------------------- /idl_toolchain.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2023 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """Defines a simple toolchain for windows IDL source files""" 5 | 6 | IdlCompilerInfo = provider( 7 | doc = "Toolchain for windows IDL source files", 8 | fields = ["midl_path", "msvc_env_app", "msvc_env_wdm", "arch_opts"], 9 | ) 10 | 11 | def _idl_toolchain_config_impl(ctx): 12 | toolchain_info = platform_common.ToolchainInfo( 13 | idlinfo = IdlCompilerInfo( 14 | midl_path = ctx.executable.midl_path, 15 | msvc_env_app = ctx.attr.msvc_env_app, 16 | msvc_env_wdm = ctx.attr.msvc_env_wdm, 17 | arch_opts = ctx.attr.arch_opts, 18 | ), 19 | ) 20 | return toolchain_info 21 | 22 | idl_toolchain_config = rule( 23 | implementation = _idl_toolchain_config_impl, 24 | attrs = { 25 | "midl_path": attr.label( 26 | allow_files = True, 27 | executable = True, 28 | cfg = "target", 29 | ), 30 | "msvc_env_app": attr.string_dict(default = {}), 31 | "msvc_env_wdm": attr.string_dict(default = {}), 32 | "arch_opts": attr.string_list(default = []), 33 | }, 34 | ) 35 | 36 | def _build_feature_flags(ctx): 37 | features = {} 38 | for feat in ctx.features: 39 | features[feat] = 1 40 | if not features.get("opt") and not features.get("dbg") and not features.get("fastbuild"): 41 | features[ctx.var.get("COMPILATION_MODE")] = 1 42 | 43 | ret = [] 44 | target = None 45 | for feature in features.keys(): 46 | if feature == "dbg" or feature == "fastbuild": 47 | ret += ["/DDEPRECATE_DDK_FUNCTIONS=1", "/DMSC_NOOPT"] 48 | elif feature == "target_win7": 49 | target = ["/DNTDDI_VERSION=0x06010000", "/D_WIN32_WINNT=0x0601", "/target", "NT61"] 50 | elif feature == "target_win8": 51 | target = ["/DNTDDI_VERSION=0x06020000", "/D_WIN32_WINNT=0x0602", "/target", "NT62"] 52 | elif feature == "target_win10": 53 | target = ["/DNTDDI_VERSION=0x0A000000", "/D_WIN32_WINNT=0x0A00", "/target", "NT100"] 54 | elif feature == "target_win11": 55 | target = ["/DNTDDI_VERSION=0x0A00000C", "/D_WIN32_WINNT=0x0A00", "/target", "NT100"] 56 | if not target: 57 | target = ["/DNTDDI_VERSION=0x06010000", "/D_WIN32_WINNT=0x0601", "/target", "NT61"] 58 | return ret + target 59 | 60 | def _compile_idl(ctx, tc, input): 61 | basename = input.basename[:-(len(input.extension) + 1)] 62 | header = basename + ".h" 63 | 64 | if ctx.attr.client: 65 | basename += "_client" 66 | else: 67 | basename += "_server" 68 | 69 | iid = basename + "_i.c" 70 | proxy = basename + "_p.c" 71 | tlb = basename + ".tlb" 72 | 73 | output = basename + "_c.c" if ctx.attr.client else basename + "_s.c" 74 | output_hdr = ctx.actions.declare_file(header) 75 | output_src = ctx.actions.declare_file(output) 76 | outdir = output_src.dirname.replace("/", "\\") 77 | 78 | env = tc.msvc_env_wdm if ctx.attr.kernel else tc.msvc_env_app 79 | includes = ["/I" + x.replace("/", "\\") for x in env["INCLUDE"].split(";") if x] 80 | includes.append("/I" + outdir) 81 | 82 | default_opts = _build_feature_flags(ctx) + [ 83 | "/D_WCHAR_T_DEFINED", 84 | "/D_USE_DECLSPECS_FOR_SAL=1", 85 | "/W1", 86 | "/nologo", 87 | "/char", 88 | "unsigned", 89 | "/h", 90 | header, 91 | "/cstub", 92 | basename + "_c.c", 93 | "/sstub", 94 | basename + "_s.c", 95 | "/dlldata", 96 | "dlldata.c", 97 | "/iid", 98 | iid, 99 | "/proxy", 100 | proxy, 101 | "/tlb", 102 | tlb, 103 | "/Zp8", 104 | "/sal", 105 | "/no_stamp", 106 | "/out" + outdir 107 | ] 108 | 109 | args = [] 110 | if not ctx.attr.disable_arch_opts: 111 | args += tc.arch_opts 112 | if not ctx.attr.disable_default_includes: 113 | args += includes 114 | if not ctx.attr.disable_default_opts: 115 | args += default_opts 116 | args += ctx.attr.opts 117 | args.append(input.path.replace("/", "\\")) 118 | 119 | ctx.actions.run( 120 | inputs = [input], 121 | outputs = [output_src, output_hdr], 122 | env = env, 123 | executable = tc.midl_path, 124 | arguments = args, 125 | mnemonic = "MidlCompile", 126 | ) 127 | 128 | return { 129 | "header": output_hdr, 130 | "src": output_src, 131 | } 132 | 133 | def _impl(ctx): 134 | tc = ctx.toolchains["@ewdk_cc//:idl_toolchain_type"].idlinfo 135 | 136 | inputs = [] 137 | for x in ctx.attr.srcs: 138 | inputs += x.files.to_list() 139 | 140 | headers = [] 141 | srcs = [] 142 | for inp in inputs: 143 | outs = _compile_idl(ctx, tc, inp) 144 | headers.append(outs["header"]) 145 | srcs.append(outs["src"]) 146 | 147 | incdirs = {} 148 | for hdr in headers: 149 | incdirs[hdr.dirname] = True 150 | incdirs = incdirs.keys() 151 | 152 | return [ 153 | DefaultInfo(files = depset(headers + srcs)), 154 | CcInfo(compilation_context = cc_common.create_compilation_context( 155 | quote_includes = depset(incdirs), 156 | headers = depset(headers), 157 | )), 158 | ] 159 | 160 | idl_script = rule( 161 | implementation = _impl, 162 | attrs = { 163 | "srcs": attr.label_list( 164 | mandatory = True, 165 | allow_files = True, 166 | ), 167 | "client": attr.bool(mandatory = True), 168 | "kernel": attr.bool(default = False), 169 | "opts": attr.string_list(default = []), 170 | "disable_default_includes": attr.bool(default = False), 171 | "disable_default_opts": attr.bool(default = False), 172 | "disable_arch_opts": attr.bool(default = False), 173 | }, 174 | toolchains = ["@ewdk_cc//:idl_toolchain_type"], 175 | ) 176 | -------------------------------------------------------------------------------- /c_cpp_properties.tpl: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "win-X86-dbg", 5 | "includePath": [ 6 | "${workspaceFolder}/**", 7 | %{system_includes} 8 | ], 9 | "defines": ["_X86_=1", "i386=1", "STD_CALL", "COMPILER_MSVC", "_M_IX86", "_DEBUG", "DBG=1", "MSC_NOOPT"], 10 | "windowsSdkVersion": "%{sdk_version}", 11 | "compilerPath": "%{cl_path}", 12 | "cStandard": "%{c_standard}", 13 | "cppStandard": "%{cpp_standard}", 14 | "intelliSenseMode": "windows-msvc-x86", 15 | "mergeConfigurations": true, 16 | "browse": { 17 | "path": [ 18 | "${workspaceFolder}/**" 19 | ], 20 | "limitSymbolsToIncludedHeaders": true 21 | } 22 | }, 23 | { 24 | "name": "win-X86-opt", 25 | "includePath": [ 26 | "${workspaceFolder}/**", 27 | %{system_includes} 28 | ], 29 | "defines": ["_X86_=1", "i386=1", "STD_CALL", "COMPILER_MSVC", "_M_IX86", "NDEBUG"], 30 | "windowsSdkVersion": "%{sdk_version}", 31 | "compilerPath": "%{cl_path}", 32 | "cStandard": "%{c_standard}", 33 | "cppStandard": "%{cpp_standard}", 34 | "intelliSenseMode": "windows-msvc-x86", 35 | "mergeConfigurations": true, 36 | "browse": { 37 | "path": [ 38 | "${workspaceFolder}/**" 39 | ], 40 | "limitSymbolsToIncludedHeaders": true 41 | } 42 | }, 43 | { 44 | "name": "win-X64-dbg", 45 | "includePath": [ 46 | "${workspaceFolder}/**", 47 | %{system_includes} 48 | ], 49 | "defines": ["_WIN64", "_AMD64_", "AMD64", "COMPILER_MSVC", "_M_AMD64", "_DEBUG", "DBG=1", "MSC_NOOPT"], 50 | "windowsSdkVersion": "%{sdk_version}", 51 | "compilerPath": "%{cl_path}", 52 | "cStandard": "%{c_standard}", 53 | "cppStandard": "%{cpp_standard}", 54 | "intelliSenseMode": "windows-msvc-x64", 55 | "mergeConfigurations": true, 56 | "browse": { 57 | "path": [ 58 | "${workspaceFolder}/**" 59 | ], 60 | "limitSymbolsToIncludedHeaders": true 61 | } 62 | }, 63 | { 64 | "name": "win-X64-opt", 65 | "includePath": [ 66 | "${workspaceFolder}/**", 67 | %{system_includes} 68 | ], 69 | "defines": ["_WIN64", "_AMD64_", "AMD64", "COMPILER_MSVC", "_M_AMD64", "NDEBUG"], 70 | "windowsSdkVersion": "%{sdk_version}", 71 | "compilerPath": "%{cl_path}", 72 | "cStandard": "%{c_standard}", 73 | "cppStandard": "%{cpp_standard}", 74 | "intelliSenseMode": "windows-msvc-x64", 75 | "mergeConfigurations": true, 76 | "browse": { 77 | "path": [ 78 | "${workspaceFolder}/**" 79 | ], 80 | "limitSymbolsToIncludedHeaders": true 81 | } 82 | }, 83 | { 84 | "name": "win-ARM-dbg", 85 | "includePath": [ 86 | "${workspaceFolder}/**", 87 | %{system_includes} 88 | ], 89 | "defines": ["_ARM_", "ARM", "STD_CALL", "COMPILER_MSVC", "_M_ARM", "_DEBUG", "DBG=1", "MSC_NOOPT"], 90 | "windowsSdkVersion": "%{sdk_version}", 91 | "compilerPath": "%{cl_path}", 92 | "cStandard": "%{c_standard}", 93 | "cppStandard": "%{cpp_standard}", 94 | "intelliSenseMode": "windows-msvc-arm", 95 | "mergeConfigurations": true, 96 | "browse": { 97 | "path": [ 98 | "${workspaceFolder}/**" 99 | ], 100 | "limitSymbolsToIncludedHeaders": true 101 | } 102 | }, 103 | { 104 | "name": "win-ARM-opt", 105 | "includePath": [ 106 | "${workspaceFolder}/**", 107 | %{system_includes} 108 | ], 109 | "defines": ["_ARM_", "ARM", "STD_CALL", "COMPILER_MSVC", "_M_ARM", "NDEBUG"], 110 | "windowsSdkVersion": "%{sdk_version}", 111 | "compilerPath": "%{cl_path}", 112 | "cStandard": "%{c_standard}", 113 | "cppStandard": "%{cpp_standard}", 114 | "intelliSenseMode": "windows-msvc-arm", 115 | "mergeConfigurations": true, 116 | "browse": { 117 | "path": [ 118 | "${workspaceFolder}/**" 119 | ], 120 | "limitSymbolsToIncludedHeaders": true 121 | } 122 | }, 123 | { 124 | "name": "win-ARM64-dbg", 125 | "includePath": [ 126 | "${workspaceFolder}/**", 127 | %{system_includes} 128 | ], 129 | "defines": ["_WIN64", "_ARM64_", "ARM64", "COMPILER_MSVC", "_M_ARM64", "STD_CALL", "_M_ARM64", "_DEBUG", "DBG=1", "MSC_NOOPT"], 130 | "windowsSdkVersion": "%{sdk_version}", 131 | "compilerPath": "%{cl_path}", 132 | "cStandard": "%{c_standard}", 133 | "cppStandard": "%{cpp_standard}", 134 | "intelliSenseMode": "windows-msvc-arm64", 135 | "mergeConfigurations": true, 136 | "browse": { 137 | "path": [ 138 | "${workspaceFolder}/**" 139 | ], 140 | "limitSymbolsToIncludedHeaders": true 141 | } 142 | }, 143 | { 144 | "name": "win-ARM64-opt", 145 | "includePath": [ 146 | "${workspaceFolder}/**", 147 | %{system_includes} 148 | ], 149 | "defines": ["_WIN64", "_ARM64_", "ARM64", "COMPILER_MSVC", "_M_ARM64", "STD_CALL", "_M_ARM64", "NDEBUG"], 150 | "windowsSdkVersion": "%{sdk_version}", 151 | "compilerPath": "%{cl_path}", 152 | "cStandard": "%{c_standard}", 153 | "cppStandard": "%{cpp_standard}", 154 | "intelliSenseMode": "windows-msvc-arm64", 155 | "mergeConfigurations": true, 156 | "browse": { 157 | "path": [ 158 | "${workspaceFolder}/**" 159 | ], 160 | "limitSymbolsToIncludedHeaders": true 161 | } 162 | }, 163 | { 164 | "name": "win-ARM64EC-dbg", 165 | "includePath": [ 166 | "${workspaceFolder}/**", 167 | %{system_includes} 168 | ], 169 | "defines": ["_WIN64", "_AMD64_", "AMD64", "COMPILER_MSVC", "_M_AMD64", "_M_ARM64EC", "_ARM64EC_", "_DEBUG", "DBG=1", "MSC_NOOPT"], 170 | "windowsSdkVersion": "%{sdk_version}", 171 | "compilerPath": "%{cl_path}", 172 | "cStandard": "%{c_standard}", 173 | "cppStandard": "%{cpp_standard}", 174 | "intelliSenseMode": "windows-msvc-x64", 175 | "mergeConfigurations": true, 176 | "browse": { 177 | "path": [ 178 | "${workspaceFolder}/**" 179 | ], 180 | "limitSymbolsToIncludedHeaders": true 181 | } 182 | }, 183 | { 184 | "name": "win-ARM64EC-opt", 185 | "includePath": [ 186 | "${workspaceFolder}/**", 187 | %{system_includes} 188 | ], 189 | "defines": ["_WIN64", "_AMD64_", "AMD64", "COMPILER_MSVC", "_M_AMD64", "_M_ARM64EC", "_ARM64EC_", "NDEBUG"], 190 | "windowsSdkVersion": "%{sdk_version}", 191 | "compilerPath": "%{cl_path}", 192 | "cStandard": "%{c_standard}", 193 | "cppStandard": "%{cpp_standard}", 194 | "intelliSenseMode": "windows-msvc-x64", 195 | "mergeConfigurations": true, 196 | "browse": { 197 | "path": [ 198 | "${workspaceFolder}/**" 199 | ], 200 | "limitSymbolsToIncludedHeaders": true 201 | } 202 | } 203 | ], 204 | "version": 4 205 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | EWDK toolchain for Bazel 2 | ========= 3 | 4 | Build windows applications and drivers with the EWDK. 5 | 6 | Supports: 7 | * Building WDM drivers (KMDF not yet implemented) 8 | * Building applications, DLLs and static libraries. 9 | * Windows resource scripts. 10 | * WPP tracing 11 | * IDL compiling (midl) 12 | * Cross-compiling to x86, x64, ARM and ARM64 13 | * Arm64EC and Arm64X 14 | * Supports building on x64 and ARM64 hosts. 15 | * Intellisense configurations for use with the EWDK. 16 | 17 | Supported bazel versions: 18 | * 6.4.0 - 8.3.0 - Built and tested with. Unknown if other versions work. (1.0.11 and prior support back to 5.1.0) 19 | 20 | ## Quick Start 21 | 22 | First, make sure the EWDKDIR environment variable is set to the root of the EWDK when executing bazel. 23 | 24 | ```cmd 25 | set EWDKDIR=D:\EWDK 26 | bazel build ... 27 | ``` 28 | 29 | Include the following in your WORKSPACE: 30 | ```starlark 31 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 32 | 33 | http_archive( 34 | name = "ewdk_cc_toolchains", 35 | sha256 = "fdc6ca9a8610f28744cf37af132a03422599f580757b6e54478e007e7505bac9", 36 | strip_prefix = "bazel_ewdk_cc-1.0.3/", 37 | url = "https://github.com/0xf005ba11/bazel_ewdk_cc/archive/refs/tags/v1.0.3.zip", 38 | ) 39 | 40 | load("@ewdk_cc_toolchains//:ewdk_cc_configure.bzl", "register_ewdk_cc_toolchains") 41 | 42 | register_ewdk_cc_toolchains() 43 | ``` 44 | 45 | Or, using the bzlmod system update your MODULE.bazel file with the following. The project is not yet 46 | published to the bzlmod repository, so you will need to use git_override and specify the a commit: 47 | ```starlark 48 | bazel_dep(name = "ewdk_cc_toolchains") 49 | git_override( 50 | module_name = "ewdk_cc_toolchains", 51 | remote = "https://github.com/0xf005ba11/bazel_ewdk_cc.git", 52 | commit = "INSERT_COMMIT_HERE", 53 | ) 54 | 55 | # You may need to register the toolchains as follows 56 | ewdk_toolchains = use_extension("@ewdk_cc_toolchains//:ewdk_extension.bzl", "toolchains") 57 | use_repo(ewdk_toolchains, ewdk_cc = "ewdk_toolchains") 58 | register_toolchains("@ewdk_cc//:all") 59 | ``` 60 | 61 | Add the following to your .bazelrc (this should hopefully no longer be needed once this [issue](https://github.com/bazelbuild/bazel/issues/7260) is closed in bazel 7.0.0): 62 | ``` 63 | build --incompatible_enable_cc_toolchain_resolution 64 | ``` 65 | 66 | If you have problems with toolchain selection (```--toolchain_resolution_debug=.*```), you may also need to set this action_env: 67 | ``` 68 | build --action_env=BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 69 | ``` 70 | 71 | An [example project](https://github.com/0xf005ba11/bazel_example_project) is available that utilizes all the features. 72 | 73 | ## Building a WDM driver 74 | 75 | The easiest way to do this is to build a DLL (```linkedshared = True```) and include the ```wdm```, ```subsystem_native``` and one of (```target_win7```, ```target_win8```, ```target_win10```, or ```target_win11```) features. You will also likely want to include the ```stdcall```, ```msvc_level4_warnings```, and ```treat_warnings_as_errors``` features. 76 | 77 | For example: 78 | ```starlark 79 | cc_binary( 80 | name = "sys-dll", 81 | srcs = glob(["*.cpp"]), 82 | features = [ 83 | "wdm", 84 | "subsystem_native", 85 | "target_win10", 86 | "stdcall", 87 | "msvc_level4_warnings", 88 | "treat_warnings_as_errors", 89 | "cpp20", 90 | "buffer_security_checks", 91 | "sdl_security_checks", 92 | "cfg_security_checks", 93 | "spectre", 94 | ], 95 | linkshared = True, 96 | target_compatible_with = ["@platforms//os:windows"], 97 | ) 98 | ``` 99 | 100 | This will result in a ```sys.dll``` being built. Bazel doesn't currently understand the ```.sys``` extension directly in a ```cc_binary``` rule. 101 | 102 | The following is an example that can copy the result ```sys.dll``` to ```sys.sys``` and sign the driver with a WDK-produced certificate. Here ```ewdk_command``` is similar to ```genrule```, but has the EWDK environment available. 103 | ```starlark 104 | load("@ewdk_cc_toolchains//:ewdk_command.bzl", "ewdk_command") 105 | 106 | ewdk_command( 107 | name = "sys", 108 | srcs = [":sys-dll"], 109 | outs = ["sys.sys"], 110 | cmd = "copy /y \"$(locations :sys-dll)\" \"$(locations :sys.sys)\" && SignTool.exe sign /ph /fd sha256 /n WDKTestCert \"$(locations :sys.sys)\"", 111 | ) 112 | ``` 113 | 114 | ## Building an executable 115 | 116 | Make sure to include one of ```subsystem_console``` or ```subsystem_windows```. Use ```subsystem_windows``` for DLLs. 117 | 118 | If you are using the MS C-Runtime, also include one of ```static_link_msvcrt``` or ```dynamic_link_msvcrt```. These features will automatically choose debug versions when building in ```dbg``` mode. 119 | 120 | ```starlark 121 | cc_binary( 122 | name = "exe", 123 | srcs = ["exe.cpp"], 124 | features = [ 125 | "subsystem_console", 126 | "static_link_msvcrt", 127 | "msvc_level4_warnings", 128 | "treat_warnings_as_errors", 129 | "cdecl", 130 | ], 131 | ) 132 | ``` 133 | 134 | ## Building a resource script 135 | 136 | ```starlark 137 | load("@ewdk_cc_toolchains//:resource_toolchain.bzl", "resource_script") 138 | 139 | resource_script( 140 | name = "your_rc", 141 | rcfile = "your.rc", 142 | rcopts = [], # put additional command line options here if needed 143 | ) 144 | 145 | # "your_rc" can now be referenced in deps of other binaries 146 | ``` 147 | 148 | ## Helper environment setup scripts 149 | 150 | Batch scripts are available that can be used to setup the environment for difficult cases that need some manual intervention. These are: 151 | * @ewdk_cc//:env_app_x86.cmd 152 | * @ewdk_cc//:env_app_x64.cmd 153 | * @ewdk_cc//:env_app_arm.cmd 154 | * @ewdk_cc//:env_app_arm64.cmd 155 | 156 | These will set the following environment variables that can then be used to update the relevant vars for your use case: 157 | * EWDK_PATH 158 | * EWDK_INCLUDE 159 | * EWDK_EXTERNAL_INCLUDE 160 | * EWDK_LIBPATH 161 | * EWDK_LIB 162 | 163 | ## Arm64EC and Arm64X support 164 | 165 | Arm64ec can be implemented by using the `arm64ec` feature for compiling and `link_arm64ec` when linking. For cc_library/cc_binary, provide both features when the `@platforms//cpu` value is `arm64`. 166 | 167 | Arm64X is more difficult as it requires finding a way to get bazel to produce both arm64 and arm64ec obj files for each source file while the `@platforms//cpu` config setting is `arm64`. The toolchain provides the `arm64ec` and `link_arm64x` features to allow using /arm64EC and /MACHINE:ARM64X. There is currently not an automatic way to deal with the object files, but it is possible to write a macro that can compile the various obj files and then provide those to a final cc_binary/cc_library in the srcs argument. 168 | 169 | ## Windows vscode intellisense settings 170 | 171 | When the toolchain is registered, it will emit a ```c_cpp_properties.json``` in its output folder that contains intellisense configurations for windows. This file can be copied into place with something like: 172 | 173 | ```powershell 174 | copy "$(bazel info output_base)/external/ewdk_cc/c_cpp_properties.json" "./.vscode/c_cpp_properties.json" 175 | ``` 176 | 177 | This file will only change if the EWDK location changes, so it is recommended to modify it as you see fit. Consider it a starting point for your configuration. Additionally, these settings will be imperfect as the kernel-mode CRT is not included to avoid conflicting with the regular CRT. However, they should work well enough. 178 | 179 | ## Features specific to this toolchain 180 | 181 | In addition to features from the built-in bazel C++ toolchain, the following have been added: 182 | 183 | * wdm - Building a WDM driver 184 | * subsystem_native - /SUBSYSTEM:NATIVE 185 | * subsystem_console - /SUBSYSTEM:CONSOLE 186 | * subsystem_windows - /SUBSYSTEM:WINDOWS 187 | * stdcall - /Gz (Note: For ARM this will automatically revert to /Gd) 188 | * cdecl - /Gd 189 | * charset_unicode - /D_UNICODE /DUNICODE 190 | * charset_multibyte - /D_MBCS 191 | * msvc_level3_warnings - /W3 192 | * msvc_level4_warnings - /W4 193 | * treat_warnings_as_errors - /WX 194 | * target_win7 - WINVER, _WIN32_WINNT and NTDDI_VERSION for Windows 7 (0x06010000) 195 | * target_win8 - 0x06020000 196 | * target_win10 - 0x0A000000 197 | * target_win11 - 0x0A00000C 198 | * c11 - /std:c11 199 | * c17 - /std:c17 200 | * cpp14 - /std:c++14 201 | * cpp17 - /std:c++17 202 | * cpp20 - /std:c++20 203 | * cpp_latest - /std:c++latest 204 | * disable_msvcrt - Bazel forces msvcrt linkage. This can be used to disable the usage. Default for `wdm`. 205 | * msvc_enable_minmax - Enable the windows SDK min and max macros (they are disabled by default with /DNOMINMAX) 206 | * no_default_cpp_unwinding - Disable the /EHsc option which is enabled by default on non-`wdm` builds 207 | * no_runtime_checks - Disable /RTC1 option which is enabled by default in non-`wdm` dbg and fastbuild 208 | * win32_lean_and_mean - /DWIN32_LEAN_AND_MEAN=1 209 | * buffer_security_checks - /GS 210 | * sdl_security_checks - /sdl 211 | * cfg_security_checks - /guard:cf 212 | * cet_compatible - /CETCOMPAT (Note: For ARM this will automatically revert to /CETCOMPAT:NO) 213 | * guard_ehcont - /guard:ehcont 214 | * retpoline_check - /d2guardretpoline and /guard:retpoline (x64-only) 215 | * spectre - /Qspectre 216 | * spectre_load_cf - /Qspectre-load-cf 217 | * arm64ec - Pass /arm64EC to cl.exe or -machine ARM64EC to armasm64.exe when compiling for arm64. 218 | * link_arm64ec - Pass /MACHINE:ARM64EC to lib.exe/link.exe instead of the default /MACHINE: flag. 219 | * link_arm64x - Pass /MACHINE:ARM64X to lib.exe/link.exe instead of the default /MACHINE: flag. 220 | * default_includes_cmdline - Adds the default include paths to the command line (/I). This can be useful for tooling like producing intellisense configurations. 221 | 222 | ## Default compile flags 223 | * /DCOMPILER_MSVC 224 | * /bigobj 225 | * /Zm500 226 | * /EHsc - non-```wdm``` builds only. Disable with no_default_cpp_unwinding 227 | * /DNOMINMAX - use the msvc_enable_minmax feature to re-enable these macros 228 | * /FC 229 | * /Zc:wchar_t 230 | * /Gm- 231 | * /GR- - ```wdm``` builds only 232 | * /DWINVER=0x0601 - Use `target_win8`, `target_win10`, or `target_win11` to change 233 | * /D_WIN32_WINNT=0x0601 - Use `target_win8`, `target_win10`, or `target_win11` to change 234 | * /DNTDDI_VERSION=0x06010000 - Use `target_win8`, `target_win10`, or `target_win11` to change 235 | 236 | When building in dbg or fastbuild mode, the following are added: 237 | * /Od 238 | * /Z7 239 | * /RTC1 - non-```wdm``` builds only 240 | * /DMSC_NOOPT - ```wdm``` builds only 241 | * /DDBG=1 - ```wdm``` builds only 242 | 243 | When building in opt mode, the following are added: 244 | * /DNDEBUG 245 | * /Gy 246 | * /GF 247 | * /Zi 248 | * /GL 249 | * /O2 - non-```wdm``` builds only 250 | * /Ox - ```wdm``` builds only 251 | * /Os - ```wdm``` builds only 252 | * /OPT:REF 253 | * /LTCG - (linker flag to compliment /GL) 254 | 255 | When building for x86 32-bit (WDM drivers): 256 | * /D_X86_=1 257 | * /Di386=1 258 | * /DSTD_CALL 259 | * /Zp8 260 | 261 | When building for x64 (WDM drivers): 262 | * /D_WIN64 263 | * /D_AMD64_ 264 | * /DAMD64 265 | * /Zp8 266 | 267 | When building for ARM (WDM drivers): 268 | * /D_ARM_ 269 | * /DARM 270 | * /DSTD_CALL 271 | * /Zp8 272 | 273 | When building for ARM64 (WDM drivers): 274 | * /D_WIN64 275 | * /D_ARM64_ 276 | * /DARM64 277 | * /DSTD_CALL 278 | * /Zp8 279 | 280 | ## Default link flags 281 | * /DYNAMICBASE 282 | * /NXCOMPAT 283 | * /INTEGRITYCHECK - ```wdm``` builds only 284 | * /DRIVER - ```wdm``` builds only 285 | * /NODEFAULTLIB - ```wdm``` builds only 286 | * /SECTION:INIT,d - ```wdm``` builds only 287 | * /MERGE:_TEXT=.text;_PAGE=PAGE - ```wdm``` builds only 288 | * /DEBUG:FULL 289 | * /INCREMENTAL:NO 290 | 291 | ## Default masm flags 292 | * /Zi 293 | * /Zd 294 | * /W3 295 | 296 | ## Default linked libs for WDM drivers 297 | * BufferOverflowFastFailK.lib 298 | * ntoskrnl.lib 299 | * hal.lib 300 | * wmilib.lib 301 | * arm64rt.lib - arm64 only 302 | -------------------------------------------------------------------------------- /BUILD.ewdk.toolchains.tpl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """ewdk_cc toolchains""" 5 | 6 | exports_files(glob(["*.cmd"])) 7 | 8 | load("@rules_cc//cc:defs.bzl", "cc_toolchain") 9 | load(":ewdk_cc_configure.bzl", "ewdk_cc_toolchain_config") 10 | load(":resource_toolchain.bzl", "resource_script_toolchain_config") 11 | load(":wpp_toolchain.bzl", "wpp_toolchain_config") 12 | load(":idl_toolchain.bzl", "idl_toolchain_config") 13 | load(":ewdk_command.bzl", "ewdk_command_config") 14 | 15 | constraint_setting( 16 | name = "ewdk_toolchain", 17 | default_constraint_value = ":ewdk_cc", 18 | visibility = ["//visibility:public"], 19 | ) 20 | 21 | constraint_value( 22 | name = "ewdk_cc", 23 | constraint_setting = ":ewdk_toolchain", 24 | visibility = ["//visibility:public"], 25 | ) 26 | 27 | filegroup( 28 | name = "empty", 29 | srcs = [], 30 | ) 31 | 32 | _EWDK_LAUNCH_ENV = { 33 | %{ewdk_launch_env} 34 | } 35 | 36 | _MSVC_ENV_WDM_X86 = { 37 | "PATH": "%{msvc_env_path_wdm_x86}", 38 | "INCLUDE": "%{msvc_env_include_wdm_x86}", 39 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_wdm_x86}", 40 | "LIBPATH": "%{msvc_env_libpath_wdm_x86}", 41 | "LIB": "%{msvc_env_lib_wdm_x86}", 42 | "TMP": "%{msvc_env_tmp}", 43 | } 44 | 45 | _MSVC_ENV_APP_X86 = { 46 | "PATH": "%{msvc_env_path_app_x86}", 47 | "INCLUDE": "%{msvc_env_include_app_x86}", 48 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_app_x86}", 49 | "LIBPATH": "%{msvc_env_libpath_app_x86}", 50 | "LIB": "%{msvc_env_lib_app_x86}", 51 | "TMP": "%{msvc_env_tmp}", 52 | } 53 | 54 | _MSVC_ENV_WDM_X64 = { 55 | "PATH": "%{msvc_env_path_wdm_x64}", 56 | "INCLUDE": "%{msvc_env_include_wdm_x64}", 57 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_wdm_x64}", 58 | "LIBPATH": "%{msvc_env_libpath_wdm_x64}", 59 | "LIB": "%{msvc_env_lib_wdm_x64}", 60 | "TMP": "%{msvc_env_tmp}", 61 | } 62 | 63 | _MSVC_ENV_APP_X64 = { 64 | "PATH": "%{msvc_env_path_app_x64}", 65 | "INCLUDE": "%{msvc_env_include_app_x64}", 66 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_app_x64}", 67 | "LIBPATH": "%{msvc_env_libpath_app_x64}", 68 | "LIB": "%{msvc_env_lib_app_x64}", 69 | "TMP": "%{msvc_env_tmp}", 70 | } 71 | 72 | _MSVC_ENV_WDM_ARM = { 73 | "PATH": "%{msvc_env_path_wdm_arm}", 74 | "INCLUDE": "%{msvc_env_include_wdm_arm}", 75 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_wdm_arm}", 76 | "LIBPATH": "%{msvc_env_libpath_wdm_arm}", 77 | "LIB": "%{msvc_env_lib_wdm_arm}", 78 | "TMP": "%{msvc_env_tmp}", 79 | } 80 | 81 | _MSVC_ENV_APP_ARM = { 82 | "PATH": "%{msvc_env_path_app_arm}", 83 | "INCLUDE": "%{msvc_env_include_app_arm}", 84 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_app_arm}", 85 | "LIBPATH": "%{msvc_env_libpath_app_arm}", 86 | "LIB": "%{msvc_env_lib_app_arm}", 87 | "TMP": "%{msvc_env_tmp}", 88 | } 89 | 90 | _MSVC_ENV_WDM_ARM64 = { 91 | "PATH": "%{msvc_env_path_wdm_arm64}", 92 | "INCLUDE": "%{msvc_env_include_wdm_arm64}", 93 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_wdm_arm64}", 94 | "LIBPATH": "%{msvc_env_libpath_wdm_arm64}", 95 | "LIB": "%{msvc_env_lib_wdm_arm64}", 96 | "TMP": "%{msvc_env_tmp}", 97 | } 98 | 99 | _MSVC_ENV_APP_ARM64 = { 100 | "PATH": "%{msvc_env_path_app_arm64}", 101 | "INCLUDE": "%{msvc_env_include_app_arm64}", 102 | "EXTERNAL_INCLUDE": "%{msvc_env_external_include_app_arm64}", 103 | "LIBPATH": "%{msvc_env_libpath_app_arm64}", 104 | "LIB": "%{msvc_env_lib_app_arm64}", 105 | "TMP": "%{msvc_env_tmp}", 106 | } 107 | 108 | _TOOL_PATHS_X86 = { 109 | "ar": "%{msvc_lib_path_x86}", 110 | "ml": "%{msvc_ml_path_x86}", 111 | "cpp": "%{msvc_cl_path_x86}", 112 | "gcc": "%{msvc_cl_path_x86}", 113 | "ld": "%{msvc_link_path_x86}", 114 | "gcov": "wrapper/bin/msvc_nop.bat", 115 | "nm": "wrapper/bin/msvc_nop.bat", 116 | "objcopy": "wrapper/bin/msvc_nop.bat", 117 | "objdump": "wrapper/bin/msvc_nop.bat", 118 | "strip": "wrapper/bin/msvc_nop.bat", 119 | "dumpbin": "%{msvc_dumpbin_path_x86}", 120 | "cpp-module-deps-scanner": "deps_scanner_x86.bat", 121 | } 122 | 123 | _TOOL_PATHS_X64 = { 124 | "ar": "%{msvc_lib_path_x64}", 125 | "ml": "%{msvc_ml_path_x64}", 126 | "cpp": "%{msvc_cl_path_x64}", 127 | "gcc": "%{msvc_cl_path_x64}", 128 | "ld": "%{msvc_link_path_x64}", 129 | "gcov": "wrapper/bin/msvc_nop.bat", 130 | "nm": "wrapper/bin/msvc_nop.bat", 131 | "objcopy": "wrapper/bin/msvc_nop.bat", 132 | "objdump": "wrapper/bin/msvc_nop.bat", 133 | "strip": "wrapper/bin/msvc_nop.bat", 134 | "dumpbin": "%{msvc_dumpbin_path_x64}", 135 | "cpp-module-deps-scanner": "deps_scanner_x64.bat", 136 | } 137 | 138 | _TOOL_PATHS_ARM = { 139 | "ar": "%{msvc_lib_path_arm}", 140 | "ml": "arm_asm.bat", 141 | "cpp": "%{msvc_cl_path_arm}", 142 | "gcc": "%{msvc_cl_path_arm}", 143 | "ld": "%{msvc_link_path_arm}", 144 | "gcov": "wrapper/bin/msvc_nop.bat", 145 | "nm": "wrapper/bin/msvc_nop.bat", 146 | "objcopy": "wrapper/bin/msvc_nop.bat", 147 | "objdump": "wrapper/bin/msvc_nop.bat", 148 | "strip": "wrapper/bin/msvc_nop.bat", 149 | "dumpbin": "%{msvc_dumpbin_path_arm}", 150 | "cpp-module-deps-scanner": "deps_scanner_arm.bat", 151 | } 152 | 153 | _TOOL_PATHS_ARM64 = { 154 | "ar": "%{msvc_lib_path_arm64}", 155 | "ml": "arm_asm64.bat", 156 | "cpp": "%{msvc_cl_path_arm64}", 157 | "gcc": "%{msvc_cl_path_arm64}", 158 | "ld": "%{msvc_link_path_arm64}", 159 | "gcov": "wrapper/bin/msvc_nop.bat", 160 | "nm": "wrapper/bin/msvc_nop.bat", 161 | "objcopy": "wrapper/bin/msvc_nop.bat", 162 | "objdump": "wrapper/bin/msvc_nop.bat", 163 | "strip": "wrapper/bin/msvc_nop.bat", 164 | "dumpbin": "%{msvc_dumpbin_path_arm64}", 165 | "cpp-module-deps-scanner": "deps_scanner_arm64.bat", 166 | } 167 | 168 | # x64 toolchain 169 | cc_toolchain( 170 | name = "ewdk-cc-compiler-x64_windows", 171 | all_files = ":empty", 172 | ar_files = ":empty", 173 | as_files = ":empty", 174 | compiler_files = ":empty", 175 | dwp_files = ":empty", 176 | linker_files = ":empty", 177 | objcopy_files = ":empty", 178 | strip_files = ":empty", 179 | supports_param_files = 1, 180 | toolchain_config = ":ewdk_msvc_x64", 181 | toolchain_identifier = "ewdk_msvc_x64", 182 | ) 183 | 184 | ewdk_cc_toolchain_config( 185 | name = "ewdk_msvc_x64", 186 | arch_c_opts_wdm = [ 187 | "/D_WIN64", 188 | "/D_AMD64_", 189 | "/DAMD64", 190 | "/Zp8", 191 | ], 192 | cetcompat_option = "/CETCOMPAT", 193 | cpu = "x64_windows", 194 | entry_symbol_suffix = "", 195 | has_gz_option = "/Gz", 196 | host_system_name = "local", 197 | link_machine_flag = "/MACHINE:X64", 198 | msvc_env_app = _MSVC_ENV_APP_X64, 199 | msvc_env_wdm = _MSVC_ENV_WDM_X64, 200 | target_system_name = "local", 201 | tool_paths = _TOOL_PATHS_X64, 202 | toolchain_identifier = "ewdk_msvc_x64", 203 | ) 204 | 205 | toolchain( 206 | name = "ewdk-cc-toolchain-x64_x64_windows", 207 | exec_compatible_with = [ 208 | "@platforms//cpu:x86_64", 209 | "@platforms//os:windows", 210 | ], 211 | target_compatible_with = [ 212 | "@platforms//cpu:x86_64", 213 | "@platforms//os:windows", 214 | ":ewdk_cc", 215 | ], 216 | toolchain = ":ewdk-cc-compiler-x64_windows", 217 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 218 | ) 219 | 220 | toolchain( 221 | name = "ewdk-cc-toolchain-arm64_x64_windows", 222 | exec_compatible_with = [ 223 | "@platforms//cpu:aarch64", 224 | "@platforms//os:windows", 225 | ], 226 | target_compatible_with = [ 227 | "@platforms//cpu:x86_64", 228 | "@platforms//os:windows", 229 | ":ewdk_cc", 230 | ], 231 | toolchain = ":ewdk-cc-compiler-x64_windows", 232 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 233 | ) 234 | 235 | # x86 toolchain 236 | cc_toolchain( 237 | name = "ewdk-cc-compiler-x86_windows", 238 | all_files = ":empty", 239 | ar_files = ":empty", 240 | as_files = ":empty", 241 | compiler_files = ":empty", 242 | dwp_files = ":empty", 243 | linker_files = ":empty", 244 | objcopy_files = ":empty", 245 | strip_files = ":empty", 246 | supports_param_files = 1, 247 | toolchain_config = ":ewdk_msvc_x86", 248 | toolchain_identifier = "ewdk_msvc_x86", 249 | ) 250 | 251 | ewdk_cc_toolchain_config( 252 | name = "ewdk_msvc_x86", 253 | arch_c_opts_wdm = [ 254 | "/D_X86_=1", 255 | "/Di386=1", 256 | "/DSTD_CALL", 257 | "/Zp8", 258 | ], 259 | cetcompat_option = "/CETCOMPAT", 260 | cpu = "x86_windows", 261 | entry_symbol_suffix = "@8", 262 | has_gz_option = "/Gz", 263 | host_system_name = "local", 264 | link_machine_flag = "/MACHINE:X86", 265 | msvc_env_app = _MSVC_ENV_APP_X86, 266 | msvc_env_wdm = _MSVC_ENV_WDM_X86, 267 | target_system_name = "local", 268 | tool_paths = _TOOL_PATHS_X86, 269 | toolchain_identifier = "ewdk_msvc_x86", 270 | ) 271 | 272 | toolchain( 273 | name = "ewdk-cc-toolchain-x64_x86_windows", 274 | exec_compatible_with = [ 275 | "@platforms//cpu:x86_64", 276 | "@platforms//os:windows", 277 | ], 278 | target_compatible_with = [ 279 | "@platforms//cpu:x86_32", 280 | "@platforms//os:windows", 281 | ":ewdk_cc", 282 | ], 283 | toolchain = ":ewdk-cc-compiler-x86_windows", 284 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 285 | ) 286 | 287 | toolchain( 288 | name = "ewdk-cc-toolchain-arm64_x86_windows", 289 | exec_compatible_with = [ 290 | "@platforms//cpu:aarch64", 291 | "@platforms//os:windows", 292 | ], 293 | target_compatible_with = [ 294 | "@platforms//cpu:x86_32", 295 | "@platforms//os:windows", 296 | ":ewdk_cc", 297 | ], 298 | toolchain = ":ewdk-cc-compiler-x86_windows", 299 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 300 | ) 301 | 302 | # arm64 toolchain 303 | cc_toolchain( 304 | name = "ewdk-cc-compiler-arm64_windows", 305 | all_files = ":empty", 306 | ar_files = ":empty", 307 | as_files = ":empty", 308 | compiler_files = ":empty", 309 | dwp_files = ":empty", 310 | linker_files = ":empty", 311 | objcopy_files = ":empty", 312 | strip_files = ":empty", 313 | supports_param_files = 1, 314 | toolchain_config = ":ewdk_msvc_arm64", 315 | toolchain_identifier = "ewdk_msvc_arm64", 316 | ) 317 | 318 | ewdk_cc_toolchain_config( 319 | name = "ewdk_msvc_arm64", 320 | arch_c_opts_wdm = [ 321 | "/D_WIN64", 322 | "/D_ARM64_", 323 | "/DARM64", 324 | "/DSTD_CALL", 325 | "/Zp8", 326 | ], 327 | arch_link_opts = [ 328 | "arm64rt.lib", 329 | ], 330 | cetcompat_option = "/CETCOMPAT:NO", 331 | cpu = "arm64_windows", 332 | entry_symbol_suffix = "", 333 | has_gz_option = "/Gd", 334 | host_system_name = "local", 335 | link_machine_flag = "/MACHINE:ARM64", 336 | msvc_env_app = _MSVC_ENV_APP_ARM64, 337 | msvc_env_wdm = _MSVC_ENV_WDM_ARM64, 338 | target_system_name = "local", 339 | tool_paths = _TOOL_PATHS_ARM64, 340 | toolchain_identifier = "ewdk_msvc_arm64", 341 | arm64ec_asm_opt = ["/machine:ARM64EC"], 342 | ) 343 | 344 | toolchain( 345 | name = "ewdk-cc-toolchain-x64_arm64_windows", 346 | exec_compatible_with = [ 347 | "@platforms//cpu:x86_64", 348 | "@platforms//os:windows", 349 | ], 350 | target_compatible_with = [ 351 | "@platforms//cpu:arm64", 352 | "@platforms//os:windows", 353 | ":ewdk_cc", 354 | ], 355 | toolchain = ":ewdk-cc-compiler-arm64_windows", 356 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 357 | ) 358 | 359 | toolchain( 360 | name = "ewdk-cc-toolchain-arm64_arm64_windows", 361 | exec_compatible_with = [ 362 | "@platforms//cpu:aarch64", 363 | "@platforms//os:windows", 364 | ], 365 | target_compatible_with = [ 366 | "@platforms//cpu:arm64", 367 | "@platforms//os:windows", 368 | ":ewdk_cc", 369 | ], 370 | toolchain = ":ewdk-cc-compiler-arm64_windows", 371 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 372 | ) 373 | 374 | # arm toolchain 375 | cc_toolchain( 376 | name = "ewdk-cc-compiler-arm_windows", 377 | all_files = ":empty", 378 | ar_files = ":empty", 379 | as_files = ":empty", 380 | compiler_files = ":empty", 381 | dwp_files = ":empty", 382 | linker_files = ":empty", 383 | objcopy_files = ":empty", 384 | strip_files = ":empty", 385 | supports_param_files = 1, 386 | toolchain_config = ":ewdk_msvc_arm", 387 | toolchain_identifier = "ewdk_msvc_arm", 388 | ) 389 | 390 | ewdk_cc_toolchain_config( 391 | name = "ewdk_msvc_arm", 392 | arch_c_opts_wdm = [ 393 | "/D_ARM_", 394 | "/DARM", 395 | "/DSTD_CALL", 396 | "/Zp8", 397 | ], 398 | arch_link_opts = [ 399 | "armrt.lib", 400 | ], 401 | cetcompat_option = "/CETCOMPAT:NO", 402 | cpu = "arm_windows", 403 | entry_symbol_suffix = "", 404 | has_gz_option = "/Gd", 405 | host_system_name = "local", 406 | link_machine_flag = "/MACHINE:ARM", 407 | msvc_env_app = _MSVC_ENV_APP_ARM, 408 | msvc_env_wdm = _MSVC_ENV_WDM_ARM, 409 | target_system_name = "local", 410 | tool_paths = _TOOL_PATHS_ARM, 411 | toolchain_identifier = "ewdk_msvc_arm", 412 | ) 413 | 414 | toolchain( 415 | name = "ewdk-cc-toolchain-x64_arm_windows", 416 | exec_compatible_with = [ 417 | "@platforms//cpu:x86_64", 418 | "@platforms//os:windows", 419 | ], 420 | target_compatible_with = [ 421 | "@platforms//cpu:arm", 422 | "@platforms//os:windows", 423 | ":ewdk_cc", 424 | ], 425 | toolchain = ":ewdk-cc-compiler-arm_windows", 426 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 427 | ) 428 | 429 | toolchain( 430 | name = "ewdk-cc-toolchain-arm64_arm_windows", 431 | exec_compatible_with = [ 432 | "@platforms//cpu:aarch64", 433 | "@platforms//os:windows", 434 | ], 435 | target_compatible_with = [ 436 | "@platforms//cpu:arm", 437 | "@platforms//os:windows", 438 | ":ewdk_cc", 439 | ], 440 | toolchain = ":ewdk-cc-compiler-arm_windows", 441 | toolchain_type = "@bazel_tools//tools/cpp:toolchain_type", 442 | ) 443 | 444 | # resource script x86 toolchain 445 | toolchain_type( 446 | name = "resource_script_toolchain_type", 447 | visibility = ["//visibility:public"], 448 | ) 449 | 450 | resource_script_toolchain_config( 451 | name = "ewdk_resource_script_toolchain_x86", 452 | defines = [ 453 | "/Di386=1", 454 | "/D_X86_=1", 455 | "/D_M_IX86", 456 | ], 457 | env = _MSVC_ENV_APP_X86, 458 | rcpath = "rc_wrapper.bat", 459 | ) 460 | 461 | toolchain( 462 | name = "resource-script-windows-x64_x86", 463 | exec_compatible_with = [ 464 | "@platforms//cpu:x86_64", 465 | "@platforms//os:windows", 466 | ], 467 | target_compatible_with = [ 468 | "@platforms//os:windows", 469 | "@platforms//cpu:x86_32", 470 | ":ewdk_cc", 471 | ], 472 | toolchain = ":ewdk_resource_script_toolchain_x86", 473 | toolchain_type = ":resource_script_toolchain_type", 474 | ) 475 | 476 | toolchain( 477 | name = "resource-script-windows-arm64_x86", 478 | exec_compatible_with = [ 479 | "@platforms//cpu:aarch64", 480 | "@platforms//os:windows", 481 | ], 482 | target_compatible_with = [ 483 | "@platforms//os:windows", 484 | "@platforms//cpu:x86_32", 485 | ":ewdk_cc", 486 | ], 487 | toolchain = ":ewdk_resource_script_toolchain_x86", 488 | toolchain_type = ":resource_script_toolchain_type", 489 | ) 490 | 491 | # resource script x64 toolchain 492 | resource_script_toolchain_config( 493 | name = "ewdk_resource_script_toolchain_x64", 494 | defines = [ 495 | "/D_WIN64", 496 | "/D_AMD64_", 497 | "/DAMD64", 498 | "/D_M_AMD64", 499 | ], 500 | env = _MSVC_ENV_APP_X64, 501 | rcpath = "rc_wrapper.bat", 502 | ) 503 | 504 | toolchain( 505 | name = "resource-script-windows-x64_x64", 506 | exec_compatible_with = [ 507 | "@platforms//cpu:x86_64", 508 | "@platforms//os:windows", 509 | ], 510 | target_compatible_with = [ 511 | "@platforms//os:windows", 512 | "@platforms//cpu:x86_64", 513 | ":ewdk_cc", 514 | ], 515 | toolchain = ":ewdk_resource_script_toolchain_x64", 516 | toolchain_type = ":resource_script_toolchain_type", 517 | ) 518 | 519 | toolchain( 520 | name = "resource-script-windows-arm64_x64", 521 | exec_compatible_with = [ 522 | "@platforms//cpu:aarch64", 523 | "@platforms//os:windows", 524 | ], 525 | target_compatible_with = [ 526 | "@platforms//os:windows", 527 | "@platforms//cpu:x86_64", 528 | ":ewdk_cc", 529 | ], 530 | toolchain = ":ewdk_resource_script_toolchain_x64", 531 | toolchain_type = ":resource_script_toolchain_type", 532 | ) 533 | 534 | # resource script arm toolchain 535 | resource_script_toolchain_config( 536 | name = "ewdk_resource_script_toolchain_arm", 537 | defines = [ 538 | "/D_ARM_", 539 | "/DARM", 540 | "/D_M_ARM", 541 | ], 542 | env = _MSVC_ENV_APP_ARM, 543 | rcpath = "rc_wrapper.bat", 544 | ) 545 | 546 | toolchain( 547 | name = "resource-script-windows-x64_arm", 548 | exec_compatible_with = [ 549 | "@platforms//cpu:x86_64", 550 | "@platforms//os:windows", 551 | ], 552 | target_compatible_with = [ 553 | "@platforms//os:windows", 554 | "@platforms//cpu:arm", 555 | ":ewdk_cc", 556 | ], 557 | toolchain = ":ewdk_resource_script_toolchain_arm", 558 | toolchain_type = ":resource_script_toolchain_type", 559 | ) 560 | 561 | toolchain( 562 | name = "resource-script-windows-arm64_arm", 563 | exec_compatible_with = [ 564 | "@platforms//cpu:aarch64", 565 | "@platforms//os:windows", 566 | ], 567 | target_compatible_with = [ 568 | "@platforms//os:windows", 569 | "@platforms//cpu:arm", 570 | ":ewdk_cc", 571 | ], 572 | toolchain = ":ewdk_resource_script_toolchain_arm", 573 | toolchain_type = ":resource_script_toolchain_type", 574 | ) 575 | 576 | # resource script arm64 toolchain 577 | resource_script_toolchain_config( 578 | name = "ewdk_resource_script_toolchain_arm64", 579 | defines = [ 580 | "/D_WIN64", 581 | "/D_ARM64_", 582 | "/DARM64", 583 | "/D_M_ARM64", 584 | ], 585 | env = _MSVC_ENV_APP_ARM64, 586 | rcpath = "rc_wrapper.bat", 587 | ) 588 | 589 | toolchain( 590 | name = "resource-script-windows-x64_arm64", 591 | exec_compatible_with = [ 592 | "@platforms//cpu:x86_64", 593 | "@platforms//os:windows", 594 | ], 595 | target_compatible_with = [ 596 | "@platforms//os:windows", 597 | "@platforms//cpu:arm64", 598 | ":ewdk_cc", 599 | ], 600 | toolchain = ":ewdk_resource_script_toolchain_arm64", 601 | toolchain_type = ":resource_script_toolchain_type", 602 | ) 603 | 604 | toolchain( 605 | name = "resource-script-windows-arm64_arm64", 606 | exec_compatible_with = [ 607 | "@platforms//cpu:aarch64", 608 | "@platforms//os:windows", 609 | ], 610 | target_compatible_with = [ 611 | "@platforms//os:windows", 612 | "@platforms//cpu:arm64", 613 | ":ewdk_cc", 614 | ], 615 | toolchain = ":ewdk_resource_script_toolchain_arm64", 616 | toolchain_type = ":resource_script_toolchain_type", 617 | ) 618 | 619 | # tracewpp toolchain 620 | toolchain_type( 621 | name = "wpp_toolchain_type", 622 | visibility = ["//visibility:public"], 623 | ) 624 | 625 | # tracewpp x86 toolchain 626 | wpp_toolchain_config( 627 | name = "ewdk_wpp_toolchain_x86", 628 | tracewpp_path = "tracewpp_wrapper.bat", 629 | env = _MSVC_ENV_APP_X86, 630 | cfgdir = "%{msvc_tracewpp_cfgdir}", 631 | ) 632 | 633 | toolchain( 634 | name = "ewdk-wpp-toolchain-x64_x86", 635 | exec_compatible_with = [ 636 | "@platforms//cpu:x86_64", 637 | "@platforms//os:windows", 638 | ], 639 | target_compatible_with = [ 640 | "@platforms//os:windows", 641 | "@platforms//cpu:x86_32", 642 | ":ewdk_cc", 643 | ], 644 | toolchain = ":ewdk_wpp_toolchain_x86", 645 | toolchain_type = ":wpp_toolchain_type", 646 | ) 647 | 648 | toolchain( 649 | name = "ewdk-wpp-toolchain-arm64_x86", 650 | exec_compatible_with = [ 651 | "@platforms//cpu:aarch64", 652 | "@platforms//os:windows", 653 | ], 654 | target_compatible_with = [ 655 | "@platforms//os:windows", 656 | "@platforms//cpu:x86_32", 657 | ":ewdk_cc", 658 | ], 659 | toolchain = ":ewdk_wpp_toolchain_x86", 660 | toolchain_type = ":wpp_toolchain_type", 661 | ) 662 | 663 | # tracewpp x64 toolchain 664 | wpp_toolchain_config( 665 | name = "ewdk_wpp_toolchain_x64", 666 | tracewpp_path = "tracewpp_wrapper.bat", 667 | env = _MSVC_ENV_APP_X64, 668 | cfgdir = "%{msvc_tracewpp_cfgdir}", 669 | ) 670 | 671 | toolchain( 672 | name = "ewdk-wpp-toolchain-x64_x64", 673 | exec_compatible_with = [ 674 | "@platforms//cpu:x86_64", 675 | "@platforms//os:windows", 676 | ], 677 | target_compatible_with = [ 678 | "@platforms//os:windows", 679 | "@platforms//cpu:x86_64", 680 | ":ewdk_cc", 681 | ], 682 | toolchain = ":ewdk_wpp_toolchain_x64", 683 | toolchain_type = ":wpp_toolchain_type", 684 | ) 685 | 686 | toolchain( 687 | name = "ewdk-wpp-toolchain-arm64_x64", 688 | exec_compatible_with = [ 689 | "@platforms//cpu:aarch64", 690 | "@platforms//os:windows", 691 | ], 692 | target_compatible_with = [ 693 | "@platforms//os:windows", 694 | "@platforms//cpu:x86_64", 695 | ":ewdk_cc", 696 | ], 697 | toolchain = ":ewdk_wpp_toolchain_x64", 698 | toolchain_type = ":wpp_toolchain_type", 699 | ) 700 | 701 | # tracewpp arm toolchain 702 | wpp_toolchain_config( 703 | name = "ewdk_wpp_toolchain_arm", 704 | tracewpp_path = "tracewpp_wrapper.bat", 705 | env = _MSVC_ENV_APP_ARM, 706 | cfgdir = "%{msvc_tracewpp_cfgdir}", 707 | ) 708 | 709 | toolchain( 710 | name = "ewdk-wpp-toolchain-x64_arm", 711 | exec_compatible_with = [ 712 | "@platforms//cpu:x86_64", 713 | "@platforms//os:windows", 714 | ], 715 | target_compatible_with = [ 716 | "@platforms//os:windows", 717 | "@platforms//cpu:arm", 718 | ":ewdk_cc", 719 | ], 720 | toolchain = ":ewdk_wpp_toolchain_arm", 721 | toolchain_type = ":wpp_toolchain_type", 722 | ) 723 | 724 | toolchain( 725 | name = "ewdk-wpp-toolchain-arm64_arm", 726 | exec_compatible_with = [ 727 | "@platforms//cpu:aarch64", 728 | "@platforms//os:windows", 729 | ], 730 | target_compatible_with = [ 731 | "@platforms//os:windows", 732 | "@platforms//cpu:arm", 733 | ":ewdk_cc", 734 | ], 735 | toolchain = ":ewdk_wpp_toolchain_arm", 736 | toolchain_type = ":wpp_toolchain_type", 737 | ) 738 | 739 | # tracewpp arm64 toolchain 740 | wpp_toolchain_config( 741 | name = "ewdk_wpp_toolchain_arm64", 742 | tracewpp_path = "tracewpp_wrapper.bat", 743 | env = _MSVC_ENV_APP_ARM64, 744 | cfgdir = "%{msvc_tracewpp_cfgdir}", 745 | ) 746 | 747 | toolchain( 748 | name = "ewdk-wpp-toolchain-x64_arm64", 749 | exec_compatible_with = [ 750 | "@platforms//cpu:x86_64", 751 | "@platforms//os:windows", 752 | ], 753 | target_compatible_with = [ 754 | "@platforms//os:windows", 755 | "@platforms//cpu:arm64", 756 | ":ewdk_cc", 757 | ], 758 | toolchain = ":ewdk_wpp_toolchain_arm64", 759 | toolchain_type = ":wpp_toolchain_type", 760 | ) 761 | 762 | toolchain( 763 | name = "ewdk-wpp-toolchain-arm64_arm64", 764 | exec_compatible_with = [ 765 | "@platforms//cpu:aarch64", 766 | "@platforms//os:windows", 767 | ], 768 | target_compatible_with = [ 769 | "@platforms//os:windows", 770 | "@platforms//cpu:arm64", 771 | ":ewdk_cc", 772 | ], 773 | toolchain = ":ewdk_wpp_toolchain_arm64", 774 | toolchain_type = ":wpp_toolchain_type", 775 | ) 776 | 777 | # idl toolchain 778 | toolchain_type( 779 | name = "idl_toolchain_type", 780 | visibility = ["//visibility:public"], 781 | ) 782 | 783 | # idl x86 toolchain 784 | idl_toolchain_config( 785 | name = "ewdk_idl_toolchain_x86", 786 | midl_path = "midl_wrapper.bat", 787 | msvc_env_app = _MSVC_ENV_APP_X86, 788 | msvc_env_wdm = _MSVC_ENV_WDM_X86, 789 | arch_opts = [ 790 | "/Di386", 791 | "/D_X86_", 792 | "/env", "win32", 793 | "/win32", 794 | ], 795 | ) 796 | 797 | toolchain( 798 | name = "ewdk-idl-toolchain-x64_x86", 799 | exec_compatible_with = [ 800 | "@platforms//cpu:x86_64", 801 | "@platforms//os:windows", 802 | ], 803 | target_compatible_with = [ 804 | "@platforms//os:windows", 805 | "@platforms//cpu:x86_32", 806 | ":ewdk_cc", 807 | ], 808 | toolchain = ":ewdk_idl_toolchain_x86", 809 | toolchain_type = ":idl_toolchain_type", 810 | ) 811 | 812 | toolchain( 813 | name = "ewdk-idl-toolchain-arm64_x86", 814 | exec_compatible_with = [ 815 | "@platforms//cpu:aarch64", 816 | "@platforms//os:windows", 817 | ], 818 | target_compatible_with = [ 819 | "@platforms//os:windows", 820 | "@platforms//cpu:x86_32", 821 | ":ewdk_cc", 822 | ], 823 | toolchain = ":ewdk_idl_toolchain_x86", 824 | toolchain_type = ":idl_toolchain_type", 825 | ) 826 | 827 | # idl x64 toolchain 828 | idl_toolchain_config( 829 | name = "ewdk_idl_toolchain_x64", 830 | midl_path = "midl_wrapper.bat", 831 | msvc_env_app = _MSVC_ENV_APP_X64, 832 | msvc_env_wdm = _MSVC_ENV_WDM_X64, 833 | arch_opts = [ 834 | "/D_AMD64_", 835 | "/D_WIN64", 836 | "/env", "x64", 837 | "/amd64", 838 | ], 839 | ) 840 | 841 | toolchain( 842 | name = "ewdk-idl-toolchain-x64_x64", 843 | exec_compatible_with = [ 844 | "@platforms//cpu:x86_64", 845 | "@platforms//os:windows", 846 | ], 847 | target_compatible_with = [ 848 | "@platforms//os:windows", 849 | "@platforms//cpu:x86_64", 850 | ":ewdk_cc", 851 | ], 852 | toolchain = ":ewdk_idl_toolchain_x64", 853 | toolchain_type = ":idl_toolchain_type", 854 | ) 855 | 856 | toolchain( 857 | name = "ewdk-idl-toolchain-arm64_x64", 858 | exec_compatible_with = [ 859 | "@platforms//cpu:aarch64", 860 | "@platforms//os:windows", 861 | ], 862 | target_compatible_with = [ 863 | "@platforms//os:windows", 864 | "@platforms//cpu:x86_64", 865 | ":ewdk_cc", 866 | ], 867 | toolchain = ":ewdk_idl_toolchain_x64", 868 | toolchain_type = ":idl_toolchain_type", 869 | ) 870 | 871 | # idl arm64 toolchain 872 | idl_toolchain_config( 873 | name = "ewdk_idl_toolchain_arm64", 874 | midl_path = "midl_wrapper.bat", 875 | msvc_env_app = _MSVC_ENV_APP_ARM64, 876 | msvc_env_wdm = _MSVC_ENV_WDM_ARM64, 877 | arch_opts = [ 878 | "/D_ARM64_", 879 | "/DARM64", 880 | "/DSTD_CALL", 881 | "/env", "arm64", 882 | ], 883 | ) 884 | 885 | toolchain( 886 | name = "ewdk-idl-toolchain-x64_arm64", 887 | exec_compatible_with = [ 888 | "@platforms//cpu:x86_64", 889 | "@platforms//os:windows", 890 | ], 891 | target_compatible_with = [ 892 | "@platforms//os:windows", 893 | "@platforms//cpu:arm64", 894 | ":ewdk_cc", 895 | ], 896 | toolchain = ":ewdk_idl_toolchain_arm64", 897 | toolchain_type = ":idl_toolchain_type", 898 | ) 899 | 900 | toolchain( 901 | name = "ewdk-idl-toolchain-arm64_arm64", 902 | exec_compatible_with = [ 903 | "@platforms//cpu:aarch64", 904 | "@platforms//os:windows", 905 | ], 906 | target_compatible_with = [ 907 | "@platforms//os:windows", 908 | "@platforms//cpu:arm64", 909 | ":ewdk_cc", 910 | ], 911 | toolchain = ":ewdk_idl_toolchain_arm64", 912 | toolchain_type = ":idl_toolchain_type", 913 | ) 914 | 915 | # ewdk command 916 | toolchain_type( 917 | name = "ewdk_command_type", 918 | visibility = ["//visibility:public"], 919 | ) 920 | 921 | ewdk_command_config( 922 | name = "ewdk_command_toolchain", 923 | command_path = "ewdk_command.bat", 924 | launch_env = _EWDK_LAUNCH_ENV, 925 | ) 926 | 927 | toolchain( 928 | name = "ewdk-command-toolchain-x64", 929 | exec_compatible_with = [ 930 | "@platforms//cpu:x86_64", 931 | "@platforms//os:windows", 932 | ], 933 | target_compatible_with = [ 934 | "@platforms//os:windows", 935 | ":ewdk_cc", 936 | ], 937 | toolchain = ":ewdk_command_toolchain", 938 | toolchain_type = "ewdk_command_type", 939 | ) 940 | 941 | toolchain( 942 | name = "ewdk-command-toolchain-arm64", 943 | exec_compatible_with = [ 944 | "@platforms//cpu:aarch64", 945 | "@platforms//os:windows", 946 | ], 947 | target_compatible_with = [ 948 | "@platforms//os:windows", 949 | ":ewdk_cc", 950 | ], 951 | toolchain = ":ewdk_command_toolchain", 952 | toolchain_type = "ewdk_command_type", 953 | ) -------------------------------------------------------------------------------- /ewdk_cc_configure.bzl: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright (c) 2022 Ira Strawser 2 | # SPDX-License-Identifier: MIT 3 | 4 | """EWDK toolchain implementation""" 5 | 6 | load( 7 | "@bazel_tools//tools/cpp:cc_toolchain_config_lib.bzl", 8 | "action_config", 9 | "artifact_name_pattern", 10 | "env_entry", 11 | "env_set", 12 | "feature", 13 | "flag_group", 14 | "flag_set", 15 | "tool", 16 | "tool_path", 17 | "variable_with_value", 18 | "with_feature_set", 19 | ) 20 | load("@bazel_tools//tools/build_defs/cc:action_names.bzl", "ACTION_NAMES") 21 | 22 | _project_types = { 23 | "app": r""" 24 | 25 | 26 | 27 | 28 | Release 29 | Win32 30 | 31 | 32 | Release 33 | x64 34 | 35 | 36 | Release 37 | ARM 38 | 39 | 40 | Release 41 | ARM64 42 | 43 | 44 | 45 | 46 | Application 47 | v143 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | """, 56 | "wdm": r""" 57 | 58 | 59 | 60 | 61 | Release 62 | Win32 63 | 64 | 65 | Release 66 | x64 67 | 68 | 69 | Release 70 | ARM 71 | 72 | 73 | Release 74 | ARM64 75 | 76 | 77 | 78 | 79 | Driver 80 | WindowsKernelModeDriver10.0 81 | WDM 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | """, 90 | } 91 | 92 | default_wdm_libs = [ 93 | "bufferoverflowfastfailk.lib", 94 | "ntoskrnl.lib", 95 | "hal.lib", 96 | "wmilib.lib", 97 | ] 98 | 99 | all_link_actions = [ 100 | ACTION_NAMES.cpp_link_executable, 101 | ACTION_NAMES.cpp_link_dynamic_library, 102 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 103 | ] 104 | 105 | def _empty_impl(ctx): 106 | file = ctx.actions.declare_file("empty_exec.bat") 107 | ctx.actions.write( 108 | output = file, 109 | content = "", 110 | is_executable = True, 111 | ) 112 | return [DefaultInfo(executable = file)] 113 | 114 | empty = rule(implementation = _empty_impl) 115 | 116 | def _get_envvar(env, name, default = None): 117 | for k, v in env.items(): 118 | if k.lower() == name.lower(): 119 | return v 120 | return default 121 | 122 | def _get_path_envvar(env, name, default = None): 123 | value = _get_envvar(env, name) 124 | if value != None: 125 | if value[0] == '"': 126 | if len(value) == 1 or value[-1] != '"': 127 | fail("Env var %s unbalanced quotes" % name) 128 | value = value[1:-1] 129 | if "/" in value: 130 | value = value.replace("/", "\\") 131 | if value[-1] == "\\": 132 | value = value.rstrip("\\") 133 | if "\\\\" in value: 134 | value = value.replace("\\\\", "\\") 135 | return value 136 | return default 137 | 138 | def _get_cpu_value(repository_ctx): 139 | """In the spirit of rules_cc's get_cpu_value""" 140 | 141 | # get_cpu_value() in the rule_cc library assumes x64 if windows is detected 142 | 143 | os_name = repository_ctx.os.name.lower() 144 | if os_name.find("windows") != -1: 145 | arch = _get_envvar(repository_ctx.os.environ, "PROCESSOR_ARCHITECTURE", "").lower() 146 | if arch == "amd64": 147 | # check if we're running under emulation 148 | processor_id = _get_envvar(repository_ctx.os.environ, "PROCESSOR_IDENTIFIER", "").lower() 149 | if processor_id.find("armv8 (64-bit)") != -1: 150 | return "arm64_windows" 151 | return "x64_windows" 152 | elif arch == "arm64": 153 | return "arm64_windows" 154 | elif arch == "x86": 155 | return "x86_windows" 156 | 157 | return "unknown" 158 | 159 | def _get_ewdk_version(repository_ctx, ewdkdir): 160 | """ Retrieves the EWDK version""" 161 | cmd = "@echo off\r\ntype \"{0}\\Version.txt\"\r\n".format(ewdkdir) 162 | repository_ctx.file("ewdk_get_version.bat", cmd, True) 163 | output = repository_ctx.execute(["./ewdk_get_version.bat"]).stdout 164 | if output.startswith("Version "): 165 | output = output[len("Version "):] 166 | numbers = [int(o) for o in output.split('.') if o.isdigit()] 167 | if len(numbers) != 2: 168 | fail("Unsupported EWDK version format: %s" % output) 169 | return (numbers[0], numbers[1]) 170 | 171 | def _does_ewdk_support_native_arm64(repository_ctx, ewdkdir): 172 | """Checks if the EWDK version supports native ARM64 compiler""" 173 | # Microsoft started delivering a native ARM64 compiler in ge_release.26100.1 174 | (major, _) = _get_ewdk_version(repository_ctx, ewdkdir) 175 | return major >= 26100 176 | 177 | def _get_ewdk_env(repository_ctx, ewdkdir, host_cpu): 178 | """Retrieve the envvars set by the EWDK's LaunchBuildEnv.cmd""" 179 | if host_cpu == "arm64_windows": 180 | if _does_ewdk_support_native_arm64(repository_ctx, ewdkdir): 181 | host_arch = "arm64" 182 | tgt_arch = "arm64" 183 | platform_arch = "ARM64" 184 | bin_arch = "arm64" 185 | else: 186 | host_arch = "x64" 187 | tgt_arch = "arm64" 188 | platform_arch = "ARM64" 189 | bin_arch = "x64" 190 | elif host_cpu == "x86_windows": 191 | host_arch = "x86" 192 | tgt_arch = "x86" 193 | platform_arch = "x86" 194 | bin_arch = "x86" 195 | else: # x64_windows 196 | host_arch = "amd64" 197 | tgt_arch = "amd64" 198 | platform_arch = "x64" 199 | bin_arch = "x64" 200 | 201 | cmd = """@echo off 202 | :: 203 | :: This script is generated by the build system to setup the EWDK environment 204 | :: 205 | 206 | :: 207 | :: Microsoft started delivering a native ARM64 compiler (ge_release.26100.1). 208 | :: Microsoft has not yet exposed parameters on SetupBuildEnv.cmd to select 209 | :: the all possible host and target architectures. At the time of writing 210 | :: Microsoft only exposes the following: 211 | :: x86 212 | :: x86_amd64 213 | :: amd64 214 | :: x86_arm64 215 | :: 216 | :: We want to compile with the native toolchain for best performance. It is 217 | :: possible to work around this limitation by not providing an argument to 218 | :: SetupBuildEnv.cmd and hacking in the internal __VSCMD_ARG_* variables 219 | :: instead. We do that here, but after calling SetupBuildEnv.cmd we need to 220 | :: fixup a few things. 221 | :: 222 | set "__VSCMD_ARG_HOST_ARCH={1}" 223 | set "__VSCMD_ARG_TGT_ARCH={2}" 224 | 225 | :: 226 | :: Setup Build Environment 227 | :: 228 | call "{0}\\BuildEnv\\SetupBuildEnv.cmd" > nul 229 | 230 | :: 231 | :: Sanitize echo after SetupBuildEnv.cmd 232 | :: 233 | @echo off 234 | 235 | :: 236 | :: Fixup what is necessary after calling SetupBuildEnv.cmd 237 | :: 238 | set Platform={3} 239 | set "WindowsSdkVerBinPath=%WindowsSdkDir%\\bin\\%Version_Number%\\{4}" 240 | 241 | :: 242 | :: Setup Visual Studio Environment 243 | :: 244 | call "{0}\\BuildEnv\\SetupVSEnv.cmd" > nul 245 | :: 246 | :: Sanitize echo after SetupVSEnv.cmd 247 | :: 248 | @echo off 249 | 250 | :: 251 | :: Setup NetFX Kits Environment 252 | :: 253 | set NETFXSDKDir=%NetFXKitsDir% 254 | cd /d "{0}" 255 | dir /b tlbexp.exe /s 2>nul 256 | 257 | :: 258 | :: Fixup VCINSTALLDIR_ not being set 259 | :: 260 | set "VisualStudioMajorVersion=%VisualStudioVersion:~0,2%" 261 | set "VCINSTALLDIR_%VisualStudioMajorVersion%0=%VCINSTALLDIR%" 262 | set VisualStudioMajorVersion= 263 | 264 | :: 265 | :: Dump the environment variables 266 | :: 267 | set 268 | """.format(ewdkdir, host_arch, tgt_arch, platform_arch, bin_arch) 269 | repository_ctx.file("ewdk_env.bat", cmd, True) 270 | envs = repository_ctx.execute(["./ewdk_env.bat"]).stdout 271 | env_map = {} 272 | netfx_x86 = None 273 | netfx_x64 = None 274 | for line in envs.split("\n"): 275 | line = line.strip() 276 | offset = line.find("=") 277 | if offset == -1: 278 | if line.lower().endswith("\\x64\\tlbexp.exe"): 279 | netfx_x64 = line[:-len("tlbexp.exe")] 280 | elif line.lower().endswith("\\tlbexp.exe"): 281 | netfx_x86 = line[:-len("tlbexp.exe")] 282 | continue 283 | env_map[line[:offset].upper()] = line[offset + 1:] 284 | if netfx_x86: 285 | env_map["WINDOWSSDK_EXECUTABLEPATH_X86"] = netfx_x86 286 | if netfx_x64: 287 | env_map["WINDOWSSDK_EXECUTABLEPATH_X64"] = netfx_x64 288 | env_str = "" 289 | for k, v in env_map.items(): 290 | env_str += " \"{}\": \"{}\",\r\n".format(k, v) 291 | env_map["_MSBUILD_PATH"] = _get_exe_path(repository_ctx, "msbuild.exe", env_map) 292 | env_map["_RC_PATH"] = _get_exe_path(repository_ctx, "rc.exe", env_map) 293 | env_map["_TRACEWPP_PATH"] = _get_exe_path(repository_ctx, "tracewpp.exe", env_map) 294 | env_map["_MIDL_PATH"] = _get_exe_path(repository_ctx, "midl.exe", env_map) 295 | env_map["_LIB_PATH"] = _get_exe_path(repository_ctx, "lib.exe", env_map) 296 | env_map["_CL_PATH"] = _get_exe_path(repository_ctx, "cl.exe", env_map) 297 | env_map["_LINK_PATH"] = _get_exe_path(repository_ctx, "link.exe", env_map) 298 | return (env_map, env_str) 299 | 300 | def _get_exe_path(repository_ctx, filename, env): 301 | """Retrieve the path to the given exe""" 302 | repository_ctx.file("ewdk_get_exe.bat", "@echo off\r\nwhere %1\r\n", True) 303 | output = repository_ctx.execute(["./ewdk_get_exe.bat", filename], environment = env).stdout 304 | for line in output.split("\n"): 305 | if len(line): 306 | return line.strip() 307 | fail("Failed to locate %s for this EWDK" % filename) 308 | 309 | def _get_msbuild_envs(repository_ctx, env): 310 | """Retrieve env vars set by msbuild used as defaults for the various project types supported here""" 311 | build_envs = {} 312 | platforms = ["x86", "x64", "arm", "arm64"] 313 | project_types = _project_types.keys() 314 | 315 | # Unknown if it is safe to use the string replace method on this version. Execute msbuild for all combos 316 | i = 0 317 | tot = len(project_types) * len(platforms) 318 | for project_type in project_types: 319 | for platform in platforms: 320 | i = i + 1 321 | progress = "Acquiring msbuild \"{} {}\" env vars... [{}/{}]".format(platform, project_type, i, tot) 322 | repository_ctx.report_progress(progress) 323 | build_env = _msbuild_extract_vars(repository_ctx, env, project_type, platform) 324 | build_envs["{}_{}".format(project_type, platform)] = build_env 325 | 326 | # NetFx (.net framework) 327 | for platform in ["x86", "x64"]: 328 | penv = "app_{}".format(platform) 329 | sdk = "WINDOWSSDK_EXECUTABLEPATH_{}".format(platform).upper() 330 | build_envs[penv]["PATH"] = "{};{}".format(env[sdk], build_envs[penv]["PATH"]) 331 | build_envs[penv]["INCLUDE"] = "{}include\\um;{}".format(env["NETFXSDKDIR"], build_envs[penv]["INCLUDE"]) 332 | build_envs[penv]["LIB"] = "{}lib\\um;{}".format(env["NETFXSDKDIR"], build_envs[penv]["LIB"]) 333 | 334 | return build_envs 335 | 336 | def _msbuild_extract_vars(repository_ctx, env, project_type, platform): 337 | """Execute msbuild.exe with detailed verbosity enabled to extract the SetEnv tasks""" 338 | vars = ("PATH=", "INCLUDE=", "EXTERNAL_INCLUDE=", "LIBPATH=", "LIB=") 339 | projfile = project_type + ".vcxproj" 340 | repository_ctx.file(projfile, _project_types[project_type]) 341 | args = [ 342 | env["_MSBUILD_PATH"], 343 | projfile, 344 | "/verbosity:detailed", 345 | "/property:Configuration=Release", 346 | "/property:Platform={}".format(platform), 347 | "/property:WindowsTargetPlatformVersion={}".format(env["VERSION_NUMBER"]), 348 | ] 349 | result = repository_ctx.execute(args, environment = env) 350 | repository_ctx.delete("Release" if platform == "x86" else platform) 351 | tmp = {} 352 | for line in result.stdout.split("\n"): 353 | line = line.strip() 354 | if line.startswith(vars): 355 | offset = line.find("=") 356 | tmp[line[:offset]] = line[offset + 1:] 357 | return tmp 358 | 359 | def _build_vscode_intellisense_config(repository_ctx, vscode_cfg_path, env, build_envs): 360 | host = env["PLATFORM"].lower() 361 | app_includes = build_envs["app_" + host]["INCLUDE"] 362 | wdm_includes = build_envs["wdm_" + host]["INCLUDE"] 363 | 364 | includes = [] 365 | prune = {} 366 | for x in app_includes.split(";") + wdm_includes.split(";"): 367 | if x and not prune.get(x) and not x.lower().endswith("\\km\\crt"): 368 | prune[x] = 1 369 | includes.append(x) 370 | 371 | indent = " " * 4 372 | includes = (",\r\n%s" % indent).join(["\"%s\"" % x for x in includes]) 373 | 374 | tpl_vars = { 375 | "%{cl_path}": env["_CL_PATH"], 376 | "%{c_standard}": "c17", 377 | "%{cpp_standard}": "c++17", 378 | "%{sdk_version}": env["VERSION_NUMBER"], 379 | "%{system_includes}": includes.replace("\\", "/"), 380 | } 381 | repository_ctx.template("c_cpp_properties.json", vscode_cfg_path, tpl_vars) 382 | 383 | def _build_cmd_env_helpers(repository_ctx, cmd_helper_path, build_envs): 384 | for arch in ["x86", "x64", "arm", "arm64"]: 385 | env = build_envs["app_" + arch] 386 | tpl_vars = { 387 | "%{path}": env["PATH"], 388 | "%{include}": env["INCLUDE"], 389 | "%{external_include}": env["EXTERNAL_INCLUDE"], 390 | "%{libpath}": env["LIBPATH"], 391 | "%{lib}": env["LIB"], 392 | } 393 | repository_ctx.template("env_app_%s.cmd" % arch, cmd_helper_path, tpl_vars) 394 | 395 | def _impl(ctx): 396 | wdm_default_includes = [x.replace("\\", "/") for x in ctx.attr.msvc_env_wdm["INCLUDE"].split(";") if x] 397 | 398 | artifact_name_patterns = [ 399 | artifact_name_pattern( 400 | category_name = "object_file", 401 | prefix = "", 402 | extension = ".obj", 403 | ), 404 | artifact_name_pattern( 405 | category_name = "static_library", 406 | prefix = "", 407 | extension = ".lib", 408 | ), 409 | artifact_name_pattern( 410 | category_name = "alwayslink_static_library", 411 | prefix = "", 412 | extension = ".lo.lib", 413 | ), 414 | artifact_name_pattern( 415 | category_name = "executable", 416 | prefix = "", 417 | extension = ".exe", 418 | ), 419 | artifact_name_pattern( 420 | category_name = "dynamic_library", 421 | prefix = "", 422 | extension = ".dll", 423 | ), 424 | artifact_name_pattern( 425 | category_name = "interface_library", 426 | prefix = "", 427 | extension = ".if.lib", 428 | ), 429 | ] 430 | 431 | cpp_link_nodeps_dynamic_library_action = action_config( 432 | action_name = ACTION_NAMES.cpp_link_nodeps_dynamic_library, 433 | implies = [ 434 | "nologo", 435 | "shared_flag", 436 | "linkstamps", 437 | "output_execpath_flags", 438 | "input_param_flags", 439 | "user_link_flags", 440 | # "linker_subsystem_flag", 441 | "linker_param_file", 442 | "msvc_env", 443 | "no_stripping", 444 | "has_configured_linker_path", 445 | "def_file", 446 | ], 447 | tools = [tool(path = ctx.attr.tool_paths["ld"])], 448 | ) 449 | 450 | cpp_link_static_library_action = action_config( 451 | action_name = ACTION_NAMES.cpp_link_static_library, 452 | implies = [ 453 | "nologo", 454 | "archiver_flags", 455 | "input_param_flags", 456 | "linker_param_file", 457 | "msvc_env", 458 | ], 459 | tools = [tool(path = ctx.attr.tool_paths["ar"])], 460 | ) 461 | 462 | assemble_action = action_config( 463 | action_name = ACTION_NAMES.assemble, 464 | implies = [ 465 | "compiler_input_flags", 466 | "compiler_output_flags", 467 | "nologo", 468 | "msvc_env", 469 | # "sysroot", 470 | ], 471 | tools = [tool(path = ctx.attr.tool_paths["ml"])], 472 | ) 473 | 474 | preprocess_assemble_action = action_config( 475 | action_name = ACTION_NAMES.preprocess_assemble, 476 | implies = [ 477 | "compiler_input_flags", 478 | "compiler_output_flags", 479 | "nologo", 480 | "msvc_env", 481 | # "sysroot", 482 | ], 483 | tools = [tool(path = ctx.attr.tool_paths["ml"])], 484 | ) 485 | 486 | c_compile_action = action_config( 487 | action_name = ACTION_NAMES.c_compile, 488 | implies = [ 489 | "compiler_input_flags", 490 | "compiler_output_flags", 491 | "nologo", 492 | "msvc_env", 493 | "user_compile_flags", 494 | # "sysroot", 495 | ], 496 | tools = [tool(path = ctx.attr.tool_paths["cpp"])], 497 | ) 498 | 499 | linkstamp_compile_action = action_config( 500 | action_name = ACTION_NAMES.linkstamp_compile, 501 | implies = [ 502 | "compiler_input_flags", 503 | "compiler_output_flags", 504 | "default_compile_flags", 505 | "nologo", 506 | "msvc_env", 507 | "user_compile_flags", 508 | # "sysroot", 509 | "unfiltered_compile_flags", 510 | ], 511 | tools = [tool(path = ctx.attr.tool_paths["cpp"])], 512 | ) 513 | 514 | cpp_compile_action = action_config( 515 | action_name = ACTION_NAMES.cpp_compile, 516 | implies = [ 517 | "compiler_input_flags", 518 | "compiler_output_flags", 519 | "nologo", 520 | "msvc_env", 521 | "user_compile_flags", 522 | # "sysroot", 523 | ], 524 | tools = [tool(path = ctx.attr.tool_paths["cpp"])], 525 | ) 526 | 527 | cpp_link_executable_action = action_config( 528 | action_name = ACTION_NAMES.cpp_link_executable, 529 | implies = [ 530 | "nologo", 531 | "linkstamps", 532 | "output_execpath_flags", 533 | "input_param_flags", 534 | "user_link_flags", 535 | # "linker_subsystem_flag", 536 | "linker_param_file", 537 | "msvc_env", 538 | "no_stripping", 539 | ], 540 | tools = [tool(path = ctx.attr.tool_paths["ld"])], 541 | ) 542 | 543 | cpp_link_dynamic_library_action = action_config( 544 | action_name = ACTION_NAMES.cpp_link_dynamic_library, 545 | implies = [ 546 | "nologo", 547 | "shared_flag", 548 | "linkstamps", 549 | "output_execpath_flags", 550 | "input_param_flags", 551 | "user_link_flags", 552 | # "linker_subsystem_flag", 553 | "linker_param_file", 554 | "msvc_env", 555 | "no_stripping", 556 | "has_configured_linker_path", 557 | "def_file", 558 | ], 559 | tools = [tool(path = ctx.attr.tool_paths["ld"])], 560 | ) 561 | 562 | cpp_module_scan_deps = action_config( 563 | action_name = ACTION_NAMES.cpp_module_deps_scanning, 564 | implies = [ 565 | "compiler_input_flags", 566 | "compiler_output_flags", 567 | "nologo", 568 | "msvc_env", 569 | "user_compile_flags", 570 | # "sysroot", 571 | ], 572 | tools = [tool(path = ctx.attr.tool_paths["cpp-module-deps-scanner"])], 573 | ) 574 | 575 | cpp20_module_compile = action_config( 576 | action_name = ACTION_NAMES.cpp20_module_compile, 577 | implies = [ 578 | "compiler_input_flags", 579 | "compiler_output_flags", 580 | "nologo", 581 | "msvc_env", 582 | "user_compile_flags", 583 | # "sysroot", 584 | ], 585 | flag_sets = [flag_set(flag_groups = [flag_group(flags = ["/TP", "/interface"])])], 586 | tools = [tool(path = ctx.attr.tool_paths["cpp"])], 587 | ) 588 | 589 | cpp20_module_codegen = action_config( 590 | action_name = ACTION_NAMES.cpp20_module_codegen, 591 | implies = [ 592 | "compiler_input_flags", 593 | "compiler_output_flags", 594 | "nologo", 595 | "msvc_env", 596 | "user_compile_flags", 597 | # "sysroot", 598 | ], 599 | tools = [tool(path = ctx.attr.tool_paths["cpp"])], 600 | ) 601 | 602 | action_configs = [ 603 | assemble_action, 604 | preprocess_assemble_action, 605 | c_compile_action, 606 | linkstamp_compile_action, 607 | cpp_compile_action, 608 | cpp_link_executable_action, 609 | cpp_link_dynamic_library_action, 610 | cpp_link_nodeps_dynamic_library_action, 611 | cpp_link_static_library_action, 612 | cpp_module_scan_deps, 613 | cpp20_module_compile, 614 | cpp20_module_codegen, 615 | ] 616 | 617 | dbg_compile_flags = [ 618 | flag_set( 619 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 620 | flag_groups = [flag_group(flags = ["/Od", "/Z7"])], 621 | ), 622 | flag_set( 623 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 624 | flag_groups = [flag_group(flags = ["/RTC1"])], 625 | with_features = [with_feature_set(not_features = ["wdm", "no_runtime_checks"])], 626 | ), 627 | flag_set( 628 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 629 | flag_groups = [flag_group(flags = ["/DMSC_NOOPT", "/DDBG=1", "/D_DEBUG=1"])], 630 | with_features = [with_feature_set(features = ["wdm"])], 631 | ), 632 | ] 633 | 634 | dbg_link_flags_fast = [ 635 | flag_set( 636 | actions = all_link_actions, 637 | flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO"])], 638 | ), 639 | ] 640 | 641 | dbg_link_flags_full = [ 642 | flag_set( 643 | actions = all_link_actions, 644 | flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO"])], 645 | ), 646 | ] 647 | 648 | msvc_link_env_feature = feature( 649 | name = "msvc_link_env", 650 | env_sets = [ 651 | env_set( 652 | actions = all_link_actions + 653 | [ACTION_NAMES.cpp_link_static_library], 654 | env_entries = [env_entry(key = "LIB", value = ctx.attr.msvc_env_app["LIB"])], 655 | with_features = [with_feature_set(not_features = ["wdm"])], 656 | ), 657 | env_set( 658 | actions = all_link_actions + 659 | [ACTION_NAMES.cpp_link_static_library], 660 | env_entries = [env_entry(key = "LIB", value = ctx.attr.msvc_env_wdm["LIB"])], 661 | with_features = [with_feature_set(features = ["wdm"])], 662 | ), 663 | ], 664 | ) 665 | 666 | shared_flag_feature = feature( 667 | name = "shared_flag", 668 | flag_sets = [ 669 | flag_set( 670 | actions = [ 671 | ACTION_NAMES.cpp_link_dynamic_library, 672 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 673 | ], 674 | flag_groups = [flag_group(flags = ["/DLL"])], 675 | with_features = [with_feature_set(not_features = ["wdm"])], 676 | ), 677 | ], 678 | ) 679 | 680 | determinism_feature = feature( 681 | name = "determinism", 682 | enabled = True, 683 | flag_sets = [ 684 | flag_set( 685 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 686 | flag_groups = [ 687 | flag_group( 688 | flags = [ 689 | "/wd4117", 690 | "-D__DATE__=\"redacted\"", 691 | "-D__TIMESTAMP__=\"redacted\"", 692 | "-D__TIME__=\"redacted\"", 693 | ], 694 | ), 695 | ], 696 | ), 697 | ], 698 | ) 699 | 700 | sysroot_feature = feature( 701 | name = "sysroot", 702 | flag_sets = [ 703 | flag_set( 704 | actions = [ 705 | ACTION_NAMES.assemble, 706 | ACTION_NAMES.preprocess_assemble, 707 | ACTION_NAMES.c_compile, 708 | ACTION_NAMES.linkstamp_compile, 709 | ACTION_NAMES.cpp_compile, 710 | ACTION_NAMES.cpp_header_parsing, 711 | ACTION_NAMES.cpp_module_compile, 712 | ACTION_NAMES.cpp_module_codegen, 713 | ACTION_NAMES.cpp_module_deps_scanning, 714 | ACTION_NAMES.cpp20_module_compile, 715 | ACTION_NAMES.cpp20_module_codegen, 716 | ACTION_NAMES.cpp_link_executable, 717 | ACTION_NAMES.cpp_link_dynamic_library, 718 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 719 | ], 720 | flag_groups = [ 721 | flag_group( 722 | flags = ["--sysroot=%{sysroot}"], 723 | iterate_over = "sysroot", 724 | expand_if_available = "sysroot", 725 | ), 726 | ], 727 | ), 728 | ], 729 | ) 730 | 731 | unfiltered_compile_flags_feature = feature( 732 | name = "unfiltered_compile_flags", 733 | enabled = True, 734 | flag_sets = [ 735 | flag_set( 736 | actions = [ 737 | ACTION_NAMES.preprocess_assemble, 738 | ACTION_NAMES.c_compile, 739 | ACTION_NAMES.linkstamp_compile, 740 | ACTION_NAMES.cpp_compile, 741 | ACTION_NAMES.cpp_header_parsing, 742 | ACTION_NAMES.cpp_module_compile, 743 | ACTION_NAMES.cpp_module_codegen, 744 | ACTION_NAMES.cpp_module_deps_scanning, 745 | ACTION_NAMES.cpp20_module_compile, 746 | ACTION_NAMES.cpp20_module_codegen, 747 | ], 748 | flag_groups = [ 749 | flag_group( 750 | flags = ["%{unfiltered_compile_flags}"], 751 | iterate_over = "unfiltered_compile_flags", 752 | expand_if_available = "unfiltered_compile_flags", 753 | ), 754 | ], 755 | ), 756 | ], 757 | ) 758 | 759 | archive_param_file_feature = feature( 760 | name = "archive_param_file", 761 | enabled = True, 762 | ) 763 | 764 | compiler_param_file_feature = feature( 765 | name = "compiler_param_file", 766 | # compiler param files are currently broken: https://github.com/bazelbuild/bazel/issues/21029 767 | # enabled = True, 768 | ) 769 | 770 | copy_dynamic_libraries_to_binary_feature = feature( 771 | name = "copy_dynamic_libraries_to_binary", 772 | ) 773 | 774 | input_param_flags_feature = feature( 775 | name = "input_param_flags", 776 | flag_sets = [ 777 | flag_set( 778 | actions = [ 779 | ACTION_NAMES.cpp_link_dynamic_library, 780 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 781 | ], 782 | flag_groups = [ 783 | flag_group( 784 | flags = ["/IMPLIB:%{interface_library_output_path}"], 785 | expand_if_available = "interface_library_output_path", 786 | ), 787 | ], 788 | ), 789 | flag_set( 790 | actions = all_link_actions, 791 | flag_groups = [ 792 | flag_group( 793 | flags = ["%{libopts}"], 794 | iterate_over = "libopts", 795 | expand_if_available = "libopts", 796 | ), 797 | ], 798 | ), 799 | flag_set( 800 | actions = all_link_actions + 801 | [ACTION_NAMES.cpp_link_static_library], 802 | flag_groups = [ 803 | flag_group( 804 | iterate_over = "libraries_to_link", 805 | flag_groups = [ 806 | flag_group( 807 | iterate_over = "libraries_to_link.object_files", 808 | flag_groups = [flag_group(flags = ["%{libraries_to_link.object_files}"])], 809 | expand_if_equal = variable_with_value( 810 | name = "libraries_to_link.type", 811 | value = "object_file_group", 812 | ), 813 | ), 814 | flag_group( 815 | flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], 816 | expand_if_equal = variable_with_value( 817 | name = "libraries_to_link.type", 818 | value = "object_file", 819 | ), 820 | ), 821 | flag_group( 822 | flag_groups = [flag_group(flags = ["%{libraries_to_link.name}"])], 823 | expand_if_equal = variable_with_value( 824 | name = "libraries_to_link.type", 825 | value = "interface_library", 826 | ), 827 | ), 828 | flag_group( 829 | flag_groups = [ 830 | flag_group( 831 | flags = ["%{libraries_to_link.name}"], 832 | expand_if_false = "libraries_to_link.is_whole_archive", 833 | ), 834 | flag_group( 835 | flags = ["/WHOLEARCHIVE:%{libraries_to_link.name}"], 836 | expand_if_true = "libraries_to_link.is_whole_archive", 837 | ), 838 | ], 839 | expand_if_equal = variable_with_value( 840 | name = "libraries_to_link.type", 841 | value = "static_library", 842 | ), 843 | ), 844 | ], 845 | expand_if_available = "libraries_to_link", 846 | ), 847 | ], 848 | ), 849 | ], 850 | ) 851 | 852 | fastbuild_feature = feature( 853 | name = "fastbuild", 854 | flag_sets = dbg_compile_flags + dbg_link_flags_fast, 855 | implies = ["generate_pdb_file"], 856 | ) 857 | 858 | user_compile_flags_feature = feature( 859 | name = "user_compile_flags", 860 | flag_sets = [ 861 | flag_set( 862 | actions = [ 863 | ACTION_NAMES.preprocess_assemble, 864 | ACTION_NAMES.c_compile, 865 | ACTION_NAMES.linkstamp_compile, 866 | ACTION_NAMES.cpp_compile, 867 | ACTION_NAMES.cpp_header_parsing, 868 | ACTION_NAMES.cpp_module_compile, 869 | ACTION_NAMES.cpp_module_codegen, 870 | ACTION_NAMES.cpp_module_deps_scanning, 871 | ACTION_NAMES.cpp20_module_compile, 872 | ACTION_NAMES.cpp20_module_codegen, 873 | ], 874 | flag_groups = [ 875 | flag_group( 876 | flags = ["%{user_compile_flags}"], 877 | iterate_over = "user_compile_flags", 878 | expand_if_available = "user_compile_flags", 879 | ), 880 | ], 881 | ), 882 | ], 883 | ) 884 | 885 | archiver_flags_feature = feature( 886 | name = "archiver_flags", 887 | flag_sets = [ 888 | flag_set( 889 | actions = [ACTION_NAMES.cpp_link_static_library], 890 | flag_groups = [ 891 | flag_group( 892 | flags = ["/OUT:%{output_execpath}"], 893 | expand_if_available = "output_execpath", 894 | ), 895 | flag_group( 896 | flags = ["%{user_archiver_flags}"], 897 | iterate_over = "user_archiver_flags", 898 | expand_if_available = "user_archiver_flags", 899 | ), 900 | ], 901 | ), 902 | ], 903 | ) 904 | 905 | default_link_flags_feature = feature( 906 | name = "default_link_flags", 907 | enabled = True, 908 | flag_sets = [ 909 | flag_set( 910 | actions = all_link_actions, 911 | flag_groups = [ 912 | flag_group( 913 | flags = [ 914 | "/DYNAMICBASE", 915 | "/NXCOMPAT", 916 | ] + ctx.attr.arch_link_opts, 917 | ), 918 | ], 919 | with_features = [with_feature_set(not_features = ["wdm"])], 920 | ), 921 | flag_set( 922 | actions = all_link_actions, 923 | flag_groups = [ 924 | flag_group( 925 | flags = [ 926 | "/INTEGRITYCHECK", 927 | "/DYNAMICBASE", 928 | "/NXCOMPAT", 929 | "/DRIVER", 930 | "/NODEFAULTLIB", 931 | "/SECTION:INIT,d", 932 | "/MERGE:_TEXT=.text;_PAGE=PAGE", 933 | ] + ctx.attr.arch_link_opts + ctx.attr.arch_link_opts_wdm + default_wdm_libs, 934 | ), 935 | ], 936 | with_features = [with_feature_set(features = ["wdm"])], 937 | ), 938 | ], 939 | ) 940 | 941 | static_link_msvcrt_feature = feature( 942 | name = "static_link_msvcrt", 943 | flag_sets = [ 944 | flag_set( 945 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 946 | flag_groups = [flag_group(flags = ["/MT"])], 947 | with_features = [with_feature_set(not_features = ["dbg", "disable_msvcrt"])], 948 | ), 949 | flag_set( 950 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 951 | flag_groups = [flag_group(flags = ["/MTd"])], 952 | with_features = [with_feature_set(features = ["dbg"], not_features = ["disable_mscvrt"])], 953 | ), 954 | flag_set( 955 | actions = all_link_actions, 956 | flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmt.lib"])], 957 | with_features = [with_feature_set(not_features = ["dbg", "disable_msvcrt"])], 958 | ), 959 | flag_set( 960 | actions = all_link_actions, 961 | flag_groups = [flag_group(flags = ["/DEFAULTLIB:libcmtd.lib"])], 962 | with_features = [with_feature_set(features = ["dbg"], not_features = ["disable_mscvrt"])], 963 | ), 964 | ], 965 | ) 966 | 967 | dynamic_link_msvcrt_feature = feature( 968 | name = "dynamic_link_msvcrt", 969 | enabled = True, 970 | flag_sets = [ 971 | flag_set( 972 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 973 | flag_groups = [flag_group(flags = ["/MD"])], 974 | with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt", "disable_msvcrt"])], 975 | ), 976 | flag_set( 977 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 978 | flag_groups = [flag_group(flags = ["/MDd"])], 979 | with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt", "disable_msvcrt"])], 980 | ), 981 | flag_set( 982 | actions = all_link_actions, 983 | flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrt.lib"])], 984 | with_features = [with_feature_set(not_features = ["dbg", "static_link_msvcrt", "disable_msvcrt"])], 985 | ), 986 | flag_set( 987 | actions = all_link_actions, 988 | flag_groups = [flag_group(flags = ["/DEFAULTLIB:msvcrtd.lib"])], 989 | with_features = [with_feature_set(features = ["dbg"], not_features = ["static_link_msvcrt", "disable_msvcrt"])], 990 | ), 991 | ], 992 | ) 993 | 994 | dbg_feature = feature( 995 | name = "dbg", 996 | flag_sets = dbg_compile_flags + dbg_link_flags_full, 997 | implies = ["generate_pdb_file"], 998 | ) 999 | 1000 | opt_feature = feature( 1001 | name = "opt", 1002 | flag_sets = [ 1003 | flag_set( 1004 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1005 | flag_groups = [flag_group(flags = ["/DNDEBUG", "/Gy", "/GF", "/Z7"])], 1006 | ), 1007 | flag_set( 1008 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1009 | flag_groups = [flag_group(flags = ["/GL", "/O2"])], 1010 | with_features = [with_feature_set(not_features = ["wdm"])], 1011 | ), 1012 | flag_set( 1013 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1014 | flag_groups = [flag_group(flags = ["/Ox", "/Os", "/GL"])], 1015 | with_features = [with_feature_set(features = ["wdm"])], 1016 | ), 1017 | flag_set( 1018 | actions = all_link_actions, 1019 | flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO", "/LTCG"])], 1020 | with_features = [with_feature_set(not_features = ["wdm"])], 1021 | ), 1022 | flag_set( 1023 | actions = all_link_actions, 1024 | flag_groups = [flag_group(flags = ["/DEBUG:FULL", "/INCREMENTAL:NO", "/LTCG"])], 1025 | with_features = [with_feature_set(features = ["wdm"])], 1026 | ), 1027 | ], 1028 | implies = ["generate_pdb_file"], 1029 | ) 1030 | 1031 | supports_interface_shared_libraries_feature = feature( 1032 | name = "supports_interface_shared_libraries", 1033 | enabled = True, 1034 | ) 1035 | 1036 | user_link_flags_feature = feature( 1037 | name = "user_link_flags", 1038 | flag_sets = [ 1039 | flag_set( 1040 | actions = all_link_actions, 1041 | flag_groups = [ 1042 | flag_group( 1043 | flags = ["%{user_link_flags}"], 1044 | iterate_over = "user_link_flags", 1045 | expand_if_available = "user_link_flags", 1046 | ), 1047 | ], 1048 | ), 1049 | ], 1050 | ) 1051 | 1052 | default_compile_flags_feature = feature( 1053 | name = "default_compile_flags", 1054 | enabled = True, 1055 | flag_sets = [ 1056 | flag_set( 1057 | actions = [ 1058 | # ACTION_NAMES.assemble, 1059 | # ACTION_NAMES.preprocess_assemble, 1060 | ACTION_NAMES.linkstamp_compile, 1061 | ACTION_NAMES.c_compile, 1062 | ACTION_NAMES.cpp_compile, 1063 | ACTION_NAMES.cpp_header_parsing, 1064 | ACTION_NAMES.cpp_module_compile, 1065 | ACTION_NAMES.cpp_module_codegen, 1066 | ACTION_NAMES.cpp_module_deps_scanning, 1067 | ACTION_NAMES.cpp20_module_compile, 1068 | ACTION_NAMES.cpp20_module_codegen, 1069 | ACTION_NAMES.lto_backend, 1070 | ACTION_NAMES.clif_match, 1071 | ], 1072 | flag_groups = [ 1073 | flag_group( 1074 | flags = [ 1075 | "/DCOMPILER_MSVC", 1076 | "/bigobj", 1077 | "/Zm500", 1078 | "/FC", 1079 | "/Zc:wchar_t", 1080 | "/Gm-", 1081 | ], 1082 | ), 1083 | ], 1084 | with_features = [with_feature_set(not_features = ["wdm"])], 1085 | ), 1086 | flag_set( 1087 | actions = [ 1088 | # ACTION_NAMES.assemble, 1089 | # ACTION_NAMES.preprocess_assemble, 1090 | ACTION_NAMES.linkstamp_compile, 1091 | ACTION_NAMES.c_compile, 1092 | ACTION_NAMES.cpp_compile, 1093 | ACTION_NAMES.cpp_header_parsing, 1094 | ACTION_NAMES.cpp_module_compile, 1095 | ACTION_NAMES.cpp_module_codegen, 1096 | ACTION_NAMES.cpp_module_deps_scanning, 1097 | ACTION_NAMES.cpp20_module_compile, 1098 | ACTION_NAMES.cpp20_module_codegen, 1099 | ACTION_NAMES.lto_backend, 1100 | ACTION_NAMES.clif_match, 1101 | ], 1102 | flag_groups = [ 1103 | flag_group( 1104 | flags = [ 1105 | "/DCOMPILER_MSVC", 1106 | "/DWINNT=1", 1107 | "/kernel", 1108 | "/FC", 1109 | "/Zc:wchar_t", 1110 | "/Gm-", 1111 | "/GR-", 1112 | ] + ctx.attr.arch_c_opts_wdm, 1113 | ), 1114 | ], 1115 | with_features = [with_feature_set(features = ["wdm"])], 1116 | ), 1117 | ], 1118 | ) 1119 | 1120 | msvc_compile_env_feature = feature( 1121 | name = "msvc_compile_env", 1122 | env_sets = [ 1123 | env_set( 1124 | actions = [ 1125 | ACTION_NAMES.c_compile, 1126 | ACTION_NAMES.linkstamp_compile, 1127 | ACTION_NAMES.cpp_compile, 1128 | ACTION_NAMES.cpp_module_compile, 1129 | ACTION_NAMES.cpp_module_codegen, 1130 | ACTION_NAMES.cpp_header_parsing, 1131 | ACTION_NAMES.cpp_module_deps_scanning, 1132 | ACTION_NAMES.cpp20_module_compile, 1133 | ACTION_NAMES.cpp20_module_codegen, 1134 | ACTION_NAMES.assemble, 1135 | ACTION_NAMES.preprocess_assemble, 1136 | ], 1137 | env_entries = [ 1138 | env_entry(key = "INCLUDE", value = ctx.attr.msvc_env_app["INCLUDE"]), 1139 | env_entry(key = "EXTERNAL_INCLUDE", value = ctx.attr.msvc_env_app["EXTERNAL_INCLUDE"]), 1140 | ], 1141 | with_features = [with_feature_set(not_features = ["wdm"])], 1142 | ), 1143 | env_set( 1144 | actions = [ 1145 | ACTION_NAMES.c_compile, 1146 | ACTION_NAMES.linkstamp_compile, 1147 | ACTION_NAMES.cpp_compile, 1148 | ACTION_NAMES.cpp_module_compile, 1149 | ACTION_NAMES.cpp_module_codegen, 1150 | ACTION_NAMES.cpp_header_parsing, 1151 | ACTION_NAMES.cpp_module_deps_scanning, 1152 | ACTION_NAMES.cpp20_module_compile, 1153 | ACTION_NAMES.cpp20_module_codegen, 1154 | ACTION_NAMES.assemble, 1155 | ACTION_NAMES.preprocess_assemble, 1156 | ], 1157 | env_entries = [ 1158 | env_entry(key = "INCLUDE", value = ctx.attr.msvc_env_wdm["INCLUDE"]), 1159 | env_entry(key = "EXTERNAL_INCLUDE", value = ctx.attr.msvc_env_wdm["EXTERNAL_INCLUDE"]), 1160 | ], 1161 | with_features = [with_feature_set(features = ["wdm"])], 1162 | ), 1163 | ], 1164 | ) 1165 | 1166 | preprocessor_defines_feature = feature( 1167 | name = "preprocessor_defines", 1168 | enabled = True, 1169 | flag_sets = [ 1170 | flag_set( 1171 | actions = [ 1172 | ACTION_NAMES.assemble, 1173 | ACTION_NAMES.preprocess_assemble, 1174 | ACTION_NAMES.c_compile, 1175 | ACTION_NAMES.linkstamp_compile, 1176 | ACTION_NAMES.cpp_compile, 1177 | ACTION_NAMES.cpp_header_parsing, 1178 | ACTION_NAMES.cpp_module_compile, 1179 | ACTION_NAMES.cpp_module_deps_scanning, 1180 | ACTION_NAMES.cpp20_module_compile, 1181 | ], 1182 | flag_groups = [ 1183 | flag_group( 1184 | flags = ["/D%{preprocessor_defines}"], 1185 | iterate_over = "preprocessor_defines", 1186 | ), 1187 | ], 1188 | ), 1189 | ], 1190 | ) 1191 | 1192 | generate_pdb_file_feature = feature( 1193 | name = "generate_pdb_file", 1194 | ) 1195 | 1196 | generate_linkmap_feature = feature( 1197 | name = "generate_linkmap", 1198 | flag_sets = [ 1199 | flag_set( 1200 | actions = [ 1201 | ACTION_NAMES.cpp_link_executable, 1202 | ], 1203 | flag_groups = [ 1204 | flag_group( 1205 | flags = [ 1206 | "/MAP:%{output_execpath}.map", 1207 | ], 1208 | expand_if_available = "output_execpath", 1209 | ), 1210 | ], 1211 | ), 1212 | ], 1213 | ) 1214 | 1215 | output_execpath_flags_feature = feature( 1216 | name = "output_execpath_flags", 1217 | flag_sets = [ 1218 | flag_set( 1219 | actions = all_link_actions, 1220 | flag_groups = [ 1221 | flag_group( 1222 | flags = ["/OUT:%{output_execpath}"], 1223 | expand_if_available = "output_execpath", 1224 | ), 1225 | ], 1226 | ), 1227 | ], 1228 | ) 1229 | 1230 | disable_assertions_feature = feature( 1231 | name = "disable_assertions", 1232 | enabled = True, 1233 | flag_sets = [ 1234 | flag_set( 1235 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1236 | flag_groups = [flag_group(flags = ["/DNDEBUG"])], 1237 | with_features = [with_feature_set(features = ["opt"])], 1238 | ), 1239 | ], 1240 | ) 1241 | 1242 | has_configured_linker_path_feature = feature(name = "has_configured_linker_path") 1243 | 1244 | supports_dynamic_linker_feature = feature(name = "supports_dynamic_linker", enabled = True) 1245 | 1246 | no_stripping_feature = feature(name = "no_stripping") 1247 | 1248 | linker_param_file_feature = feature( 1249 | name = "linker_param_file", 1250 | flag_sets = [ 1251 | flag_set( 1252 | actions = all_link_actions + 1253 | [ACTION_NAMES.cpp_link_static_library], 1254 | flag_groups = [ 1255 | flag_group( 1256 | flags = ["@%{linker_param_file}"], 1257 | expand_if_available = "linker_param_file", 1258 | ), 1259 | ], 1260 | ), 1261 | ], 1262 | ) 1263 | 1264 | ignore_noisy_warnings_feature = feature( 1265 | name = "ignore_noisy_warnings", 1266 | enabled = True, 1267 | flag_sets = [ 1268 | flag_set( 1269 | actions = [ACTION_NAMES.cpp_link_static_library], 1270 | flag_groups = [flag_group(flags = ["/ignore:4221"])], 1271 | ), 1272 | ], 1273 | ) 1274 | 1275 | no_legacy_features_feature = feature(name = "no_legacy_features") 1276 | 1277 | parse_showincludes_feature = feature( 1278 | name = "parse_showincludes", 1279 | enabled = True, 1280 | flag_sets = [ 1281 | flag_set( 1282 | actions = [ 1283 | ACTION_NAMES.preprocess_assemble, 1284 | ACTION_NAMES.c_compile, 1285 | ACTION_NAMES.linkstamp_compile, 1286 | ACTION_NAMES.cpp_compile, 1287 | ACTION_NAMES.cpp_module_compile, 1288 | ACTION_NAMES.cpp_header_parsing, 1289 | ACTION_NAMES.cpp_module_deps_scanning, 1290 | ACTION_NAMES.cpp20_module_compile, 1291 | ], 1292 | flag_groups = [flag_group(flags = ["/showIncludes"])], 1293 | ), 1294 | ], 1295 | env_sets = [ 1296 | env_set( 1297 | actions = [ 1298 | ACTION_NAMES.preprocess_assemble, 1299 | ACTION_NAMES.c_compile, 1300 | ACTION_NAMES.linkstamp_compile, 1301 | ACTION_NAMES.cpp_compile, 1302 | ACTION_NAMES.cpp_module_compile, 1303 | ACTION_NAMES.cpp_header_parsing, 1304 | ], 1305 | # Force English (and thus a consistent locale) output so that Bazel can parse 1306 | # the /showIncludes output without having to guess the encoding. 1307 | env_entries = [env_entry(key = "VSLANG", value = "1033")], 1308 | ), 1309 | ], 1310 | ) 1311 | 1312 | # MSVC does not emit .d files. 1313 | no_dotd_file_feature = feature( 1314 | name = "no_dotd_file", 1315 | enabled = True, 1316 | ) 1317 | 1318 | treat_warnings_as_errors_feature = feature( 1319 | name = "treat_warnings_as_errors", 1320 | flag_sets = [ 1321 | flag_set( 1322 | actions = [ 1323 | ACTION_NAMES.assemble, 1324 | ACTION_NAMES.c_compile, 1325 | ACTION_NAMES.cpp_compile, 1326 | ] + all_link_actions, 1327 | flag_groups = [flag_group(flags = ["/WX"])], 1328 | ), 1329 | ], 1330 | ) 1331 | 1332 | windows_export_all_symbols_feature = feature(name = "windows_export_all_symbols") 1333 | 1334 | no_windows_export_all_symbols_feature = feature( 1335 | name = "no_windows_export_all_symbols", 1336 | # This shouldn't be enabled by default. 1337 | # Hack around bazel DefParser crash: https://github.com/bazelbuild/bazel/issues/25531 1338 | enabled = True, 1339 | ) 1340 | 1341 | include_paths_feature = feature( 1342 | name = "include_paths", 1343 | enabled = True, 1344 | flag_sets = [ 1345 | flag_set( 1346 | actions = [ 1347 | ACTION_NAMES.assemble, 1348 | ACTION_NAMES.preprocess_assemble, 1349 | ACTION_NAMES.c_compile, 1350 | ACTION_NAMES.linkstamp_compile, 1351 | ACTION_NAMES.cpp_compile, 1352 | ACTION_NAMES.cpp_header_parsing, 1353 | ACTION_NAMES.cpp_module_compile, 1354 | ], 1355 | flag_groups = [ 1356 | flag_group( 1357 | flags = ["/I%{quote_include_paths}"], 1358 | iterate_over = "quote_include_paths", 1359 | ), 1360 | flag_group( 1361 | flags = ["/I%{include_paths}"], 1362 | iterate_over = "include_paths", 1363 | ), 1364 | flag_group( 1365 | flags = ["/I%{system_include_paths}"], 1366 | iterate_over = "system_include_paths", 1367 | ), 1368 | ], 1369 | ), 1370 | ], 1371 | ) 1372 | 1373 | external_include_paths_feature = feature( 1374 | name = "external_include_paths", 1375 | flag_sets = [ 1376 | flag_set( 1377 | actions = [ 1378 | ACTION_NAMES.preprocess_assemble, 1379 | ACTION_NAMES.linkstamp_compile, 1380 | ACTION_NAMES.c_compile, 1381 | ACTION_NAMES.cpp_compile, 1382 | ACTION_NAMES.cpp_header_parsing, 1383 | ACTION_NAMES.cpp_module_compile, 1384 | ACTION_NAMES.cpp_module_deps_scanning, 1385 | ACTION_NAMES.cpp20_module_compile, 1386 | ACTION_NAMES.clif_match, 1387 | ACTION_NAMES.objc_compile, 1388 | ACTION_NAMES.objcpp_compile, 1389 | ], 1390 | flag_groups = [ 1391 | flag_group( 1392 | flags = ["/external:I%{external_include_paths}"], 1393 | iterate_over = "external_include_paths", 1394 | expand_if_available = "external_include_paths", 1395 | ), 1396 | ], 1397 | ), 1398 | ], 1399 | ) 1400 | 1401 | linkstamps_feature = feature( 1402 | name = "linkstamps", 1403 | flag_sets = [ 1404 | flag_set( 1405 | actions = all_link_actions, 1406 | flag_groups = [ 1407 | flag_group( 1408 | flags = ["%{linkstamp_paths}"], 1409 | iterate_over = "linkstamp_paths", 1410 | expand_if_available = "linkstamp_paths", 1411 | ), 1412 | ], 1413 | ), 1414 | ], 1415 | ) 1416 | 1417 | targets_windows_feature = feature( 1418 | name = "targets_windows", 1419 | enabled = True, 1420 | implies = ["copy_dynamic_libraries_to_binary"], 1421 | ) 1422 | 1423 | # For parity with default features. Prefer the subsystem_* features instead. 1424 | linker_subsystem_flag_feature = feature( 1425 | name = "linker_subsystem_flag", 1426 | flag_sets = [ 1427 | flag_set( 1428 | actions = all_link_actions, 1429 | flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])], 1430 | ), 1431 | ], 1432 | ) 1433 | 1434 | frame_pointer_feature = feature( 1435 | name = "frame_pointer", 1436 | flag_sets = [ 1437 | flag_set( 1438 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1439 | flag_groups = [flag_group(flags = ["/Oy-"])], 1440 | ), 1441 | ], 1442 | ) 1443 | 1444 | compiler_output_flags_feature = feature( 1445 | name = "compiler_output_flags", 1446 | flag_sets = [ 1447 | flag_set( 1448 | actions = [ACTION_NAMES.assemble], 1449 | flag_groups = [ 1450 | flag_group( 1451 | flag_groups = [ 1452 | flag_group( 1453 | flags = ["/Fo", "%{output_file}", "/c", "/Zi", "/Zd", "/W3"], 1454 | expand_if_available = "output_file", 1455 | expand_if_not_available = "output_assembly_file", 1456 | ), 1457 | ], 1458 | expand_if_not_available = "output_preprocess_file", 1459 | ), 1460 | ], 1461 | ), 1462 | flag_set( 1463 | actions = [ACTION_NAMES.assemble], 1464 | flag_groups = [ 1465 | flag_group( 1466 | flag_groups = [ 1467 | flag_group( 1468 | flags = ["/Ta", "%{source_file}"], 1469 | expand_if_available = "source_file", 1470 | ), 1471 | ], 1472 | ), 1473 | ], 1474 | ), 1475 | flag_set( 1476 | actions = [ 1477 | ACTION_NAMES.preprocess_assemble, 1478 | ACTION_NAMES.c_compile, 1479 | ACTION_NAMES.linkstamp_compile, 1480 | ACTION_NAMES.cpp_compile, 1481 | ACTION_NAMES.cpp_header_parsing, 1482 | ACTION_NAMES.cpp_module_compile, 1483 | ACTION_NAMES.cpp_module_codegen, 1484 | ACTION_NAMES.cpp_module_deps_scanning, 1485 | ACTION_NAMES.cpp20_module_compile, 1486 | ACTION_NAMES.cpp20_module_codegen, 1487 | ], 1488 | flag_groups = [ 1489 | flag_group( 1490 | flag_groups = [ 1491 | flag_group( 1492 | flags = ["/Fo%{output_file}"], 1493 | expand_if_not_available = "output_preprocess_file", 1494 | ), 1495 | ], 1496 | expand_if_available = "output_file", 1497 | expand_if_not_available = "output_assembly_file", 1498 | ), 1499 | flag_group( 1500 | flag_groups = [ 1501 | flag_group( 1502 | flags = ["/Fa%{output_file}"], 1503 | expand_if_available = "output_assembly_file", 1504 | ), 1505 | ], 1506 | expand_if_available = "output_file", 1507 | ), 1508 | flag_group( 1509 | flag_groups = [ 1510 | flag_group( 1511 | flags = ["/P", "/Fi%{output_file}"], 1512 | expand_if_available = "output_preprocess_file", 1513 | ), 1514 | ], 1515 | expand_if_available = "output_file", 1516 | ), 1517 | ], 1518 | ), 1519 | ], 1520 | ) 1521 | 1522 | nologo_feature = feature( 1523 | name = "nologo", 1524 | flag_sets = [ 1525 | flag_set( 1526 | actions = [ 1527 | ACTION_NAMES.c_compile, 1528 | ACTION_NAMES.linkstamp_compile, 1529 | ACTION_NAMES.cpp_compile, 1530 | ACTION_NAMES.cpp_module_compile, 1531 | ACTION_NAMES.cpp_module_codegen, 1532 | ACTION_NAMES.cpp_header_parsing, 1533 | ACTION_NAMES.cpp_module_deps_scanning, 1534 | ACTION_NAMES.cpp20_module_compile, 1535 | ACTION_NAMES.cpp20_module_codegen, 1536 | ACTION_NAMES.assemble, 1537 | ACTION_NAMES.preprocess_assemble, 1538 | ACTION_NAMES.cpp_link_executable, 1539 | ACTION_NAMES.cpp_link_dynamic_library, 1540 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1541 | ACTION_NAMES.cpp_link_static_library, 1542 | ], 1543 | flag_groups = [flag_group(flags = ["/nologo"])], 1544 | ), 1545 | ], 1546 | ) 1547 | 1548 | smaller_binary_feature = feature( 1549 | name = "smaller_binary", 1550 | enabled = True, 1551 | flag_sets = [ 1552 | flag_set( 1553 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1554 | flag_groups = [flag_group(flags = ["/Gy", "/Gw"])], 1555 | with_features = [with_feature_set(features = ["opt"])], 1556 | ), 1557 | flag_set( 1558 | actions = all_link_actions, 1559 | flag_groups = [flag_group(flags = ["/OPT:ICF", "/OPT:REF"])], 1560 | with_features = [with_feature_set(features = ["opt"])], 1561 | ), 1562 | ], 1563 | ) 1564 | 1565 | remove_unreferenced_code_feature = feature( 1566 | name = "remove_unreferenced_code", 1567 | enabled = True, 1568 | flag_sets = [ 1569 | flag_set( 1570 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 1571 | flag_groups = [flag_group(flags = ["/Zc:inline"])], 1572 | ), 1573 | ], 1574 | ) 1575 | 1576 | compiler_input_flags_feature = feature( 1577 | name = "compiler_input_flags", 1578 | flag_sets = [ 1579 | flag_set( 1580 | actions = [ 1581 | # ACTION_NAMES.assemble, 1582 | ACTION_NAMES.preprocess_assemble, 1583 | ACTION_NAMES.c_compile, 1584 | ACTION_NAMES.linkstamp_compile, 1585 | ACTION_NAMES.cpp_compile, 1586 | ACTION_NAMES.cpp_header_parsing, 1587 | ACTION_NAMES.cpp_module_compile, 1588 | ACTION_NAMES.cpp_module_codegen, 1589 | ACTION_NAMES.cpp_module_deps_scanning, 1590 | ACTION_NAMES.cpp20_module_compile, 1591 | ACTION_NAMES.cpp20_module_codegen, 1592 | ], 1593 | flag_groups = [ 1594 | flag_group( 1595 | flags = ["/c", "%{source_file}"], 1596 | expand_if_available = "source_file", 1597 | ), 1598 | ], 1599 | ), 1600 | ], 1601 | ) 1602 | 1603 | def_file_feature = feature( 1604 | name = "def_file", 1605 | flag_sets = [ 1606 | flag_set( 1607 | actions = all_link_actions, 1608 | flag_groups = [ 1609 | flag_group( 1610 | flags = ["/DEF:%{def_file_path}", "/ignore:4070"], 1611 | expand_if_available = "def_file_path", 1612 | ), 1613 | ], 1614 | ), 1615 | ], 1616 | ) 1617 | 1618 | msvc_env_feature = feature( 1619 | name = "msvc_env", 1620 | env_sets = [ 1621 | env_set( 1622 | actions = [ 1623 | ACTION_NAMES.c_compile, 1624 | ACTION_NAMES.linkstamp_compile, 1625 | ACTION_NAMES.cpp_compile, 1626 | ACTION_NAMES.cpp_module_compile, 1627 | ACTION_NAMES.cpp_module_codegen, 1628 | ACTION_NAMES.cpp_header_parsing, 1629 | ACTION_NAMES.cpp_module_deps_scanning, 1630 | ACTION_NAMES.cpp20_module_compile, 1631 | ACTION_NAMES.cpp20_module_codegen, 1632 | ACTION_NAMES.assemble, 1633 | ACTION_NAMES.preprocess_assemble, 1634 | ACTION_NAMES.cpp_link_executable, 1635 | ACTION_NAMES.cpp_link_dynamic_library, 1636 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1637 | ACTION_NAMES.cpp_link_static_library, 1638 | ], 1639 | env_entries = [ 1640 | env_entry(key = "PATH", value = ctx.attr.msvc_env_app["PATH"]), 1641 | env_entry(key = "LIBPATH", value = ctx.attr.msvc_env_app["LIBPATH"]), 1642 | env_entry(key = "TMP", value = ctx.attr.msvc_env_app["TMP"]), 1643 | env_entry(key = "TEMP", value = ctx.attr.msvc_env_app["TMP"]), 1644 | ], 1645 | with_features = [with_feature_set(not_features = ["wdm"])], 1646 | ), 1647 | env_set( 1648 | actions = [ 1649 | ACTION_NAMES.c_compile, 1650 | ACTION_NAMES.linkstamp_compile, 1651 | ACTION_NAMES.cpp_compile, 1652 | ACTION_NAMES.cpp_module_compile, 1653 | ACTION_NAMES.cpp_module_codegen, 1654 | ACTION_NAMES.cpp_header_parsing, 1655 | ACTION_NAMES.cpp_module_deps_scanning, 1656 | ACTION_NAMES.cpp20_module_compile, 1657 | ACTION_NAMES.cpp20_module_codegen, 1658 | ACTION_NAMES.assemble, 1659 | ACTION_NAMES.preprocess_assemble, 1660 | ACTION_NAMES.cpp_link_executable, 1661 | ACTION_NAMES.cpp_link_dynamic_library, 1662 | ACTION_NAMES.cpp_link_nodeps_dynamic_library, 1663 | ACTION_NAMES.cpp_link_static_library, 1664 | ], 1665 | env_entries = [ 1666 | env_entry(key = "PATH", value = ctx.attr.msvc_env_wdm["PATH"]), 1667 | env_entry(key = "LIBPATH", value = ctx.attr.msvc_env_wdm["LIBPATH"]), 1668 | env_entry(key = "TMP", value = ctx.attr.msvc_env_wdm["TMP"]), 1669 | env_entry(key = "TEMP", value = ctx.attr.msvc_env_wdm["TMP"]), 1670 | ], 1671 | with_features = [with_feature_set(features = ["wdm"])], 1672 | ), 1673 | ], 1674 | implies = ["msvc_compile_env", "msvc_link_env"], 1675 | ) 1676 | 1677 | symbol_check_feature = feature( 1678 | name = "symbol_check", 1679 | flag_sets = [ 1680 | flag_set( 1681 | actions = [ACTION_NAMES.cpp_link_static_library], 1682 | flag_groups = [flag_group(flags = ["/WX:4006"])], 1683 | ), 1684 | ], 1685 | ) 1686 | 1687 | # 1688 | # Features unique to this toolchain 1689 | # 1690 | 1691 | disable_msvcrt_feature = feature(name = "disable_msvcrt") 1692 | 1693 | wdm_feature = feature( 1694 | name = "wdm", 1695 | provides = ["project_type"], 1696 | implies = [ 1697 | "wdm_entry", 1698 | "disable_msvcrt", 1699 | "no_default_cpp_unwinding", 1700 | "no_runtime_checks", 1701 | ], 1702 | ) 1703 | 1704 | wdm_entry_feature = feature( 1705 | name = "wdm_entry", 1706 | flag_sets = [ 1707 | flag_set( 1708 | actions = [ACTION_NAMES.cpp_link_dynamic_library, ACTION_NAMES.cpp_link_nodeps_dynamic_library], 1709 | flag_groups = [flag_group(flags = ["/ENTRY:DriverEntry"])], 1710 | with_features = [with_feature_set(not_features = ["buffer_security_checks"])], 1711 | ), 1712 | ], 1713 | ) 1714 | 1715 | no_runtime_checks_feature = feature(name = "no_runtime_checks") 1716 | 1717 | msvc_enable_minmax_feature = feature(name = "msvc_enable_minmax") 1718 | 1719 | msvc_no_minmax_feature = feature( 1720 | name = "msvc_no_minmax", 1721 | enabled = True, 1722 | flag_sets = [ 1723 | flag_set( 1724 | actions = [ 1725 | ACTION_NAMES.c_compile, 1726 | ACTION_NAMES.linkstamp_compile, 1727 | ACTION_NAMES.cpp_compile, 1728 | ACTION_NAMES.cpp_header_parsing, 1729 | ACTION_NAMES.cpp_module_compile, 1730 | ACTION_NAMES.cpp_module_codegen, 1731 | ACTION_NAMES.cpp_module_deps_scanning, 1732 | ACTION_NAMES.cpp20_module_compile, 1733 | ACTION_NAMES.cpp20_module_codegen, 1734 | ], 1735 | flag_groups = [flag_group(flags = ["/DNOMINMAX"])], 1736 | with_features = [with_feature_set(not_features = ["msvc_enable_minmax"])], 1737 | ), 1738 | ], 1739 | ) 1740 | 1741 | no_default_cpp_unwinding_feature = feature(name = "no_default_cpp_unwinding") 1742 | 1743 | default_cpp_unwinding_feature = feature( 1744 | name = "default_cpp_unwinding", 1745 | enabled = True, 1746 | flag_sets = [ 1747 | flag_set( 1748 | actions = [ 1749 | ACTION_NAMES.c_compile, 1750 | ACTION_NAMES.linkstamp_compile, 1751 | ACTION_NAMES.cpp_compile, 1752 | ACTION_NAMES.cpp_header_parsing, 1753 | ACTION_NAMES.cpp_module_compile, 1754 | ACTION_NAMES.cpp_module_codegen, 1755 | ACTION_NAMES.cpp_module_deps_scanning, 1756 | ACTION_NAMES.cpp20_module_compile, 1757 | ACTION_NAMES.cpp20_module_codegen, 1758 | ], 1759 | flag_groups = [flag_group(flags = ["/EHsc"])], 1760 | with_features = [with_feature_set(not_features = ["no_default_cpp_unwinding"])], 1761 | ), 1762 | ], 1763 | ) 1764 | 1765 | msvc_profile_feature = feature( 1766 | name = "msvc_profile", 1767 | flag_sets = [ 1768 | flag_set( 1769 | actions = all_link_actions, 1770 | flag_groups = [flag_group(flags = ["/PROFILE"])], 1771 | ), 1772 | ], 1773 | ) 1774 | subsystem_console_feature = feature( 1775 | name = "subsystem_console", 1776 | enabled = True, 1777 | flag_sets = [ 1778 | flag_set( 1779 | actions = all_link_actions, 1780 | flag_groups = [flag_group(flags = ["/SUBSYSTEM:CONSOLE"])], 1781 | with_features = [with_feature_set(not_features = ["subsystem_windows", "subsystem_native"])], 1782 | ), 1783 | ], 1784 | ) 1785 | 1786 | subsystem_windows_feature = feature( 1787 | name = "subsystem_windows", 1788 | flag_sets = [ 1789 | flag_set( 1790 | actions = all_link_actions, 1791 | flag_groups = [flag_group(flags = ["/SUBSYSTEM:WINDOWS"])], 1792 | ), 1793 | ], 1794 | provides = ["subsystem"], 1795 | ) 1796 | 1797 | subsystem_native_feature = feature( 1798 | name = "subsystem_native", 1799 | flag_sets = [ 1800 | flag_set( 1801 | actions = all_link_actions, 1802 | flag_groups = [flag_group(flags = ["/SUBSYSTEM:NATIVE"])], 1803 | ), 1804 | ], 1805 | provides = ["subsystem"], 1806 | ) 1807 | 1808 | win32_lean_and_mean_feature = feature( 1809 | name = "win32_lean_and_mean", 1810 | flag_sets = [ 1811 | flag_set( 1812 | actions = [ 1813 | ACTION_NAMES.c_compile, 1814 | ACTION_NAMES.linkstamp_compile, 1815 | ACTION_NAMES.cpp_compile, 1816 | ACTION_NAMES.cpp_header_parsing, 1817 | ACTION_NAMES.cpp_module_compile, 1818 | ACTION_NAMES.cpp_module_codegen, 1819 | ACTION_NAMES.cpp_module_deps_scanning, 1820 | ACTION_NAMES.cpp20_module_compile, 1821 | ACTION_NAMES.cpp20_module_codegen, 1822 | ], 1823 | flag_groups = [flag_group(flags = ["/DWIN32_LEAN_AND_MEAN=1"])], 1824 | ), 1825 | ], 1826 | ) 1827 | 1828 | cdecl_feature = feature( 1829 | name = "cdecl", 1830 | flag_sets = [ 1831 | flag_set( 1832 | actions = [ 1833 | ACTION_NAMES.c_compile, 1834 | ACTION_NAMES.linkstamp_compile, 1835 | ACTION_NAMES.cpp_compile, 1836 | ACTION_NAMES.cpp_header_parsing, 1837 | ACTION_NAMES.cpp_module_compile, 1838 | ACTION_NAMES.cpp_module_codegen, 1839 | ACTION_NAMES.cpp_module_deps_scanning, 1840 | ACTION_NAMES.cpp20_module_compile, 1841 | ACTION_NAMES.cpp20_module_codegen, 1842 | ], 1843 | flag_groups = [flag_group(flags = ["/Gd"])], 1844 | ), 1845 | ], 1846 | ) 1847 | 1848 | stdcall_feature = feature( 1849 | name = "stdcall", 1850 | flag_sets = [ 1851 | flag_set( 1852 | actions = [ 1853 | ACTION_NAMES.c_compile, 1854 | ACTION_NAMES.linkstamp_compile, 1855 | ACTION_NAMES.cpp_compile, 1856 | ACTION_NAMES.cpp_header_parsing, 1857 | ACTION_NAMES.cpp_module_compile, 1858 | ACTION_NAMES.cpp_module_codegen, 1859 | ACTION_NAMES.cpp_module_deps_scanning, 1860 | ACTION_NAMES.cpp20_module_compile, 1861 | ACTION_NAMES.cpp20_module_codegen, 1862 | ], 1863 | flag_groups = [flag_group(flags = [ctx.attr.has_gz_option])], 1864 | ), 1865 | ], 1866 | ) 1867 | 1868 | target_win7_default_feature = feature( 1869 | name = "target_win7_default", 1870 | enabled = True, 1871 | flag_sets = [ 1872 | flag_set( 1873 | actions = [ 1874 | ACTION_NAMES.c_compile, 1875 | ACTION_NAMES.linkstamp_compile, 1876 | ACTION_NAMES.cpp_compile, 1877 | ACTION_NAMES.cpp_header_parsing, 1878 | ACTION_NAMES.cpp_module_compile, 1879 | ACTION_NAMES.cpp_module_codegen, 1880 | ACTION_NAMES.cpp_module_deps_scanning, 1881 | ACTION_NAMES.cpp20_module_compile, 1882 | ACTION_NAMES.cpp20_module_codegen, 1883 | ], 1884 | flag_groups = [flag_group(flags = ["/DWINVER=0x0601", "/D_WIN32_WINNT=0x0601", "/DNTDDI_VERSION=0x06010000"])], 1885 | with_features = [with_feature_set(not_features = ["target_win7", "target_win8", "target_win10", "target_win11"])], 1886 | ), 1887 | ], 1888 | ) 1889 | 1890 | target_win7_feature = feature( 1891 | name = "target_win7", 1892 | flag_sets = [ 1893 | flag_set( 1894 | actions = [ 1895 | ACTION_NAMES.c_compile, 1896 | ACTION_NAMES.linkstamp_compile, 1897 | ACTION_NAMES.cpp_compile, 1898 | ACTION_NAMES.cpp_header_parsing, 1899 | ACTION_NAMES.cpp_module_compile, 1900 | ACTION_NAMES.cpp_module_codegen, 1901 | ACTION_NAMES.cpp_module_deps_scanning, 1902 | ACTION_NAMES.cpp20_module_compile, 1903 | ACTION_NAMES.cpp20_module_codegen, 1904 | ], 1905 | flag_groups = [flag_group(flags = ["/DWINVER=0x0601", "/D_WIN32_WINNT=0x0601", "/DNTDDI_VERSION=0x06010000"])], 1906 | ), 1907 | ], 1908 | provides = ["windows_target_version"], 1909 | ) 1910 | 1911 | target_win8_feature = feature( 1912 | name = "target_win8", 1913 | flag_sets = [ 1914 | flag_set( 1915 | actions = [ 1916 | ACTION_NAMES.c_compile, 1917 | ACTION_NAMES.linkstamp_compile, 1918 | ACTION_NAMES.cpp_compile, 1919 | ACTION_NAMES.cpp_header_parsing, 1920 | ACTION_NAMES.cpp_module_compile, 1921 | ACTION_NAMES.cpp_module_codegen, 1922 | ACTION_NAMES.cpp_module_deps_scanning, 1923 | ACTION_NAMES.cpp20_module_compile, 1924 | ACTION_NAMES.cpp20_module_codegen, 1925 | ], 1926 | flag_groups = [flag_group(flags = ["/DWINVER=0x0602", "/D_WIN32_WINNT=0x0602", "/DNTDDI_VERSION=0x06020000"])], 1927 | ), 1928 | ], 1929 | provides = ["windows_target_version"], 1930 | ) 1931 | 1932 | target_win10_feature = feature( 1933 | name = "target_win10", 1934 | flag_sets = [ 1935 | flag_set( 1936 | actions = [ 1937 | ACTION_NAMES.c_compile, 1938 | ACTION_NAMES.linkstamp_compile, 1939 | ACTION_NAMES.cpp_compile, 1940 | ACTION_NAMES.cpp_header_parsing, 1941 | ACTION_NAMES.cpp_module_compile, 1942 | ACTION_NAMES.cpp_module_codegen, 1943 | ACTION_NAMES.cpp_module_deps_scanning, 1944 | ACTION_NAMES.cpp20_module_compile, 1945 | ACTION_NAMES.cpp20_module_codegen, 1946 | ], 1947 | flag_groups = [flag_group(flags = ["/DWINVER=0x0A00", "/D_WIN32_WINNT=0x0A00", "/DNTDDI_VERSION=0x0A000000"])], 1948 | ), 1949 | ], 1950 | provides = ["windows_target_version"], 1951 | ) 1952 | 1953 | target_win11_feature = feature( 1954 | name = "target_win11", 1955 | flag_sets = [ 1956 | flag_set( 1957 | actions = [ 1958 | ACTION_NAMES.c_compile, 1959 | ACTION_NAMES.linkstamp_compile, 1960 | ACTION_NAMES.cpp_compile, 1961 | ACTION_NAMES.cpp_header_parsing, 1962 | ACTION_NAMES.cpp_module_compile, 1963 | ACTION_NAMES.cpp_module_codegen, 1964 | ACTION_NAMES.cpp_module_deps_scanning, 1965 | ACTION_NAMES.cpp20_module_compile, 1966 | ACTION_NAMES.cpp20_module_codegen, 1967 | ], 1968 | flag_groups = [flag_group(flags = ["/DWINVER=0x0A00", "/D_WIN32_WINNT=0x0A00", "/DNTDDI_VERSION=0x0A00000C"])], 1969 | ), 1970 | ], 1971 | provides = ["windows_target_version"], 1972 | ) 1973 | 1974 | c11_feature = feature( 1975 | name = "c11", 1976 | flag_sets = [ 1977 | flag_set( 1978 | actions = [ 1979 | ACTION_NAMES.c_compile, 1980 | ACTION_NAMES.linkstamp_compile, 1981 | ACTION_NAMES.cpp_compile, 1982 | ACTION_NAMES.cpp_header_parsing, 1983 | ACTION_NAMES.cpp_module_compile, 1984 | ACTION_NAMES.cpp_module_codegen, 1985 | ACTION_NAMES.cpp_module_deps_scanning, 1986 | ACTION_NAMES.cpp20_module_compile, 1987 | ACTION_NAMES.cpp20_module_codegen, 1988 | ], 1989 | flag_groups = [flag_group(flags = ["/std:c11"])], 1990 | with_features = [with_feature_set(not_features = ["c17"])], 1991 | ), 1992 | ], 1993 | ) 1994 | 1995 | c17_feature = feature( 1996 | name = "c17", 1997 | flag_sets = [ 1998 | flag_set( 1999 | actions = [ 2000 | ACTION_NAMES.c_compile, 2001 | ACTION_NAMES.linkstamp_compile, 2002 | ACTION_NAMES.cpp_compile, 2003 | ACTION_NAMES.cpp_header_parsing, 2004 | ACTION_NAMES.cpp_module_compile, 2005 | ACTION_NAMES.cpp_module_codegen, 2006 | ACTION_NAMES.cpp_module_deps_scanning, 2007 | ACTION_NAMES.cpp20_module_compile, 2008 | ACTION_NAMES.cpp20_module_codegen, 2009 | ], 2010 | flag_groups = [flag_group(flags = ["/std:c17"])], 2011 | ), 2012 | ], 2013 | ) 2014 | 2015 | cpp14_feature = feature( 2016 | name = "cpp14", 2017 | flag_sets = [ 2018 | flag_set( 2019 | actions = [ 2020 | ACTION_NAMES.c_compile, 2021 | ACTION_NAMES.linkstamp_compile, 2022 | ACTION_NAMES.cpp_compile, 2023 | ACTION_NAMES.cpp_header_parsing, 2024 | ACTION_NAMES.cpp_module_compile, 2025 | ACTION_NAMES.cpp_module_codegen, 2026 | ACTION_NAMES.cpp_module_deps_scanning, 2027 | ACTION_NAMES.cpp20_module_compile, 2028 | ACTION_NAMES.cpp20_module_codegen, 2029 | ], 2030 | flag_groups = [flag_group(flags = ["/std:c++14"])], 2031 | with_features = [with_feature_set(not_features = ["cpp_latest","cpp20","cpp17"])], 2032 | ), 2033 | ], 2034 | ) 2035 | 2036 | cpp17_feature = feature( 2037 | name = "cpp17", 2038 | flag_sets = [ 2039 | flag_set( 2040 | actions = [ 2041 | ACTION_NAMES.c_compile, 2042 | ACTION_NAMES.linkstamp_compile, 2043 | ACTION_NAMES.cpp_compile, 2044 | ACTION_NAMES.cpp_header_parsing, 2045 | ACTION_NAMES.cpp_module_compile, 2046 | ACTION_NAMES.cpp_module_codegen, 2047 | ACTION_NAMES.cpp_module_deps_scanning, 2048 | ACTION_NAMES.cpp20_module_compile, 2049 | ACTION_NAMES.cpp20_module_codegen, 2050 | ], 2051 | flag_groups = [flag_group(flags = ["/std:c++17"])], 2052 | with_features = [with_feature_set(not_features = ["cpp_latest","cpp20"])], 2053 | ), 2054 | ], 2055 | ) 2056 | 2057 | cpp20_feature = feature( 2058 | name = "cpp20", 2059 | flag_sets = [ 2060 | flag_set( 2061 | actions = [ 2062 | ACTION_NAMES.c_compile, 2063 | ACTION_NAMES.linkstamp_compile, 2064 | ACTION_NAMES.cpp_compile, 2065 | ACTION_NAMES.cpp_header_parsing, 2066 | ACTION_NAMES.cpp_module_compile, 2067 | ACTION_NAMES.cpp_module_codegen, 2068 | ACTION_NAMES.cpp_module_deps_scanning, 2069 | ACTION_NAMES.cpp20_module_compile, 2070 | ACTION_NAMES.cpp20_module_codegen, 2071 | ], 2072 | flag_groups = [flag_group(flags = ["/std:c++20"])], 2073 | with_features = [with_feature_set(not_features = ["cpp_latest"])], 2074 | ), 2075 | ], 2076 | ) 2077 | 2078 | cpp_latest_feature = feature( 2079 | name = "cpp_latest", 2080 | flag_sets = [ 2081 | flag_set( 2082 | actions = [ 2083 | ACTION_NAMES.c_compile, 2084 | ACTION_NAMES.linkstamp_compile, 2085 | ACTION_NAMES.cpp_compile, 2086 | ACTION_NAMES.cpp_header_parsing, 2087 | ACTION_NAMES.cpp_module_compile, 2088 | ACTION_NAMES.cpp_module_codegen, 2089 | ACTION_NAMES.cpp_module_deps_scanning, 2090 | ACTION_NAMES.cpp20_module_compile, 2091 | ACTION_NAMES.cpp20_module_codegen, 2092 | ], 2093 | flag_groups = [flag_group(flags = ["/std:c++latest"])], 2094 | ), 2095 | ], 2096 | ) 2097 | 2098 | buffer_security_checks_feature = feature( 2099 | name = "buffer_security_checks", 2100 | flag_sets = [ 2101 | flag_set( 2102 | actions = [ 2103 | ACTION_NAMES.c_compile, 2104 | ACTION_NAMES.linkstamp_compile, 2105 | ACTION_NAMES.cpp_compile, 2106 | ACTION_NAMES.cpp_header_parsing, 2107 | ACTION_NAMES.cpp_module_compile, 2108 | ACTION_NAMES.cpp_module_codegen, 2109 | ACTION_NAMES.cpp_module_deps_scanning, 2110 | ACTION_NAMES.cpp20_module_compile, 2111 | ACTION_NAMES.cpp20_module_codegen, 2112 | ], 2113 | flag_groups = [flag_group(flags = ["/GS"])], 2114 | ), 2115 | flag_set( 2116 | actions = [ACTION_NAMES.cpp_link_dynamic_library, ACTION_NAMES.cpp_link_nodeps_dynamic_library], 2117 | flag_groups = [flag_group(flags = ["/ENTRY:GsDriverEntry" + ctx.attr.entry_symbol_suffix])], 2118 | with_features = [with_feature_set(features = ["wdm"])], 2119 | ), 2120 | ], 2121 | ) 2122 | 2123 | sdl_security_checks_feature = feature( 2124 | name = "sdl_security_checks", 2125 | flag_sets = [ 2126 | flag_set( 2127 | actions = [ 2128 | ACTION_NAMES.c_compile, 2129 | ACTION_NAMES.linkstamp_compile, 2130 | ACTION_NAMES.cpp_compile, 2131 | ACTION_NAMES.cpp_header_parsing, 2132 | ACTION_NAMES.cpp_module_compile, 2133 | ACTION_NAMES.cpp_module_codegen, 2134 | ACTION_NAMES.cpp_module_deps_scanning, 2135 | ACTION_NAMES.cpp20_module_compile, 2136 | ACTION_NAMES.cpp20_module_codegen, 2137 | ], 2138 | flag_groups = [flag_group(flags = ["/sdl"])], 2139 | ), 2140 | ], 2141 | ) 2142 | 2143 | cfg_security_checks_feature = feature( 2144 | name = "cfg_security_checks", 2145 | flag_sets = [ 2146 | flag_set( 2147 | actions = [ 2148 | ACTION_NAMES.c_compile, 2149 | ACTION_NAMES.linkstamp_compile, 2150 | ACTION_NAMES.cpp_compile, 2151 | ACTION_NAMES.cpp_header_parsing, 2152 | ACTION_NAMES.cpp_module_compile, 2153 | ACTION_NAMES.cpp_module_codegen, 2154 | ACTION_NAMES.cpp_module_deps_scanning, 2155 | ACTION_NAMES.cpp20_module_compile, 2156 | ACTION_NAMES.cpp20_module_codegen, 2157 | ], 2158 | flag_groups = [flag_group(flags = ["/guard:cf"])], 2159 | ), 2160 | flag_set( 2161 | actions = all_link_actions, 2162 | flag_groups = [flag_group(flags = ["/guard:cf"])], 2163 | ), 2164 | ], 2165 | ) 2166 | 2167 | cet_compatible_feature = feature( 2168 | name = "cet_compatible", 2169 | flag_sets = [ 2170 | flag_set( 2171 | actions = all_link_actions, 2172 | flag_groups = [flag_group(flags = [ctx.attr.cetcompat_option])], 2173 | ), 2174 | ], 2175 | provides = ["cet_spectre_load_cf_incompatible"], 2176 | ) 2177 | 2178 | guard_ehcont_feature = feature( 2179 | name = "guard_ehcont", 2180 | flag_sets = [ 2181 | flag_set( 2182 | actions = [ 2183 | ACTION_NAMES.c_compile, 2184 | ACTION_NAMES.linkstamp_compile, 2185 | ACTION_NAMES.cpp_compile, 2186 | ACTION_NAMES.cpp_header_parsing, 2187 | ACTION_NAMES.cpp_module_compile, 2188 | ACTION_NAMES.cpp_module_codegen, 2189 | ACTION_NAMES.cpp_module_deps_scanning, 2190 | ACTION_NAMES.cpp20_module_compile, 2191 | ACTION_NAMES.cpp20_module_codegen, 2192 | ], 2193 | flag_groups = [flag_group(flags = ["/guard:ehcont"])], 2194 | ), 2195 | ], 2196 | ) 2197 | 2198 | spectre_feature = feature( 2199 | name = "spectre", 2200 | flag_sets = [ 2201 | flag_set( 2202 | actions = [ 2203 | ACTION_NAMES.c_compile, 2204 | ACTION_NAMES.linkstamp_compile, 2205 | ACTION_NAMES.cpp_compile, 2206 | ACTION_NAMES.cpp_header_parsing, 2207 | ACTION_NAMES.cpp_module_compile, 2208 | ACTION_NAMES.cpp_module_codegen, 2209 | ACTION_NAMES.cpp_module_deps_scanning, 2210 | ACTION_NAMES.cpp20_module_compile, 2211 | ACTION_NAMES.cpp20_module_codegen, 2212 | ], 2213 | flag_groups = [flag_group(flags = ["/Qspectre"])], 2214 | ), 2215 | ], 2216 | ) 2217 | 2218 | spectre_load_cf_feature = feature( 2219 | name = "spectre_load_cf", 2220 | flag_sets = [ 2221 | flag_set( 2222 | actions = [ 2223 | ACTION_NAMES.c_compile, 2224 | ACTION_NAMES.linkstamp_compile, 2225 | ACTION_NAMES.cpp_compile, 2226 | ACTION_NAMES.cpp_header_parsing, 2227 | ACTION_NAMES.cpp_module_compile, 2228 | ACTION_NAMES.cpp_module_codegen, 2229 | ACTION_NAMES.cpp_module_deps_scanning, 2230 | ACTION_NAMES.cpp20_module_compile, 2231 | ACTION_NAMES.cpp20_module_codegen, 2232 | ], 2233 | flag_groups = [flag_group(flags = ["/Qspectre-load-cf"])], 2234 | ), 2235 | ], 2236 | provides = ["cet_spectre_load_cf_incompatible"], 2237 | ) 2238 | 2239 | retpoline_check_feature = feature( 2240 | name = "retpoline_check", 2241 | flag_sets = [ 2242 | flag_set( 2243 | actions = [ 2244 | ACTION_NAMES.c_compile, 2245 | ACTION_NAMES.linkstamp_compile, 2246 | ACTION_NAMES.cpp_compile, 2247 | ACTION_NAMES.cpp_header_parsing, 2248 | ACTION_NAMES.cpp_module_compile, 2249 | ACTION_NAMES.cpp_module_codegen, 2250 | ACTION_NAMES.cpp_module_deps_scanning, 2251 | ACTION_NAMES.cpp20_module_compile, 2252 | ACTION_NAMES.cpp20_module_codegen, 2253 | ], 2254 | flag_groups = [flag_group(flags = ["/d2guardretpoline"])], 2255 | ), 2256 | flag_set( 2257 | actions = all_link_actions, 2258 | flag_groups = [flag_group(flags = ["/guard:retpoline"])], 2259 | ), 2260 | ], 2261 | ) 2262 | 2263 | charset_unicode_feature = feature( 2264 | name = "charset_unicode", 2265 | flag_sets = [ 2266 | flag_set( 2267 | actions = [ 2268 | ACTION_NAMES.c_compile, 2269 | ACTION_NAMES.linkstamp_compile, 2270 | ACTION_NAMES.cpp_compile, 2271 | ACTION_NAMES.cpp_header_parsing, 2272 | ACTION_NAMES.cpp_module_compile, 2273 | ACTION_NAMES.cpp_module_codegen, 2274 | ACTION_NAMES.cpp_module_deps_scanning, 2275 | ACTION_NAMES.cpp20_module_compile, 2276 | ACTION_NAMES.cpp20_module_codegen, 2277 | ], 2278 | flag_groups = [flag_group(flags = ["/D_UNICODE", "/DUNICODE"])], 2279 | ), 2280 | ], 2281 | ) 2282 | 2283 | charset_multibyte_feature = feature( 2284 | name = "charset_multibyte", 2285 | flag_sets = [ 2286 | flag_set( 2287 | actions = [ 2288 | ACTION_NAMES.c_compile, 2289 | ACTION_NAMES.linkstamp_compile, 2290 | ACTION_NAMES.cpp_compile, 2291 | ACTION_NAMES.cpp_header_parsing, 2292 | ACTION_NAMES.cpp_module_compile, 2293 | ACTION_NAMES.cpp_module_codegen, 2294 | ACTION_NAMES.cpp_module_deps_scanning, 2295 | ACTION_NAMES.cpp20_module_compile, 2296 | ACTION_NAMES.cpp20_module_codegen, 2297 | ], 2298 | flag_groups = [flag_group(flags = ["/D_MBCS"])], 2299 | ), 2300 | ], 2301 | ) 2302 | 2303 | default_includes_cmdline_feature = feature( 2304 | name = "default_includes_cmdline", 2305 | flag_sets = [ 2306 | flag_set( 2307 | actions = [ 2308 | ACTION_NAMES.linkstamp_compile, 2309 | ACTION_NAMES.c_compile, 2310 | ACTION_NAMES.cpp_compile, 2311 | ACTION_NAMES.cpp_header_parsing, 2312 | ACTION_NAMES.cpp_module_compile, 2313 | ACTION_NAMES.cpp_module_codegen, 2314 | ACTION_NAMES.cpp_module_deps_scanning, 2315 | ACTION_NAMES.cpp20_module_compile, 2316 | ACTION_NAMES.cpp20_module_codegen, 2317 | ACTION_NAMES.lto_backend, 2318 | ACTION_NAMES.clif_match, 2319 | ], 2320 | flag_groups = [flag_group(flags = ["/I" + x for x in wdm_default_includes])], 2321 | with_features = [with_feature_set(features = ["wdm"])], 2322 | ), 2323 | ], 2324 | ) 2325 | 2326 | arm64ec_feature = feature( 2327 | name = "arm64ec", 2328 | flag_sets = [ 2329 | flag_set( 2330 | actions = [ 2331 | ACTION_NAMES.linkstamp_compile, 2332 | ACTION_NAMES.c_compile, 2333 | ACTION_NAMES.cpp_compile, 2334 | ACTION_NAMES.cpp_header_parsing, 2335 | ACTION_NAMES.cpp_module_compile, 2336 | ACTION_NAMES.cpp_module_codegen, 2337 | ACTION_NAMES.cpp_module_deps_scanning, 2338 | ACTION_NAMES.cpp20_module_compile, 2339 | ACTION_NAMES.cpp20_module_codegen, 2340 | ACTION_NAMES.lto_backend, 2341 | ACTION_NAMES.clif_match, 2342 | ], 2343 | flag_groups = [flag_group(flags = ["/arm64EC"])], 2344 | with_features = [with_feature_set(not_features = ["wdm"])], 2345 | ), 2346 | flag_set( 2347 | actions = [ 2348 | ACTION_NAMES.preprocess_assemble, 2349 | ACTION_NAMES.assemble, 2350 | ], 2351 | flag_groups = [flag_group(flags = ["/nologo"] + ctx.attr.arm64ec_asm_opt)], 2352 | with_features = [with_feature_set(not_features = ["wdm"])], 2353 | ), 2354 | ], 2355 | ) 2356 | 2357 | link_arm64ec_feature = feature( 2358 | name = "link_arm64ec", 2359 | flag_sets = [ 2360 | flag_set( 2361 | actions = all_link_actions + 2362 | [ACTION_NAMES.cpp_link_static_library], 2363 | flag_groups = [flag_group(flags = ["/MACHINE:ARM64EC"])], 2364 | with_features = [with_feature_set(not_features = ["wdm"])], 2365 | ), 2366 | ], 2367 | ) 2368 | 2369 | link_arm64x_feature = feature( 2370 | name = "link_arm64x", 2371 | flag_sets = [ 2372 | flag_set( 2373 | actions = all_link_actions + 2374 | [ACTION_NAMES.cpp_link_static_library], 2375 | flag_groups = [flag_group(flags = ["/MACHINE:ARM64X"])], 2376 | with_features = [with_feature_set(not_features = ["wdm"])], 2377 | ), 2378 | ], 2379 | ) 2380 | 2381 | link_machine_feature = feature( 2382 | name = "link_machine", 2383 | enabled = True, 2384 | flag_sets = [ 2385 | flag_set( 2386 | actions = all_link_actions + 2387 | [ACTION_NAMES.cpp_link_static_library], 2388 | flag_groups = [flag_group(flags = [ctx.attr.link_machine_flag])], 2389 | with_features = [with_feature_set(not_features = ["link_arm64ec", "link_arm64x"])], 2390 | ), 2391 | ], 2392 | ) 2393 | 2394 | msvc_level3_warnings_feature = feature( 2395 | name = "msvc_level3_warnings", 2396 | flag_sets = [ 2397 | flag_set( 2398 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 2399 | flag_groups = [flag_group(flags = ["/W3"])], 2400 | ), 2401 | ], 2402 | provides = ["warning_level"], 2403 | ) 2404 | 2405 | msvc_level4_warnings_feature = feature( 2406 | name = "msvc_level4_warnings", 2407 | flag_sets = [ 2408 | flag_set( 2409 | actions = [ACTION_NAMES.c_compile, ACTION_NAMES.cpp_compile], 2410 | flag_groups = [flag_group(flags = ["/W4"])], 2411 | ), 2412 | ], 2413 | provides = ["warning_level"], 2414 | ) 2415 | 2416 | features = [ 2417 | # features from the bazel windows toolchain 2418 | no_legacy_features_feature, 2419 | nologo_feature, 2420 | has_configured_linker_path_feature, 2421 | no_stripping_feature, 2422 | targets_windows_feature, 2423 | copy_dynamic_libraries_to_binary_feature, 2424 | default_compile_flags_feature, 2425 | msvc_env_feature, 2426 | msvc_compile_env_feature, 2427 | msvc_link_env_feature, 2428 | include_paths_feature, 2429 | external_include_paths_feature, 2430 | preprocessor_defines_feature, 2431 | parse_showincludes_feature, 2432 | no_dotd_file_feature, 2433 | generate_pdb_file_feature, 2434 | generate_linkmap_feature, 2435 | shared_flag_feature, 2436 | linkstamps_feature, 2437 | output_execpath_flags_feature, 2438 | archiver_flags_feature, 2439 | input_param_flags_feature, 2440 | linker_subsystem_flag_feature, 2441 | user_link_flags_feature, 2442 | default_link_flags_feature, 2443 | linker_param_file_feature, 2444 | static_link_msvcrt_feature, 2445 | dynamic_link_msvcrt_feature, 2446 | dbg_feature, 2447 | fastbuild_feature, 2448 | opt_feature, 2449 | frame_pointer_feature, 2450 | disable_assertions_feature, 2451 | determinism_feature, 2452 | treat_warnings_as_errors_feature, 2453 | smaller_binary_feature, 2454 | remove_unreferenced_code_feature, 2455 | ignore_noisy_warnings_feature, 2456 | user_compile_flags_feature, 2457 | sysroot_feature, 2458 | unfiltered_compile_flags_feature, 2459 | archive_param_file_feature, 2460 | compiler_param_file_feature, 2461 | compiler_output_flags_feature, 2462 | compiler_input_flags_feature, 2463 | def_file_feature, 2464 | windows_export_all_symbols_feature, 2465 | no_windows_export_all_symbols_feature, 2466 | supports_dynamic_linker_feature, 2467 | supports_interface_shared_libraries_feature, 2468 | symbol_check_feature, 2469 | 2470 | # features from this toolchain 2471 | disable_msvcrt_feature, 2472 | wdm_feature, 2473 | wdm_entry_feature, 2474 | no_runtime_checks_feature, 2475 | msvc_enable_minmax_feature, 2476 | msvc_no_minmax_feature, 2477 | msvc_profile_feature, 2478 | no_default_cpp_unwinding_feature, 2479 | default_cpp_unwinding_feature, 2480 | subsystem_console_feature, 2481 | subsystem_windows_feature, 2482 | subsystem_native_feature, 2483 | win32_lean_and_mean_feature, 2484 | cdecl_feature, 2485 | stdcall_feature, 2486 | target_win7_feature, 2487 | target_win7_default_feature, 2488 | target_win8_feature, 2489 | target_win10_feature, 2490 | target_win11_feature, 2491 | c11_feature, 2492 | c17_feature, 2493 | cpp14_feature, 2494 | cpp17_feature, 2495 | cpp20_feature, 2496 | cpp_latest_feature, 2497 | buffer_security_checks_feature, 2498 | sdl_security_checks_feature, 2499 | cfg_security_checks_feature, 2500 | cet_compatible_feature, 2501 | guard_ehcont_feature, 2502 | spectre_feature, 2503 | spectre_load_cf_feature, 2504 | retpoline_check_feature, 2505 | charset_unicode_feature, 2506 | charset_multibyte_feature, 2507 | default_includes_cmdline_feature, 2508 | arm64ec_feature, 2509 | link_arm64ec_feature, 2510 | link_arm64x_feature, 2511 | link_machine_feature, 2512 | msvc_level3_warnings_feature, 2513 | msvc_level4_warnings_feature, 2514 | ] 2515 | 2516 | tool_paths = [ 2517 | tool_path(name = name, path = path) 2518 | for name, path in ctx.attr.tool_paths.items() 2519 | ] 2520 | 2521 | builtin_includes = ("%s;%s;%s;%s" % ( 2522 | ctx.attr.msvc_env_app["INCLUDE"], 2523 | ctx.attr.msvc_env_app["EXTERNAL_INCLUDE"], 2524 | ctx.attr.msvc_env_wdm["INCLUDE"], 2525 | ctx.attr.msvc_env_wdm["EXTERNAL_INCLUDE"], 2526 | )).split(";") 2527 | tmp = {} 2528 | for inc in builtin_includes: 2529 | if len(inc): 2530 | tmp[inc] = None 2531 | builtin_includes = tmp.keys() 2532 | 2533 | return cc_common.create_cc_toolchain_config_info( 2534 | ctx = ctx, 2535 | features = features, 2536 | action_configs = action_configs, 2537 | artifact_name_patterns = artifact_name_patterns, 2538 | cxx_builtin_include_directories = builtin_includes, 2539 | toolchain_identifier = ctx.attr.toolchain_identifier, 2540 | host_system_name = ctx.attr.host_system_name, 2541 | target_system_name = ctx.attr.target_system_name, 2542 | target_cpu = ctx.attr.cpu, 2543 | target_libc = "msvcrt", 2544 | compiler = "msvc-cl", 2545 | abi_version = "local", 2546 | abi_libc_version = "local", 2547 | tool_paths = tool_paths, 2548 | ) 2549 | 2550 | ewdk_cc_toolchain_config = rule( 2551 | implementation = _impl, 2552 | attrs = { 2553 | "cpu": attr.string(mandatory = True), 2554 | "link_machine_flag": attr.string(mandatory = True), 2555 | "entry_symbol_suffix": attr.string(mandatory = True), 2556 | "has_gz_option": attr.string(mandatory = True), 2557 | "cetcompat_option": attr.string(mandatory = True), 2558 | "toolchain_identifier": attr.string(), 2559 | "host_system_name": attr.string(), 2560 | "target_system_name": attr.string(), 2561 | "msvc_env_wdm": attr.string_dict(), 2562 | "msvc_env_app": attr.string_dict(), 2563 | "arch_c_opts_wdm": attr.string_list(default = []), 2564 | "arch_link_opts": attr.string_list(default = []), 2565 | "arch_link_opts_wdm": attr.string_list(default = []), 2566 | "arm64ec_asm_opt": attr.string_list(default = []), 2567 | "tool_paths": attr.string_dict(), 2568 | }, 2569 | ) 2570 | 2571 | def _configure_ewdk_cc(repository_ctx, host_cpu): 2572 | """Produce toolchain BUILD file from template. 2573 | 2574 | Args: 2575 | repository_ctx: 2576 | host_cpu: Build execution cpu (e.g. x64_windows) 2577 | """ 2578 | 2579 | tpl_path = repository_ctx.path(Label("//:BUILD.ewdk.toolchains.tpl")) 2580 | arm_asm = repository_ctx.path(Label("//:arm_asm.bat.tpl")) 2581 | deps_scanner = repository_ctx.path(Label("//:deps_scanner.bat.tpl")) 2582 | vscode_cfg_path = repository_ctx.path(Label("//:c_cpp_properties.tpl")) 2583 | cmd_helper_path = repository_ctx.path(Label("//:cmd_helper.tpl")) 2584 | 2585 | # First, we need to get the envvars from executing the EWDK LaunchBuildEnv.cmd. 2586 | # The user must have specified an EWDKDIR env var to the root of the EWDK location before executing bazel 2587 | ewdkdir = _get_path_envvar(repository_ctx.os.environ, "EWDKDIR") 2588 | if not ewdkdir: 2589 | fail("EWDKDIR envvar undefined. Please define to point to the root of the EWDK.") 2590 | (env, env_str) = _get_ewdk_env(repository_ctx, ewdkdir, host_cpu) 2591 | 2592 | # Next we need to get the relevant env vars set by msbuild for the various project types we will support. 2593 | # This is currently limited to project types "Application" and "Driver" (WDM driver type only). 2594 | build_envs = _get_msbuild_envs(repository_ctx, env) 2595 | 2596 | # Now we produce the toolchain's BUILD file from the template 2597 | content_root = env["WINDOWSSDKDIR"].rstrip("\\").replace("\\", "/") 2598 | host_binroot = env["_CL_PATH"] 2599 | host_binroot = host_binroot[:-len("\\cl.exe")] 2600 | host_binroot = host_binroot[:host_binroot.rfind('\\')] 2601 | host_binroot = host_binroot.rstrip("\\").replace("\\", "/") 2602 | 2603 | intels = ["x86", "x64"] 2604 | arms = ["arm", "arm64"] 2605 | plat32 = ["x86", "arm"] 2606 | platforms = intels + arms 2607 | tpl_vars = { 2608 | "%{ewdk_launch_env}": env_str.replace("\\", "\\\\"), 2609 | "%{msvc_env_tmp}": env["TMP"].replace("\\", "\\\\"), 2610 | "%{msvc_rc_path}": env["_RC_PATH"].replace("\\", "/"), 2611 | "%{msvc_tracewpp_path}": env["_TRACEWPP_PATH"].replace("\\", "/"), 2612 | "%{msvc_tracewpp_cfgdir}": "{}/bin/{}/wppconfig/rev1".format(content_root, env["VERSION_NUMBER"]).replace("/", "\\\\"), 2613 | "%{msvc_midl_path}": env["_MIDL_PATH"].replace("\\", "/"), 2614 | } 2615 | for platform in platforms: 2616 | tpl_vars["%%{msvc_lib_path_%s}" % platform] = "{}/{}/lib.exe".format(host_binroot, platform) 2617 | tpl_vars["%%{msvc_cl_path_%s}" % platform] = "{}/{}/cl.exe".format(host_binroot, platform) 2618 | tpl_vars["%%{msvc_link_path_%s}" % platform] = "{}/{}/link.exe".format(host_binroot, platform) 2619 | tpl_vars["%%{msvc_dumpbin_path_%s}" % platform] = "{}/{}/dumpbin.exe".format(host_binroot, platform) 2620 | if platform in arms: 2621 | asm_name = "armasm.exe" if platform in plat32 else "armasm64.exe" 2622 | tpl_vars["%%{msvc_armasm_path_%s}" % platform] = "{}/{}/{}".format(host_binroot, platform, asm_name) 2623 | else: 2624 | ml_name = "ml.exe" if platform in plat32 else "ml64.exe" 2625 | tpl_vars["%%{msvc_ml_path_%s}" % platform] = "{}/{}/{}".format(host_binroot, platform, ml_name) 2626 | 2627 | for platform, buildenv in build_envs.items(): 2628 | include = buildenv["INCLUDE"] 2629 | tpl_vars["%%{msvc_env_path_%s}" % platform] = buildenv["PATH"].replace("\\", "\\\\") 2630 | tpl_vars["%%{msvc_env_include_%s}" % platform] = include.replace("\\", "\\\\") 2631 | tpl_vars["%%{msvc_env_external_include_%s}" % platform] = buildenv.get("EXTERNAL_INCLUDE", include).replace("\\", "\\\\") 2632 | tpl_vars["%%{msvc_env_libpath_%s}" % platform] = buildenv["LIBPATH"].replace("\\", "\\\\") 2633 | tpl_vars["%%{msvc_env_lib_%s}" % platform] = buildenv["LIB"].replace("\\", "\\\\") 2634 | repository_ctx.template("BUILD", tpl_path, tpl_vars) 2635 | 2636 | arm_vars = {"%{cl_path}": tpl_vars["%{msvc_cl_path_arm}"], "%{armasm_path}": tpl_vars["%{msvc_armasm_path_arm}"]} 2637 | arm64_vars = {"%{cl_path}": tpl_vars["%{msvc_cl_path_arm64}"], "%{armasm_path}": tpl_vars["%{msvc_armasm_path_arm64}"]} 2638 | repository_ctx.template("arm_asm.bat", arm_asm, arm_vars) 2639 | repository_ctx.template("arm_asm64.bat", arm_asm, arm64_vars) 2640 | 2641 | scan_vars_x86 = {"%{cl_path}": tpl_vars["%{msvc_cl_path_x86}"]} 2642 | scan_vars_x64 = {"%{cl_path}": tpl_vars["%{msvc_cl_path_x64}"]} 2643 | scan_vars_arm = {"%{cl_path}": tpl_vars["%{msvc_cl_path_arm}"]} 2644 | scan_vars_arm64 = {"%{cl_path}": tpl_vars["%{msvc_cl_path_arm64}"]} 2645 | repository_ctx.template("deps_scanner_x86.bat", deps_scanner, scan_vars_x86) 2646 | repository_ctx.template("deps_scanner_x64.bat", deps_scanner, scan_vars_x64) 2647 | repository_ctx.template("deps_scanner_arm.bat", deps_scanner, scan_vars_arm) 2648 | repository_ctx.template("deps_scanner_arm64.bat", deps_scanner, scan_vars_arm64) 2649 | 2650 | repository_ctx.file("rc_wrapper.bat", content = "@echo off\r\n\"%s\" %%*\r\n" % env["_RC_PATH"]) 2651 | repository_ctx.file("tracewpp_wrapper.bat", content = "@echo off\r\n\"%s\" %%3 %%4 %%5 %%6 %%7 %%8 %%9 && copy /Y /V \"%%1\" \"%%2\" >nul" % env["_TRACEWPP_PATH"]) 2652 | repository_ctx.file("midl_wrapper.bat", content = "@echo off\r\n\"%s\" %%*\r\n" % env["_MIDL_PATH"]) 2653 | repository_ctx.file("ewdk_command.bat", content = "@echo off\r\n%*\r\n") 2654 | 2655 | _build_vscode_intellisense_config(repository_ctx, vscode_cfg_path, env, build_envs) 2656 | _build_cmd_env_helpers(repository_ctx, cmd_helper_path, build_envs) 2657 | 2658 | def _ewdk_cc_autoconf_toolchains_impl(repository_ctx): 2659 | """Produce BUILD file containing toolchain() definitions for EWDK C++ 2660 | 2661 | Args: 2662 | repository_ctx: 2663 | """ 2664 | 2665 | repository_ctx.symlink( 2666 | repository_ctx.path(Label("//:ewdk_cc_configure.bzl")), 2667 | "ewdk_cc_configure.bzl", 2668 | ) 2669 | repository_ctx.symlink( 2670 | repository_ctx.path(Label("//:resource_toolchain.bzl")), 2671 | "resource_toolchain.bzl", 2672 | ) 2673 | repository_ctx.symlink( 2674 | repository_ctx.path(Label("//:wpp_toolchain.bzl")), 2675 | "wpp_toolchain.bzl", 2676 | ) 2677 | repository_ctx.symlink( 2678 | repository_ctx.path(Label("//:idl_toolchain.bzl")), 2679 | "idl_toolchain.bzl", 2680 | ) 2681 | repository_ctx.symlink( 2682 | repository_ctx.path(Label("//:ewdk_command.bzl")), 2683 | "ewdk_command.bzl", 2684 | ) 2685 | noewdk_path = repository_ctx.path(Label("//:BUILD.no_ewdk")) 2686 | 2687 | host_cpu = _get_cpu_value(repository_ctx) 2688 | if host_cpu not in ["x64_windows", "arm64_windows"]: 2689 | repository_ctx.template("BUILD", noewdk_path, {}) 2690 | 2691 | ewdkdir = _get_path_envvar(repository_ctx.os.environ, "EWDKDIR") 2692 | if not ewdkdir: 2693 | repository_ctx.template("BUILD", noewdk_path, {}) 2694 | else: 2695 | _configure_ewdk_cc(repository_ctx, host_cpu) 2696 | 2697 | ewdk_cc_autoconf_toolchains = repository_rule( 2698 | implementation = _ewdk_cc_autoconf_toolchains_impl, 2699 | local = True, 2700 | configure = True, 2701 | ) 2702 | 2703 | def register_ewdk_cc_toolchains(name = "ewdk_cc"): 2704 | """Register EWDK C++ toolchains""" 2705 | ewdk_cc_autoconf_toolchains(name = name) 2706 | native.register_toolchains("@%s//:all" % name) 2707 | --------------------------------------------------------------------------------