Skip to content

Commit 44f9797

Browse files
committed
Create a redist package for tensorflowCreate a nuget package that redistributes the TensorFlow C-API.This is needed because TensorFlow doesn't ship an official NuGet package.This is a straight up repack of the bits published on tensorflow.org. I made sure to apply the TensorFlow license to this package and not sign it with our authenticate certificates.
1 parent 105975b commit 44f9797

11 files changed

+189
-17
lines changed

build.proj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
<TraversalBuildDependsOn>
3232
CreateOrUpdateCurrentVersionFile;
3333
RestoreProjects;
34+
BuildRedist;
3435
BuildNative;
3536
$(TraversalBuildDependsOn);
3637
DownloadExternalTestFiles;
@@ -44,6 +45,14 @@
4445
Properties="MSBuildWarningsAsMessages=NU1503" />
4546
</Target>
4647

48+
<Target Name="BuildRedist"
49+
Condition="'$(SkipRedistBuild)' != 'true'"
50+
DependsOnTargets="RestoreProjects">
51+
<Message Importance="High" Text="Building redist components..." />
52+
<MSBuild Projects="src/Redist/build.proj"
53+
Targets="Build" />
54+
</Target>
55+
4756
<Target Name="BuildNative"
4857
Condition="'$(SkipNativeBuild)' != 'true'"
4958
DependsOnTargets="RestoreProjects">

build/Dependencies.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<MlNetMklDepsPackageVersion>0.0.0.5</MlNetMklDepsPackageVersion>
1212
<SystemDrawingCommonPackageVersion>4.5.0</SystemDrawingCommonPackageVersion>
1313
<BenchmarkDotNetVersion>0.11.0</BenchmarkDotNetVersion>
14+
<TensorFlowVersion>1.10.0</TensorFlowVersion>
1415
</PropertyGroup>
1516
</Project>

build/sign.proj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030

3131
<!-- If we are not signing nuget packages we default to sign binaries -->
3232
<ItemGroup Condition="'$(SignNugetPackages)' != 'true'">
33-
<FilesToSign Include="$(OutDir)**/*.dll">
33+
<!-- Don't sign tensorflow since we don't build it. -->
34+
<ExcludeFilesToSign Include="$(OutDir)**/tensorflow.dll" />
35+
36+
<FilesToSign Include="$(OutDir)**/*.dll" Exclude="@(ExcludeFilesToSign)">
3437
<Authenticode>Microsoft</Authenticode>
3538
</FilesToSign>
3639
</ItemGroup>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Pack">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
<PackageDescription>$(MSBuildProjectName) contains the TensorFlow C library version $(TensorFlowVersion) redistributed as a NuGet package.</PackageDescription>
6+
<PackageLicenseUrl>https://github.com/tensorflow/tensorflow/blob/master/LICENSE</PackageLicenseUrl>
7+
<PackageProjectUrl>https://www.tensorflow.org/install/install_c</PackageProjectUrl>
8+
<PackageReleaseNotes>https://github.com/tensorflow/tensorflow/releases/tag/v$(TensorFlowVersion)</PackageReleaseNotes>
9+
<PackageTags>$(PackageTags) TensorFlow</PackageTags>
10+
<!-- TODO: consider PackageIconUrl -->
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<Content Include="..\common\CommonPackage.props" Pack="true" PackagePath="build\netstandard2.0\$(MSBuildProjectName).props" />
15+
</ItemGroup>
16+
</Project>

src/Directory.Build.props

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
<WarningsNotAsErrors>$(WarningsNotAsErrors);1591</WarningsNotAsErrors>
1313

1414
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)\Source.ruleset</CodeAnalysisRuleSet>
15+
16+
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
17+
18+
<NativeAssetsBuiltPath>$(BaseOutputPath)$(TargetArchitecture).$(Configuration)\Native</NativeAssetsBuiltPath>
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>
1524
</PropertyGroup>
1625

1726
<ItemGroup>

src/Native/build.proj

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<!-- versioning.targets will import this file, so don't import it again -->
44
<DisableImportVersioningProps>true</DisableImportVersioningProps>
55

