Skip to content

Commit

Permalink
WIP: WebAssembly support
Browse files Browse the repository at this point in the history
  • Loading branch information
j20001970 committed May 15, 2024
1 parent c3f2bef commit 7377cfe
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions GDMP/io/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cc_library(
] + select({
"//mediapipe:android": [":camera_helper_android"],
"//mediapipe:ios": [":camera_helper_ios"],
"//GDMP/web:web": [],
"//conditions:default": [":camera_helper_cv"],
}),
)
Expand Down
23 changes: 23 additions & 0 deletions GDMP/web/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")

config_setting(
name = "web",
values = {
"crosstool_top": "@emsdk//emscripten_toolchain:everything",
},
visibility = ["//visibility:public"],
)

cc_binary(
name = "GDMP",
linkopts = [
"-s STANDALONE_WASM=1",
"--no-entry",
],
deps = ["//GDMP"],
)

wasm_cc_binary(
name = "GDMP_wasm",
cc_target = ":GDMP",
)
10 changes: 10 additions & 0 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"android": "//GDMP/android:GDMP",
"desktop": "//GDMP/desktop:GDMP",
"ios": "//GDMP/ios:GDMP",
"web": "//GDMP/web:GDMP_wasm",
}

TARGET_ARGS = {
Expand All @@ -39,6 +40,11 @@
"--apple_generate_dsym=false",
"--config=ios",
],
"web": [
"--crosstool_top=@emsdk//emscripten_toolchain:everything",
"--host_crosstool_top=@bazel_tools//tools/cpp:toolchain",
"--define', 'MEDIAPIPE_DISABLE_GPU=1",
],
}


Expand Down Expand Up @@ -153,6 +159,9 @@ def copy_ios(args: Namespace):
f.extractall(output)


def copy_web(args: Namespace):
pass

def copy_output(args: Namespace):
target: str = args.target
output: str = args.output
Expand All @@ -163,6 +172,7 @@ def copy_output(args: Namespace):
"android": copy_android,
"desktop": copy_desktop,
"ios": copy_ios,
"web": copy_web,
}
copy_actions[target](args)

Expand Down
21 changes: 21 additions & 0 deletions patch/mediapipe/00-WORKSPACE.diff
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,24 @@ diff --git a/WORKSPACE b/WORKSPACE
# Protobuf expects an //external:python_headers target
bind(
name = "python_headers",
@@ -519,6 +533,20 @@ http_archive(
load("@build_bazel_rules_nodejs//:repositories.bzl", "build_bazel_rules_nodejs_dependencies")
build_bazel_rules_nodejs_dependencies()

+# Emscripten toolchain
+http_archive(
+ name = "emsdk",
+ sha256 = "d55e3c73fc4f8d1fecb7aabe548de86bdb55080fe6b12ce593d63b8bade54567",
+ strip_prefix = "emsdk-3891e7b04bf8cbb3bc62758e9c575ae096a9a518/bazel",
+ url = "https://github.com/emscripten-core/emsdk/archive/3891e7b04bf8cbb3bc62758e9c575ae096a9a518.tar.gz",
+)
+
+load("@emsdk//:deps.bzl", emsdk_deps = "deps")
+emsdk_deps()
+
+load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")
+emsdk_emscripten_deps(emscripten_version = "2.0.31")
+
# fetches nodejs, npm, and yarn
load("@build_bazel_rules_nodejs//:index.bzl", "node_repositories", "yarn_install")
node_repositories()

0 comments on commit 7377cfe

Please sign in to comment.