Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dockerfiles for emsdk #4771

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 22 additions & 16 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@
# editor's search path.
build --symlink_prefix=dist/

# Use our custom-configured c++ toolchain.
build:wasm --crosstool_top=//toolchain:emscripten

# Use --cpu as a differentiator.
build:wasm --cpu=wasm

# Use the default C++ toolchain to build the tools used during the build.
build:wasm --host_crosstool_top=@bazel_tools//tools/cpp:toolchain

# These compile flags are active no matter which build mode we are in
# (dbg vs opt). For flags specific to build mode, see cc_toolchain_config.bzl.
build:wasm --cxxopt="-std=c++11"
build:wasm --cxxopt="-fno-rtti"
build:wasm --cxxopt="-fno-exceptions"
build:wasm --cxxopt="-fomit-frame-pointer"
build --cxxopt="-std=c++11"
build --cxxopt="-fno-rtti"
build --cxxopt="-fno-exceptions"
build --cxxopt="-fomit-frame-pointer"

# Remote cache config. Users should override this in .bazelrc.user
build:remote --remote_http_cache=https://storage.googleapis.com/bazel-remote-cache-tfjs
build:remote --google_default_credentials

# This flag is needed to so that the bazel cache is not invalidated
# when running bazel via `yarn bazel`.
# See https://github.com/angular/angular/issues/27514.
build --incompatible_strict_action_env
run --incompatible_strict_action_env

# Disable sandbox environment because emsdk caches files by writing to
# home directory.
build:wasm --spawn_strategy=local
# Load any settings specific to the current user.
# .bazelrc.user should appear in .gitignore so that settings are not shared with team members
# This needs to be last statement in this
# config, as the user configuration should be able to overwrite flags from this file.
# See https://docs.bazel.build/versions/master/best-practices.html#bazelrc
# (Note that we use .bazelrc.user so the file appears next to .bazelrc in directory listing,
# rather than user.bazelrc as suggested in the Bazel docs)
try-import %workspace%/.bazelrc.user
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,7 @@ tfjs-backend-wasm/wasm-out/*.js
tfjs-backend-wasm/wasm-out/*.wasm
yalc.lock
yarn-error.log
cloudbuild_generated.yml
cloudbuild_generated.yml

# User-specific .bazelrc
.bazelrc.user
28 changes: 21 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,32 @@ yarn_install(
yarn_lock = "//:yarn.lock",
)

# Make all files under $HOME/emsdk/* visible to the toolchain. The files are
# available as external/emsdk/emsdk/*
load("//toolchain:cc_toolchain_config.bzl", "emsdk_configure")
emsdk_configure(name = "emsdk")
# npm_install used for emscripten dependencies
load("@build_bazel_rules_nodejs//:index.bzl", "npm_install")

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

# Install emscripten dependencies
npm_install(
name = "emsdk_npm",
package_json = "@emscripten//:emscripten/package.json",
package_lock_json = "@emscripten//:emscripten/package-lock.json",
)

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
# xnnpack used for fast vectorized wasm operations
git_repository(
name = "xnnpack",
commit = "55d53a4e7079d38e90acd75dd9e4f9e781d2da35",
remote = "https://github.com/google/XNNPACK.git",
shallow_since = "1614036677 -0800",
branch = "emsdk_fix",
remote = "https://github.com/mattsoulanille/XNNPACK.git",
)

# The libraries below are transitive dependencies of XNNPACK that we need to
Expand Down
6 changes: 5 additions & 1 deletion dockers/release-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ RUN apt-get update -qqy && apt-get install -qqy \
lsb-release \
openssh-client \
git \
gnupg && \
gnupg \
file && \
pip3 install -U crcmod && \
export CLOUD_SDK_REPO="cloud-sdk-$(lsb_release -c -s)" && \
echo "deb https://packages.cloud.google.com/apt $CLOUD_SDK_REPO main" > /etc/apt/sources.list.d/google-cloud-sdk.list && \
Expand All @@ -36,3 +37,6 @@ RUN npm install -g yarn

# Install virtualenv
RUN pip3 install virtualenv

# Install absl
RUN pip3 install absl-py
16 changes: 16 additions & 0 deletions dockers/wasm-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,19 @@

# Install yarn
RUN npm install -g yarn

RUN apt-get update -qqy && apt-get install -qqy \
curl \
gcc \
python \
python3 \
python3-setuptools \
python3-dev \
python3-pip \
apt-transport-https \
lsb-release \
openssh-client \
git \
gnupg \
file && \
pip3 install -U absl-py
80 changes: 80 additions & 0 deletions emscripten_toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
load(":crosstool.bzl", "emscripten_cc_toolchain_config_rule")

package(default_visibility = ["//visibility:public"])

filegroup(
name = "common-script-includes",
srcs = [
"emar.sh",
"emcc.sh",
"emscripten_config",
"env.sh",
"@emscripten//:all",
"@nodejs//:node_files",
"@emsdk_npm//:node_modules",
],
)

filegroup(
name = "compile-emscripten",
srcs = [":common-script-includes"],
)

filegroup(
name = "link-emscripten",
srcs = [
"emcc_link.sh",
"link_wrapper.py",
":common-script-includes",
"@emscripten//:all",
"@nodejs//:node_files",
],
)

filegroup(
name = "every-file",
srcs = [
":compile-emscripten",
":link-emscripten",
"@emscripten//:all",
"@nodejs//:node_files",
],
)

filegroup(name = "empty")

# dlmalloc.bc is implictly added by the emscripten toolchain
cc_library(name = "malloc")

emscripten_cc_toolchain_config_rule(
name = "wasm",
cpu = "wasm",
emscripten_version = "emscripten",
)

cc_toolchain(
name = "cc-compiler-wasm",
all_files = ":every-file",
ar_files = ":common-script-includes",
as_files = ":empty",
compiler_files = ":compile-emscripten",
dwp_files = ":empty",
linker_files = ":link-emscripten",
objcopy_files = ":empty",
strip_files = ":empty",
toolchain_config = "wasm",
toolchain_identifier = "emscripten-wasm",
)

cc_toolchain_suite(
name = "everything",
toolchains = {
"wasm": ":cc-compiler-wasm",
"wasm|emscripten": ":cc-compiler-wasm",
},
)

py_binary(
name = "wasm_binary",
srcs = ["wasm_binary.py"],
)
Loading