Add embind example to Bazel docs (#910)
* Add embind example to Bazel docs * address feedback
This commit is contained in:
4
bazel/test_external/.gitignore
vendored
Normal file
4
bazel/test_external/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
bazel-bin
|
||||
bazel-out
|
||||
bazel-test_external
|
||||
bazel-testlogs
|
||||
@@ -10,3 +10,22 @@ wasm_cc_binary(
|
||||
cc_target = ":hello-world",
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "hello-embind",
|
||||
srcs = ["hello-embind.cc"],
|
||||
# It's probably a good idea to use select() and config_setting
|
||||
# to add different linkopts to BASE_LINKOPTS depending on things
|
||||
# like a "opt" or "dbg" compilation mode.
|
||||
linkopts = [
|
||||
"--bind", # Enable embind
|
||||
"-sMODULARIZE",
|
||||
],
|
||||
# This target won't build successfully on its own because of missing emscripten
|
||||
# headers etc. Therefore, we hide it from wildcards.
|
||||
tags = ["manual"],
|
||||
)
|
||||
|
||||
wasm_cc_binary(
|
||||
name = "hello-embind-wasm",
|
||||
cc_target = ":hello-embind",
|
||||
)
|
||||
|
||||
16
bazel/test_external/hello-embind.cc
Normal file
16
bazel/test_external/hello-embind.cc
Normal file
@@ -0,0 +1,16 @@
|
||||
#include <emscripten/bind.h>
|
||||
|
||||
using namespace emscripten;
|
||||
|
||||
class HelloClass {
|
||||
public:
|
||||
static std::string SayHello(const std::string &name) {
|
||||
return "Yo! " + name;
|
||||
};
|
||||
};
|
||||
|
||||
EMSCRIPTEN_BINDINGS(Hello) {
|
||||
emscripten::class_<HelloClass>("HelloClass")
|
||||
.constructor<>()
|
||||
.class_function("SayHello", &HelloClass::SayHello);
|
||||
}
|
||||
Reference in New Issue
Block a user