Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

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.

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 350648f to 6a100fa Compare May 2, 2025 19:35
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