Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm export #38

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 57 additions & 21 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,31 +1,67 @@
load("@rules_cc//cc:defs.bzl", "cc_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
load("@emsdk//emscripten_toolchain:wasm_rules.bzl", "wasm_cc_binary")
load("//bazel:copts.bzl", "copts")

package(default_visibility = ["//visibility:public"])

# keep sorted
_srcs = [
"ecsact/detail/check_set.hh",
"ecsact/detail/fixed_stack.hh",
"ecsact/detail/grammar.hh",
"ecsact/detail/read_util.hh",
"ecsact/detail/stack_util.hh",
"ecsact/ecsact_parse.cc",
"ecsact/ecsact_parse_statement.cc",
]

# keep sorted
_hdrs = [
"ecsact/parse.h",
"ecsact/parse/error.h",
"ecsact/parse/statements.h",
"ecsact/parse/status.h",
"ecsact/parse/string.h",
]

# keep sorted
_deps = [
"@ecsact_runtime//:common",
"@ecsact_runtime//:definitions",
"@lexy",
"@magic_enum",
]

cc_library(
name = "ecsact_parse",
srcs = [
"ecsact/detail/check_set.hh",
"ecsact/detail/fixed_stack.hh",
"ecsact/detail/grammar.hh",
"ecsact/detail/read_util.hh",
"ecsact/detail/stack_util.hh",
"ecsact/ecsact_parse.cc",
"ecsact/ecsact_parse_statement.cc",
srcs = _srcs,
hdrs = _hdrs,
copts = copts,
deps = _deps,
)

cc_binary(
name = "ecsact_parse_shared",
srcs = _srcs + _hdrs,
copts = copts,
features = [
"wasm_standalone",
"wasm_no_entry",
"-wasm_warnings_as_errors",
"-wasm_error_on_undefined_symbols",
"-exceptions",
],
hdrs = [
"ecsact/parse.h",
"ecsact/parse/error.h",
"ecsact/parse/statements.h",
"ecsact/parse/status.h",
"ecsact/parse/string.h",
linkshared = True,
deps = _deps,
)

wasm_cc_binary(
name = "ecsact_parse_wasm",
cc_target = ":ecsact_parse_shared",
exported_functions = [
"_ecsact_parse_statement",
],
copts = copts,
deps = [
"@ecsact_runtime//:common",
"@ecsact_runtime//:definitions",
"@lexy",
"@magic_enum",
outputs = [
"ecsact_parse_shared.wasm",
],
)
19 changes: 19 additions & 0 deletions WORKSPACE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ http_archive(
url = "https://github.com/google/googletest/archive/d1a0039b97291dd1dc14f123b906bb7622ffe07c.zip",
)

http_archive(
name = "emsdk",
sha256 = "28bba9c179854b0f7e548a7adf87173e8cbe098ddfdbe25fa9f5a5875faa0a1a",
strip_prefix = "emsdk-589dd6a639ff428852cf998607cf226c5ce12efb/bazel",
url = "https://github.com/zaucy/emsdk/archive/589dd6a639ff428852cf998607cf226c5ce12efb.zip",
)

load("@emsdk//:deps.bzl", emsdk_deps = "deps")

emsdk_deps()

load("@emsdk//:emscripten_deps.bzl", emsdk_emscripten_deps = "emscripten_deps")

emsdk_emscripten_deps()

load("@emsdk//:toolchains.bzl", "register_emscripten_toolchains")

register_emscripten_toolchains()

http_archive(
name = "hedron_compile_commands",
sha256 = "4deb7cd90ba69983ec7734c0dcc7071828ebdc430a69f82ddbccf698018b9c04",
Expand Down
10 changes: 8 additions & 2 deletions ecsact/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include "ecsact/parse/status.h"
#include "ecsact/parse/error.h"

#ifdef __cplusplus
# define ECSACT_PARSE_API extern "C"
#else
# define ECSACT_PARSE_API extern
#endif

typedef enum {
ECSACT_PARSE_CALLBACK_STOP,
ECSACT_PARSE_CALLBACK_CONTINUE,
Expand Down Expand Up @@ -34,15 +40,15 @@ typedef ecsact_parse_callback_result(*ecsact_parse_callback)
* parsing `statement_string`. May be `NULL`.
* @returns read length
*/
int ecsact_parse_statement
ECSACT_PARSE_API int ecsact_parse_statement
( const char* statement_string
, int max_read_length
, const ecsact_statement* context_statement
, ecsact_statement* out_statement
, ecsact_parse_status* out_status
);

void ecsact_parse
ECSACT_PARSE_API void ecsact_parse
( const char** file_paths
, int file_paths_count
, ecsact_parse_callback callback
Expand Down