rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.81k stars 434 forks source link

Console output is full of `xcrun: error: unable to lookup item 'PlatformVersion' from command line tools installation` #1001

Closed Zalathar closed 5 months ago

Zalathar commented 6 months ago

After rust-lang/rust updated cc from 1.0.79 to 1.0.90 (https://github.com/rust-lang/rust/pull/119199), I started seeing several copies of this message appearing on my console during a build:

warning: profiler_builtins@0.0.0: xcrun: error: unable to lookup item 'PlatformVersion' from command line tools installation
warning: profiler_builtins@0.0.0: xcrun: error: unable to lookup item 'PlatformVersion' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

warning: rustc_llvm@0.0.0: xcrun: error: unable to lookup item 'PlatformVersion' from command line tools installation
warning: rustc_llvm@0.0.0: xcrun: error: unable to lookup item 'PlatformVersion' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

My build still seems to work just fine, so I'm trying to figure out the appropriate way to resolve these annoying console messages.

It seems that the changes made in #943 don't interact nicely with macOS systems that have the command-line developer tools installed, but don't have a full Xcode installation.

NobodyXu commented 6 months ago

I seem to have the same warnings on my macOS, which also don't have the full xcode installed

cc @BlackHoleFox

Zalathar commented 6 months ago

For reference, the xcrun message is the same as what I would get when running this command manually:

$ xcrun --show-sdk-platform-version
xcrun: error: unable to lookup item 'PlatformVersion' from command line tools installation
xcrun: error: unable to lookup item 'PlatformVersion' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk'

For whatever reason, the --show-sdk-platform-version flag doesn't work with Apple's own CommandLineTools.

BlackHoleFox commented 6 months ago

@Zalathar xcrun --show-sdk-path works still with the CommandLineTools right?

Also would you mind confirming /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/SDKSettings.json exists in your installation? Its been ages since I haven't had the full XCode installed.

@NobodyXu This will get fixed by the patch I'm working on that will handle #963 too.

Zalathar commented 6 months ago

Yes, --show-sdk-path, --show-sdk-version, and --show-sdk-build-version all work fine with CommandLineTools.

It's only --show-sdk-platform-path and --show-sdk-platform-version that are broken.

Zalathar commented 6 months ago

And yes, /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/SDKSettings.json exists and seems to be full of information.

BlackHoleFox commented 6 months ago

Those ended platform flags up not being what I thought they were (shocker, a poorly documented command line flag was deceptive!) so I'm removing their usage soon. The new changeset will just read from the SDK's JSON file (thanks for confirming its there for you) to get the data it needs. This is exactly what clang does so hopefully the weird issues go away.

ToufeeqP commented 5 months ago

This issue was not there until version 1.0.83, I switched back to 1.0.83 from 1.0.90 and it works.

eliezhao commented 5 months ago

I encountered a similar issue: cargo:warning=xcrun: error: unable to lookup item 'PlatformVersion' from command line tools installation cargo:warning=xcrun: error: unable to lookup item 'PlatformVersion' in SDK '/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk' cargo:warning=macOS deployment target (10.7) too low, it will be increase My Mac information: ProductName: macOS ProductVersion: 14.4.1 BuildVersion: 23E22

This error message showed that xcrun could not find the version number. After finding the answer in a post on Stack Overflow, and install the Xcode APP Finally, I solved the problem by downloading the Xcode application and successfully compiled librocksdb-sys. Hope this helps you.

ritalin commented 5 months ago

I've occured on building duckdb-rs.

In this case, setting MACOSX_DEPLOYMENT_TARGET environment variable led to work around this problem.

export MACOSX_DEPLOYMENT_TARGET=10.11
cargo run
steezeburger commented 4 months ago

MACOSX_DEPLOYMENT_TARGET=14.4.1 cargo build ... was a workaround for me