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
diff --git a/bazel/test_external/BUILD b/bazel/test_external/BUILD
index d824f09..4e69238 100644
--- a/bazel/test_external/BUILD
+++ b/bazel/test_external/BUILD
@@ -13,10 +13,14 @@
 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 @@
 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 @@
     name = "hello-embind-wasm",
     cc_target = ":hello-embind",
 )
+
diff --git a/bazel/test_external/hello-embind-externs.js b/bazel/test_external/hello-embind-externs.js
new file mode 100644
index 0000000..864d220
--- /dev/null
+++ b/bazel/test_external/hello-embind-externs.js
@@ -0,0 +1,2 @@
+// This file prevents customJSFunctionToTestClosure from being minified by the Closure compiler.
+Module.customJSFunctionToTestClosure = function() {}
\ No newline at end of file
diff --git a/bazel/test_external/hello-embind-interface.js b/bazel/test_external/hello-embind-interface.js
new file mode 100644
index 0000000..ddc4d2f
--- /dev/null
+++ b/bazel/test_external/hello-embind-interface.js
@@ -0,0 +1,3 @@
+Module.customJSFunctionToTestClosure = function(firstParam, secondParam) {
+	console.log("This function adds two numbers to get", firstParam + secondParam);
+}
\ No newline at end of file
diff --git a/test/test_bazel.sh b/test/test_bazel.sh
index 5b06692..f52daa4 100755
--- a/test/test_bazel.sh
+++ b/test/test_bazel.sh
@@ -27,5 +27,8 @@
 cd test_external
 bazel build //:hello-world-wasm
 bazel build //:hello-embind-wasm --compilation_mode dbg # debug
+
 # Test use of the closure compiler
 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
\ No newline at end of file