Bazel Windows Support (#929)

This commit is contained in:
Ezekiel Warren
2021-12-20 11:24:56 -08:00
committed by GitHub
parent bb9a6a326f
commit 774b871eca
16 changed files with 110 additions and 33 deletions

View File

@@ -6,9 +6,12 @@ filegroup(
name = "common-script-includes",
srcs = [
"emar.sh",
"emar.bat",
"emcc.sh",
"emcc.bat",
"emscripten_config",
"env.sh",
"env.bat",
"@emsdk//:binaries",
"@emsdk//:node_modules",
"@nodejs//:node_files",
@@ -24,6 +27,7 @@ filegroup(
name = "link-emscripten",
srcs = [
"emcc_link.sh",
"emcc_link.bat",
"link_wrapper.py",
":common-script-includes",
"@emsdk//:binaries",
@@ -51,6 +55,10 @@ emscripten_cc_toolchain_config_rule(
cpu = "wasm",
em_config = "emscripten_config",
emscripten_binaries = "@emsdk//:binaries",
script_extension = select({
"@bazel_tools//src/conditions:host_windows": "bat",
"//conditions:default": "sh",
}),
)
cc_toolchain(

View File

@@ -74,23 +74,27 @@ def _impl(ctx):
builtin_sysroot = emscripten_dir + "/emscripten/cache/sysroot"
emcc_script = "emcc.%s" % ctx.attr.script_extension
emcc_link_script = "emcc_link.%s" % ctx.attr.script_extension
emar_script = "emar.%s" % ctx.attr.script_extension
################################################################
# Tools
################################################################
clang_tool = tool(path = "emcc.sh")
clang_tool = tool(path = emcc_script)
clif_match_tool = tool(path = "dummy_clif_matcher")
link_tool = tool(path = "emcc_link.sh")
archive_tool = tool(path = "emar.sh")
link_tool = tool(path = emcc_link_script)
archive_tool = tool(path = emar_script)
strip_tool = tool(path = "NOT_USED_STRIP_TOOL")
#### Legacy tool paths (much of this is redundant with action_configs, but
#### these are still used for some things)
tool_paths = [
tool_path(name = "ar", path = "emar.sh"),
tool_path(name = "ar", path = emar_script),
tool_path(name = "cpp", path = "/bin/false"),
tool_path(name = "gcc", path = "emcc.sh"),
tool_path(name = "gcc", path = emcc_script),
tool_path(name = "gcov", path = "/bin/false"),
tool_path(name = "ld", path = "emcc_link.sh"),
tool_path(name = "ld", path = emcc_link_script),
tool_path(name = "nm", path = "NOT_USED"),
tool_path(name = "objdump", path = "/bin/false"),
tool_path(name = "strip", path = "NOT_USED"),
@@ -1106,6 +1110,7 @@ emscripten_cc_toolchain_config_rule = rule(
"cpu": attr.string(mandatory = True, values = ["asmjs", "wasm"]),
"em_config": attr.label(mandatory = True, allow_single_file = True),
"emscripten_binaries": attr.label(mandatory = True),
"script_extension": attr.string(mandatory = True, values = ["sh", "bat"]),
},
provides = [CcToolchainConfigInfo],
)

View File

@@ -0,0 +1,5 @@
@ECHO OFF
call external\emsdk\emscripten_toolchain\env.bat
py -3 %EMSCRIPTEN%\emar.py %*

View File

@@ -0,0 +1,5 @@
@ECHO OFF
call external\emsdk\emscripten_toolchain\env.bat
py -3 %EMSCRIPTEN%\emcc.py %*

View File

@@ -0,0 +1,5 @@
@ECHO OFF
call external\emsdk\emscripten_toolchain\env.bat
py -3 external\emsdk\emscripten_toolchain\link_wrapper.py %*

View File

@@ -8,5 +8,5 @@ LLVM_ROOT = BINARYEN_ROOT + "/bin"
FROZEN_CACHE = True
system = platform.system()
nodejs_binary = "node.exe" if(system =="Windows") else "bin/node"
nodejs_binary = "bin/nodejs/node.exe" if(system =="Windows") else "bin/node"
NODE_JS = ROOT_DIR + "/external/nodejs_{}_amd64/{}".format(system.lower(), nodejs_binary)

View File

@@ -0,0 +1,5 @@
@ECHO OFF
set ROOT_DIR=%CD%
set EMSCRIPTEN=%ROOT_DIR%\%EM_BIN_PATH%\emscripten
set EM_CONFIG=%ROOT_DIR%\%EM_CONFIG_PATH%

View File

@@ -39,7 +39,7 @@ if any(' ' in a for a in param_file_args):
sys.argv[1] = '@' + new_param_filename
emcc_py = os.path.join(os.environ['EMSCRIPTEN'], 'emcc.py')
rtn = subprocess.call(['python3', emcc_py] + sys.argv[1:])
rtn = subprocess.call([sys.executable, emcc_py] + sys.argv[1:])
if rtn != 0:
sys.exit(1)

View File

@@ -20,7 +20,7 @@ WebAssembly binary into a larger web application.
import argparse
import os
import subprocess
import tarfile
def ensure(f):
@@ -40,12 +40,14 @@ def main():
parser.add_argument('--output_path', help='The path to extract into.')
args = parser.parse_args()
args.archive = os.path.normpath(args.archive)
basename = os.path.basename(args.archive)
stem = basename.split('.')[0]
# Extract all files from the tarball.
subprocess.check_call(
['tar', 'xf', args.archive, '-C', args.output_path])
tar = tarfile.open(args.archive)
tar.extractall(args.output_path)
# At least one of these two files should exist at this point.
ensure(os.path.join(args.output_path, stem + '.js'))

View File

@@ -55,15 +55,10 @@ _wasm_transition = transition(
)
def _wasm_binary_impl(ctx):
cc_target = ctx.attr.cc_target[0]
args = ctx.actions.args()
args.add("--output_path", ctx.outputs.loader.dirname)
args.add_all("--archive", ctx.files.cc_target)
args = [
"--output_path={}".format(ctx.outputs.loader.dirname),
] + [
ctx.expand_location("--archive=$(location {})".format(
cc_target.label,
), [cc_target]),
]
outputs = [
ctx.outputs.loader,
ctx.outputs.wasm,
@@ -80,7 +75,7 @@ def _wasm_binary_impl(ctx):
ctx.actions.run(
inputs = ctx.files.cc_target,
outputs = outputs,
arguments = args,
arguments = [args],
executable = ctx.executable._wasm_binary_extractor,
)