Skip to content

[msbuild] Update 'metal' binary path for Xcode 10 - #4601

Merged
VincentDondain merged 4 commits into
dotnet:xcode10from
VincentDondain:issue-4576
Aug 17, 2018
Merged

VincentDondain merged 4 commits into
dotnet:xcode10from
VincentDondain:issue-4576

Conversation

@VincentDondain

Copy link
Copy Markdown
Contributor

In Xcode 10 Apple moved the "metal" binary from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal to /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal.

- Fixes dotnet#4576: [xcode10] 'Metal Game' fails to build. (dotnet#4576)

In Xcode 10 Apple moved the "metal" binary from `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/usr/bin/metal` to `/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/metal`.
@VincentDondain

Copy link
Copy Markdown
Contributor Author

Same thing for metallib.

@spouliot spouliot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this not a case where xcrun should be used ?

xcrun -f metal returns the correct path on both versions (and we can assume it will continue to do so) without continuously adding logic

At the very least we should add a unit test that compare the computed path with what xcrun returns (for all tools)

@VincentDondain

Copy link
Copy Markdown
Contributor Author

Ah! Nice nice nice.

Yeah about the unit test..., it's not trivial to add msbuild mac unit tests (it is for iOS...)

@spouliot

spouliot commented Aug 8, 2018

Copy link
Copy Markdown
Contributor

@VincentDondain it does not have to be an MSBuild unit test. A normal one (e.g. mtouch tests) can verify that condition and (ideally) embed some, not all, of the logic (to avoid code duplication).

@monojenkins

Copy link
Copy Markdown
Contributor

Build success
✅ Build succeeded
✅ API Diff (from stable)
✅ API Diff (from PR only) (please review changes)
✅ Generator Diff (only version changes)
✅ Test run succeeded

@VincentDondain

Copy link
Copy Markdown
Contributor Author

Oh wow even better than xcrun -f I offer you xcrun -r where you can execute whatever tool with arguments. So effectively we should replace all our direct tools paths with xcrun.

@VincentDondain

Copy link
Copy Markdown
Contributor Author

@spouliot I'm not sure I understand the philosophy of the test. If I move to xcrun -r metal I don't have to check that a specific path exists, it'll find it for me. What we need is a msbuild test that will build a metal app (that should be doable).

@spouliot

spouliot commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

@VincentDondain you don't need -r since it's the default behaviour. However you need to make sure xcrun is using the right Xcode, e.g. setting DEVELOPER_DIR, or you won't get the right/expected tool.

As for the test(s) they should be added unless xcrun is used. That's what I meant by at least - if we need our own logic (not the first time we talked about xcrun and I don't recall all the ins-and-outs) then we should have (xcrun-based) tests to ensure that logic remains true.

@VincentDondain

Copy link
Copy Markdown
Contributor Author

you don't need -r since it's the default behavior

Not sure where you get that from. -f just prints the path.

E.g:

xcrun -f actool --errors --warnings --notices --output-format xml1 --output-partial-info-plist /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/partial-info.plist --app-icon AppIcon --minimum-deployment-target 10.12 --platform macosx --compile /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/bundle /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/cloned-assets/Assets.xcassets
xcrun: error: unrecognized option: --errors

However if you want xcrun to find + execute the found binary then -r is your friend:

xcrun -r actool --errors --warnings --notices --output-format xml1 --output-partial-info-plist /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/partial-info.plist --app-icon AppIcon --minimum-deployment-target 10.12 --platform macosx --compile /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/bundle /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/cloned-assets/Assets.xcassets
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.actool.compilation-results</key>
	<dict>
		<key>output-files</key>
		<array>
			<string>/Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/bundle/AppIcon.icns</string>
			<string>/Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/bundle/Assets.car</string>
			<string>/Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/partial-info.plist</string>
		</array>
	</dict>
</dict>
</plist>

@VincentDondain

Copy link
Copy Markdown
Contributor Author

I mean yes -f is what would be useful for the tests. But -r is what's useful long term if we want all the tasks to be updated to not deal with paths.

