Use emsdk as external bazel dependency (#766)
* Makes provided bazel rules look up @emsdk workspace instead of local workspace * Uses system-specific emscripten binaries instead of defaulting to linux * Provides macros for loading emsdk dependencies (nodejs and emscripten binaries) * Unhardcodes paths in bazel rules and .sh wrappers * `update_bazel_workspace.sh` now updates `revisions.bzl` * `emscripten_deps()` can be fed with specific emscripten version * Adds external usage test Addresses #650 and #696
This commit is contained in:
@@ -9,9 +9,9 @@ filegroup(
|
||||
"emcc.sh",
|
||||
"emscripten_config",
|
||||
"env.sh",
|
||||
"@emscripten//:all",
|
||||
"@nodejs//:node_files",
|
||||
"@npm//:node_modules",
|
||||
"@emsdk//:binaries",
|
||||
"@emsdk//:node_modules",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ filegroup(
|
||||
"emcc_link.sh",
|
||||
"link_wrapper.py",
|
||||
":common-script-includes",
|
||||
"@emscripten//:all",
|
||||
"@emsdk//:binaries",
|
||||
"@nodejs//:node_files",
|
||||
],
|
||||
)
|
||||
@@ -36,7 +36,7 @@ filegroup(
|
||||
srcs = [
|
||||
":compile-emscripten",
|
||||
":link-emscripten",
|
||||
"@emscripten//:all",
|
||||
"@emsdk//:binaries",
|
||||
"@nodejs//:node_files",
|
||||
],
|
||||
)
|
||||
@@ -49,7 +49,8 @@ cc_library(name = "malloc")
|
||||
emscripten_cc_toolchain_config_rule(
|
||||
name = "wasm",
|
||||
cpu = "wasm",
|
||||
emscripten_version = "emscripten",
|
||||
em_config = "emscripten_config",
|
||||
emscripten_binaries = "@emsdk//:binaries",
|
||||
)
|
||||
|
||||
cc_toolchain(
|
||||
|
||||
@@ -69,9 +69,10 @@ def _impl(ctx):
|
||||
abi_libc_version = "default"
|
||||
|
||||
cc_target_os = "emscripten"
|
||||
emscripten_version = ctx.attr.emscripten_version
|
||||
|
||||
builtin_sysroot = "external/emscripten/emscripten/cache/sysroot"
|
||||
emscripten_dir = ctx.attr.emscripten_binaries.label.workspace_root
|
||||
|
||||
builtin_sysroot = emscripten_dir + "/emscripten/cache/sysroot"
|
||||
|
||||
################################################################
|
||||
# Tools
|
||||
@@ -909,7 +910,7 @@ def _impl(ctx):
|
||||
"-iwithsysroot" + "/include/c++/v1",
|
||||
"-iwithsysroot" + "/include/compat",
|
||||
"-iwithsysroot" + "/include",
|
||||
"-isystem", "external/emscripten/lib/clang/13.0.0/include",
|
||||
"-isystem", emscripten_dir + "/lib/clang/13.0.0/include",
|
||||
],
|
||||
),
|
||||
# Inputs and outputs
|
||||
@@ -1016,6 +1017,22 @@ def _impl(ctx):
|
||||
]
|
||||
|
||||
crosstool_default_env_sets = [
|
||||
# Globals
|
||||
env_set(
|
||||
actions = all_compile_actions +
|
||||
all_link_actions +
|
||||
[ACTION_NAMES.cpp_link_static_library],
|
||||
env_entries = [
|
||||
env_entry(
|
||||
key = "EM_BIN_PATH",
|
||||
value = emscripten_dir,
|
||||
),
|
||||
env_entry(
|
||||
key = "EM_CONFIG_PATH",
|
||||
value = ctx.file.em_config.path,
|
||||
),
|
||||
],
|
||||
),
|
||||
# Use llvm backend. Off by default, enabled via --features=llvm_backend
|
||||
env_set(
|
||||
actions = all_compile_actions +
|
||||
@@ -1052,49 +1069,42 @@ def _impl(ctx):
|
||||
features.append(crosstool_default_flags_feature)
|
||||
|
||||
cxx_builtin_include_directories = [
|
||||
"external/emscripten/emscripten/cache/sysroot/include/c++/v1",
|
||||
"external/emscripten/emscripten/cache/sysroot/include/compat",
|
||||
"external/emscripten/emscripten/cache/sysroot/include",
|
||||
"external/emscripten/lib/clang/13.0.0/include",
|
||||
emscripten_dir + "/emscripten/cache/sysroot/include/c++/v1",
|
||||
emscripten_dir + "/emscripten/cache/sysroot/include/compat",
|
||||
emscripten_dir + "/emscripten/cache/sysroot/include",
|
||||
emscripten_dir + "/lib/clang/13.0.0/include",
|
||||
]
|
||||
|
||||
artifact_name_patterns = []
|
||||
|
||||
make_variables = []
|
||||
|
||||
out = ctx.actions.declare_file(ctx.label.name)
|
||||
ctx.actions.write(out, "Fake executable")
|
||||
return [
|
||||
cc_common.create_cc_toolchain_config_info(
|
||||
ctx = ctx,
|
||||
features = features,
|
||||
action_configs = action_configs,
|
||||
artifact_name_patterns = artifact_name_patterns,
|
||||
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
||||
toolchain_identifier = toolchain_identifier,
|
||||
host_system_name = host_system_name,
|
||||
target_system_name = target_system_name,
|
||||
target_cpu = target_cpu,
|
||||
target_libc = target_libc,
|
||||
compiler = compiler,
|
||||
abi_version = abi_version,
|
||||
abi_libc_version = abi_libc_version,
|
||||
tool_paths = tool_paths,
|
||||
make_variables = make_variables,
|
||||
builtin_sysroot = builtin_sysroot,
|
||||
cc_target_os = cc_target_os,
|
||||
),
|
||||
DefaultInfo(
|
||||
executable = out,
|
||||
),
|
||||
]
|
||||
return cc_common.create_cc_toolchain_config_info(
|
||||
ctx = ctx,
|
||||
features = features,
|
||||
action_configs = action_configs,
|
||||
artifact_name_patterns = artifact_name_patterns,
|
||||
cxx_builtin_include_directories = cxx_builtin_include_directories,
|
||||
toolchain_identifier = toolchain_identifier,
|
||||
host_system_name = host_system_name,
|
||||
target_system_name = target_system_name,
|
||||
target_cpu = target_cpu,
|
||||
target_libc = target_libc,
|
||||
compiler = compiler,
|
||||
abi_version = abi_version,
|
||||
abi_libc_version = abi_libc_version,
|
||||
tool_paths = tool_paths,
|
||||
make_variables = make_variables,
|
||||
builtin_sysroot = builtin_sysroot,
|
||||
cc_target_os = cc_target_os,
|
||||
)
|
||||
|
||||
emscripten_cc_toolchain_config_rule = rule(
|
||||
implementation = _impl,
|
||||
attrs = {
|
||||
"cpu": attr.string(mandatory = True, values = ["asmjs", "wasm"]),
|
||||
"emscripten_version": attr.string(mandatory = True),
|
||||
"em_config": attr.label(mandatory = True, allow_single_file=True),
|
||||
"emscripten_binaries": attr.label(mandatory = True),
|
||||
},
|
||||
provides = [CcToolchainConfigInfo],
|
||||
executable = True,
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
source emscripten_toolchain/env.sh
|
||||
source external/emsdk/emscripten_toolchain/env.sh
|
||||
|
||||
exec python3 $EMSCRIPTEN/emar.py "$@"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
source emscripten_toolchain/env.sh
|
||||
source external/emsdk/emscripten_toolchain/env.sh
|
||||
|
||||
exec python3 external/emscripten/emscripten/emcc.py "$@"
|
||||
exec python3 $EMSCRIPTEN/emcc.py "$@"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
source emscripten_toolchain/env.sh
|
||||
source external/emsdk/emscripten_toolchain/env.sh
|
||||
|
||||
exec python3 emscripten_toolchain/link_wrapper.py "$@"
|
||||
exec python3 external/emsdk/emscripten_toolchain/link_wrapper.py "$@"
|
||||
|
||||
@@ -3,8 +3,8 @@ import platform
|
||||
|
||||
ROOT_DIR = os.environ["ROOT_DIR"]
|
||||
EMSCRIPTEN_ROOT = os.environ["EMSCRIPTEN"]
|
||||
LLVM_ROOT = ROOT_DIR + "/external/emscripten/bin"
|
||||
BINARYEN_ROOT = ROOT_DIR + "/external/emscripten"
|
||||
BINARYEN_ROOT = ROOT_DIR + "/" + os.environ["EM_BIN_PATH"]
|
||||
LLVM_ROOT = BINARYEN_ROOT + "/bin"
|
||||
FROZEN_CACHE = True
|
||||
|
||||
system = platform.system()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
export ROOT_DIR=`(pwd -P)`
|
||||
export EMSCRIPTEN=${ROOT_DIR}/external/emscripten/emscripten
|
||||
export EM_CONFIG=${ROOT_DIR}/emscripten_toolchain/emscripten_config
|
||||
export EMSCRIPTEN=$ROOT_DIR/$EM_BIN_PATH/emscripten
|
||||
export EM_CONFIG=$ROOT_DIR/$EM_CONFIG_PATH
|
||||
|
||||
@@ -27,13 +27,13 @@ def _wasm_transition_impl(settings, attr):
|
||||
|
||||
return {
|
||||
"//command_line_option:compiler": "emscripten",
|
||||
"//command_line_option:crosstool_top": "//emscripten_toolchain:everything",
|
||||
"//command_line_option:crosstool_top": "@emsdk//emscripten_toolchain:everything",
|
||||
"//command_line_option:cpu": "wasm",
|
||||
"//command_line_option:features": features,
|
||||
"//command_line_option:dynamic_mode": "off",
|
||||
"//command_line_option:linkopt": linkopts,
|
||||
"//command_line_option:platforms": [],
|
||||
"//command_line_option:custom_malloc": "//emscripten_toolchain:malloc",
|
||||
"//command_line_option:custom_malloc": "@emsdk//emscripten_toolchain:malloc",
|
||||
}
|
||||
|
||||
_wasm_transition = transition(
|
||||
@@ -145,7 +145,7 @@ wasm_cc_binary = rule(
|
||||
executable = True,
|
||||
allow_files = True,
|
||||
cfg = "exec",
|
||||
default = Label("//emscripten_toolchain:wasm_binary"),
|
||||
default = Label("@emsdk//emscripten_toolchain:wasm_binary"),
|
||||
),
|
||||
},
|
||||
outputs = _wasm_binary_outputs,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
"""Rules related to C++ and WebAssembly.
|
||||
"""
|
||||
|
||||
load("//emscripten_toolchain:wasm_cc_binary.bzl", _wasm_cc_binary = "wasm_cc_binary")
|
||||
load(":wasm_cc_binary.bzl", _wasm_cc_binary = "wasm_cc_binary")
|
||||
|
||||
wasm_cc_binary = _wasm_cc_binary
|
||||
|
||||
Reference in New Issue
Block a user