Skip to content

Commit 75130e5

Browse files
committed
Compile libsass for one platform at a time
Added an inline MSBuild task, which make use of a new CoreFX API `System.Runtime.InteropServices.RuntimeInformation` to obtain OS description and architecture information, then translates into `LibSassPlatform` (Win32 or Win64 etc.). Also added ability to cross compile, e.g. Win32 on 64-bit system. Additional OSes will be added with .NET Core support. Fixes sass#47.
1 parent 72a0578 commit 75130e5

File tree

5 files changed

+50
-6
lines changed

5 files changed

+50
-6
lines changed

Diff for: LibSass.NET.Tests/LibSass.NET.Tests.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
</Target>
118118
<Target Name="AfterBuild">
119119
<Copy
120-
SourceFiles="$(LibSassPath)libsass32.dll;$(LibSassPath)libsass64.dll"
120+
SourceFiles="$(LibSassPath)libsass.dll"
121121
DestinationFolder="$(OutputPath)"
122122
SkipUnchangedFiles="true" />
123123
</Target>

Diff for: LibSass.NET/LibSass.NET.csproj

+42-3
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,54 @@
6767
<ItemGroup>
6868
<None Include="LibSass.Net.nuspec" />
6969
<None Include="libsassnet.targets" />
70+
<None Include="packages.config" />
7071
</ItemGroup>
7172
<ItemGroup>
7273
<Reference Include="System" />
7374
<Reference Include="System.Runtime.Serialization" />
7475
</ItemGroup>
7576
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
77+
<!-- Detect Platform -->
78+
<UsingTask TaskName="OSVersionInformation" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
79+
<ParameterGroup>
80+
<LibSassPlatform ParameterType="System.String" Output="true" />
81+
</ParameterGroup>
82+
<Task>
83+
<Using Namespace="System.Reflection" />
84+
<Code Type="Fragment" Language="cs"><![CDATA[
85+
var assembly = Assembly.LoadFrom(@"..\packages\System.Runtime.InteropServices.RuntimeInformation.4.3.0\lib\net45\System.Runtime.InteropServices.RuntimeInformation.dll");
86+
Type runtimeType = assembly.GetType("System.Runtime.InteropServices.RuntimeInformation");
87+
var osDescription = runtimeType.GetProperty("OSDescription")
88+
.GetValue(null, null).ToString();
89+
var osArchitecture = runtimeType.GetProperty("OSArchitecture")
90+
.GetValue(null, null).ToString();
91+
92+
if (osDescription.StartsWith("Microsoft Windows"))
93+
{
94+
if (osArchitecture == "X86")
95+
{
96+
LibSassPlatform = "Win32";
97+
}
98+
else if (osArchitecture == "X64")
99+
{
100+
LibSassPlatform = "Win64";
101+
}
102+
}
103+
]]></Code>
104+
</Task>
105+
</UsingTask>
106+
<Target Name="GetOSIdentifiers" Condition=" '$(LibSassPlatform)' == '' ">
107+
<OSVersionInformation>
108+
<Output TaskParameter="LibSassPlatform" PropertyName="LibSassPlatform" />
109+
</OSVersionInformation>
110+
</Target>
76111
<!-- Build LibSass -->
77-
<Target Name="AfterBuild">
78-
<MSBuild Targets="Build" Projects="..\LibSass\win\libsass.sln" BuildInParallel="true" Properties="Configuration=$(Configuration);Platform=Win32;TargetName=libsass32;OutDir=$(OutputPath);IntDir=$(IntermediateOutputPath)" />
79-
<MSBuild Targets="Build" Projects="..\LibSass\win\libsass.sln" BuildInParallel="true" Properties="Configuration=$(Configuration);Platform=Win64;TargetName=libsass64;OutDir=$(OutputPath);IntDir=$(IntermediateOutputPath)" />
112+
<Target Name="AfterBuild" DependsOnTargets="GetOSIdentifiers">
113+
<Message Text="Commencing build for platform: $(LibSassPlatform)" />
114+
115+
<!-- Windows -->
116+
<MSBuild Projects="..\LibSass\win\libsass.sln" BuildInParallel="true"
117+
Condition="'$(LibSassPlatform)' == 'Win32' or '$(LibSassPlatform)' == 'Win64'"
118+
Properties="Configuration=$(Configuration);Platform=$(LibSassPlatform);OutDir=$(OutputPath);IntDir=$(IntermediateOutputPath)" />
80119
</Target>
81120
</Project>

Diff for: LibSass.NET/packages.config

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NETStandard.Library" version="1.6.1" targetFramework="net40" />
4+
<package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net45" />
5+
</packages>

Diff for: contrib/LibSass.NET.Console/LibSass.NET.Console.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5252
<Target Name="AfterBuild">
5353
<Copy
54-
SourceFiles="$(LibSassPath)libsass32.dll;$(LibSassPath)libsass64.dll"
54+
SourceFiles="$(LibSassPath)libsass.dll"
5555
DestinationFolder="$(OutputPath)"
5656
SkipUnchangedFiles="true" />
5757
</Target>

Diff for: contrib/LibSass.NET.Web/LibSass.NET.Web.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
5959
<Target Name="AfterBuild">
6060
<Copy
61-
SourceFiles="$(LibSassPath)libsass32.dll;$(LibSassPath)libsass64.dll"
61+
SourceFiles="$(LibSassPath)libsass.dll"
6262
DestinationFolder="$(OutputPath)"
6363
SkipUnchangedFiles="true" />
6464
</Target>

0 commit comments

Comments
 (0)