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

@@ -206,6 +206,28 @@ jobs:
brew install bazel brew install bazel
- run: test/test_bazel_mac.sh - run: test/test_bazel_mac.sh
test-bazel-windows:
executor:
name: win/vs2019
shell: powershell.exe -ExecutionPolicy Bypass
environment:
PYTHONUNBUFFERED: "1"
EMSDK_NOTTY: "1"
steps:
- checkout
- run:
name: Download Bazelisk
shell: powershell.exe
command: |
$ProgressPreference = "SilentlyContinue"
Invoke-WebRequest -Uri https://github.com/bazelbuild/bazelisk/releases/download/v1.10.1/bazelisk-windows-amd64.exe -OutFile ( New-Item -Path "temp\bazel\bazel.exe" -Force )
- run:
name: Run Tests
shell: powershell.exe
command: |
$env:Path += ";C:\Python27amd64;$pwd\temp\bazel"
.\test\test_bazel.ps1
workflows: workflows:
flake8: flake8:
jobs: jobs:
@@ -234,3 +256,6 @@ workflows:
test-bazel-mac: test-bazel-mac:
jobs: jobs:
- test-bazel-mac - test-bazel-mac
test-bazel-windows:
jobs:
- test-bazel-windows

1
bazel/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/bazel-*

View File