6-
<TargetArchitecture Condition="'$(TargetArchitecture)' == ''">x64</TargetArchitecture>
76
<StripNativeSymbols Condition="'$(StripNativeSymbols)' == '' and '$(Configuration)' == 'Release'">True</StripNativeSymbols>
87
</PropertyGroup>
98

@@ -26,21 +25,14 @@
2625
</PropertyGroup>
2726

2827
<PropertyGroup>
29-
<NativeAssetsBuiltPath>$(BaseOutputPath)$(TargetArchitecture).$(Configuration)\Native</NativeAssetsBuiltPath>
30-
31-
<NativeLibPrefix Condition="'$(OS)' != 'Windows_NT'">lib</NativeLibPrefix>
32-
<NativeLibExtension Condition="'$(OS)' == 'Windows_NT'">.dll</NativeLibExtension>
33-
<NativeLibExtension Condition="'$(OS)' != 'Windows_NT'">.so</NativeLibExtension>
34-
<NativeLibExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib</NativeLibExtension>
35-
36-
<NativeLibSymbolExtension Condition="'$(OS)' == 'Windows_NT'">.pdb</NativeLibSymbolExtension>
37-
<NativeLibSymbolExtension Condition="'$(OS)' != 'Windows_NT'">.so.dbg</NativeLibSymbolExtension>
38-
<NativeLibSymbolExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib.dwarf</NativeLibSymbolExtension>
39-
40-
<PackageRid Condition="'$(OS)' == 'Windows_NT'">win</PackageRid>
41-
<PackageRid Condition="'$(OS)' != 'Windows_NT'">linux</PackageRid>
42-
<PackageRid Condition="$([MSBuild]::IsOSPlatform('osx'))">osx</PackageRid>
43-
<PackageRid>$(PackageRid)-$(TargetArchitecture)</PackageRid>
28+
<NativeLibPrefix Condition="'$(OS)' != 'Windows_NT'">lib</NativeLibPrefix>
29+
<NativeLibExtension Condition="'$(OS)' == 'Windows_NT'">.dll</NativeLibExtension>
30+
<NativeLibExtension Condition="'$(OS)' != 'Windows_NT'">.so</NativeLibExtension>
31+
<NativeLibExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib</NativeLibExtension>
32+
33+
<NativeLibSymbolExtension Condition="'$(OS)' == 'Windows_NT'">.pdb</NativeLibSymbolExtension>
34+
<NativeLibSymbolExtension Condition="'$(OS)' != 'Windows_NT'">.so.dbg</NativeLibSymbolExtension>
35+
<NativeLibSymbolExtension Condition="$([MSBuild]::IsOSPlatform('osx'))">.dylib.dwarf</NativeLibSymbolExtension>
4436
</PropertyGroup>
4537

