From 9e619fe10b63ee4b3a51df0939d06cf21b7372b5 Mon Sep 17 00:00:00 2001 From: gamer147 Date: Fri, 31 Jul 2026 08:55:17 -0400 Subject: [PATCH] Make Godot native staging target-aware --- docs/platform-portability.md | 5 +++ .../FfmpegMovieNativeTests.cs | 31 +++++++++++++++++++ godot/FfmpegMovieNative.cs | 24 ++++++++++++-- godot/Himegari.csproj | 30 +++++++++++++----- 4 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 engine/Age.Engine.Tests/FfmpegMovieNativeTests.cs diff --git a/docs/platform-portability.md b/docs/platform-portability.md index c8781ff..2ab73d5 100644 --- a/docs/platform-portability.md +++ b/docs/platform-portability.md @@ -21,6 +21,11 @@ The VM and content pipeline are already mostly platform-neutral: - The Himegari Godot assembly embeds generated `build/opcodes.json` as profile runtime metadata. Exported builds never search for an `age-reimpl` repository ancestor; their automatic page-map diagnostics live under `user://diagnostics/page-maps`, while editor/development runs retain the workspace `build/` handoff. +- `GodotTargetPlatform`, not the build host OS, selects the optional Windows GDI adapter. `AgeNativeRid` + follows an explicit export `RuntimeIdentifier` and otherwise supplies the current x64 development default; + mutually exclusive `win-x64` DLL and `linux-x64` shared-object groups stage to build and publish output. + The managed FFmpeg resolver derives reserved Windows, Linux, and macOS x64/arm64 RIDs from the actual + process and rejects unreserved architectures instead of silently looking in the wrong directory. The sole movie path now uses the project-owned FFmpeg C ABI rather than a Windows multimedia API, but only a Windows-x64 native bundle is built and staged today. The accepted DirectShow fallback was deleted after the diff --git a/engine/Age.Engine.Tests/FfmpegMovieNativeTests.cs b/engine/Age.Engine.Tests/FfmpegMovieNativeTests.cs new file mode 100644 index 0000000..facddbc --- /dev/null +++ b/engine/Age.Engine.Tests/FfmpegMovieNativeTests.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; + +public class FfmpegMovieNativeTests +{ + [Theory] + [InlineData(true, false, Architecture.X64, "win-x64")] + [InlineData(true, false, Architecture.Arm64, "win-arm64")] + [InlineData(false, true, Architecture.X64, "osx-x64")] + [InlineData(false, true, Architecture.Arm64, "osx-arm64")] + [InlineData(false, false, Architecture.X64, "linux-x64")] + [InlineData(false, false, Architecture.Arm64, "linux-arm64")] + public void ResolverUsesOperatingSystemAndProcessArchitecture( + bool isWindows, + bool isMacOS, + Architecture architecture, + string expected) + { + Assert.Equal( + expected, + FfmpegMovieNative.RuntimeIdentifierFor(isWindows, isMacOS, architecture)); + } + + [Fact] + public void ResolverRejectsUnreservedArchitectures() + { + var error = Assert.Throws(() => + FfmpegMovieNative.RuntimeIdentifierFor(false, false, Architecture.Wasm)); + + Assert.Contains("Linux/Wasm", error.Message); + } +} diff --git a/godot/FfmpegMovieNative.cs b/godot/FfmpegMovieNative.cs index f46e14f..bbf3d3e 100644 --- a/godot/FfmpegMovieNative.cs +++ b/godot/FfmpegMovieNative.cs @@ -209,9 +209,10 @@ internal static class FfmpegMovieNative ? "age_movie_ffmpeg.dll" : OperatingSystem.IsMacOS() ? "libage_movie_ffmpeg.dylib" : "libage_movie_ffmpeg.so"; string? configured = Environment.GetEnvironmentVariable("AGE_FFMPEG_NATIVE_DIR"); - string rid = OperatingSystem.IsWindows() ? "win-x64" - : OperatingSystem.IsMacOS() ? (RuntimeInformation.ProcessArchitecture == Architecture.Arm64 ? "osx-arm64" : "osx-x64") - : "linux-x64"; + string rid = RuntimeIdentifierFor( + OperatingSystem.IsWindows(), + OperatingSystem.IsMacOS(), + RuntimeInformation.ProcessArchitecture); string[] candidates = { configured == null ? "" : Path.Combine(configured, fileName), @@ -225,6 +226,23 @@ internal static class FfmpegMovieNative $"{fileName} was not found; set AGE_FFMPEG_NATIVE_DIR or package runtimes/{rid}/native"); } + internal static string RuntimeIdentifierFor( + bool isWindows, + bool isMacOS, + Architecture architecture) + => (isWindows, isMacOS, architecture) switch + { + (true, _, Architecture.X64) => "win-x64", + (true, _, Architecture.Arm64) => "win-arm64", + (false, true, Architecture.X64) => "osx-x64", + (false, true, Architecture.Arm64) => "osx-arm64", + (false, false, Architecture.X64) => "linux-x64", + (false, false, Architecture.Arm64) => "linux-arm64", + _ => throw new PlatformNotSupportedException( + $"The FFmpeg movie backend has no reserved RID for " + + $"{(isWindows ? "Windows" : isMacOS ? "macOS" : "Linux")}/{architecture}."), + }; + internal static string DecodeUtf8(byte[] buffer) { int length = Array.IndexOf(buffer, (byte)0); diff --git a/godot/Himegari.csproj b/godot/Himegari.csproj index 3510f5f..552e122 100644 --- a/godot/Himegari.csproj +++ b/godot/Himegari.csproj @@ -3,8 +3,12 @@ net8.0 true enable + $(RuntimeIdentifier) + win-x64 + linux-x64 + ..\build\native\$(AgeNativeRid) - + $(DefineConstants);AGE_WINDOWS_GDI @@ -12,16 +16,28 @@ - + - - + - + + CopyToOutputDirectory="PreserveNewest" + CopyToPublishDirectory="PreserveNewest" /> + + + +