Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6b73a28
Externalize @emsdk lookups
celentes Mar 17, 2021
1b20685
Externalize deps
celentes Mar 17, 2021
1948766
Do not use @npm as that will likely class in any downstream projects
celentes Mar 17, 2021
6a6db25
Declare top level bazel folder as package
celentes Mar 17, 2021
747c919
Fix @npm --> @emsdk_npm
celentes Mar 17, 2021
dac9166
Use external paths in .sh wrappers
celentes Mar 18, 2021
3f27ad2
Add test bazel repo for external project
celentes Mar 18, 2021
4b6e8b9
Do not hardcode emscripten paths in emcc.sh
celentes Mar 18, 2021
5576500
Do not hardcode EM_CONFIG location
celentes Mar 18, 2021
b4ca695
Do not hardcode emscripten paths
celentes Mar 18, 2021
39995ce
Do not hardcode emscripten paths vol 2
celentes Mar 18, 2021
3836b2b
Get rid of fake executable in emscripten toolchain config
celentes Mar 18, 2021
e94e9d1
Add empty revisions file
celentes Mar 19, 2021
e3079c8
Rework update_bazel_workspace.sh to modify revisions.bzl instead
celentes Mar 19, 2021
b96569a
Alias emscripten binaries and node_modules
celentes Mar 19, 2021
b704571
Do not hardcode emscripten paths vol 3
celentes Mar 19, 2021
60c8a5d
Make @emsdk-local emscripten alias instead
celentes Mar 19, 2021
5134dc3
Add crossplatform selects for binaries
celentes Mar 19, 2021
7a2d5b4
Check for excludes before declaring deps
celentes Mar 19, 2021
4a7ca3a
Use default emscripten_version="latest"
celentes Mar 19, 2021
5c78144
Fill in some of the older revisions
celentes Mar 19, 2021
22251b2
Provide error message on emscripten version not found
celentes Mar 19, 2021
a0158c7
Remove incompatible revisions
celentes Mar 19, 2021
3d9a00f
Update test_bazel.sh
celentes Mar 19, 2021
0d0b64b
Add test_bazel_mac.sh
celentes Mar 19, 2021
88094c9
Add test_bazel_mac to circleci
celentes Mar 19, 2021
5384597
Revert scrapping pip install in test_bazel_linux
celentes Mar 19, 2021
72832a3
Sort version numbers when using emscripten_version="latest"
celentes Mar 19, 2021
ff0f3d4
Fix wrong lib include paths
celentes Mar 22, 2021
dbda15d
Quickfix emscripten_dir
celentes Mar 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ jobs:
docker login -u "$DOCKER_USER" -p "$DOCKER_PASS"
make -C ./docker version=${CIRCLE_TAG} alias=latest push

test-bazel:
test-bazel-linux:
executor: bionic
steps:
- checkout
Expand All @@ -186,6 +186,21 @@ jobs:
apt-get install -q -y bazel
- run: test/test_bazel.sh

test-bazel-mac:
macos:
xcode: "12.2.0"
environment:
EMSDK_NOTTY: "1"
HOMEBREW_NO_AUTO_UPDATE: "1"
steps:
- checkout
- run: brew install grep
- run:
name: install bazel
command: |
brew install bazel
- run: test/test_bazel_mac.sh

workflows:
flake8:
jobs:
Expand All @@ -208,6 +223,9 @@ workflows:
ignore: /.*/
tags:
only: /.*/
test-bazel:
test-bazel-linux:
jobs:
- test-bazel-linux
test-bazel-mac:
jobs:
- test-bazel
- test-bazel-mac
44 changes: 44 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package(default_visibility = ['//visibility:public'])

config_setting(
name = "linux",
constraint_values = [
"@platforms//os:linux",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "macos",
constraint_values = [
"@platforms//os:macos",
"@platforms//cpu:x86_64",
],
)

config_setting(
name = "windows",
constraint_values = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
],
)

alias(
name = "binaries",
actual = select({
":linux": "@emscripten_bin_linux//:all",
":macos": "@emscripten_bin_mac//:all",
":windows": "@emscripten_bin_win//:all",
}),
)

alias(
name = "node_modules",
actual = select({
":linux": "@emscripten_npm_linux//:node_modules",
":macos": "@emscripten_npm_mac//:node_modules",
":windows": "@emscripten_npm_win//:node_modules",
}),
)

28 changes: 5 additions & 23 deletions bazel/WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
workspace(name = "emsdk")

http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "0f2de53628e848c1691e5729b515022f5a77369c76a09fbe55611e12731c90e3",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.0.1/rules_nodejs-2.0.1.tar.gz"],
)
load(":deps.bzl", "deps")
deps()

load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")

# emscripten 2.0.15
http_archive(
name = "emscripten",
sha256 = "7ff49fc63adf29970f6e7af1df445d7f554bdbbb2606db1cb5d3567ce69df1db",
strip_prefix = "install",
url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/linux/89202930a98fe7f9ed59b574469a9471b0bda7dd/wasm-binaries.tbz2",
build_file = "//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2",
)