@@ -19,7 +19,7 @@ def emscripten_deps(emscripten_version = "latest"):
revision = EMSCRIPTEN_TAGS[version] revision = EMSCRIPTEN_TAGS[version]
emscripten_url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/{}/{}/wasm-binaries.tbz2" emscripten_url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/{}/{}/wasm-binaries.{}"
# This could potentially backfire for projects with multiple emscripten # This could potentially backfire for projects with multiple emscripten
# dependencies that use different emscripten versions # dependencies that use different emscripten versions
@@ -28,7 +28,7 @@ def emscripten_deps(emscripten_version = "latest"):
http_archive( http_archive(
name = "emscripten_bin_linux", name = "emscripten_bin_linux",
strip_prefix = "install", strip_prefix = "install",
url = emscripten_url.format("linux", revision.hash), url = emscripten_url.format("linux", revision.hash, "tbz2"),
sha256 = revision.sha_linux, sha256 = revision.sha_linux,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD", build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2", type = "tar.bz2",
@@ -38,7 +38,7 @@ def emscripten_deps(emscripten_version = "latest"):
http_archive( http_archive(
name = "emscripten_bin_mac", name = "emscripten_bin_mac",
strip_prefix = "install", strip_prefix = "install",
url = emscripten_url.format("mac", revision.hash), url = emscripten_url.format("mac", revision.hash, "tbz2"),
sha256 = revision.sha_mac, sha256 = revision.sha_mac,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD", build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2", type = "tar.bz2",
@@ -48,10 +48,10 @@ def emscripten_deps(emscripten_version = "latest"):
http_archive( http_archive(
name = "emscripten_bin_win", name = "emscripten_bin_win",
strip_prefix = "install", strip_prefix = "install",
url = emscripten_url.format("win", revision.hash), url = emscripten_url.format("win", revision.hash, "zip"),
sha256 = revision.sha_win, sha256 = revision.sha_win,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD", build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2", type = "zip",
) )
if "emscripten_npm_linux" not in excludes: if "emscripten_npm_linux" not in excludes:

View File

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

View File

@@ -74,23 +74,27 @@ def _impl(ctx):
builtin_sysroot = emscripten_dir + "/emscripten/cache/sysroot" 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 # Tools
################################################################ ################################################################
clang_tool = tool(path = "emcc.sh") clang_tool = tool(path = emcc_script)
clif_match_tool = tool(path = "dummy_clif_matcher") clif_match_tool = tool(path = "dummy_clif_matcher")
link_tool = tool(path = "emcc_link.sh") link_tool = tool(path = emcc_link_script)
archive_tool = tool(path = "emar.sh") archive_tool = tool(path = emar_script)
strip_tool = tool(path = "NOT_USED_STRIP_TOOL") strip_tool = tool(path = "NOT_USED_STRIP_TOOL")
#### Legacy tool paths (much of this is redundant with action_configs, but #### Legacy tool paths (much of this is redundant with action_configs, but
#### these are still used for some things) #### these are still used for some things)
tool_paths = [ 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 = "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 = "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 = "nm", path = "NOT_USED"),
tool_path(name = "objdump", path = "/bin/false"), tool_path(name = "objdump", path = "/bin/false"),
tool_path(name = "strip", path = "NOT_USED"), 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"]), "cpu": attr.string(mandatory = True, values = ["asmjs", "wasm"]),
"em_config": attr.label(mandatory = True, allow_single_file = True), "em_config": attr.label(mandatory = True, allow_single_file = True),
"emscripten_binaries": attr.label(mandatory = True), "emscripten_binaries": attr.label(mandatory = True),
"script_extension": attr.string(mandatory = True, values = ["sh", "bat"]),
}, },
provides = [CcToolchainConfigInfo], 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 FROZEN_CACHE = True
system = platform.system() 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) 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 sys.argv[1] = '@' + new_param_filename
emcc_py = os.path.join(os.environ['EMSCRIPTEN'], 'emcc.py') 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: if rtn != 0:
sys.exit(1) sys.exit(1)

View File

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

View File

@@ -55,15 +55,10 @@ _wasm_transition = transition(
) )
def _wasm_binary_impl(ctx): 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 = [ outputs = [
ctx.outputs.loader, ctx.outputs.loader,
ctx.outputs.wasm, ctx.outputs.wasm,
@@ -80,7 +75,7 @@ def _wasm_binary_impl(ctx):
ctx.actions.run( ctx.actions.run(
inputs = ctx.files.cc_target, inputs = ctx.files.cc_target,
outputs = outputs, outputs = outputs,
arguments = args, arguments = [args],
executable = ctx.executable._wasm_binary_extractor, executable = ctx.executable._wasm_binary_extractor,
) )

View File

@@ -12,13 +12,13 @@ EMSCRIPTEN_TAGS = {
hash = "7fbe748230f2ce99abbf975d9ad997699efb3153", hash = "7fbe748230f2ce99abbf975d9ad997699efb3153",
sha_linux = "10646b64daea15354f14f89f7e79937f420b77f31bda7c4b174de2474835950f", sha_linux = "10646b64daea15354f14f89f7e79937f420b77f31bda7c4b174de2474835950f",
sha_mac = "ebb17bc91c6a72ca06d17337d27aa1a2be4c9af4c68644c221712123f663b8ab", sha_mac = "ebb17bc91c6a72ca06d17337d27aa1a2be4c9af4c68644c221712123f663b8ab",
sha_win = "28a0a5983d8cdbe6b61439a111ef8a5f0f93ccb444d08e0540682b8d3c8c0f2e", sha_win = "0d4f2ff5d88a8eef5ed769ee4ffc5d5574143911d2e0079325cdc5206c9e9bb1",
), ),
"2.0.34": struct( "2.0.34": struct(
hash = "d8fc1b92dbc0ce8d740a7adb937c5137ba4755e0", hash = "d8fc1b92dbc0ce8d740a7adb937c5137ba4755e0",
sha_linux = "a6304e3a52c172eb178c6f9817d74aa3ee411e97ef00bcae0884377799c49954", sha_linux = "a6304e3a52c172eb178c6f9817d74aa3ee411e97ef00bcae0884377799c49954",
sha_mac = "975ae11000100362baf19d161fec04d82e1f7c9fb7d43c43864ddd65a47f1780", sha_mac = "975ae11000100362baf19d161fec04d82e1f7c9fb7d43c43864ddd65a47f1780",
sha_win = "30f64dbc6425490157360439d40141feae359dbf586f59fa23185d7e009f3209", sha_win = "8167a44bb895a0fdc153836bed91bf387be57f2dc1b8f103bf70e68923b61d39",
), ),
"2.0.33": struct( "2.0.33": struct(
hash = "cef8850d57278271766fb2163eebcb07354018e7", hash = "cef8850d57278271766fb2163eebcb07354018e7",

View File

@@ -34,16 +34,16 @@ if [[ $ERR = 1 ]]; then
fi fi
URL1=https://storage.googleapis.com/webassembly/emscripten-releases-builds/ URL1=https://storage.googleapis.com/webassembly/emscripten-releases-builds/
URL2=/wasm-binaries.tbz2 URL2=/wasm-binaries.
# Get commit hash for $1 version # Get commit hash for $1 version
get_hash () { get_hash () {
echo $(grep "$1" emscripten-releases-tags.json | grep -v latest | cut -f4 -d\") echo $(grep "$1" emscripten-releases-tags.json | grep -v latest | cut -f4 -d\")
} }
# Get sha256 for $1 os $2 hash # Get sha256 for $1 os $2 extname $3 hash
get_sha () { get_sha () {
echo $(curl "${URL1}$1/$2${URL2}" 2>/dev/null | sha256sum | awk '{print $1}') echo $(curl "${URL1}$1/$3${URL2}$2" 2>/dev/null | sha256sum | awk '{print $1}')
} }
# Assemble dictionary line # Assemble dictionary line
@@ -52,9 +52,9 @@ revisions_item () {
echo \ echo \
"\ \"$1\": struct(\n" \ "\ \"$1\": struct(\n" \
"\ hash = \"$(get_hash ${hash})\",\n" \ "\ hash = \"$(get_hash ${hash})\",\n" \
"\ sha_linux = \"$(get_sha linux ${hash})\",\n" \ "\ sha_linux = \"$(get_sha linux tbz2 ${hash})\",\n" \
"\ sha_mac = \"$(get_sha mac ${hash})\",\n" \ "\ sha_mac = \"$(get_sha mac tbz2 ${hash})\",\n" \
"\ sha_win = \"$(get_sha win ${hash})\",\n" \ "\ sha_win = \"$(get_sha win zip ${hash})\",\n" \
"\ )," "\ ),"
} }

21
test/test_bazel.ps1 Normal file
View File

@@ -0,0 +1,21 @@
$ErrorActionPreference = 'Stop'
Set-Location bazel
bazel build //hello-world:hello-world-wasm
if (-not $?) { Exit $LastExitCode }
bazel build //hello-world:hello-world-wasm-simd
if (-not $?) { Exit $LastExitCode }
Set-Location test_external
bazel build //:hello-world-wasm
if (-not $?) { Exit $LastExitCode }
bazel build //:hello-embind-wasm --compilation_mode dbg # debug
if (-not $?) { Exit $LastExitCode }
# Test use of the closure compiler
bazel build //:hello-embind-wasm --compilation_mode opt # release
if (-not $?) { Exit $LastExitCode }