From 7b1bb1586d7c8a650937165d231d66165af0a533 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 31 Jan 2025 11:38:04 -0800 Subject: [PATCH 1/4] feat: support new ecsact si modules --- MODULE.bazel | 2 +- ecsact/cli/commands/build/BUILD.bazel | 3 ++- ecsact/cli/commands/build/cc_defines_gen.cc | 30 +++++++++++++++------ ecsact/cli/commands/build/get_modules.cc | 2 ++ 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index b17e42a..91e8770 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -9,7 +9,7 @@ bazel_dep(name = "nlohmann_json", version = "3.11.3") bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_pkg", version = "0.10.1") bazel_dep(name = "bazel_skylib", version = "1.6.1") -bazel_dep(name = "ecsact_runtime", version = "0.7.1", max_compatibility_level = 8) +bazel_dep(name = "ecsact_runtime", version = "0.8.2") bazel_dep(name = "ecsact_interpret", version = "0.6.6") bazel_dep(name = "ecsact_codegen", version = "0.4.3") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") diff --git a/ecsact/cli/commands/build/BUILD.bazel b/ecsact/cli/commands/build/BUILD.bazel index 63632ac..f53cee3 100644 --- a/ecsact/cli/commands/build/BUILD.bazel +++ b/ecsact/cli/commands/build/BUILD.bazel @@ -10,8 +10,8 @@ cc_library( copts = copts, deps = [ "//ecsact/cli:report", - "//ecsact/cli/commands/codegen:codegen_util", "//ecsact/cli/commands/build:get_modules", + "//ecsact/cli/commands/codegen:codegen_util", "@yaml-cpp", ], ) @@ -75,5 +75,6 @@ cc_library( "@ecsact_runtime//:dynamic", "@ecsact_runtime//:meta", "@ecsact_runtime//:serialize", + "@ecsact_runtime//:si_wasm", ], ) diff --git a/ecsact/cli/commands/build/cc_defines_gen.cc b/ecsact/cli/commands/build/cc_defines_gen.cc index e619adb..16d0825 100644 --- a/ecsact/cli/commands/build/cc_defines_gen.cc +++ b/ecsact/cli/commands/build/cc_defines_gen.cc @@ -20,17 +20,31 @@ auto ecsact::cli::cc_defines_gen( // auto defines = std::vector{}; for(auto&& [mod, _] : export_modules.module_methods) { - defines.push_back(std::format( // - "ECSACT_{}_API_EXPORT", - boost::to_upper_copy(mod) - )); + if(mod.starts_with("si_")) { + defines.push_back(std::format( // + "ECSACTSI_{}_API_EXPORT", + boost::to_upper_copy(mod) + )); + } else { + defines.push_back(std::format( // + "ECSACT_{}_API_EXPORT", + boost::to_upper_copy(mod) + )); + } } for(auto&& [mod, _] : import_modules.module_methods) { - defines.push_back(std::format( // - "ECSACT_{}_API_LOAD_AT_RUNTIME", - boost::to_upper_copy(mod) - )); + if(mod.starts_with("si_")) { + defines.push_back(std::format( // + "ECSACTSI_{}_API_LOAD_AT_RUNTIME", + boost::to_upper_copy(mod) + )); + } else { + defines.push_back(std::format( // + "ECSACT_{}_API_LOAD_AT_RUNTIME", + boost::to_upper_copy(mod) + )); + } } return defines; } diff --git a/ecsact/cli/commands/build/get_modules.cc b/ecsact/cli/commands/build/get_modules.cc index d0b9de7..729bd32 100644 --- a/ecsact/cli/commands/build/get_modules.cc +++ b/ecsact/cli/commands/build/get_modules.cc @@ -5,6 +5,7 @@ #include "ecsact/runtime/dynamic.h" #include "ecsact/runtime/meta.h" #include "ecsact/runtime/serialize.h" +#include "ecsact/si/wasm.h" auto ecsact::cli::detail::get_ecsact_modules( // std::vector methods @@ -24,6 +25,7 @@ auto ecsact::cli::detail::get_ecsact_modules( // FOR_EACH_ECSACT_DYNAMIC_API_FN(CHECK_MODULE, "dynamic"); FOR_EACH_ECSACT_META_API_FN(CHECK_MODULE, "meta"); FOR_EACH_ECSACT_SERIALIZE_API_FN(CHECK_MODULE, "serialize"); + FOR_EACH_ECSACT_SI_WASM_API_FN(CHECK_MODULE, "si_wasm"); result.unknown_module_methods.emplace_back(method); } From 473252afff3488f7bbcba8bd4809af4f104b22b3 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 31 Jan 2025 11:59:58 -0800 Subject: [PATCH 2/4] feat: use new runtime version --- .bazelversion | 2 +- MODULE.bazel | 9 +++++++-- test/.bazelversion | 1 + test/MODULE.bazel | 12 ++++++++---- 4 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 test/.bazelversion diff --git a/.bazelversion b/.bazelversion index 815da58..18bb418 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.4.1 +7.5.0 diff --git a/MODULE.bazel b/MODULE.bazel index 91e8770..73e97c4 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -10,8 +10,13 @@ bazel_dep(name = "platforms", version = "0.0.10") bazel_dep(name = "rules_pkg", version = "0.10.1") bazel_dep(name = "bazel_skylib", version = "1.6.1") bazel_dep(name = "ecsact_runtime", version = "0.8.2") -bazel_dep(name = "ecsact_interpret", version = "0.6.6") -bazel_dep(name = "ecsact_codegen", version = "0.4.3") +single_version_override( + module_name = "ecsact_runtime", + version = "0.8.2", +) + +bazel_dep(name = "ecsact_interpret", version = "0.6.7") +bazel_dep(name = "ecsact_codegen", version = "0.4.4") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") bazel_dep(name = "magic_enum", version = "0.9.3") bazel_dep(name = "curl", version = "8.7.1.bcr.1") diff --git a/test/.bazelversion b/test/.bazelversion new file mode 100644 index 0000000..18bb418 --- /dev/null +++ b/test/.bazelversion @@ -0,0 +1 @@ +7.5.0 diff --git a/test/MODULE.bazel b/test/MODULE.bazel index 287d76e..eff6610 100644 --- a/test/MODULE.bazel +++ b/test/MODULE.bazel @@ -1,10 +1,15 @@ -bazel_dep(name = "rules_cc", version = "0.0.9") +bazel_dep(name = "rules_cc", version = "0.0.17") bazel_dep(name = "rules_ecsact", version = "0.5.0") -bazel_dep(name = "ecsact_codegen", version = "0.4.1") +bazel_dep(name = "ecsact_codegen", version = "0.4.4") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") bazel_dep(name = "boost.process", version = "1.83.0.bzl.2") bazel_dep(name = "boost.regex", version = "1.83.0.bcr.1") -bazel_dep(name = "ecsact_runtime", version = "0.7.0") +bazel_dep(name = "ecsact_runtime", version = "0.8.2") +single_version_override( + module_name = "ecsact_runtime", + version = "0.8.2", +) + bazel_dep(name = "docopt.cpp", version = "0.6.2") bazel_dep(name = "toolchains_llvm", version = "1.0.0", dev_dependency = True) @@ -12,7 +17,6 @@ bazel_dep(name = "hedron_compile_commands", dev_dependency = True) bazel_dep(name = "googletest", version = "1.14.0") bazel_dep(name = "ecsact_cli") - local_path_override( module_name = "ecsact_cli", path = "..", From 37b01436474cf7356246e256d03e2f7af24d146c Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 31 Jan 2025 14:15:58 -0800 Subject: [PATCH 3/4] feat: add wasmer exception for system lib --- ecsact/cli/commands/build/cc_defines_gen.cc | 30 +++-------- ecsact/cli/commands/build/recipe/BUILD.bazel | 2 + ecsact/cli/commands/build/recipe/cook.cc | 51 +++++++++++++++++++ .../commands/build/recipe/cook_runfiles.cc | 2 + 4 files changed, 63 insertions(+), 22 deletions(-) diff --git a/ecsact/cli/commands/build/cc_defines_gen.cc b/ecsact/cli/commands/build/cc_defines_gen.cc index 16d0825..e619adb 100644 --- a/ecsact/cli/commands/build/cc_defines_gen.cc +++ b/ecsact/cli/commands/build/cc_defines_gen.cc @@ -20,31 +20,17 @@ auto ecsact::cli::cc_defines_gen( // auto defines = std::vector{}; for(auto&& [mod, _] : export_modules.module_methods) { - if(mod.starts_with("si_")) { - defines.push_back(std::format( // - "ECSACTSI_{}_API_EXPORT", - boost::to_upper_copy(mod) - )); - } else { - defines.push_back(std::format( // - "ECSACT_{}_API_EXPORT", - boost::to_upper_copy(mod) - )); - } + defines.push_back(std::format( // + "ECSACT_{}_API_EXPORT", + boost::to_upper_copy(mod) + )); } for(auto&& [mod, _] : import_modules.module_methods) { - if(mod.starts_with("si_")) { - defines.push_back(std::format( // - "ECSACTSI_{}_API_LOAD_AT_RUNTIME", - boost::to_upper_copy(mod) - )); - } else { - defines.push_back(std::format( // - "ECSACT_{}_API_LOAD_AT_RUNTIME", - boost::to_upper_copy(mod) - )); - } + defines.push_back(std::format( // + "ECSACT_{}_API_LOAD_AT_RUNTIME", + boost::to_upper_copy(mod) + )); } return defines; } diff --git a/ecsact/cli/commands/build/recipe/BUILD.bazel b/ecsact/cli/commands/build/recipe/BUILD.bazel index ca7f601..a3f2814 100644 --- a/ecsact/cli/commands/build/recipe/BUILD.bazel +++ b/ecsact/cli/commands/build/recipe/BUILD.bazel @@ -95,6 +95,8 @@ cc_library( "@ecsact_runtime//:ecsact/runtime/serialize.h", "@ecsact_runtime//:ecsact/runtime/serialize.hh", "@ecsact_runtime//:ecsact/runtime/static.h", + "@ecsact_runtime//:ecsact/si/wasm.h", + "@ecsact_runtime//:ecsact/si/wasm.hh", ], }), ) diff --git a/ecsact/cli/commands/build/recipe/cook.cc b/ecsact/cli/commands/build/recipe/cook.cc index f488d0e..85242ba 100644 --- a/ecsact/cli/commands/build/recipe/cook.cc +++ b/ecsact/cli/commands/build/recipe/cook.cc @@ -120,6 +120,24 @@ static auto write_file(fs::path path, std::span data) -> void { file.write(reinterpret_cast(data.data()), data.size()); } +static auto find_wasmer_dir() -> std::optional { + auto wasmer_dir_env = std::getenv("WASMER_DIR"); + if(wasmer_dir_env) { + if(fs::exists(wasmer_dir_env)) { + return wasmer_dir_env; + } else { + report_warning( + "WASMER_DIR is set, but could not be found: {}", + wasmer_dir_env + ); + } + } else { + report_warning("WASMER_DIR environment variable is unset"); + } + + return std::nullopt; +} + static auto handle_source( // fs::path base_directory, ecsact::build_recipe::source_fetch src, @@ -722,6 +740,18 @@ auto cl_compile(compile_options options) -> int { return params_file_path; }; + const bool wants_wasmer = std::ranges::find(options.system_libs, "wasmer"s) != + options.system_libs.end(); + const auto wasmer_dir = wants_wasmer ? find_wasmer_dir() : std::nullopt; + + if(wants_wasmer && !wasmer_dir) { + report_error( + "Recipe wants 'wasmer' system lib, but wasmer directory could not be " + "found" + ); + return 1; + } + cl_args.push_back("/nologo"); cl_args.push_back("/D_WIN32_WINNT=0x0A00"); cl_args.push_back("/diagnostics:column"); @@ -768,6 +798,10 @@ auto cl_compile(compile_options options) -> int { cl_args.push_back(std::format("/I{}", inc_dir.string())); } + if(wants_wasmer && wasmer_dir) { + cl_args.push_back(std::format("/I{}", (*wasmer_dir / "include").string())); + } + if(options.tracy_dir) { cl_args.push_back(std::format("/I{}", options.tracy_dir->string())); } @@ -868,6 +902,10 @@ auto cl_compile(compile_options options) -> int { cl_args.push_back("@" + obj_params_file.string()); cl_args.push_back("@" + main_params_file.string()); + if(wants_wasmer && wasmer_dir) { + cl_args.push_back((*wasmer_dir / "lib" / "wasmer.lib").string()); + } + if(options.tracy_dir) { auto tracy_lib = fs::path{options.output_path.parent_path() / "profiler.lib"}; @@ -881,6 +919,19 @@ auto cl_compile(compile_options options) -> int { cl_args.push_back("/DLL"); for(auto sys_lib : options.system_libs) { + if(sys_lib == "wasmer" && wasmer_dir) { + // Wasmer has some special treatment + cl_args.push_back(std::format("/DEFAULTLIB:{}", "ws2_32")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "Advapi32")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "Userenv")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "Bcrypt")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "ntdll")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "Shell32")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "Ole32")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "OleAut32")); + cl_args.push_back(std::format("/DEFAULTLIB:{}", "RuntimeObject")); + continue; + } cl_args.push_back(std::format("/DEFAULTLIB:{}", sys_lib)); } diff --git a/ecsact/cli/commands/build/recipe/cook_runfiles.cc b/ecsact/cli/commands/build/recipe/cook_runfiles.cc index ba23f21..c017b0e 100644 --- a/ecsact/cli/commands/build/recipe/cook_runfiles.cc +++ b/ecsact/cli/commands/build/recipe/cook_runfiles.cc @@ -46,6 +46,8 @@ auto ecsact::cli::cook::load_runfiles( "ecsact_runtime/ecsact/runtime/serialize.h", "ecsact_runtime/ecsact/runtime/serialize.hh", "ecsact_runtime/ecsact/runtime/static.h", + "ecsact_runtime/ecsact/si/wasm.h", + "ecsact_runtime/ecsact/si/wasm.hh", }; for(auto hdr : ecsact_runtime_headers_from_runfiles) { From 8e311d4671077c3a3da553af6b179f82bb7a035e Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 31 Jan 2025 14:16:59 -0800 Subject: [PATCH 4/4] chore: update rules_ecsact --- test/MODULE.bazel | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MODULE.bazel b/test/MODULE.bazel index eff6610..53e2513 100644 --- a/test/MODULE.bazel +++ b/test/MODULE.bazel @@ -1,5 +1,5 @@ bazel_dep(name = "rules_cc", version = "0.0.17") -bazel_dep(name = "rules_ecsact", version = "0.5.0") +bazel_dep(name = "rules_ecsact", version = "0.5.10") bazel_dep(name = "ecsact_codegen", version = "0.4.4") bazel_dep(name = "boost.dll", version = "1.83.0.bzl.2") bazel_dep(name = "boost.process", version = "1.83.0.bzl.2")