Make Godot native staging target-aware

This commit is contained in:
gamer147
2026-07-31 08:55:17 -04:00
parent 53823d4c10
commit c33b21ef82
4 changed files with 80 additions and 10 deletions

View File

@@ -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

View File

@@ -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<PlatformNotSupportedException>(() =>
FfmpegMovieNative.RuntimeIdentifierFor(false, false, Architecture.Wasm));
Assert.Contains("Linux/Wasm", error.Message);
}
}

View File

@@ -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);

View File

@@ -3,8 +3,12 @@
<TargetFramework>net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
<Nullable>enable</Nullable>
<AgeNativeRid Condition="'$(RuntimeIdentifier)' != ''">$(RuntimeIdentifier)</AgeNativeRid>
<AgeNativeRid Condition="'$(AgeNativeRid)' == '' and '$(GodotTargetPlatform)' == 'windows'">win-x64</AgeNativeRid>
<AgeNativeRid Condition="'$(AgeNativeRid)' == '' and '$(GodotTargetPlatform)' == 'linuxbsd'">linux-x64</AgeNativeRid>
<AgeNativeDirectory>..\build\native\$(AgeNativeRid)</AgeNativeDirectory>
</PropertyGroup>
<PropertyGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<PropertyGroup Condition="'$(GodotTargetPlatform)' == 'windows'">
<DefineConstants>$(DefineConstants);AGE_WINDOWS_GDI</DefineConstants>
</PropertyGroup>
<ItemGroup>
@@ -12,16 +16,28 @@
<EmbeddedResource Include="..\build\opcodes.json"
LogicalName="Himegari.Runtime.opcodes.json" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('Windows'))">
<ItemGroup Condition="'$(GodotTargetPlatform)' == 'windows'">
<ProjectReference Include="..\engine\Age.Engine.Text.Windows\Age.Engine.Text.Windows.csproj" />
</ItemGroup>
<ItemGroup Condition="Exists('..\build\native\win-x64\age_movie_ffmpeg.dll')">
<None Include="..\build\native\win-x64\*.dll"
<ItemGroup Condition="'$(AgeNativeRid)' == 'win-x64' and Exists('$(AgeNativeDirectory)\age_movie_ffmpeg.dll')">
<None Include="$(AgeNativeDirectory)\*.dll"
Link="%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest" />
<None Include="..\build\native\win-x64\FFmpeg-LICENSE.txt"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
<None Include="$(AgeNativeDirectory)\FFmpeg-LICENSE.txt"
Link="FFmpeg-LICENSE.txt"
CopyToOutputDirectory="PreserveNewest" />
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<ItemGroup Condition="'$(AgeNativeRid)' == 'linux-x64' and Exists('$(AgeNativeDirectory)\libage_movie_ffmpeg.so')">
<None Include="$(AgeNativeDirectory)\*.so*"
Link="%(Filename)%(Extension)"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
<None Include="$(AgeNativeDirectory)\FFmpeg-LICENSE.txt"
Link="FFmpeg-LICENSE.txt"
CopyToOutputDirectory="PreserveNewest"
CopyToPublishDirectory="PreserveNewest" />
</ItemGroup>
<Target Name="RequireGeneratedRuntimeMetadata" BeforeTargets="PrepareForBuild"
Condition="!Exists('..\build\opcodes.json')">