Skip to content

feat: support new ecsact si modules #140

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

Merged
merged 4 commits into from
Jan 31, 2025
Merged
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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.4.1
7.5.0
11 changes: 8 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ 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_interpret", version = "0.6.6")
bazel_dep(name = "ecsact_codegen", version = "0.4.3")
bazel_dep(name = "ecsact_runtime", version = "0.8.2")
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")
Expand Down
3 changes: 2 additions & 1 deletion ecsact/cli/commands/build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
Expand Down Expand Up @@ -75,5 +75,6 @@ cc_library(
"@ecsact_runtime//:dynamic",
"@ecsact_runtime//:meta",
"@ecsact_runtime//:serialize",
"@ecsact_runtime//:si_wasm",
],
)
2 changes: 2 additions & 0 deletions ecsact/cli/commands/build/get_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> methods
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions ecsact/cli/commands/build/recipe/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
}),
)
51 changes: 51 additions & 0 deletions ecsact/cli/commands/build/recipe/cook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,24 @@ static auto write_file(fs::path path, std::span<std::byte> data) -> void {
file.write(reinterpret_cast<const char*>(data.data()), data.size());
}

static auto find_wasmer_dir() -> std::optional<fs::path> {
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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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"};
Expand All @@ -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));
}

Expand Down
2 changes: 2 additions & 0 deletions ecsact/cli/commands/build/recipe/cook_runfiles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions test/.bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
7.5.0
14 changes: 9 additions & 5 deletions test/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
bazel_dep(name = "rules_cc", version = "0.0.9")
bazel_dep(name = "rules_ecsact", version = "0.5.0")
bazel_dep(name = "ecsact_codegen", version = "0.4.1")
bazel_dep(name = "rules_cc", version = "0.0.17")
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")
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)
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 = "..",
Expand Down