This commit is contained in:
udo
2026-06-13 02:07:38 +00:00
parent eb8f303f94
commit 577aae076e
27 changed files with 2937 additions and 21 deletions
+32 -1
View File
@@ -132,6 +132,23 @@ String compiler_unit_metadata_text(Request* context, SharedUnit* su)
);
}
bool compiler_wasm_unit_compile_enabled(Request* context)
{
if(!context || !context->server)
return(false);
return(config_bool("COMPILE_WASM_UNITS", false));
}
String compiler_wasm_compile_script(Request* context)
{
String script = "scripts/compile_wasm_unit";
if(context && context->server)
script = first(context->server->config["WASM_COMPILE_SCRIPT"], script);
if(script != "" && script[0] != '/' && context && context->server)
script = path_join(context->server->config["COMPILER_SYS_PATH"], script);
return(script);
}
SharedUnitCompileCheck shared_unit_compile_check(const SharedUnitFilesystemState& state)
{
SharedUnitCompileCheck result;
@@ -647,9 +664,12 @@ void setup_unit_paths(Request* context, SharedUnit* su, String file_name)
su->src_file_name = basename(file_name);
su->bin_file_name = su->src_file_name + ".so";
su->wasm_file_name = su->src_file_name + ".wasm";
su->pre_file_name = su->src_file_name + ".cpp";
su->so_name = su->bin_path + "/" + su->bin_file_name;
su->wasm_name = su->bin_path + "/" + su->wasm_file_name;
su->wasm_check_file_name = su->bin_path + "/" + su->src_file_name + ".wasm-check.txt";
su->api_file_name = su->bin_path + "/" + su->src_file_name + ".exports.txt";
su->meta_file_name = su->bin_path + "/" + su->src_file_name + ".meta.txt";
su->compile_output_file_name = su->bin_path + "/" + su->src_file_name + ".compile.txt";
@@ -740,7 +760,7 @@ void load_shared_unit(Request* context, SharedUnit* su)
String result =
String("#ifndef UCE_LIB_INCLUDED\n") +
"#define UCE_LIB_INCLUDED\n" +
("#include \"")+context->server->config["COMPILER_SYS_PATH"] +"/src/lib/uce_lib.h\" \n"+
"#include \"uce_lib.h\" \n"+
file_get_contents(
context->server->config["COMPILER_SYS_PATH"] + "/" + context->server->config["SETUP_TEMPLATE"]) +
"#endif \n";
@@ -839,6 +859,15 @@ void compile_shared_unit(Request* context, SharedUnit* su)
shell_escape(su->bin_file_name)
));
if(su->compiler_messages.length() == 0 && !su->opt_so_optional && compiler_wasm_unit_compile_enabled(context))
su->compiler_messages = trim(shell_exec(shell_escape(compiler_wasm_compile_script(context))+" "+
shell_escape(su->src_path)+" "+
shell_escape(su->bin_path)+" "+
shell_escape(su->file_name)+" "+
shell_escape(su->pre_file_name)+" "+
shell_escape(su->wasm_file_name)
));
if(su->compiler_messages.length() > 0)
{
String raw_messages = su->compiler_messages;
@@ -1171,6 +1200,8 @@ DValue unit_info(String path)
info["bin_file_name"] = su->bin_file_name;
info["pre_file_name"] = su->pre_file_name;
info["so_name"] = su->so_name;
info["wasm_name"] = su->wasm_name;
info["wasm_exists"].set_bool(file_exists(su->wasm_name));
info["api_file_name"] = su->api_file_name;
info["meta_file_name"] = su->meta_file_name;
info["compile_output_file_name"] = su->compile_output_file_name;