Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
af82fb8
Add FlatBuffers schema and dependency-free C# FlatBuffers writer/reader
Copilot Aug 31, 2026
720203b
Use official Google.FlatBuffers tooling instead of hand-rolled reader…
Copilot Aug 31, 2026
a5b2695
Add GraphIndexer: deterministic reference-identity walk of the WinCom…
Copilot Aug 31, 2026
41d7107
Add CompositionSerializer: WinCompData graph to FlatBuffer
Copilot Aug 31, 2026
fc62c84
Fix metadata string interning and marker duration; validate against C…
Copilot Aug 31, 2026
9badd65
Add the managed FlatBuffer to WinCompData deserializer
Copilot Aug 31, 2026
30619a5
Add round-trip tests comparing JSON-translated and FlatBuffer-restore…
Copilot Aug 31, 2026
4de1b91
Reject malformed buffers as format errors; add robustness tests
Copilot Aug 31, 2026
428db70
Add coverage tests exercising every CompositionObjectType and geometr…
Copilot Aug 31, 2026
bf8e9db
Add native C++/WinRT runtime interpreter for serialized compositions
Copilot Aug 31, 2026
8cf90b6
Document the format, the native interpreter and how they relate
Copilot Aug 31, 2026
5e3e9aa
Address code review feedback in glob parsing, indexer and coverage test
Copilot Aug 31, 2026
53c3e34
Fix LottieRuntime C++/WinRT COM interop and build errors
jonwis Sep 1, 2026
ebce829
Add LottieRuntimeDump sample tool
jonwis Sep 1, 2026
4e2ac80
Add classic COM loader interface for LottieRuntime
jonwis Sep 1, 2026
75d048b
Initialize DispatcherQueue for COM loader
jonwis Sep 1, 2026
c2a9e36
Track LottieRuntime COM server lifetime
jonwis Sep 1, 2026
6bc9cc7
Add LottieRuntime COM trace collector
jonwis Sep 1, 2026
9449edd
Remove temporary COM trace collector
jonwis Sep 1, 2026
76617d8
Fix interpreter realization gaps
jonwis Sep 1, 2026
7e0245e
Regenerate native bindings from pinned FlatBuffers
jonwis Sep 1, 2026
70f33da
Support custom animation controllers
jonwis Sep 1, 2026
b8867d7
Make LottieRuntime DLL ABI-only
jonwis Sep 1, 2026
d28d46a
Consolidate LottieRuntime sample tooling
jonwis Sep 1, 2026
aa21a6d
Optimize LottieRuntime tool for size
jonwis Sep 1, 2026
93b1cb9
Validate buffer UAP requirements
jonwis Sep 1, 2026
f215215
Add a managed FlatBuffer interpreter with dump-and-compare tests
Copilot Sep 2, 2026
44b3258
Simplify property set name enumeration in the interpreted tree dumper
Copilot Sep 2, 2026
731b12c
Improve managed runtime Native AOT integration
jonwis Sep 2, 2026
1ba5744
Merge pull request #3 from jonwis/copilot/add-csharp-flatbuffer-inter…
jonwis Sep 2, 2026
9ebcc9e
Remove ineffective Visual Studio setup step
jonwis Sep 30, 2026
2478651
Refactor native Lottie runtime integration
jonwis Oct 12, 2026
a380992
Vendor FlatBuffers C++ headers
jonwis Oct 13, 2026
ace2593
Expose composition metadata and reusable image surfaces
Oct 16, 2026
898681d
Merge branch 'main' into jonwis-build-windows-interpreter-sample-tool
jonwis Oct 16, 2026
3f64a00
Add animation stop and restart support to LottieRuntime
Oct 17, 2026
c36b7b9
Add shared AnimatedVisualPlayer source to LottieRuntime
Oct 17, 2026
d6b7117
Merge remote-tracking branch 'origin/jonwis-build-windows-interpreter…
Oct 19, 2026
28a5166
Accept flatbuffer language in LottieGen MSBuild task
Oct 19, 2026
287736c
Consume FlatBuffers through vcpkg and package native headers
jonwis Oct 21, 2026
a83fb52
Simplify FlatBuffers regeneration and align dependencies at 25.2.10
jonwis Oct 21, 2026
a14704f
Keep managed package references out of native runtime builds
jonwis Oct 21, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions .github/workflows/dotnet-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ jobs:
fetch-depth: 0
submodules: true

