Skip to content

Commit 854a5ba

Browse files
authored
Merge pull request #288 from harishsk/TFRedistMigration
Tf redist migration
2 parents 2e3cf24 + 580ae1a commit 854a5ba

File tree

6 files changed

+241
-0
lines changed

6 files changed

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

0 commit comments

Comments
 (0)