Skip to content

Commit

Permalink
[msbuild] Fix metal targets for Xcode8 (xamarin#1838)
Browse files Browse the repository at this point in the history
Fixes bug #52982: [iOS]Metal samples fail to build with Xcode8.3
(https://bugzilla.xamarin.com/show_bug.cgi?id=52982)

Basically with Xcode8 Apple stopped using an intermediary step to generate the
default.metallib. This was what our `_ForgeMetal` target was doing, generate a `default.metal-ar`
file which was used as input for `_TemperMetal` and then generate the default.metallib.

Instead with Xcode8 you can just give Shaders.air directly to the metallib tool.

The fix in this commit is made in such a way that it still supports Xcode7.

if !Xcode8 then don't change anything.
if Xcode8+ then have `_ForgedMetal` output equal `@(_SmeltedMetal)` (basically skip the _ForgeMetal target).
  • Loading branch information
VincentDondain committed Mar 7, 2017
1 parent 78e3ae2 commit 2ffe5fd
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public string SdkVersion {
get; set;
}

[Output]
public bool IsXcode8 {
get; set;
}

#endregion Outputs

public override bool Execute ()
Expand All @@ -60,6 +65,8 @@ public override bool Execute ()
EnsureXamarinSdkRoot ();
EnsureSdkPath ();

IsXcode8 = AppleSdkSettings.XcodeVersion.Major >= 8;

return !Log.HasLoggedErrors;
}

Expand Down
13 changes: 11 additions & 2 deletions msbuild/Xamarin.Mac.Tasks/Xamarin.Mac.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,21 @@ Copyright (C) 2014 Xamarin. All rights reserved.
<Target Name="_ForgeMetal" Condition="'$(_CanOutputAppBundle)' == 'true' And '@(_SmeltedMetal)' != ''" DependsOnTargets="_SmeltMetal"
Inputs="@(_SmeltedMetal)" Outputs="$(IntermediateOutputPath)metal\default.metal-ar">
<ArTool
Condition="'$(IsMacEnabled)' == 'true'"
Condition="'$(IsMacEnabled)' == 'true' and '$(_IsXcode8)' == 'false'"
SessionId="$(BuildSessionId)"
Items="@(_SmeltedMetal)"
Archive="$(IntermediateOutputPath)metal\default.metal-ar">
</ArTool>

<CreateItem Include="$(IntermediateOutputPath)metal\default.metal-ar">
<!-- If !Xcode8 -->
<CreateItem Include="$(IntermediateOutputPath)metal\default.metal-ar"
Condition="'$(_IsXcode8)' == 'false'">
<Output TaskParameter="Include" ItemName="_ForgedMetal" />
</CreateItem>

<!-- Else -->
<CreateItem Include="@(_SmeltedMetal)"
Condition="'$(_IsXcode8)' == 'true'">
<Output TaskParameter="Include" ItemName="_ForgedMetal" />
</CreateItem>
</Target>
Expand Down Expand Up @@ -447,6 +455,7 @@ Copyright (C) 2014 Xamarin. All rights reserved.
<Output TaskParameter="SdkBinPath" PropertyName="_SdkBinPath" />
<Output TaskParameter="SdkDevPath" PropertyName="_SdkDevPath" />
<Output TaskParameter="SdkUsrPath" PropertyName="_SdkUsrPath" />
<Output TaskParameter="IsXcode8" PropertyName="_IsXcode8" />
</DetectSdkLocations>
</Target>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public bool SdkIsSimulator {
get; set;
}

[Output]
public bool IsXcode8 {
get; set;
}

#endregion Outputs

public PlatformFramework Framework {
Expand All @@ -92,6 +97,8 @@ public override bool Execute ()

SdkIsSimulator = (architectures & (TargetArchitecture.i386 | TargetArchitecture.x86_64)) != 0;

IsXcode8 = AppleSdkSettings.XcodeVersion.Major >= 8;

EnsureAppleSdkRoot ();
EnsureXamarinSdkRoot ();
switch (Framework) {
Expand Down
13 changes: 11 additions & 2 deletions msbuild/Xamarin.iOS.Tasks.Core/Xamarin.iOS.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,20 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
Inputs="@(_SmeltedMetal)" Outputs="$(DeviceSpeficicIntermediateOutputPath)metal\default.metal-ar">
<ArTool
SessionId="$(BuildSessionId)"
Condition="'$(IsMacEnabled)' == 'true'"
Condition="'$(IsMacEnabled)' == 'true' and '$(_IsXcode8)' == 'false'"
Items="@(_SmeltedMetal)"
Archive="$(DeviceSpecificIntermediateOutputPath)metal\default.metal-ar">
</ArTool>

<CreateItem Include="$(DeviceSpecificIntermediateOutputPath)metal\default.metal-ar">
<!-- If !Xcode8 -->
<CreateItem Include="$(DeviceSpecificIntermediateOutputPath)metal\default.metal-ar"
Condition="'$(_IsXcode8)' == 'false'">
<Output TaskParameter="Include" ItemName="_ForgedMetal" />
</CreateItem>

<!-- Else -->
<CreateItem Include="@(_SmeltedMetal)"
Condition="'$(_IsXcode8)' == 'true'">
<Output TaskParameter="Include" ItemName="_ForgedMetal" />
</CreateItem>
</Target>
Expand Down Expand Up @@ -559,6 +567,7 @@ Copyright (C) 2013-2016 Xamarin. All rights reserved.
<Output TaskParameter="SdkUsrPath" PropertyName="_SdkUsrPath" />
<Output TaskParameter="SdkPlatform" PropertyName="_SdkPlatform" />
<Output TaskParameter="SdkIsSimulator" PropertyName="_SdkIsSimulator" />
<Output TaskParameter="IsXcode8" PropertyName="_IsXcode8" />
</DetectSdkLocations>
</Target>

Expand Down

0 comments on commit 2ffe5fd

Please sign in to comment.