Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[lldb][cmake] Set CMAKE_OSX_SYSROOT when building debugserver with CMake 4 #138020

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

Merged
merged 1 commit into from
May 14, 2025

Conversation

chelcassanova
Copy link
Contributor

CMake 4 no longer sets the CMAKE_OSX_SYSROOT variable by default. If you've updated to CMake 4 on macOS (e.g. with brew) and try building LLDB with CMake/ninja, this will yield an error when building debugserver that clang is unable to run since it tries to compile files that don't exist.

These files are supposed to be generated by the mig process. mig needs the CMAKE_OSX_SYSROOT variable in order to work and without it, it silently fails to generate the files that later on need to be compiled.

This commit will fatal error out of config when building debugserver without having set CMAKE_OSX_SYSROOT.

@llvmbot
Copy link
Member

llvmbot commented Apr 30, 2025

@llvm/pr-subscribers-lldb

Author: Chelsea Cassanova (chelcassanova)

Changes

CMake 4 no longer sets the CMAKE_OSX_SYSROOT variable by default. If you've updated to CMake 4 on macOS (e.g. with brew) and try building LLDB with CMake/ninja, this will yield an error when building debugserver that clang is unable to run since it tries to compile files that don't exist.

These files are supposed to be generated by the mig process. mig needs the CMAKE_OSX_SYSROOT variable in order to work and without it, it silently fails to generate the files that later on need to be compiled.

This commit will fatal error out of config when building debugserver without having set CMAKE_OSX_SYSROOT.


Full diff: https://github.com/llvm/llvm-project/pull/138020.diff

1 Files Affected:

  • (modified) lldb/tools/debugserver/source/CMakeLists.txt (+4)
diff --git a/lldb/tools/debugserver/source/CMakeLists.txt b/lldb/tools/debugserver/source/CMakeLists.txt
index 1a433898f6aa4..45b16c74f5197 100644
--- a/lldb/tools/debugserver/source/CMakeLists.txt
+++ b/lldb/tools/debugserver/source/CMakeLists.txt
@@ -154,6 +154,10 @@ endif()
 
 add_definitions(-DLLDB_USE_OS_LOG)
 
+if(NOT CMAKE_OSX_SYSROOT)
+  message(FATAL_ERROR "debugserver needs the macOS SDK root. Please pass in -DCMAKE_OSX_SYSROOT in your CMake invocation")
+endif()
+
 if(${CMAKE_OSX_SYSROOT} MATCHES ".Internal.sdk$")
   message(STATUS "LLDB debugserver energy support is enabled")
   add_definitions(-DLLDB_ENERGY)

@medismailben
Copy link
Member

Shouldn't we just pre-populate that cmake variable when it's not set ? That would be a better user experience.

@chelcassanova chelcassanova force-pushed the fix-cmake4-macos-build branch from df5306b to 4e7c209 Compare April 30, 2025 22:03
@chelcassanova
Copy link
Contributor Author

Just updated the patch to set the CMAKE_OSX_SYSROOT variable.

@chelcassanova chelcassanova changed the title [lldb][cmake] Error out when building debugserver with CMake 4 [lldb][cmake] Set CMAKRE_OSX_SYSROOT when building debugserver with CMake 4 Apr 30, 2025
@chelcassanova chelcassanova changed the title [lldb][cmake] Set CMAKRE_OSX_SYSROOT when building debugserver with CMake 4 [lldb][cmake] Set CMAKE_OSX_SYSROOT when building debugserver with CMake 4 May 1, 2025
Comment on lines 157 to 170
if(NOT CMAKE_OSX_SYSROOT)
execute_process(COMMAND xcodebuild -version -sdk macosx Path
OUTPUT_VARIABLE SDKROOT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)

if(NOT EXISTS ${SDKROOT})
message(FATAL_ERROR "Unable to obtain macOS SDK root, debugserver cannot be built.")
endif()

message(STATUS "Using macOS SDK root: ${SDKROOT}")
set(CMAKE_OSX_SYSROOT ${SDKROOT})
endif()
Copy link
Member

@JDevlieghere JDevlieghere May 1, 2025

Choose a reason for hiding this comment

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

I don't think we should try to compute CMAKE_OSX_SYSROOT ourselves. If we need an -isysroot for the mig invocation, it's fine to compute it, but we shouldn't reuse CMAKE_OSX_SYSROOT for that. The documentation also says that it should be set before the project() call (i.e. you're not supposed to compute it).

Here's what I think we should do instead:

if (CMAKE_OSX_SYSROOT)
  set(MIG_SYSROOT ${CMAKE_OSX_SYSROOT})
else() 
  # Set the sysroot based on the output of `xcrun --show-sdk-path`
endif()

And then the mig invocation should use ${MIG_SYSROOT} instead of ${CMAKE_OSX_SYSROOT}.

xcrun is the usual way to get the SDK path and by not specifying the SDK, it will honor the usual ways of changing the SDK (which matters to us internally).

Copy link
Contributor Author

@chelcassanova chelcassanova May 1, 2025

Choose a reason for hiding this comment

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

The documentation also says that it should be set before the project()

Ah, I wasn't aware of that. In that case then I can update this to use a local variable instead of messing with the CMake variable itself.

Though I do also have a question. If CMake no longer computes this value and we're not computing it ourselves, is this now Clang's responsibility? The CMake 4 release notes note that Instead, compilers are expected to choose a default macOS SDK on their own so I guess it is?

Either way, we can get the path we need from xcrun as you said.

@chelcassanova chelcassanova force-pushed the fix-cmake4-macos-build branch from 4e7c209 to 350648f Compare May 1, 2025 21:31
@@ -154,6 +154,19 @@ endif()

add_definitions(-DLLDB_USE_OS_LOG)

if(CMAKE_OSX_SYSROOT)
set(${MIG_SYSROOT} CMAKE_OSX_SYSROOT)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be set(MIG_SYSROOT ${CMAKE_OSX_SYSROOT})? Does this work as-is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, this doesn't work as-is. I'll update to correct this.

@chelcassanova chelcassanova force-pushed the fix-cmake4-macos-build branch from 350648f to 6a100fa Compare May 2, 2025 19:35
lum1n0us added a commit to lum1n0us/wasm-micro-runtime that referenced this pull request May 13, 2025
CMake 4 no longer sets the CMAKE_OSX_SYSROOT variable by default, causing the
lldb build to fail after all GitHub-hosted runners have been upgraded to
CMake 4.

As a workaround, the variable is set using CMake command line options. There
is a PR to fix this issue in the llvm-project:
llvm/llvm-project#138020. We might want to remove
this workaround after that PR has been merged.
lum1n0us added a commit to bytecodealliance/wasm-micro-runtime that referenced this pull request May 14, 2025
CMake 4 no longer sets the CMAKE_OSX_SYSROOT variable by default, causing the
lldb build to fail after all GitHub-hosted runners have been upgraded to
CMake 4.

As a workaround, the variable is set using CMake command line options. There
is a PR to fix this issue in the llvm-project:
llvm/llvm-project#138020. We might want to remove
this workaround after that PR has been merged.
@chelcassanova
Copy link
Contributor Author

@bulbazord @JDevlieghere Is it possible to take another pass over at this? I think this should be good to land now.

Copy link
Member

@JDevlieghere JDevlieghere left a comment

Choose a reason for hiding this comment

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

LGTM modulo wording.

endif()

if(NOT MIG_SYSROOT)
message(FATAL_ERROR "Unable to obtain macOS SDK root, debugserver cannot be built.")
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this more specific and actionable.

Suggested change
message(FATAL_ERROR "Unable to obtain macOS SDK root, debugserver cannot be built.")
message(FATAL_ERROR "Unable to obtain sysroot required by mig (Mach Interface Generator). Set CMAKE_OSX_SYSROOT to explicitly specify a sysroot.")

CMake 4 no longer sets the `CMAKE_OSX_SYSROOT` variable by default. If
you've updated to CMake 4 on macOS (e.g. with brew) and try building LLDB with
CMake/ninja, this will yield an error when building debugserver that
clang is unable to run since it tries to compile files that don't exist.

These files are supposed to be generated by the `mig` process. `mig`
needs the `CMAKE_OSX_SYSROOT` variable in order to work and without it,
it silently fails to generate the files that later on need to be
compiled.

This commit sets this SDK path for mig and will fatal error out of config
when building debugserver without having set CMAKE_OSX_SYSROOT.
@chelcassanova chelcassanova force-pushed the fix-cmake4-macos-build branch from 6a100fa to f6f7c91 Compare May 14, 2025 17:31
@chelcassanova chelcassanova merged commit 28d732a into llvm:main May 14, 2025
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.