npm_install(
name = "npm",
package_json = "@emscripten//:emscripten/package.json",
package_lock_json = "@emscripten//:emscripten/package-lock.json",
)
load(":emscripten_deps.bzl", "emscripten_deps")
emscripten_deps()
11 changes: 11 additions & 0 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

def deps():
excludes = native.existing_rules().keys()

if "build_bazel_rules_nodejs" not in excludes:
http_archive(
name = "build_bazel_rules_nodejs",
sha256 = "0f2de53628e848c1691e5729b515022f5a77369c76a09fbe55611e12731c90e3",
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/2.0.1/rules_nodejs-2.0.1.tar.gz"],
)
76 changes: 76 additions & 0 deletions bazel/emscripten_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")
load(":revisions.bzl", "EMSCRIPTEN_TAGS")

def _parse_version(v):
return [int(u) for u in v.split(".")]

def emscripten_deps(emscripten_version = "latest"):
version = emscripten_version

if version == "latest":
version = reversed(sorted(EMSCRIPTEN_TAGS.keys(), key=_parse_version))[0]

if version not in EMSCRIPTEN_TAGS.keys():
error_msg = "Emscripten version {} not found.".format(version)
error_msg += " Look at @emsdk//:revisions.bzl for the list "
error_msg += "of currently supported versions."
fail(error_msg)

revision = EMSCRIPTEN_TAGS[version]

emscripten_url = "https://storage.googleapis.com/webassembly/emscripten-releases-builds/{}/{}/wasm-binaries.tbz2"

# This could potentially backfire for projects with multiple emscripten
# dependencies that use different emscripten versions
excludes = native.existing_rules().keys()
if "emscripten_bin_linux" not in excludes:
http_archive(
name = "emscripten_bin_linux",
strip_prefix = "install",
url = emscripten_url.format("linux", revision.hash),
sha256 = revision.sha_linux,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2",
)

if "emscripten_bin_mac" not in excludes:
http_archive(
name = "emscripten_bin_mac",
strip_prefix = "install",
url = emscripten_url.format("mac", revision.hash),
sha256 = revision.sha_mac,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2",
)

if "emscripten_bin_win" not in excludes:
http_archive(
name = "emscripten_bin_win",
strip_prefix = "install",
url = emscripten_url.format("win", revision.hash),
sha256 = revision.sha_win,
build_file = "@emsdk//emscripten_toolchain:emscripten.BUILD",
type = "tar.bz2",
)

if "emscripten_npm_linux" not in excludes:
npm_install(
name = "emscripten_npm_linux",
package_json = "@emscripten_bin_linux//:emscripten/package.json",
package_lock_json = "@emscripten_bin_linux//:emscripten/package-lock.json",
)

if "emscripten_npm_mac" not in excludes:
npm_install(
name = "emscripten_npm_mac",
package_json = "@emscripten_bin_mac//:emscripten/package.json",
package_lock_json = "@emscripten_bin_mac//:emscripten/package-lock.json",
)

if "emscripten_npm_win" not in excludes:
npm_install(
name = "emscripten_npm_win",
package_json = "@emscripten_bin_win//:emscripten/package.json",
package_lock_json = "@emscripten_bin_win//:emscripten/package-lock.json",
)
11 changes: 6 additions & 5 deletions bazel/emscripten_toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ filegroup(
"emcc.sh",
"emscripten_config",
"env.sh",
"@emscripten//:all",
"@nodejs//:node_files",
"@npm//:node_modules",
"@emsdk//:binaries",
"@emsdk//:node_modules",
],
)

Expand All @@ -26,7 +26,7 @@ filegroup(
"emcc_link.sh",
"link_wrapper.py",
":common-script-includes",
"@emscripten//:all",
"@emsdk//:binaries",
"@nodejs//:node_files",
],
)
Expand All @@ -36,7 +36,7 @@ filegroup(
srcs = [
":compile-emscripten",
":link-emscripten",
"@emscripten//:all",
"@emsdk//:binaries",
"@nodejs//:node_files",
],
)
Expand All @@ -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(
Expand Down
80 changes: 45 additions & 35 deletions bazel/emscripten_toolchain/crosstool.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -899,7 +900,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
Expand Down Expand Up @@ -1006,6 +1007,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 +
Expand Down Expand Up @@ -1042,49 +1059,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,
)
2 changes: 1 addition & 1 deletion bazel/emscripten_toolchain/emar.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

source emscripten_toolchain/env.sh
source external/emsdk/emscripten_toolchain/env.sh

exec python3 $EMSCRIPTEN/emar.py "$@"
4 changes: 2 additions & 2 deletions bazel/emscripten_toolchain/emcc.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
4 changes: 2 additions & 2 deletions bazel/emscripten_toolchain/emcc_link.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
Loading