Add closure example for wasm_cc_binary (#941)
* Stub out addition of closure_externs_file option in wasm_cc_binary * WIP * args are passed, externs cannot be found * try location * update tests
This commit is contained in:
@@ -13,10 +13,14 @@ wasm_cc_binary(
|
||||
BASE_LINKOPTS = [
|
||||
"--bind", # Enable embind
|
||||
"-sMODULARIZE",
|
||||
"--pre-js",
|
||||
"hello-embind-interface.js",
|
||||
]
|
||||
|
||||
RELEASE_OPTS = [
|
||||
"--closure=1", # Run the closure compiler
|
||||
# Tell closure about the externs file, so as not to minify our JS public API.
|
||||
"--closure-args=--externs=$(location hello-embind-externs.js)"
|
||||
]
|
||||
|
||||
DEBUG_OPTS = [
|
||||
@@ -36,6 +40,11 @@ config_setting(
|
||||
cc_binary(
|
||||
name = "hello-embind",
|
||||
srcs = ["hello-embind.cc"],
|
||||
features = ["emcc_debug_link"],
|
||||
additional_linker_inputs = [
|
||||
"hello-embind-externs.js",
|
||||
"hello-embind-interface.js",
|
||||
],
|
||||
linkopts = select({
|
||||
":debug_opts": BASE_LINKOPTS + DEBUG_OPTS,
|
||||
":release_opts": BASE_LINKOPTS + RELEASE_OPTS,
|
||||
@@ -50,3 +59,4 @@ wasm_cc_binary(
|
||||
name = "hello-embind-wasm",
|
||||
cc_target = ":hello-embind",
|
||||
)
|
||||
|
||||
|
||||
2
bazel/test_external/hello-embind-externs.js
Normal file
2
bazel/test_external/hello-embind-externs.js
Normal file
@@ -0,0 +1,2 @@
|
||||
// This file prevents customJSFunctionToTestClosure from being minified by the Closure compiler.
|
||||
Module.customJSFunctionToTestClosure = function() {}
|
||||
3
bazel/test_external/hello-embind-interface.js
Normal file
3
bazel/test_external/hello-embind-interface.js
Normal file
@@ -0,0 +1,3 @@
|
||||
Module.customJSFunctionToTestClosure = function(firstParam, secondParam) {
|
||||
console.log("This function adds two numbers to get", firstParam + secondParam);
|
||||
}
|
||||
Reference in New Issue
Block a user