From 0835a6559cf676eaff8a966a945b8c993bd4fd67 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 16 Feb 2026 21:31:12 +0100 Subject: [PATCH] Fix Web build issues --- Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp | 7 +++++-- Source/Engine/Platform/Platform.Build.cs | 4 ++-- Source/Engine/Platform/Web/WebPlatform.cpp | 5 ++--- Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs | 4 ++++ 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp b/Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp index f735130bf..a2ad52b67 100644 --- a/Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp +++ b/Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp @@ -55,7 +55,7 @@ bool WebPlatformTools::IsNativeCodeFile(CookingData& data, const String& file) void WebPlatformTools::OnBuildStarted(CookingData& data) { - // Adjust the cooking output folder for the data files so file_packager tool can build the and output final data inside the cooker output folder + // Adjust the cooking output folder for the data files so file_packager tool can compress and output final data inside the cooker output folder data.DataOutputPath = data.CacheDirectory / TEXT("Files"); } @@ -122,11 +122,11 @@ bool WebPlatformTools::OnPostProcess(CookingData& data) } const String filesIncludeBegin = TEXT("// include: files.js"); const String filesIncludeEnd = TEXT("// end include: files.js"); + String fileJs = data.OriginalOutputPath / TEXT("files.js"); if (!gameJsText.Contains(filesIncludeBegin)) { // Insert generated files.js into the main game file after the minimum_runtime_check.js include String fileJsText; - String fileJs = data.OriginalOutputPath / TEXT("files.js"); if (File::ReadAllText(fileJs, fileJsText)) { data.Error(String::Format(TEXT("Failed to load file '{}'"), fileJs)); @@ -140,6 +140,9 @@ bool WebPlatformTools::OnPostProcess(CookingData& data) gameJsText.Insert(location, fileJsText); File::WriteAllText(gameJs, gameJsText, Encoding::UTF8); } + + // Remove the generated files.js as it's now included in the main game JS file + FileSystem::DeleteFile(fileJs); } const auto buildSettings = BuildSettings::Get(); diff --git a/Source/Engine/Platform/Platform.Build.cs b/Source/Engine/Platform/Platform.Build.cs index dc976088c..cf16aee2c 100644 --- a/Source/Engine/Platform/Platform.Build.cs +++ b/Source/Engine/Platform/Platform.Build.cs @@ -96,10 +96,10 @@ public class Platform : EngineModule if (EngineConfiguration.WithSDL(options)) { - options.PublicDependencies.Add("SDL"); + options.PrivateDependencies.Add("SDL"); options.SourcePaths.Add(Path.Combine(FolderPath, "SDL")); if (options.Platform.Target == TargetPlatform.Linux) - options.PublicDependencies.Add("Wayland"); + options.PrivateDependencies.Add("Wayland"); } if (options.Target.IsEditor) { diff --git a/Source/Engine/Platform/Web/WebPlatform.cpp b/Source/Engine/Platform/Web/WebPlatform.cpp index 24dcf4f16..822aa21e5 100644 --- a/Source/Engine/Platform/Web/WebPlatform.cpp +++ b/Source/Engine/Platform/Web/WebPlatform.cpp @@ -49,7 +49,6 @@ CPUInfo WebPlatform::GetCPUInfo() MemoryStats WebPlatform::GetMemoryStats() { - // Mock memory stats MemoryStats result; result.TotalPhysicalMemory = emscripten_get_heap_max(); result.UsedPhysicalMemory = emscripten_get_heap_size(); @@ -116,7 +115,7 @@ void WebPlatform::GetSystemTime(int32& year, int32& month, int32& dayOfWeek, int hour = time.tm_hour; minute = time.tm_min; second = time.tm_sec; - millisecond = (int64)emscripten_get_now() % 1000; // Fake it based on other timer + millisecond = abs((int64)emscripten_get_now()) % 1000; // Fake it based on other timer } void WebPlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& day, int32& hour, int32& minute, int32& second, int32& millisecond) @@ -135,7 +134,7 @@ void WebPlatform::GetUTCTime(int32& year, int32& month, int32& dayOfWeek, int32& hour = time.tm_hour; minute = time.tm_min; second = time.tm_sec; - millisecond = (int64)emscripten_get_now() % 1000; // Fake it based on other timer + millisecond = abs((int64)emscripten_get_now()) % 1000; // Fake it based on other timer } #if !BUILD_RELEASE diff --git a/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs b/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs index 70551db4d..a39a50bb4 100644 --- a/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs +++ b/Source/Tools/Flax.Build/Platforms/Web/WebToolchain.cs @@ -153,6 +153,10 @@ namespace Flax.Build.Platforms commonArgs.Add("-c"); AddSharedArgs(commonArgs, options, options.CompileEnv.DebugInformation, options.CompileEnv.Optimization); + + // Hack to pull SDL3 port via emcc + if (options.CompileEnv.PreprocessorDefinitions.Contains("PLATFORM_SDL")) + commonArgs.Add("--use-port=sdl3"); } // Add preprocessor definitions