xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.49k stars 515 forks source link

Build fails for metal shader on Mojave #4926

Open mikebluestein opened 6 years ago

mikebluestein commented 6 years ago

Steps to Reproduce

  1. Create a new iOS project in VS for Mac
  2. Add this metal shader: https://raw.githubusercontent.com/laanlabs/SCNTechniqueGlow/master/SCNTechniqueGlow/NodeRender.metal
  3. Build for an iOS device

Expected Behavior

It builds.

Actual Behavior

Build fails with error: /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(3,3): Error MSB6006: "metal" exited with code 1. (MSB6006)

Note: The shader builds fine in Xcode or with Metal's command line tools.

Environment

=== Visual Studio Community 2017 for Mac ===

Version 7.6.6 (build 14)
Installation UUID: 2aa0e016-a24d-4d38-b7a1-1664ab263dd1
Runtime:
    Mono 5.12.0.305 (2018-02/e0e035e3b14) (64-bit)
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

    Package version: 512000305

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    2.1.2
    2.1.1
    2.0.5
    2.0.0
SDK: /usr/local/share/dotnet/sdk/2.1.302/Sdks
SDK Versions:
    2.1.302
    2.1.301
    2.1.4
    2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.12.0/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.3
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Xamarin.Android ===

Version: 9.0.0.20 (Visual Studio Community)
Android SDK: /Users/mike/Library/Android/sdk
    Supported Android versions:
        6.0 (API level 23)
        8.0 (API level 26)
        8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 27.0.1
SDK Build Tools Version: 27.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Apple Developer Tools ===

Xcode 10.0 (14320.25)
Build 10A255

=== Xamarin.Mac ===

Version: 4.99.3.741 (Visual Studio Community)
Hash: eeca0b87
Branch: 
Build date: 2018-09-13 15:01:04-0400

=== Xamarin.iOS ===

Version: 12.0.0.11 (Visual Studio Community)
Hash: eeca0b87
Branch: xcode10
Build date: 2018-09-13 15:01:03-0400

=== Xamarin Inspector ===

Version: 1.4.3
Hash: db27525
Branch: 1.4-release
Build date: Mon, 09 Jul 2018 21:20:18 GMT
Client compatibility: 1

=== Build Information ===

Release ID: 706060014
Git revision: 5fb9d5d4381378b850aab3fb6c59252695f6776d
Build date: 2018-09-14 16:13:50+00
Build branch: release-7.6-xcode10
Xamarin extensions: 96db24c7730531168cd53408e452a6d95150e05b

=== Operating System ===

Mac OS X 10.14.0
Darwin 18.0.0 Darwin Kernel Version 18.0.0
    Wed Aug 22 20:13:40 PDT 2018
    root:xnu-4903.201.2~1/RELEASE_X86_64 x86_64

=== Enabled user installed extensions ===

Internet of Things (IoT) development (Preview) 7.1

Build Logs

https://gist.github.com/mikebluestein/200d75a0b29b616dface410b3c2c1123

Example Project (If Possible)

test case.zip

VincentDondain commented 6 years ago

Hi,

Thanks for the precise bug and the attached test case.

However I cannot reproduce this locally with this environment: https://gist.github.com/VincentDondain/006f62855a5fc424a2661fbc314d67e4. Here is my successful build output: https://gist.github.com/VincentDondain/2798b04bad78a168ff2fa7376ac4aa99

It's weird because it looks like the metal command line tool is failing when producing the NodeRender.metal file.

NodeRender.metal:3:10: fatal error: 'SceneKit/scn_metal' file not found.

#include <SceneKit/scn_metal> is required and I don't know why it fails on that. See https://developer.apple.com/documentation/scenekit/scnprogram.

When you said: "The shader builds fine in Xcode or with Metal's command line tools.", does that mean you tried running the command from a terminal: https://gist.github.com/mikebluestein/200d75a0b29b616dface410b3c2c1123#file-gistfile1-txt-L78?

I don't see anything special that our msbuild tasks do that would cause that behavior. I believe the fatal error reported is from the metal command line tool itself so I don't expect that command to work locally if you try in a terminal. @jstedfast thoughts?

Note: I tried this on a Mojave machine, this doesn't make a difference for me compared to running on High Sierra, both work.

mikebluestein commented 6 years ago

When you said: "The shader builds fine in Xcode or with Metal's command line tools.", does that mean you tried running the command from a terminal:

I can run this to compile the metallib:

xcrun -sdk iphoneos metal -c HighlightRenderer.metal -o default.air
xcrun -sdk iphoneos metallib default.air -o default.metallib

It worked in VS for Mac before I upgraded to Mojave. I can reproduce on 2 different machines as well.

spouliot commented 6 years ago

I get the same error with the attached test case.

Sebastiens-MacBook-Pro:foo poupou$ /Applications/Xcode101-beta3.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal -arch air64 -emit-llvm -c -gline-tables-only -ffast-math -serialize-diagnostics obj/iPhone/Debug/metal/NodeRender.dia -o obj/iPhone/Debug/metal/NodeRender.air -mios-version-min=12.0 NodeRender.metal 
NodeRender.metal:3:10: fatal error: 'SceneKit/scn_metal' file not found
#include <SceneKit/scn_metal>
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.

and, like @mikebluestein, it works when using xcrun

Sebastiens-MacBook-Pro:foo poupou$ xcrun -sdk iphoneos metal -arch air64 -emit-llvm -c -gline-tables-only -ffast-math -serialize-diagnostics obj/iPhone/Debug/metal/NodeRender.dia -o obj/iPhone/Debug/metal/NodeRender.air -mios-version-min=12.0 NodeRender.metal 

The main difference is the -sdk iphoneos argument to xcrun which (I would assume) is implied when using .../iPhoneOS.platform/usr/bin/metal

It seems another case to push #4634 forward.

andrewbenson92 commented 5 years ago

I'd like to +1 this bug. Working with XCode Project but build fails with Xamarin

Target _SmeltMetal:
    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal -arch air64 -emit-llvm -c -gline-tables-only -ffast-math -serialize-diagnostics obj/iPhone/Debug/device-builds/iphone9.3-12.1.1/metal/StencilRender.dia -o obj/iPhone/Debug/device-builds/iphone9.3-12.1.1/metal/StencilRender.air -mios-version-min=11.0 StencilRender.metal 
    StencilRender.metal:3:10: fatal error: 'SceneKit/scn_metal' file not found
    #include <SceneKit/scn_metal>
             ^~~~~~~~~~~~~~~~~~~~
    1 error generated.
    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(555,3): error MSB6006: "metal" exited with code 1.
Done building target "_SmeltMetal" in project "ARWallpaper.iOS.csproj" -- FAILED.

Done building project "ARWallpaper.iOS.csproj" -- FAILED.

Build FAILED.
StainlessTobii commented 5 years ago

Hi guys, looks like this is a path problem as any #include fails for me except the base metallib and simd

include "lib_Common.metal"

Always fails even though the library is in the correct location.