4638
<Target Name="BuildNativeUnix"
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Restore;Build">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
6+
<DisableImplicitFrameworkReferences>true</DisableImplicitFrameworkReferences>
7+
<CopyBuildOutputToOutputDirectory>false</CopyBuildOutputToOutputDirectory>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<TensorFlowConfig Include="windows" FileExtension=".zip" FilesFromArchive="lib\tensorflow.dll" Runtime="win-x64"/>
12+
<TensorFlowConfig Include="linux" FileExtension=".tar.gz" FilesFromArchive="lib\libtensorflow.so;lib\libtensorflow_framework.so" Runtime="linux-x64" />
13+
<TensorFlowConfig Include="darwin" FileExtension=".tar.gz" FilesFromArchive="lib\libtensorflow.so;lib\libtensorflow_framework.so" Runtime="osx-x64" />
14+
<TensorFlowArchive Include="@(TensorFlowConfig->'https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-%(Identity)-x86_64-$(TensorFlowVersion)%(FileExtension)')" />
15+
</ItemGroup>
16+
17+
<Target Name="PrepareArchives">
18+
<ItemGroup>
19+
<!-- set up metdata used by all targets -->
20+
<TensorFlowArchive DownloadFile="$(IntermediateOutputPath)%(FileName)%(Extension)"
21+
DownloadShaFile="$(IntermediateOutputPath)%(FileName)%(Extension).sha"
22+
ExtractDirectory="$(IntermediateOutputPath)%(FileName)"
23+
ExtractSemaphore="$(IntermediateOutputPath)%(FileName)\.extracted"
24+
LocalShaFile="$(MSBuildProjectDirectory)\%(FileName)%(Extension).sha"/>
25+
</ItemGroup>
26+
</Target>
27+
28+
<UsingTask TaskName="DownloadFilesFromUrl" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/>
29+
<Target Name="DownloadArchives"
30+
DependsOnTargets="PrepareArchives"
31+
Inputs="$(MSBuildProjectFile)"
32+
Outputs="@(TensorFlowArchive->'%(DownloadFile)')">
33+
<MakeDir Directories="$(IntermediateOutputPath)" />
34+
<ItemGroup>
35+
<!-- DownloadFilesFromUrl requires Url metadata is set and ignores the identity of the item -->
36+
<_downloadFiles Include="@(TensorFlowArchive)" Url="%(Identity)" DestinationFile="%(DownloadFile)" />
37+
</ItemGroup>
38+
<DownloadFilesFromUrl Items="@(_downloadFiles)">
39+
<Output TaskParameter="FilesCreated" ItemName="FileWrites" />
40+
</DownloadFilesFromUrl>
41+
</Target>
42+
43+
<UsingTask TaskName="GenerateChecksums" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/>
44+
<UsingTask TaskName="ZipFileExtractToDirectory" AssemblyFile="$(ToolsDir)Microsoft.DotNet.Build.Tasks.dll"/>
45+
<Target Name="ValidateAndExtractArchives"
46+
DependsOnTargets="DownloadArchives"
47+
Inputs="@(TensorFlowArchive->'%(DownloadFile)')"
48+
Outputs="@(TensorFlowArchive->'%(ExtractSemaphore)')">
49+
<!-- GenerateChecksums writes a sha checksum to the file specified by DestinationPath metadata -->
50+
<ItemGroup>
51+
<_filesToCheckSum Include="@(TensorFlowArchive->'%(DownloadFile)')" DestinationPath="%(DownloadShaFile)" />
52+
</ItemGroup>
53+
<GenerateChecksums Items="@(_filesToCheckSum)" />
54+
<ItemGroup>
55+
<FileWrites Include="@(TensorFlowArchive->'%(DownloadShaFile)')" />
56+
</ItemGroup>
57+
58+
<!-- If specified we'll update the checked in SHAs with the downloaded ones. -->
59+
<Copy Condition="'$(UpdateSHA)' == 'true'"
60+
SourceFiles="@(TensorFlowArchive->'%(DownloadShaFile)')"
61+
DestinationFiles="@(TensorFlowArchive->'%(LocalShaFile)')" />
62+
63+
<Error Condition="!Exists('%(TensorFlowArchive.LocalShaFile)')" Text="SHA file '%(TensorFlowArchive.LocalShaFile)' does not exist. Build with /p:UpdateSHA=true to save it." />
64+
65+
<!-- Read in the SHAs as metadata on the archive items -->
66+
<ItemGroup>
67+
<TensorFlowArchive>
68+
<LocalSha>$([System.IO.File]::ReadAllText('%(LocalShaFile)'))</LocalSha>
69+
<DownloadSha>$([System.IO.File]::ReadAllText('%(DownloadShaFile)'))</DownloadSha>
70+
</TensorFlowArchive>
71+
</ItemGroup>
72+
<!-- Validate that the downloaded SHAs match the expected checked in SHAs -->
73+
<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." />
74+
75+
<!-- The archives are valid, lets extract them, ensuring an empty directory -->
76+
<RemoveDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" />
77+
<MakeDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" />
78+
<ZipFileExtractToDirectory Condition="'%(FileExtension)' == '.zip'"
79+
SourceArchive="%(TensorFlowArchive.DownloadFile)"
80+
DestinationDirectory="%(TensorFlowArchive.ExtractDirectory)"
81+
OverwriteDestination="true" />
82+
<Exec Condition="'%(FileExtension)' == '.tar.gz'"
83+
Command="tar -xzmf &quot;%(TensorFlowArchive.DownloadFile)&quot; -C &quot;%(TensorFlowArchive.ExtractDirectory)&quot;" />
84+
<Touch Files="@(TensorFlowArchive->'%(ExtractSemaphore)')" AlwaysCreate="true" />
85+
86+
<ItemGroup>
87+
<FileWrites Include="%(TensorFlowArchive.ExtractDirectory)\**\*" />
88+
</ItemGroup>
89+
</Target>
90+
91+
<!-- Clean up empty directories left behind by clean, since it otherwise would not do this -->
92+
<Target Name="CleanExtractDirectories"
93+
BeforeTargets="AfterClean"
94+
DependsOnTargets="PrepareArchives">
95+
<RemoveDir Directories="@(TensorFlowArchive->'%(ExtractDirectory)')" />
96+
</Target>
97+
98+
<!-- Select the files we want to copy out of each archive. -->
99+
<Target Name="GetFilesFromArchive"
100+
DependsOnTargets="ValidateAndExtractArchives" >
101+
<ItemGroup>
102+
<!-- batch rather than transform so that we can split FilesFromArchive metadata -->
103+
<_fileFromArchive Include="%(TensorFlowArchive.FilesFromArchive)" ExtractDirectory="%(TensorFlowArchive.ExtractDirectory)" Runtime="%(TensorFlowArchive.Runtime)" />
104+
<_fileFromArchive DestinationFile="%(FileName)%(Extension)"/>
105+
<!-- rename the .so to .dylib -->
106+
<_fileFromArchive Condition="'%(Runtime)' == 'osx-x64'" DestinationFile="%(FileName).dylib" />
107+
108+
<!-- copy to packaging location -->
109+
<FilesFromArchive Include="%(_fileFromArchive.ExtractDirectory)\%(_fileFromArchive.Identity)"
110+
TargetPath="$(PackageAssetsPath)$(MSBuildProjectName)\runtimes\%(_fileFromArchive.Runtime)\native\%(_fileFromArchive.DestinationFile)" />
111+
112+
<!-- copy to NativeAssets location, only for current RID, so that they may be used by tests -->
113+
<FilesFromArchive Condition="'$(PackageRID)' == '%(_fileFromArchive.Runtime)'"
114+
Include="%(_fileFromArchive.ExtractDirectory)\%(_fileFromArchive.Identity)"
115+
TargetPath="$(NativeAssetsBuiltPath)\%(_fileFromArchive.DestinationFile)" />
116+
</ItemGroup>
117+
</Target>
118+
119+
<Target Name="CopyFilesFromArchive"
120+
DependsOnTargets="GetFilesFromArchive">
121+
<Copy SourceFiles="@(FilesFromArchive)"
122+
DestinationFiles="@(FilesFromArchive->'%(TargetPath)')">
123+
<Output TaskParameter="DestinationFiles" ItemName="FileWrites" />
124+
</Copy>
125+
</Target>
126+
127+
<!-- Define CoreCompile to do the work of downloading and copying assets -->
128+
<Target Name="CoreCompile"
129+
DependsOnTargets="CopyFilesFromArchive" />
130+
131+
<!-- required by common targets -->
132+
<Target Name="CreateManifestResourceNames" />
133+
</Project>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
77218EC4DA96A73B15B8AA5637C9F21B389510A9FAF4DCF06DF5B81A5403015C6BA3EEE29BD8BA5B0694F40C671D8E6722D554C4F93F95C33F29AB491C70263C
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
B9E9CD95BC6A28297ACAB0D684FBBFAFF1F9AE893432AC2D208120D767101AC20E2C55BC79E59DBE6E5BD9EC802026694960FA12137BB303061C5A21B62BD29E
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
66F3A9522917076038AE9CCA11FE805DD516C60B3A3E156B78C2E4BD0E3E5785A9D0380C5E06411473EF14A72B72FD93F954AA3496A12D1FAF0FA3393970E700

0 commit comments

Comments
 (0)