@@ -120,6 +120,24 @@ static auto write_file(fs::path path, std::span<std::byte> data) -> void {
120120 file.write (reinterpret_cast <const char *>(data.data ()), data.size ());
121121}
122122
123+ static auto find_wasmer_dir () -> std::optional<fs::path> {
124+ auto wasmer_dir_env = std::getenv (" WASMER_DIR" );
125+ if (wasmer_dir_env) {
126+ if (fs::exists (wasmer_dir_env)) {
127+ return wasmer_dir_env;
128+ } else {
129+ report_warning (
130+ " WASMER_DIR is set, but could not be found: {}" ,
131+ wasmer_dir_env
132+ );
133+ }
134+ } else {
135+ report_warning (" WASMER_DIR environment variable is unset" );
136+ }
137+
138+ return std::nullopt ;
139+ }
140+
123141static auto handle_source ( //
124142 fs::path base_directory,
125143 ecsact::build_recipe::source_fetch src,
@@ -722,6 +740,18 @@ auto cl_compile(compile_options options) -> int {
722740 return params_file_path;
723741 };
724742
743+ const bool wants_wasmer = std::ranges::find (options.system_libs , " wasmer" s) !=
744+ options.system_libs .end ();
745+ const auto wasmer_dir = wants_wasmer ? find_wasmer_dir () : std::nullopt ;
746+
747+ if (wants_wasmer && !wasmer_dir) {
748+ report_error (
749+ " Recipe wants 'wasmer' system lib, but wasmer directory could not be "
750+ " found"
751+ );
752+ return 1 ;
753+ }
754+
725755 cl_args.push_back (" /nologo" );
726756 cl_args.push_back (" /D_WIN32_WINNT=0x0A00" );
727757 cl_args.push_back (" /diagnostics:column" );
@@ -768,6 +798,10 @@ auto cl_compile(compile_options options) -> int {
768798 cl_args.push_back (std::format (" /I{}" , inc_dir.string ()));
769799 }
770800
801+ if (wants_wasmer && wasmer_dir) {
802+ cl_args.push_back (std::format (" /I{}" , (*wasmer_dir / " include" ).string ()));
803+ }
804+
771805 if (options.tracy_dir ) {
772806 cl_args.push_back (std::format (" /I{}" , options.tracy_dir ->string ()));
773807 }
@@ -868,6 +902,10 @@ auto cl_compile(compile_options options) -> int {
868902 cl_args.push_back (" @" + obj_params_file.string ());
869903 cl_args.push_back (" @" + main_params_file.string ());
870904
905+ if (wants_wasmer && wasmer_dir) {
906+ cl_args.push_back ((*wasmer_dir / " lib" / " wasmer.lib" ).string ());
907+ }
908+
871909 if (options.tracy_dir ) {
872910 auto tracy_lib =
873911 fs::path{options.output_path .parent_path () / " profiler.lib" };
@@ -881,6 +919,19 @@ auto cl_compile(compile_options options) -> int {
881919 cl_args.push_back (" /DLL" );
882920
883921 for (auto sys_lib : options.system_libs ) {
922+ if (sys_lib == " wasmer" && wasmer_dir) {
923+ // Wasmer has some special treatment
924+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " ws2_32" ));
925+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " Advapi32" ));
926+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " Userenv" ));
927+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " Bcrypt" ));
928+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " ntdll" ));
929+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " Shell32" ));
930+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " Ole32" ));
931+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " OleAut32" ));
932+ cl_args.push_back (std::format (" /DEFAULTLIB:{}" , " RuntimeObject" ));
933+ continue ;
934+ }
884935 cl_args.push_back (std::format (" /DEFAULTLIB:{}" , sys_lib));
885936 }
886937
0 commit comments