| 135 | } |
| 136 | |
| 137 | bool WebPlatformTools::OnPostProcess(CookingData& data) |
| 138 | { |
| 139 | const auto gameSettings = GameSettings::Get(); |
| 140 | const auto platformSettings = WebPlatformSettings::Get(); |
| 141 | const auto platformDataPath = data.GetPlatformBinariesRoot(); |
| 142 | |
| 143 | // Get name of the output binary (JavaScript and WebAssembly files match) |
| 144 | String gameJs; |
| 145 | { |
| 146 | Array<String> files; |
| 147 | FileSystem::DirectoryGetFiles(files, data.OriginalOutputPath, TEXT("*"), DirectorySearchOption::TopDirectoryOnly); |
| 148 | for (const String& file : files) |
| 149 | { |
| 150 | if (file.EndsWith(TEXT(".js"))) |
| 151 | { |
| 152 | String outputWasm = String(StringUtils::GetPathWithoutExtension(file)) + TEXT(".wasm"); |
| 153 | if (files.Contains(outputWasm)) |
| 154 | { |
| 155 | gameJs = file; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | if (gameJs.IsEmpty()) |
| 162 | { |
| 163 | data.Error(TEXT("Failed to find the main JavaScript for the output game")); |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | // Move .wasm assemblies into the data files in order for dlopen to work (blocking) |
| 168 | { |
| 169 | Array<String> files; |
| 170 | FileSystem::DirectoryGetFiles(files, data.OriginalOutputPath, TEXT("*.wasm"), DirectorySearchOption::AllDirectories); |
| 171 | StringView gameWasm = StringUtils::GetFileNameWithoutExtension(gameJs); |
| 172 | for (const String& file : files) |
| 173 | { |
| 174 | if (StringUtils::GetFileNameWithoutExtension(file) == gameWasm) |
| 175 | continue; // Skip the main game module |
| 176 | FileSystem::MoveFile(data.DataOutputPath / StringUtils::GetFileName(file), file, true); |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | // Pack data files into a single file using Emscripten's file_packager tool |
| 181 | { |
| 182 | CreateProcessSettings procSettings; |
| 183 | String emscriptenSdk = TEXT("EMSDK"); |
| 184 | Platform::GetEnvironmentVariable(emscriptenSdk, emscriptenSdk); |
| 185 | procSettings.FileName = emscriptenSdk / TEXT("upstream/emscripten/tools/file_packager"); |
| 186 | procSettings.Arguments = String::Format(TEXT("files.data --preload \"{}@/\" --lz4 --js-output=files.js"), data.DataOutputPath); |
| 187 | procSettings.WorkingDirectory = data.OriginalOutputPath; |
| 188 | #if PLATFORM_MAC || PLATFORM_WINDOWS |
| 189 | // Use python bundled with SDK (python from min-spec XCode 16.4 is 3.9.6 which is < 3.10 needed by SDK 5.0) |
| 190 | Array<String> pythons; |
| 191 | FileSystem::GetChildDirectories(pythons, emscriptenSdk / TEXT("/python")); |
| 192 | if (pythons.HasItems()) |
| 193 | { |
| 194 | procSettings.Arguments = procSettings.FileName + TEXT(".py ") + procSettings.Arguments; |
no test coverage detected