Skip to content

Commit 9e666df

Browse files
authored
feat: support bundled codegen plugins (#90)
1 parent df45dca commit 9e666df

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

ecsact/cli/commands/codegen/codegen_util.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ auto ecsact::cli::resolve_plugin_path(
6363
}
6464
}
6565

66-
fs::path plugin_path = fs::weakly_canonical(options.plugin_arg);
66+
fs::path plugin_path = fs::path(options.plugin_arg).lexically_normal();
6767
if(plugin_path.extension().empty()) {
6868
plugin_path.replace_extension(current_platform_codegen_plugin_extension());
6969
}
@@ -74,6 +74,7 @@ auto ecsact::cli::resolve_plugin_path(
7474

7575
if(plugin_path.is_relative()) {
7676
for(auto dir : options.additional_plugin_dirs) {
77+
checked_plugin_paths.emplace_back(dir / plugin_path);
7778
if(fs::exists(dir / plugin_path)) {
7879
return dir / plugin_path;
7980
}

ecsact/cli/commands/recipe-bundle/build_recipe_bundle.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "ecsact/cli/report.hh"
2323
#include "ecsact/cli/detail/download.hh"
24+
#include "ecsact/cli/commands/codegen/codegen_util.hh"
2425

2526
using namespace std::string_literals;
2627
using namespace std::string_view_literals;
@@ -191,6 +192,48 @@ auto ecsact::build_recipe_bundle::create( //
191192
};
192193
},
193194
[&](build_recipe::source_codegen src) -> source_visitor_result_t {
195+
auto new_archive_rel_plugin_paths = std::vector<std::string>{};
196+
new_archive_rel_plugin_paths.reserve(src.plugins.size());
197+
for(auto plugin : src.plugins) {
198+
if(cli::is_default_plugin(plugin)) {
199+
new_archive_rel_plugin_paths.emplace_back(plugin);
200+
continue;
201+
}
202+
203+
auto plugin_file_path =
204+
cli::resolve_plugin_path(cli::resolve_plugin_path_options{
205+
.plugin_arg = plugin,
206+
.default_plugins_dir = recipe.base_directory(),
207+
.additional_plugin_dirs = {recipe.base_directory()},
208+
});
209+
210+
if(!plugin_file_path) {
211+
return std::logic_error{
212+
std::format("Unable to resolve codegen plugin: {}", plugin)
213+
};
214+
}
215+
216+
if(plugin_file_path->extension() != ".wasm") {
217+
ecsact::cli::report_warning(
218+
"Bundled codegen plugin {} is platform specific. Bundle will only "
219+
"work on current platform.",
220+
plugin_file_path->filename().string()
221+
);
222+
}
223+
224+
auto plugin_file_data = read_file(*plugin_file_path);
225+
auto archive_rel_path =
226+
(fs::path{"codegen"} / plugin_file_path->filename())
227+
.lexically_normal();
228+
229+
auto& p = new_archive_rel_plugin_paths.emplace_back(
230+
archive_rel_path.generic_string()
231+
);
232+
add_simple_buffer(p, plugin_file_data);
233+
}
234+
235+
src.plugins = new_archive_rel_plugin_paths;
236+
194237
return src;
195238
},
196239
[&](build_recipe::source_path src) -> source_visitor_result_t {

0 commit comments

Comments
 (0)