Skip to content

Commit

Permalink
Proof of concept for emcmake toolchain registration
Browse files Browse the repository at this point in the history
INCOMPLETE, see proxy-wasm/proxy-wasm-cpp-sdk#157

Signed-off-by: Martijn Stevenson <[email protected]>
  • Loading branch information
martijneken committed Aug 26, 2023
1 parent 350c19a commit a871cd0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 41 deletions.
35 changes: 0 additions & 35 deletions bazel/emscripten_deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -167,38 +167,3 @@ def emscripten_deps(emscripten_version = "latest"):
build_file_content = BUILD_FILE_CONTENT_TEMPLATE.format(bin_extension = ".exe"),
type = "zip",
)

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_linux_arm64" not in excludes:
npm_install(
name = "emscripten_npm_linux_arm64",
package_json = "@emscripten_bin_linux_arm64//:emscripten/package.json",
package_lock_json = "@emscripten_bin_linux_arm64//: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_mac_arm64" not in excludes:
npm_install(
name = "emscripten_npm_mac",
package_json = "@emscripten_bin_mac_arm64//:emscripten/package.json",
package_lock_json = "@emscripten_bin_mac_arm64//: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",
)
38 changes: 32 additions & 6 deletions bazel/emscripten_toolchain/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,44 +1,54 @@
load(":toolchain.bzl", "emscripten_cc_toolchain_config_rule")
load("@rules_foreign_cc//toolchains/native_tools:native_tools_toolchain.bzl", "native_tool_toolchain")

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

filegroup(
name = "common_files",
srcs = [
"emscripten_config",
"env.sh",
"env.bat",
"env.sh",
"@nodejs//:node_files",
],
)

filegroup(
name = "compiler_files",
srcs = [
"emcc.sh",
"emcc.bat",
"@emsdk//:compiler_files",
"emcc.sh",
":common_files",
"@emsdk//:compiler_files",
],
)

filegroup(
name = "linker_files",
srcs = [
"emcc_link.sh",
"emcc_link.bat",
"emcc_link.sh",
"link_wrapper.py",
"@emsdk//:linker_files",
":common_files",
"@emsdk//:linker_files",
],
)

filegroup(
name = "ar_files",
srcs = [
"emar.sh",
"emar.bat",
"emar.sh",
":common_files",
"@emsdk//:ar_files",
],
)

filegroup(
name = "cmake_files",
srcs = [
"emcmake.bat",
"emcmake.sh",
":common_files",
],
)
Expand Down Expand Up @@ -81,13 +91,29 @@ cc_toolchain_suite(
},
)

native_tool_toolchain(
name = "cmake-compiler-wasm",
path = select({
"@platforms//os:windows": "$(execpath :cmake_files)/emcmake.bat",
"//conditions:default": "$(execpath :cmake_files)/emcmake.sh",
}),
target = ":cmake_files",
)

toolchain(
name = "cc-toolchain-wasm",
target_compatible_with = ["@platforms//cpu:wasm32"],
toolchain = ":cc-compiler-wasm",
toolchain_type = "@bazel_tools//tools/cpp:toolchain_type",
)

toolchain(
name = "cmake-toolchain-wasm",
target_compatible_with = ["@platforms//cpu:wasm32"],
toolchain = ":cmake-compiler-wasm",
toolchain_type = "@rules_foreign_cc//toolchains:cmake_toolchain",
)

py_binary(
name = "wasm_binary",
srcs = ["wasm_binary.py"],
Expand Down
5 changes: 5 additions & 0 deletions bazel/emscripten_toolchain/emcmake.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@ECHO OFF

call external\emsdk\emscripten_toolchain\env.bat

py -3 %EMSCRIPTEN%\emcmake.py %*
5 changes: 5 additions & 0 deletions bazel/emscripten_toolchain/emcmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

source $(dirname $0)/env.sh

exec python3 $EMSCRIPTEN/emcmake.py "$@"
1 change: 1 addition & 0 deletions bazel/toolchains.bzl
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
def register_emscripten_toolchains():
native.register_toolchains(str(Label("//emscripten_toolchain:cc-toolchain-wasm")))
native.register_toolchains(str(Label("//emscripten_toolchain:cmake-toolchain-wasm")))

0 comments on commit a871cd0

Please sign in to comment.