(maybe that's the confusion in this discussion).

@spouliot

spouliot commented Aug 9, 2018

Copy link
Copy Markdown
Contributor

Not sure where you get that from.

🐴 😮
xcrun --help or man xcrun

-f just prints the path.

Yes but I did not mention -f. I said -r is the default, i.e. xcrun metal and xcrun -r metal are identical, so -r is not needed.

For your example:

xcrun actool --errors --warnings --notices --output-format xml1 --output-partial-info-plist /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/partial-info.plist --app-icon AppIcon --minimum-deployment-target 10.12 --platform macosx --compile /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/bundle /Users/vidondai/Projects/MacMetal/MacMetal/obj/x86/Debug/actool/cloned-assets/Assets.xcassets

works without -r - at least as long as you don't use -f

@VincentDondain

Copy link
Copy Markdown
Contributor Author

Ah ok got it. I thought you meant I should forget -r because it's the default behavior for -f (to also execute). #communication

Comment thread tests/mtouch/ToolTasksBinPathTest.cs Outdated
var proc = Process.Start (psi);

string output = proc.StandardOutput.ReadToEnd ();
Console.WriteLine (output); // Print the output in case something wrong happens when executing the command

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we get anything in StandardError?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably but I'm not sure it's critical to get it. The standard output tells you what happened. The test will fail also.

Comment thread tests/mtouch/ToolTasksBinPathTest.cs Outdated
var proc = Process.Start (psi);

string output = proc.StandardOutput.ReadToEnd ();
Console.WriteLine (output); // Print the output in case something wrong happens when executing the command

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same stderr comment

@monojenkins

Copy link
Copy Markdown
Contributor

Build failure
✅ Build succeeded
✅ API Diff (from stable)
✅ API Diff (from PR only) (please review changes)
✅ Generator Diff (only version changes)
🔥 Test run failed 🔥

Test results

1 tests failed, 81 tests passed.

Failed tests

  • monotouch-test/watchOS - simulator/Debug: Crashed

@VincentDondain

Copy link
Copy Markdown
Contributor Author

@mandel-macaque @spouliot please re-review (:

@monojenkins

Copy link
Copy Markdown
Contributor

Build success
✅ Build succeeded
✅ API Diff (from stable)
✅ API Diff (from PR only) (please review changes)
✅ Generator Diff (only version changes)
✅ Test run succeeded

@spouliot spouliot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great :)
just a small change to avoid future potential pain

Comment thread tests/mtouch/ToolTasksBinPathTest.cs Outdated
[SetUp]
public void Setup ()
{
Environment.SetEnvironmentVariable ("DEVELOPER_DIR", Configuration.xcode_root);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that change the execution environment, i.e. it could affect other (existing or future) tests randomly (since the execution order is not guaranteed) and that will be hard to diagnose

To avoid this you can move this into a

var dd = getenv ("DEVELOPER_DIR");
try {
   setenv ("DEVELOPER_DIR", Configuration.xcode_root);
   xcrun (...);
}
finally {
   setenv ("DEVELOPER_DIR", dd);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could set the environment variable in the ProcessStartInfo instead, then you wouldn't need any cleanup.

Comment thread tests/mtouch/ToolTasksBinPathTest.cs Outdated
var proc = Process.Start (psi);

string output = proc.StandardOutput.ReadToEnd ();
string err = proc.StandardError.ReadToEnd ();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a large part of the above could be shared across both (likely more in the future) tests - in addition to the try/catch

@spouliot spouliot added this to the xcode10 milestone Aug 15, 2018

@rolfbjarne rolfbjarne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see you've added a test that runs xcrun, but the actual MSBuild task code still calls metal(lib) directly.

Am I missing something?

Comment thread tests/mtouch/ToolTasksBinPathTest.cs Outdated
[SetUp]
public void Setup ()
{
Environment.SetEnvironmentVariable ("DEVELOPER_DIR", Configuration.xcode_root);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you could set the environment variable in the ProcessStartInfo instead, then you wouldn't need any cleanup.

@VincentDondain

Copy link
Copy Markdown
Contributor Author

@rolfbjarne so the idea if that this PR contains the simplest fix (call updated metal/lib path) and we'll revisit all the msbuild tasks to make them all use xcrun (a bit more work). #4634

@spouliot

Copy link
Copy Markdown
Contributor

@rolfbjarne the test is just a canary in case the location changes (again) before the tasks are updated (or in case they can't be)

@monojenkins

Copy link
Copy Markdown
Contributor

Build success
✅ Build succeeded
✅ API Diff (from stable)
✅ API Diff (from PR only) (please review changes)
✅ Generator Diff (only version changes)
✅ Test run succeeded

@VincentDondain
VincentDondain merged commit c516912 into dotnet:xcode10 Aug 17, 2018
@VincentDondain
VincentDondain deleted the issue-4576 branch August 17, 2018 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants