diff --git a/BUILD.bazel b/BUILD.bazel index 9bea823..218706b 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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", ], ) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index c76492d..91281ce 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -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", diff --git a/ecsact/parse.h b/ecsact/parse.h index 0435261..2a98175 100644 --- a/ecsact/parse.h +++ b/ecsact/parse.h @@ -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, @@ -34,7 +40,7 @@ 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 @@ -42,7 +48,7 @@ int ecsact_parse_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