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 = [
|
BASE_LINKOPTS = [
|
||||||
"--bind", # Enable embind
|
"--bind", # Enable embind
|
||||||
"-sMODULARIZE",
|
"-sMODULARIZE",
|
||||||
|
"--pre-js",
|
||||||
|
"hello-embind-interface.js",
|
||||||
]
|
]
|
||||||
|
|
||||||
RELEASE_OPTS = [
|
RELEASE_OPTS = [
|
||||||
"--closure=1", # Run the closure compiler
|
"--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 = [
|
DEBUG_OPTS = [
|
||||||
@@ -36,6 +40,11 @@ config_setting(
|
|||||||
cc_binary(
|
cc_binary(
|
||||||
name = "hello-embind",
|
name = "hello-embind",
|
||||||
srcs = ["hello-embind.cc"],
|
srcs = ["hello-embind.cc"],
|
||||||
|
features = ["emcc_debug_link"],
|
||||||
|
additional_linker_inputs = [
|
||||||
|
"hello-embind-externs.js",
|
||||||
|
"hello-embind-interface.js",
|
||||||
|
],
|
||||||
linkopts = select({
|
linkopts = select({
|
||||||
":debug_opts": BASE_LINKOPTS + DEBUG_OPTS,
|
":debug_opts": BASE_LINKOPTS + DEBUG_OPTS,
|
||||||
":release_opts": BASE_LINKOPTS + RELEASE_OPTS,
|
":release_opts": BASE_LINKOPTS + RELEASE_OPTS,
|
||||||
@@ -50,3 +59,4 @@ wasm_cc_binary(
|
|||||||
name = "hello-embind-wasm",
|
name = "hello-embind-wasm",
|
||||||
cc_target = ":hello-embind",
|
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);
|
||||||
|
}
|
||||||
@@ -27,5 +27,8 @@ bazel build //hello-world:hello-world-wasm-simd
|
|||||||
cd test_external
|
cd test_external
|
||||||
bazel build //:hello-world-wasm
|
bazel build //:hello-world-wasm
|
||||||
bazel build //:hello-embind-wasm --compilation_mode dbg # debug
|
bazel build //:hello-embind-wasm --compilation_mode dbg # debug
|
||||||
|
|
||||||
# Test use of the closure compiler
|
# Test use of the closure compiler
|
||||||
bazel build //:hello-embind-wasm --compilation_mode opt # release
|
bazel build //:hello-embind-wasm --compilation_mode opt # release
|
||||||
|
# This function should not be minified if the externs file is loaded correctly.
|
||||||
|
grep "customJSFunctionToTestClosure" bazel-bin/hello-embind-wasm/hello-embind.js
|
||||||
Reference in New Issue
Block a user