Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xcode-select : error : tool 'xcodebuild' requires Xcode - new error with nativeaot in .NET 9 preview 2 #100189

Closed
LLT21 opened this issue Mar 23, 2024 · 7 comments · Fixed by #100190

Comments

@LLT21
Copy link

LLT21 commented Mar 23, 2024

With the following project file settings:

    <TargetFramework>net9.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <PublishAot>true</PublishAot>
    <RuntimeIdentifier>osx-arm64</RuntimeIdentifier>

when publishing in release mode, I receive the following errors on my Mac M1 with .NET 9 preview 2, which I do not have with previous versions:

Restore complete (0,3s)
You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy
  lib2 failed with errors (0,3s) → bin/release/net9.0/osx-arm64/lib2.dll
    xcode-select : error : tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance [/Users/llt/Projects/dotnetoni/libs/lib2/lib2.csproj]
    /Users/llt/.nuget/packages/microsoft.dotnet.ilcompiler/9.0.0-preview.2.24128.5/build/Microsoft.NETCore.Native.Unix.targets(243,24): error MSB4086: A numeric comparison was attempted on "$(_XcodeVersion)" that evaluates to "" instead of a number, in condition "'$(_XcodeVersion)' >= '15'". [/Users/llt/Projects/dotnetoni/libs/lib2/lib2.csproj]

Build failed with errors in 0,8s
Copy link
Contributor

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Mar 23, 2024
@jkotas
Copy link
Member

jkotas commented Mar 23, 2024

@LLT21 Please check https://stackoverflow.com/questions/55939354/tool-xcodebuild-requires-xcode-but-active-developer-directory-library-devel for how to work around this issue for now.

This is regression from #97856 / #98726 . cc @VSadov @filipnavara

Can we check e.g. clang --version to avoid depending on command-line tools being configured for XCode?

@filipnavara
Copy link
Member

filipnavara commented Mar 23, 2024

I'm not sure if the same regex works for the build version of other tools.

For reference, on my machine:

> xcodebuild -version
Xcode 15.2
Build version 15C500b
> clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Applications/Xcode-15.2.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> ld -v      
@(#)PROGRAM:ld  PROJECT:dyld-1022.1
BUILD 05:27:37 Dec  7 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.8)
Library search paths:
Framework search paths:
> xcrun --show-sdk-version
14.2
> xcrun --show-sdk-build-version
23C53
> xcrun --show-sdk-platform-version
14.2

The clang version only loosely correlates to the Xcode version, so it's not perfect. We'd lose the ability to enable the new ld64 on minor Xcode release, at very least.

Xamarin also has a similar check, so we should double check what they are doing.

@filipnavara
Copy link
Member

filipnavara commented Mar 23, 2024

Xamarin also has a similar check, so we should double check what they are doing.

https://github.com/xamarin/xamarin-macios/blob/a150c6068c1b5659af4f0b7217bdf572c1e213b4/dotnet/targets/Xamarin.Shared.Sdk.targets#L1599-L1601
https://github.com/xamarin/xamarin-macios/blob/a150c6068c1b5659af4f0b7217bdf572c1e213b4/msbuild/Xamarin.MacDev.Tasks/Tasks/DetectSdkLocationCore.cs#L210
I don't see where AppleSdkSettings is coming from... (and not at my computer at the moment to do proper search)
...and AppleSdkSettings here, which gets too complicated:
https://github.com/xamarin/Xamarin.MacDev/blob/main/Xamarin.MacDev/AppleSdkSettings.cs

@filipnavara
Copy link
Member

For reference, on the same machine with just command line tools installed:

> xcodebuild -version
xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance
> clang --version
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.3.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
> ld -v  
@(#)PROGRAM:ld  PROJECT:dyld-1022.1
BUILD 13:21:42 Nov 10 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.8)
Library search paths:
Framework search paths:
> xcrun --show-sdk-version
14.2
> xcrun --show-sdk-build-version
23C53
> xcrun --show-sdk-platform-version
14.2
> pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 15.1.0.0.1.1700200546
volume: /
location: /
install-time: 1707554069

@jkotas
Copy link
Member

jkotas commented Mar 23, 2024

the same regex works for the build version of other tools.

The regex picks up the first number that it sees in the output. As far as I can tell, it works for the clang output just fine.

We'd lose the ability to enable the new ld64 on minor Xcode release, at very least.

We just need something simple that works out-of-the-box for the common cases. The logic does not need to be perfect. In case we need to do something extra for minor xcode releases in future, we can deal with once it shows up.

@LLT21
Copy link
Author

LLT21 commented Mar 23, 2024

For your information: on my MacBook Air M1 I do not have Xcode installed, only the command line tools. This because it only has 256GB and Xcode is pretty big. Up to now this worked fine up to .NET 9 preview 1 for NativeAOT compilation of asp.net applications.

@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label Mar 24, 2024
jkotas added a commit that referenced this issue Apr 4, 2024
Fixes #100189

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
@github-actions github-actions bot locked and limited conversation to collaborators Apr 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants