Skip to content

Commit 1b5445c

Browse files
committed
Initial commit for redistributing TF binaries as a nuget package
1 parent e3c3ed5 commit 1b5445c

File tree

5 files changed

+222
-0
lines changed

5 files changed

+222
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
3+
<!--
4+
NuGet packages.config doesn't support native assemblies automatically,
5+
so copy the native assemblies to the output directory.
6+
-->
7+
<ItemGroup Condition="Exists('packages.config') OR
8+
Exists('$(MSBuildProjectName).packages.config') OR
9+
Exists('packages.$(MSBuildProjectName).config')">
10+
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x64\native\*.dll"
11+
Condition="'$(PlatformTarget)' == 'x64'">
12+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
13+
<Visible>false</Visible>
14+
<Link>%(Filename)%(Extension)</Link>
15+
</Content>
16+
<Content Include="$(MSBuildThisFileDirectory)\..\..\runtimes\win-x86\native\*.dll"
17+
Condition="'$(PlatformTarget)' == 'x86'">
18+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
19+
<Visible>false</Visible>
20+
<Link>%(Filename)%(Extension)</Link>
21+
</Content>
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<ProjDir>$(MSBuildThisFileDirectory)</ProjDir>
5+
<BinDir>$(ProjRoot)bin\</BinDir>
6+
<ObjDir>$(ProjRoot)obj\</ObjDir>
7+
<PackageAssetsPath>$(BinDir)packages\</PackageAssetsPath>
8+
9+
10+
<NoBuild>true</NoBuild>
11+
<IncludeBuildOutput>false</IncludeBuildOutput>
12+
13+
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
14+
<TargetFramework>netstandard2.0</TargetFramework>
15+
<TensorFlowVersion>1.14.0</TensorFlowVersion>
16+
<TensorFlowMajorVersion>1</TensorFlowMajorVersion>
17+
18+
<GenerateNuspecDependsOn>CopyFilesFromArchive</GenerateNuspecDependsOn>
19+
20+
<PackageRid Condition="'$(OS)' == 'Windows_NT'">win</PackageRid>
21+
<PackageRid Condition="'$(OS)' != 'Windows_NT'">linux</PackageRid>
22+
<PackageRid Condition="$([MSBuild]::IsOSPlatform('osx'))">osx</PackageRid>
23+
<PackageRid>$(PackageRid)-$(TargetArchitecture)</PackageRid>
24+
25+
<PackageId>TensorFlowNET.Redist</PackageId>
26+
<Authors>The TensorFlow Authors</Authors>
27+
<TargetFramework>netstandard2.0</TargetFramework>
28+
<PackageDescription>$(MSBuildProjectName) contains the TensorFlow C library version $(TensorFlowVersion) redistributed as a NuGet package.</PackageDescription>
29+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
30+
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
31+
<Copyright>Copyright 2019 The TensorFlow Authors. All rights reserved.</Copyright>
32+
<PackageProjectUrl>https://www.tensorflow.org</PackageProjectUrl>
33+
<PackageReleaseNotes>https://github.com/tensorflow/tensorflow/releases/tag/v$(TensorFlowVersion)</PackageReleaseNotes>
34+
<PackageTags>$(PackageTags) TensorFlow</PackageTags>
35+
<!-- TODO: consider PackageIconUrl -->
36+
</PropertyGroup>
37+
38+
<PropertyGroup>
39+
<IncludeMLNetNotices>false</IncludeMLNetNotices>
40+
</PropertyGroup>
41+
42+
<ItemGroup>
43+
<Content Include="CommonPackage.props" Pack="true" PackagePath="build\netstandard2.0\$(MSBuildProjectName).props" />
44+
<Content Include="$(PackageAssetsPath)$(PackageId)\LICENSE.txt" Pack="true" PackagePath="" />
45+
<Content Condition="Exists('$(PackageAssetsPath)\$(PackageId)\THIRD_PARTY_NOTICES.txt')" Include="$(PackageAssetsPath)\$(PackageId)\THIRD_PARTY_NOTICES.txt" Pack="true" PackagePath="" />
46+
<Content Include="$(PackageAssetsPath)$(PackageId)\runtimes\**\*" Pack="true" PackagePath="runtimes" />
47+
</ItemGroup>
48+
49+
<ItemGroup>
50+
<TensorFlowConfig Include="windows"
51+
FileExtension=".zip"
52+
FilesFromArchive="lib\tensorflow.dll;
53+
include\tensorflow\c\LICENSE"
54+
Runtime="win-x64"/>
55+
56+
<TensorFlowConfig Condition="'$(OS)' != 'Windows_NT'"
57+
Include="linux"
58+
FileExtension=".tar.gz"
59+
FilesFromArchive="lib\libtensorflow.so;
60+
lib\libtensorflow_framework.so.$(TensorFlowMajorVersion);
61+
include\tensorflow\c\LICENSE"
62+
Runtime="linux-x64" />
63+
64+
<TensorFlowConfig Condition="'$(OS)' != 'Windows_NT'"
65+
Include="darwin" FileExtension=".tar.gz"
66+
FilesFromArchive="lib\libtensorflow.dylib;
67+
lib\libtensorflow_framework.$(TensorFlowMajorVersion).dylib;
68+
include\tensorflow\c\LICENSE"
69+
Runtime="osx-x64" />
70+
71+
<AdditionalDownloadFile Include="https://raw.githubusercontent.com/tensorflow/tensorflow/master/LICENSE"
72+
DownloadFile="$(BinDir)LICENSE" />
73+
</ItemGroup>
74+
75+
<Target Name="PrepareArchives">
76+
<ItemGroup>
77+
<!-- although we could extract all archives on all machines, mac requires a fixup which can only be run on mac
78+
so we split these per-rid and join during the official build packaging. -->
79+
<TensorFlowArchive
80+
Include="@(TensorFlowConfig->'https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-%(Identity)-x86_64-$(TensorFlowVersion)%(FileExtension)')" />
81+
<!-- set up metdata used by all targets -->
82+
<TensorFlowArchive DownloadFile="$(BinDir)%(FileName)%(Extension)"
83+
DownloadShaFile="$(BinDir)%(FileName)%(Extension).sha"
84+
ExtractDirectory="$(BinDir)%(FileName)"
85+
ExtractSemaphore="$(BinDir)%(FileName)\.extracted"
86+
LocalShaFile="$(MSBuildProjectDirectory)\%(FileName)%(Extension).sha"/>
87+
</ItemGroup>
88+
<Message Importance="high" Text="%(TensorFlowConfig.Runtime)"/>
89+
</Target>
90+
91+
<Target Name="DownloadArchives"
92+
DependsOnTargets="PrepareArchives"
93+
Inputs="$(MSBuildProjectFile)"
94+
Outputs="@(TensorFlowArchive->'%(DownloadFile)');@(AdditionalDownloadFile->'%(DownloadFile)')">
95+
<MakeDir Directories="$(BinDir)" />
96+
<ItemGroup>
97+
<_downloadFiles Include="@(TensorFlowArchive);@(AdditionalDownloadFile)" Url="%(Identity)" DestinationFile="%(DownloadFile)" />
98+
</ItemGroup>
99+
<Message Importance="High" Text="Downloading '%(_downloadFiles.Identity)' to '$(BinDir)'." />
100+
<DownloadFile SourceUrl="%(_downloadFiles.Identity)" DestinationFolder="$(BinDir)">
101+
<Output TaskParameter="DownloadedFile" ItemName="Content" />
102+
</DownloadFile>
103+
</Target>
104+
105+
106+
<Target Name="ValidateAndExtractArchives"
107+
DependsOnTargets="DownloadArchives"
108+
Inputs="@(TensorFlowArchive->'%(DownloadFile)')"
109+
Outputs="@(TensorFlowArchive->'%(ExtractSemaphore)')">
110+
111+
<GetFileHash Files="@(TensorFlowArchive->'%(DownloadFile)')" Algorithm="SHA512">
112+
<Output
113+
TaskParameter="Items"
114+
ItemName="FilesWithHashes" />
115+
</GetFileHash>
116+
117+
<Message Importance="High"
118+
Text="%(FilesWithHashes.Identity): %(FilesWithHashes.FileHash)" />
119+
120+
<ItemGroup>
121+
<TensorFlowArchive>
122+
<DownloadSha>@(FilesWithHashes->'%(FileHash)')</DownloadSha>
123+
<LocalSha>$([System.IO.File]::ReadAllText('%(LocalShaFile)'))</LocalSha>
124+
</TensorFlowArchive>
125+
</ItemGroup>
126+
127+
<!-- If specified we'll update the checked in SHAs with the downloaded ones. -->
128+
<!--<WriteLinesToFile Condition="'$(UpdateSHA)' == 'true'"
129+
File="@(TensorFlowArchive->'%(LocalShaFile)')"
130+
Lines="@(TensorFlowArchive->'%(LocalShaFile)')" />-->
131+
132+
<Error Condition="!Exists('%(TensorFlowArchive.LocalShaFile)')" Text="SHA file '%(TensorFlowArchive.LocalShaFile)' does not exist. Build with /p:UpdateSHA=true to save it." />
133+
134+
<Message Importance="High" Text="@TensorFlowArchive->'%(TensorFlowArchive.DownloadFile) - %(TensorFlowArchive.LocalSha) - %(TensorFlowArchive.DownloadSha)"/>
135+
136+
<!-- Validate that the downloaded SHAs match the expected checked in SHAs -->
137+
<Error Condition="'%(TensorFlowArchive.LocalSha)' != '%(TensorFlowArchive.DownloadSha)'" Text="Downloaded file '%(TensorFlowArchive.DownloadFile)' has unexpected SHA.%0A expected: %(_downloadedTensorFlowArchive.LocalSha)%0A actual: %(_downloadedTensorFlowArchive.DownloadSha)%0ABuild with /p:UpdateSHA=true if you intentionally changed the URL and wish to update the SHAs, otherwise this could indicate an incomplete download or intercerpted URL and should be examined." />
138+
139+
140+
<!-- The archives are valid, lets extract them, ensuring an empty directory -->
141+
<RemoveDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" />
142+
<MakeDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" />
143+
144+
<Message Importance="High" Text="Decompressing '%(TensorFlowArchive.DownloadFile)' to '%(TensorFlowArchive.ExtractDirectory)'." />
145+
146+
<Unzip Condition="'$(PackageRid)' == 'win-x64'"
147+
SourceFiles="%(TensorFlowArchive.DownloadFile)"
148+
DestinationFolder="%(TensorFlowArchive.ExtractDirectory)" />
149+
150+
<Exec Condition="'$(OS)' != 'Windows_NT'"
151+
WorkingDirectory="%(TensorFlowArchive.ExtractDirectory)"
152+
Command="tar -xzmf %(TensorFlowArchive.DownloadFile) -C %(TensorFlowArchive.ExtractDirectory)" />
153+
154+
<Touch Files="@(TensorFlowArchive->'%(ExtractSemaphore)')" AlwaysCreate="true" />
155+
</Target>
156+
157+
<!-- Select the files we want to copy out of each archive. -->
158+
<Target Name="GetFilesFromArchive"
159+
DependsOnTargets="ValidateAndExtractArchives" >
160+
<ItemGroup>
161+
<!-- batch rather than transform so that we can split FilesFromArchive metadata -->
162+
<_fileFromArchive Include="%(TensorFlowArchive.FilesFromArchive)" ExtractDirectory="%(TensorFlowArchive.ExtractDirectory)" Runtime="%(TensorFlowArchive.Runtime)" />
163+
<_fileFromArchive DestinationFile="%(FileName)%(Extension)"/>
164+
<_fileFromArchive PackagePath="runtimes\%(_fileFromArchive.Runtime)\native\%(_fileFromArchive.DestinationFile)" />
165+
166+
<!-- LICENSE from the package is actually THIRD_PARTY_NOTICES-->
167+
<_fileFromArchive Condition="'%(DestinationFile)' == 'LICENSE'" PackagePath="THIRD_PARTY_NOTICES.txt" Runtime="" />
168+
169+
<!-- copy to packaging location -->
170+
<FilesFromArchive Include="@(_fileFromArchive->'%(ExtractDirectory)\%(Identity)')"
171+
TargetPath="$(PackageAssetsPath)$(MSBuildProjectName)\%(PackagePath)" />
172+
<!-- include LICENSE that was downloaded from GitHub -->
173+
<FilesFromArchive Include="$(BinDir)\LICENSE"
174+
TargetPath="$(PackageAssetsPath)$(MSBuildProjectName)\LICENSE.txt" />
175+
176+
<!-- copy to NativeAssets location, only for current RID, so that they may be used by tests -->
177+
<FilesFromArchive Condition="'$(PackageRID)' == '%(_fileFromArchive.Runtime)'"
178+
Include="@(_fileFromArchive->'%(ExtractDirectory)\%(Identity)')"
179+
TargetPath="$(NativeAssetsBuiltPath)\%(_fileFromArchive.DestinationFile)" />
180+
</ItemGroup>
181+
</Target>
182+
183+
<Target Name="CopyFilesFromArchive"
184+
DependsOnTargets="GetFilesFromArchive">
185+
<Message Importance="High" Text="@(FilesFromArchive) -> %(FilesFromArchive.TargetPath)" />
186+
<Copy SourceFiles="@(FilesFromArchive)"
187+
DestinationFiles="@(FilesFromArchive->'%(TargetPath)')" />
188+
</Target>
189+
190+
<Target Name="Clean">
191+
<Message Importance="High" Text="Deleting $(BinDir);$(ObjDir)" />
192+
<RemoveDir Directories="$(BinDir);$(ObjDir)" />
193+
</Target>
194+
195+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7002EF701BD23C5EF5FF94192E935F0DDF960A21BE2531CEE158586830C00E0BA889900F7F6E8AB568BEE0ACF1F5A6A246BB43D11C4109E9DC782B46377D8142
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
E3F6D0309117E9E45780ECF8BC4D0268B3FC9F12E3E38FFE58496789330A4ACD2DC8FF721F3B8900357F6155F8A54000E45B99495F823486B558E8B42532392D
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
59A2B80B441439B851202358CE4A65BA0DDDB319A8A29E87B135DCD9954BC5B0628F2C0C8E72D6942EA3CDCE172805C2BD5421815B3D0210B62BC0936DC59A08

0 commit comments

Comments
 (0)