-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
setup bazel to run emscripten on files
it works!
- Loading branch information
1 parent
f8fb781
commit a13ece9
Showing
8 changed files
with
116 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
6.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,9 @@ | |
*.cmake | ||
Makefile | ||
CMakeCache.txt | ||
|
||
# bazel | ||
bazel-bin | ||
bazel-conway-rts | ||
bazel-out | ||
bazel-testlogs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
load("@rules_cc//cc:defs.bzl", "cc_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
cc_library( | ||
name = "vector2", | ||
srcs = ["src/Vector2.cpp"], | ||
hdrs = ["include/Vector2.hpp", "include/ISerializable.hpp"], | ||
copts = ["-I include"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
workspace( | ||
name = "conway_rts", | ||
) | ||
|
||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
http_archive( | ||
name = "aspect_rules_js", | ||
sha256 = "77c4ea46c27f96e4aadcc580cd608369208422cf774988594ae8a01df6642c82", | ||
strip_prefix = "rules_js-1.32.2", | ||
url = "https://github.com/aspect-build/rules_js/releases/download/v1.32.2/rules_js-v1.32.2.tar.gz", | ||
) | ||
|
||
load("@aspect_rules_js//js:repositories.bzl", "rules_js_dependencies") | ||
rules_js_dependencies() | ||
|
||
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains") | ||
nodejs_register_toolchains( | ||
name = "nodejs", | ||
node_version = DEFAULT_NODE_VERSION, | ||
) | ||
|
||
# Emscripten toolchain | ||
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") | ||
http_archive( | ||
name = "emsdk", | ||
sha256 = "5dd94e557b720800a60387ec078bf3b3a527cbd916ad74a696fe399f1544474f", | ||
strip_prefix = "emsdk-3.1.46/bazel", | ||
url = "https://github.com/emscripten-core/emsdk/archive/refs/tags/3.1.46.tar.gz", | ||
) | ||
|
||
load("@emsdk//:deps.bzl", emsdk_deps = "deps") | ||
emsdk_deps() | ||
|
||
load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps") | ||
emsdk_emscripten_deps(emscripten_version = "3.1.46") | ||
|
||
load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains") | ||
register_emscripten_toolchains() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
DEFAULT_EMSCRIPTEN_LINKOPTS = [ | ||
# LTO broken when using hermetic emsdk | ||
# "-flto", # Specify lto (has to be set on for compiler as well) | ||
"--bind", # Compiles the source code using the Embind bindings to connect C/C++ and JavaScript | ||
"--closure 1", # Run the closure compiler | ||
"-s MALLOC=emmalloc", # Switch to using the much smaller implementation | ||
"-s ALLOW_MEMORY_GROWTH=0", # Our example doesn't need memory growth | ||
"-s USE_PTHREADS=0", # Disable pthreads | ||
"-s ASSERTIONS=0", # Turn off assertions | ||
# "-s EXPORT_ES6=1", # Export as es6 module, used for rollup | ||
"-s MODULARIZE=1", # Allows us to manually invoke the initializatio of wasm | ||
"-s EXPORT_NAME=createModule", # Not used, but good to specify | ||
# "-s USE_ES6_IMPORT_META=1", # needed for somethingggg --- Disable loading from import meta since we use rollup | ||
"-s SINGLE_FILE=1", # Pack all webassembly into base64 | ||
"-s DISABLE_EXCEPTION_CATCHING=1", # Disable all exception catching | ||
"-s NODEJS_CATCH_EXIT=0", # We don't have a 'main' so disable exit() catching | ||
] | ||
|
||
WASM_LINKOPTS = [ | ||
"-s WASM=0", # Specify wasm output | ||
] | ||
|
||
cc_binary( | ||
name = "lib-wasm.js", | ||
srcs = ["bindings.cpp"], | ||
linkopts = DEFAULT_EMSCRIPTEN_LINKOPTS + WASM_LINKOPTS, | ||
deps = [ | ||
"//:vector2", | ||
# "//hello-world/cpp:localtime", | ||
], | ||
) | ||
|
||
wasm_cc_binary( | ||
name = "lib-wasm", | ||
cc_target = ":lib-wasm.js", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include "emscripten/bind.h" | ||
#include "include/Vector2.hpp" | ||
|
||
EMSCRIPTEN_BINDINGS(Vector2) { | ||
emscripten::class_<Vector2>("Vector2") | ||
.constructor<int, int>() | ||
.function("x", &Vector2::GetX) | ||
.function("y", &Vector2::GetY) | ||
.function("SetX", &Vector2::SetX) | ||
.function("SetY", &Vector2::SetY) | ||
; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters