Skip to content

Commit

Permalink
CheckReleaseBinaries logic
Browse files Browse the repository at this point in the history
  • Loading branch information
m0nsky committed Jul 12, 2024
1 parent 4d1310a commit 975da97
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions LLama/LLamaSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<BinaryReleaseId>1c5eba6f8e62</BinaryReleaseId>
</PropertyGroup>

<!-- When UnzipReleaseBinaries is called, this will run first, as UnzipReleaseBinaries depends on it (check DependsOnTargets of UnzipReleaseBinaries) -->
<Target Name="DownloadReleaseBinaries">
<Message Importance="High" Text="Download '$(BinaryReleaseId)/deps.zip' to 'runtimes'" />
<DownloadFile
Expand All @@ -67,7 +68,8 @@
/>
</Target>

<Target Name="UnzipReleaseBinaries" DependsOnTargets="DownloadReleaseBinaries">
<!-- This automatically runs after CheckReleaseBinaries has completed, but only if SkipDownloadReleaseBinaries is not true -->
<Target Name="UnzipReleaseBinaries" DependsOnTargets="DownloadReleaseBinaries" AfterTargets="CheckReleaseBinaries" Condition="'$(SkipDownloadReleaseBinaries)' != 'true'">
<Message Importance="High" Text="Zip file was found before starting unzip." Condition="Exists('runtimes/deps.zip')" />
<Message Importance="High" Text="Zip file was NOT found before starting unzip!" Condition="!Exists('runtimes/deps.zip')" />
<Message Importance="High" Text="Unzip '$(BinaryReleaseId)/deps.zip'" />
Expand All @@ -78,10 +80,34 @@
OverwriteReadOnlyFiles="true"
Include="*.dll;*.so;*.dylib;*.metal;"
/>
<WriteLinesToFile
File="runtimes/version.txt"
Lines="$(BinaryReleaseId)"
Overwrite="true"
/>
</Target>

<Target Name="CheckReleaseBinaries">
<!-- First, we read the previous binary release id from disk -->
<ReadLinesFromFile File="runtimes/version.txt">
<Output TaskParameter="Lines" ItemName="PreviousBinaryReleaseId" />
</ReadLinesFromFile>

<!-- Log it to console -->
<Message Importance="High" Text="PreviousBinaryReleaseId: %(PreviousBinaryReleaseId.Identity), CurrentBinaryReleaseId: $(BinaryReleaseId)" />

<!-- If the previous binary release id is the same as the current one (which we define at the top of this file), we skip the download -->
<PropertyGroup>
<SkipDownloadReleaseBinaries Condition="'%(PreviousBinaryReleaseId.Identity)' == '$(BinaryReleaseId)'">true</SkipDownloadReleaseBinaries>
</PropertyGroup>

<!-- Log it to console -->
<Message Importance="High" Text="SkipDownloadReleaseBinaries: $(SkipDownloadReleaseBinaries)" />
</Target>

<!-- This always gets called before the build -->
<Target Name="PrepareReleaseBinaries" BeforeTargets="DispatchToInnerBuilds;BeforeBuild">
<MSBuild Projects="$(MSBuildProjectFile)" Targets="UnzipReleaseBinaries" Properties="TargetFramework=once" />
<MSBuild Projects="$(MSBuildProjectFile)" Targets="CheckReleaseBinaries" Properties="TargetFramework=once" />
</Target>

</Project>

0 comments on commit 975da97

Please sign in to comment.