This is an archive of the discontinued LLVM Phabricator instance.

[compiler-rt][macOS]: Disable iOS support if iOS SDK is not found
ClosedPublic

Authored by thieta on Sep 4 2022, 7:31 AM.

Details

Summary

If you are missing the iOS SDK on your macOS (for example you don't have
full Xcode but just CommandLineTools) then CMake currently errors
out without a helpful message. This patch disables iOS support in
compiler-rt if the iOS SDK is not found. This can be overriden by
passing -DCOMPILER_RT_ENABLE_IOS=ON.

Diff Detail

Event Timeline

thieta created this revision.Sep 4 2022, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 4 2022, 7:31 AM
thieta requested review of this revision.Sep 4 2022, 7:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 4 2022, 7:31 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript
thieta updated this revision to Diff 457858.Sep 4 2022, 7:33 AM

Removed whitespaces

delcypher requested changes to this revision.Sep 4 2022, 8:04 AM

I don't think this is the right fix. Having a broken SDK setup is a real problem that should not be hidden by changing this to a warning.

As the original issue notes you can configure with -DCOMPILER_RT_ENABLE_IOS=OFF to explicitly not build compiler-rt for iOS.

If you wanted this to be more automatic then the right fix would be to compute the default for COMPILER_RT_ENABLE_IOS to be ON if the iOS SDK is present and OFF if it is not. So roughly something like

find_darwin_sdk_dir(has_ios_sdk ios)
if ("${has_ios_sdk}" STREQUAL "")
  set(COMPILER_RT_ENABLE_IOS_DEFAULT OFF)
else()
  set(COMPILER_RT_ENABLE_IOS_DEFAULT ON)
endif()

option(COMPILER_RT_ENABLE_IOS "Enable building for iOS" "${COMPILER_RT_ENABLE_IOS_DEFAULT}")

Doing it this way means that

  • by default if there's no iOS SDK then the iOS compiler-rt build will be disabled
  • if COMPILER_RT_ENABLE_IOS=ON is explicitly provided and there's no iOS SDK when we will still fail the build which is desirable.
  • if COMPILER_RT_ENABLE_IOS=OFF is explicitly provided and there's an iOS SDK available then we will respect the explicit request to not build compiler-rt for iOS
This revision now requires changes to proceed.Sep 4 2022, 8:04 AM

@yln @kubamracek @thetruestblue @rsundahl @wrotki Adding you as reviewers as I don't work on the Sanitizers much anymore.

keith added a subscriber: keith.Sep 4 2022, 8:15 AM
wrotki added a comment.Sep 6 2022, 2:18 PM

+1 to delcypher's suggestion

thieta updated this revision to Diff 495093.Feb 6 2023, 5:14 AM

Addressed comments

thieta added a comment.Feb 6 2023, 5:16 AM

A long time later, I finally got time to test this since it was marked as necessary to fix before 16.x release.

I tested this with both command line tools and xcode and it behaves correctly as far as I can figure out.

delcypher requested changes to this revision.Feb 6 2023, 12:22 PM

@thieta Thanks for working on this. I don't think can land as is because I'm not convinced this works correctly. Please see my comments.

compiler-rt/cmake/base-config-ix.cmake
154

What is this ${DEFAULT} variable? Shouldn't this just be:

set(COMPILER_RT_ENABLE_IOS_DEFAULT ON)

?

158

Should this be

option(COMPILER_RT_ENABLE_IOS_DEFAULT "Enable building for iOS" ${COMPILER_RT_ENABLE_IOS_DEFAULT})

?

I.e.: Explicitly expand the variable?

Although if() will implicitly expand variables as noted here I'm not aware of such a behavior for option(). Even if this was supported I think we should explicitly expand the variables as is done elsewhere in this source file.

This revision now requires changes to proceed.Feb 6 2023, 12:22 PM

Whoops. Bad copy and paste job. I first made it into a macro and did it for all three SDKs and then realised watchos and tvos is off by default and don't need that probing. Then I probably messed it up when removing the macro. Pretty sure I tested it in this form though ... hmm. Anyway I agree with your comments and will address and retest it tomorrow.

Thanks @delcypher for reviewing. Thanks @thieta for the work -- I'll keep an eye out for the updated diff, @delcypher doesn't work on Sanitizers as much anymore.

thieta updated this revision to Diff 495393.Feb 6 2023, 11:22 PM

Addressed comments

thieta marked 2 inline comments as done.Feb 6 2023, 11:23 PM

I fixed the obvious errors and re-testing it and it seems to behave correctly now. Sorry for the noise.

thetruestblue accepted this revision.Feb 7 2023, 9:54 AM

Nit: When you land this will you update commit message to reflect the new change?

This LGTM with the most recent changes. One additional Nit inline.

compiler-rt/cmake/base-config-ix.cmake
156

Nit: I'm wondering if there is any concern about this being a silent failure if there is no iOS SDK unexpectedly, as now we explicitly need to set COMPILER_RT_ENABLE_IOS=ON to catch a missing iOS SDK. Which is a change of behavior, correct?

Is it worth adding a compiler message or warning similar to the messages printed when looking for macosx sdk above to call out the change in what was previously "default".

message(WARNING "No iOS SDK found. Building for iOS not enabled.")

Seems like an inconvenient warning in the the small subset of cases where there is no iOS SDK, but could save a headache if there's an unexpectedly missing SDK.

thieta updated this revision to Diff 495626.Feb 7 2023, 1:04 PM

Added warning when the iOS sdk is not found.
Reworded the commit message to reflect the current state of the patch

thieta marked an inline comment as done.Feb 7 2023, 1:04 PM
thieta added inline comments.
compiler-rt/cmake/base-config-ix.cmake
156

Seems like a warning might be good here. I'll add one.

thieta retitled this revision from [compiler-rt][macOS]: Fix building compiler-rt without iOS related SDKs to [compiler-rt][macOS]: Disable iOS support if iOS SDK is not found.Feb 7 2023, 1:05 PM
thieta edited the summary of this revision. (Show Details)
delcypher accepted this revision.Feb 7 2023, 4:30 PM

LGTM. Thanks for addressing my comments.

This revision is now accepted and ready to land.Feb 7 2023, 4:30 PM
This revision was automatically updated to reflect the committed changes.
thieta marked an inline comment as done.