# Set up a VS build environment.
- name: Setup Environment Variables
run: |
"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\VsDevCmd.bat" -no_logo
shell: cmd

# Install NuGet tools.
- name: Setup NuGet
uses: NuGet/setup-nuget@v2
Expand Down Expand Up @@ -172,4 +166,4 @@ jobs:
**/*.nupkg
--source https://api.nuget.org/v3/index.json
--api-key ${{ secrets.NUGET_PACKAGE_PUSH_TOKEN }}
--skip-duplicate
--skip-duplicate
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,7 @@ launchSettings.json

# Nuget Package files.
pack/

# Native dependencies restored by MSBuild.
/.vcpkg/
/vcpkg_installed/
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
</Choose>

<Choose>
<When Condition="'$(IsTestProject)' != 'true' and '$(IsSampleProject)' != 'true' and '$(IsDesignProject)' != 'true'">
<When Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(IsTestProject)' != 'true' and '$(IsSampleProject)' != 'true' and '$(IsDesignProject)' != 'true'">
<ItemGroup>
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.5.22" PrivateAssets="all" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
Expand All @@ -144,7 +144,7 @@
<NoWarn>$(NoWarn);8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(MSBuildProjectExtension)' == '.csproj'">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.5.119" PrivateAssets="all" />
</ItemGroup>

Expand Down
24 changes: 24 additions & 0 deletions Lottie-Windows.sln
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LottieSamples", "LottieSamp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lottie-Windows-UwpNET", "Lottie-Windows\Lottie-Windows-UwpNET\Lottie-Windows-UwpNET.csproj", "{FA1977D8-5C6F-DF3A-0926-C12A1A415024}"
EndProject
Project("{BC8A1FFA-BEE3-4634-8014-F334798102B3}") = "LottieRuntimeTool", "source\LottieRuntime\LottieRuntimeTool.vcxproj", "{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
BETA|Any CPU = BETA|Any CPU
Expand All @@ -192,6 +194,27 @@ Global
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|Any CPU.ActiveCfg = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|ARM.ActiveCfg = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|ARM64.ActiveCfg = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|ARM64.Build.0 = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|x64.ActiveCfg = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|x64.Build.0 = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.BETA|x86.ActiveCfg = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|Any CPU.ActiveCfg = Debug|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|ARM.ActiveCfg = Debug|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|ARM64.ActiveCfg = Debug|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|ARM64.Build.0 = Debug|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|x64.ActiveCfg = Debug|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|x64.Build.0 = Debug|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Debug|x86.ActiveCfg = Debug|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|Any CPU.ActiveCfg = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|ARM.ActiveCfg = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|ARM64.ActiveCfg = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|ARM64.Build.0 = Release|ARM64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|x64.ActiveCfg = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|x64.Build.0 = Release|x64
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48}.Release|x86.ActiveCfg = Release|x64
{5120EFD7-A556-46BF-8D56-F65F1EF9A305}.BETA|Any CPU.ActiveCfg = BETA|x86
{5120EFD7-A556-46BF-8D56-F65F1EF9A305}.BETA|ARM.ActiveCfg = BETA|ARM
{5120EFD7-A556-46BF-8D56-F65F1EF9A305}.BETA|ARM.Build.0 = BETA|ARM
Expand Down Expand Up @@ -685,6 +708,7 @@ Global
{FC89273A-B2DA-4625-8A73-EF02A658D65E} = {AB232F35-AAF7-4AE2-B1D2-45DD9BC2F7D7}
{7654A857-9A99-4185-9F8E-DD0CE662AF23} = {AB232F35-AAF7-4AE2-B1D2-45DD9BC2F7D7}
{DC7F7A39-B7A7-40B4-937A-601460CAE38C} = {AB232F35-AAF7-4AE2-B1D2-45DD9BC2F7D7}
{9A7B4C2E-1F3D-4B7A-9C3E-2D5A8F0B2E48} = {AB232F35-AAF7-4AE2-B1D2-45DD9BC2F7D7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {51B9BB4C-5196-41CF-950C-12B04AD8A61C}
Expand Down
31 changes: 31 additions & 0 deletions LottieGen/DotnetTool/LottieGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
<IsPackable>true</IsPackable>
<PackAsTool>true</PackAsTool>
<ToolCommandName>LottieGen</ToolCommandName>
<FlatBuffersVcpkgTriplet Condition="'$(FlatBuffersVcpkgTriplet)' == ''">x64-windows</FlatBuffersVcpkgTriplet>
</PropertyGroup>
<Import Project="..\..\build\FlatBuffers.targets" />

<PropertyGroup>
<_SourceDir>..\..\source\</_SourceDir>
Expand All @@ -18,6 +20,7 @@

<Import Project="..\Common.proj" />
<Import Project="$(_SourceDir)Animatables\Animatables.projitems" Label="Shared" />
<Import Project="$(_SourceDir)CompDataFlatbuffer\CompDataFlatbuffer.projitems" Label="Shared" />
<Import Project="$(_SourceDir)CompMetadata\CompMetadata.projitems" Label="Shared" />
<Import Project="$(_SourceDir)DotLottie\DotLottie.projitems" Label="Shared" />
<Import Project="$(_SourceDir)GenericData\GenericData.projitems" Label="Shared" />
Expand All @@ -33,4 +36,32 @@
<Import Project="$(_SourceDir)WinUIXamlMediaData\WinUIXamlMediaData.projitems" Label="Shared" />
<Import Project="$(_SourceDir)YamlData\YamlData.projitems" Label="Shared" />
<Import Project="$(_SourceDir)UIDataCodeGen\UIDataCodeGen.projitems" Label="Shared" />
<ItemGroup>
<PackageReference Include="Google.FlatBuffers" Version="25.2.10" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\source\LottieRuntime\LottieRuntime.h" Pack="true" PackagePath="inc\lottiecomp\" />
<None Include="..\..\source\LottieRuntime\LottieVisualSource.h" Pack="true" PackagePath="inc\lottiecomp\" />
<None Include="..\..\source\LottieRuntime\LottieRuntime.cpp" Pack="true" PackagePath="LottieRuntime\" />
<None Include="..\..\source\LottieRuntime\LottieVisualSource.cpp" Pack="true" PackagePath="LottieRuntime\" />
<None Include="..\..\source\LottieRuntime\README.md" Pack="true" PackagePath="LottieRuntime\" />
<None Include="..\..\source\LottieRuntime\Generated\lottie_comp_generated.h" Pack="true" PackagePath="inc\lottiecomp\Generated\" />
<None Include="..\..\source\LottieFlatbuffer\lottie_comp.fbs" Pack="true" PackagePath="LottieRuntime\" />
<None Include="..\..\LICENSE.md" Pack="true" PackagePath="LottieRuntime\" />
</ItemGroup>

<Target Name="CollectLottieRuntimePackageContent" BeforeTargets="_GetPackageFiles"
DependsOnTargets="RestoreFlatBuffers">
<Error Condition="!Exists('$(FlatBuffersVcpkgInstalledDir)\$(FlatBuffersVcpkgTriplet)\share\flatbuffers\copyright')"
Text="The restored FlatBuffers license is required to package LottieGen." />
<Copy SourceFiles="$(FlatBuffersVcpkgInstalledDir)\$(FlatBuffersVcpkgTriplet)\share\flatbuffers\copyright"
DestinationFiles="$(IntermediateOutputPath)flatbuffers.LICENSE.txt" />
<ItemGroup>
<None Include="$(FlatBuffersIncludeDirectory)\flatbuffers\**\*"
Pack="true" PackagePath="inc\lottiecomp\flatbuffers\%(RecursiveDir)" />
<None Include="$(IntermediateOutputPath)flatbuffers.LICENSE.txt"
Pack="true" PackagePath="LottieRuntime\" />
</ItemGroup>
</Target>
</Project>
17 changes: 15 additions & 2 deletions LottieGen/MSBuildTask/LottieGen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public sealed class LottieGen : Microsoft.Build.Utilities.ToolTask
public string? InputFile { get; set; }

/// <summary>
/// cs, cppcx, or cppwinrt.
/// cs, cppcx, cppwinrt, or flatbuffer.
/// </summary>
[Required]
public string? Language { get; set; }
Expand Down Expand Up @@ -190,6 +190,13 @@ public override bool Execute()
}

break;

case Lang.Flatbuffer:
// The number of .lcomp variants depends on the UAP versions
// required by the animation, so use the paths LottieGen reported.
OutputFiles = _outputFiles.ConvertAll(f => (ITaskItem)new TaskItem(f)).ToArray();
break;

default:
throw new InvalidOperationException();
}
Expand Down Expand Up @@ -341,6 +348,7 @@ protected override bool ValidateParameters()
case Lang.Cppwinrt:
case Lang.CSharp:
case Lang.Cx:
case Lang.Flatbuffer:
break;

default:
Expand Down Expand Up @@ -379,7 +387,8 @@ protected override void LogEventsFromTextOutput(string singleLine, MessageImport
singleLine.StartsWith("C# code for class ") ||
singleLine.StartsWith("Cppwinrt header for class ") ||
singleLine.StartsWith("Cppwinrt source for class ") ||
singleLine.StartsWith("Cppwinrt IDL for class ");
singleLine.StartsWith("Cppwinrt IDL for class ") ||
singleLine.StartsWith("Flatbuffer data for class ");
}

Lang GetNormalizedLanguage()
Expand All @@ -397,6 +406,9 @@ Lang GetNormalizedLanguage()
case "cx":
return Lang.Cx;

case "flatbuffer":
return Lang.Flatbuffer;

default:
return Lang.Unknown;
}
Expand All @@ -408,6 +420,7 @@ enum Lang
CSharp,
Cx,
Cppwinrt,
Flatbuffer,
}
}
}
4 changes: 4 additions & 0 deletions LottieGen/win-x64/LottieGen.win-x64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

<Import Project="..\Common.proj" />
<Import Project="$(_SourceDir)Animatables\Animatables.projitems" Label="Shared" />
<Import Project="$(_SourceDir)CompDataFlatbuffer\CompDataFlatbuffer.projitems" Label="Shared" />
<Import Project="$(_SourceDir)CompMetadata\CompMetadata.projitems" Label="Shared" />
<Import Project="$(_SourceDir)DotLottie\DotLottie.projitems" Label="Shared" />
<Import Project="$(_SourceDir)GenericData\GenericData.projitems" Label="Shared" />
Expand All @@ -50,4 +51,7 @@
<Import Project="$(_SourceDir)WinUIXamlMediaData\WinUIXamlMediaData.projitems" Label="Shared" />
<Import Project="$(_SourceDir)YamlData\YamlData.projitems" Label="Shared" />
<Import Project="$(_SourceDir)UIDataCodeGen\UIDataCodeGen.projitems" Label="Shared" />
<ItemGroup>
<PackageReference Include="Google.FlatBuffers" Version="25.2.10" />
</ItemGroup>
</Project>
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Lottie-Windows consists of 3 related products:

This repo also contains source code for **[samples](/LottieViewer)**.

It also contains **[LottieRuntime](/source/LottieRuntime)**, native C++/WinRT source that
builds the composition tree at runtime from a serialized animation produced by
`LottieGen -Language flatbuffer`. It keeps the animation as data, like the JSON path does, but
without shipping a JSON parser or the translator. See
[the format](/source/LottieFlatbuffer/README.md) for how the two relate.

## <a name="quickstart"></a> Quick start

There are **two** options to integrate Lottie animations into your **WinUI 3** or **UWP** project.
Expand Down
27 changes: 27 additions & 0 deletions build/FlatBuffers.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_FlatBuffersRepoRoot>$(MSBuildThisFileDirectory)..\</_FlatBuffersRepoRoot>
<_RestoreFlatBuffers Condition="'$(FlatBuffersIncludeDirectory)' == ''">true</_RestoreFlatBuffers>
<FlatBuffersVcpkgRoot Condition="'$(FlatBuffersVcpkgRoot)' == '' and '$(VcpkgRoot)' != ''">$(VcpkgRoot)</FlatBuffersVcpkgRoot>
<FlatBuffersVcpkgRoot Condition="'$(FlatBuffersVcpkgRoot)' == '' and '$(VCPKG_ROOT)' != ''">$(VCPKG_ROOT)</FlatBuffersVcpkgRoot>
<FlatBuffersVcpkgRoot Condition="'$(FlatBuffersVcpkgRoot)' == '' and Exists('$(VSInstallRoot)\VC\vcpkg\vcpkg.exe')">$(VSInstallRoot)\VC\vcpkg</FlatBuffersVcpkgRoot>
<FlatBuffersVcpkgRoot Condition="'$(FlatBuffersVcpkgRoot)' == ''">$(_FlatBuffersRepoRoot).vcpkg</FlatBuffersVcpkgRoot>
<FlatBuffersVcpkgInstalledDir Condition="'$(FlatBuffersVcpkgInstalledDir)' == ''">$(_FlatBuffersRepoRoot)vcpkg_installed</FlatBuffersVcpkgInstalledDir>
<FlatBuffersVcpkgTriplet Condition="'$(FlatBuffersVcpkgTriplet)' == '' and '$(Platform)' == 'x64'">x64-windows</FlatBuffersVcpkgTriplet>
<FlatBuffersVcpkgTriplet Condition="'$(FlatBuffersVcpkgTriplet)' == '' and '$(Platform)' == 'ARM64'">arm64-windows</FlatBuffersVcpkgTriplet>
<FlatBuffersVcpkgHostTriplet Condition="'$(FlatBuffersVcpkgHostTriplet)' == '' and ('$(PROCESSOR_ARCHITECTURE)' == 'ARM64' or '$(PROCESSOR_ARCHITEW6432)' == 'ARM64')">arm64-windows</FlatBuffersVcpkgHostTriplet>
<FlatBuffersVcpkgHostTriplet Condition="'$(FlatBuffersVcpkgHostTriplet)' == ''">x64-windows</FlatBuffersVcpkgHostTriplet>
<FlatBuffersIncludeDirectory Condition="'$(_RestoreFlatBuffers)' == 'true'">$(FlatBuffersVcpkgInstalledDir)\$(FlatBuffersVcpkgTriplet)\include</FlatBuffersIncludeDirectory>
</PropertyGroup>

<!-- Invoke vcpkg explicitly so a first-build bootstrap works without evaluation-time imports. -->
<Target Name="RestoreFlatBuffers" BeforeTargets="$(FlatBuffersRestoreBeforeTargets)"
Condition="'$(DesignTimeBuild)' != 'true'">
<Error Condition="'$(_RestoreFlatBuffers)' == 'true' and '$(FlatBuffersVcpkgTriplet)' == ''"
Text="Set FlatBuffersVcpkgTriplet for platform '$(Platform)'. Supported defaults are x64 and ARM64." />
<Exec Condition="'$(_RestoreFlatBuffers)' == 'true'"
Command="powershell.exe -NoProfile -ExecutionPolicy Bypass -File &quot;$(MSBuildThisFileDirectory)RestoreFlatBuffers.ps1&quot; -VcpkgRoot &quot;$(FlatBuffersVcpkgRoot)\.&quot; -InstalledDir &quot;$(FlatBuffersVcpkgInstalledDir)\.&quot; -Triplet &quot;$(FlatBuffersVcpkgTriplet)&quot; -HostTriplet &quot;$(FlatBuffersVcpkgHostTriplet)&quot;" />
<Error Condition="!Exists('$(FlatBuffersIncludeDirectory)\flatbuffers\flatbuffers.h')"
Text="FlatBuffers headers were not found at '$(FlatBuffersIncludeDirectory)'. Restore vcpkg dependencies or set FlatBuffersIncludeDirectory to the include directory for FlatBuffers 25.2.10." />
</Target>
</Project>
49 changes: 49 additions & 0 deletions build/RegenerateFlatbuffers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Regenerates the FlatBuffers code for lottie_comp.fbs.
#
# The generated C# and C++ sources are checked in so that contributors do not
# need flatc installed in order to build. Run this script after any change to
# source/LottieFlatbuffer/lottie_comp.fbs, and check in the result.
#
[CmdletBinding()]
param(
[string]$VcpkgRoot = $env:VCPKG_ROOT,

[string]$InstalledDir = (Join-Path $PSScriptRoot "..\vcpkg_installed"),

[string]$HostTriplet = $(if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64" -or $env:PROCESSOR_ARCHITEW6432 -eq "ARM64") { "arm64-windows" } else { "x64-windows" })
)

$ErrorActionPreference = "Stop"

$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
$schema = Join-Path $repoRoot "source\LottieFlatbuffer\lottie_comp.fbs"
$csharpOut = Join-Path $repoRoot "source\CompDataFlatbuffer\Generated"
$cppOut = Join-Path $repoRoot "source\LottieRuntime\Generated"

if (!$VcpkgRoot) {
$VcpkgRoot = Join-Path $repoRoot ".vcpkg"
}

& (Join-Path $PSScriptRoot "RestoreFlatBuffers.ps1") -VcpkgRoot $VcpkgRoot `
-InstalledDir $InstalledDir -Triplet $HostTriplet -HostTriplet $HostTriplet
$flatc = Join-Path $InstalledDir "$HostTriplet\tools\flatbuffers\flatc.exe"

New-Item -ItemType Directory -Force -Path $csharpOut, $cppOut | Out-Null

# --gen-onefile keeps the checked in C# to a single file rather than one file
# per type spread over a namespace directory tree.
& $flatc --csharp --gen-onefile -o $csharpOut $schema
if ($LASTEXITCODE -ne 0) { throw "flatc failed to generate C#." }

& $flatc --cpp --scoped-enums -o $cppOut $schema
if ($LASTEXITCODE -ne 0) { throw "flatc failed to generate C++." }

foreach ($path in @(
(Join-Path $csharpOut "lottie_comp_generated.cs"),
(Join-Path $cppOut "lottie_comp_generated.h")
)) {
$contents = [IO.File]::ReadAllText($path)
[IO.File]::WriteAllText($path, ($contents -replace '\r?\n', "`r`n"), [Text.UTF8Encoding]::new($false))
}

Write-Host "Generated FlatBuffers code from $schema"
67 changes: 67 additions & 0 deletions build/RestoreFlatBuffers.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string]$VcpkgRoot,

[Parameter(Mandatory)]
[string]$InstalledDir,

[Parameter(Mandatory)]
[string]$Triplet,

[string]$HostTriplet = "x64-windows"
)

$ErrorActionPreference = "Stop"
$repoRoot = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
$VcpkgRoot = [IO.Path]::GetFullPath($VcpkgRoot)
$InstalledDir = [IO.Path]::GetFullPath($InstalledDir)
$localRoot = Join-Path $repoRoot ".vcpkg"
$vcpkg = Join-Path $VcpkgRoot "vcpkg.exe"
$baseline = (Get-Content (Join-Path $repoRoot "vcpkg.json") -Raw | ConvertFrom-Json).'builtin-baseline'

function Invoke-Checked([string]$Program, [string[]]$Arguments) {
& $Program @Arguments
if ($LASTEXITCODE -ne 0) {
throw "'$Program $($Arguments -join ' ')' failed with exit code $LASTEXITCODE."
}
}

if (!(Test-Path -LiteralPath $vcpkg)) {
if ($VcpkgRoot -ne $localRoot) {
throw "vcpkg.exe was not found at '$VcpkgRoot'. Bootstrap that installation or omit FlatBuffersVcpkgRoot to use automatic discovery."
}

if (!(Test-Path -LiteralPath $VcpkgRoot)) {
Invoke-Checked "git" @("init", $VcpkgRoot)
Invoke-Checked "git" @("-C", $VcpkgRoot, "remote", "add", "origin", "https://github.com/microsoft/vcpkg.git")
}

$remote = & git -C $VcpkgRoot remote get-url origin
if ($LASTEXITCODE -ne 0 -or $remote -ne "https://github.com/microsoft/vcpkg.git") {
throw "'$VcpkgRoot' must be a checkout of https://github.com/microsoft/vcpkg.git."
}

Invoke-Checked "git" @("-C", $VcpkgRoot, "fetch", "origin", $baseline)
Invoke-Checked "git" @("-C", $VcpkgRoot, "checkout", "--detach", $baseline)
Invoke-Checked (Join-Path $VcpkgRoot "bootstrap-vcpkg.bat") @("-disableMetrics")
}

if ($VcpkgRoot -eq $localRoot) {
$shallow = & git -C $VcpkgRoot rev-parse --is-shallow-repository
if ($LASTEXITCODE -ne 0) {
throw "Could not inspect the repo-local vcpkg checkout at '$VcpkgRoot'."
}
if ($shallow -eq "true") {
Invoke-Checked "git" @("-C", $VcpkgRoot, "fetch", "--unshallow", "origin", $baseline)
}
}

Invoke-Checked $vcpkg @(
"install",
"--triplet=$Triplet",
"--host-triplet=$HostTriplet",
"--x-wait-for-lock",
"--x-manifest-root=$repoRoot",
"--x-install-root=$InstalledDir"
)
2 changes: 2 additions & 0 deletions build/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static bool IsExcludedDirectory(FilePath path)
return
segments.Contains("bin") ||
segments.Contains("external") ||
segments.Contains(".vcpkg") ||
segments.Contains("vcpkg_installed") ||
segments.Contains("internal") ||
segments.Contains("obj");
}
Expand Down
Loading