rust icon indicating copy to clipboard operation
rust copied to clipboard

Upgrade cmake to v0.1.50

Open jfgoog opened this issue 1 year ago • 14 comments

This is the latest version. Now that the cc crate has been successfully upgraded, we should upgrade cmake as well, as v0.1.48 is now over 2 years old.

cmake v1.0.49 requires CMAKE_SYSTEM_NAME to be set when cross-compiling, so ensure that we do this for supported Apple OSes.

jfgoog avatar May 08 '24 14:05 jfgoog

r? @albertlarsan68

rustbot has assigned @albertlarsan68. They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

rustbot avatar May 08 '24 14:05 rustbot

I hope this will be much easier than cc..

@bors r+ rollup=never

onur-ozkan avatar May 08 '24 15:05 onur-ozkan

:pushpin: Commit c4135b0c0c4240c5654d64fa75e751cf9ae68c01 has been approved by onur-ozkan

It is now in the queue for this repository.

bors avatar May 08 '24 15:05 bors

:hourglass: Testing commit c4135b0c0c4240c5654d64fa75e751cf9ae68c01 with merge 4d27423712c629cee670b7eedaf3c430ca7218c4...

bors avatar May 09 '24 00:05 bors

The job dist-apple-various failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

rust-log-analyzer avatar May 09 '24 01:05 rust-log-analyzer

:broken_heart: Test failed - checks-actions

bors avatar May 09 '24 01:05 bors

This PR changes how LLVM is built. Consider updating src/bootstrap/download-ci-llvm-stamp.

rustbot avatar May 09 '24 16:05 rustbot

Try CI again?

jfgoog avatar May 13 '24 14:05 jfgoog

Try CI again?

fyi I missed the PR due to "S-waiting-on-author" label.

@bors r+

onur-ozkan avatar May 13 '24 15:05 onur-ozkan

:pushpin: Commit 474248289f914f3d144c79e1db5a620bf49b210e has been approved by onur-ozkan

It is now in the queue for this repository.

bors avatar May 13 '24 15:05 bors

:hourglass: Testing commit 474248289f914f3d144c79e1db5a620bf49b210e with merge 9f330de484197486d7cf4696b6f62a318354d665...

bors avatar May 13 '24 18:05 bors

The job dist-apple-various failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  /usr/local/Cellar/cmake/3.29.2/share/cmake/Modules/CMakeSystemSpecificInitialize.cmake:34 (include)
  CMakeLists.txt:16 (project)


-- Configuring incomplete, errors occurred!
thread 'main' panicked at /Users/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cmake-0.1.50/src/lib.rs:1098:5:
command did not execute successfully, got: exit status: 1

build script failed, must exit now
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

rust-log-analyzer avatar May 13 '24 20:05 rust-log-analyzer

:broken_heart: Test failed - checks-actions

bors avatar May 13 '24 20:05 bors

@bors rollup=never

onur-ozkan avatar May 13 '24 20:05 onur-ozkan

  • cmake v1.0.49 insists that CMAKE_SYSTEM_NAME be set when cross-compiling, and will set it if not provided by the caller.

  • cmake v1.0.50 removes a workaround to for iOS and tvos to prevent an incorrect sysroot from being used from the SDKROOT environment variable (similar to an issue we faced updating the cc crate in https://github.com/rust-lang/rust/pull/122504). The same workaround appears in src/bootstrap/src/core/build_steps/llvm.rs when building LLVM for ios, watchos, tvos, and visionos.

The result of these two changes is that when running cmake, we add "-DCMAKE_SYSTEM_NAME=iOS" and remove "-DCMAKE_OSX_SYSROOT=/" and "-DCMAKE_OSX_DEPLOYMENT_TARGET="

These two seem to interact badly with some built-in cmake logic. On my system, /usr/share/cmake-3.28/Modules/Platform/Darwin-Initialize.cmake has logic based on CMAKE_OSX_SYSROOT:

if(CMAKE_OSX_SYSROOT)
  # Use the existing value without further computation to choose a default.
  set(_CMAKE_OSX_SYSROOT_DEFAULT "${CMAKE_OSX_SYSROOT}")
elseif(NOT "x$ENV{SDKROOT}" STREQUAL "x" AND
        (NOT "x$ENV{SDKROOT}" MATCHES "/" OR IS_DIRECTORY "$ENV{SDKROOT}"))
  # Use the value of SDKROOT from the environment.
  set(_CMAKE_OSX_SYSROOT_DEFAULT "$ENV{SDKROOT}")
elseif(CMAKE_SYSTEM_NAME STREQUAL iOS)
  set(_CMAKE_OSX_SYSROOT_DEFAULT "iphoneos")
elseif(CMAKE_SYSTEM_NAME STREQUAL tvOS)
  set(_CMAKE_OSX_SYSROOT_DEFAULT "appletvos")
# etc.

Then, later on:

# Transform CMAKE_OSX_SYSROOT to absolute path
set(_CMAKE_OSX_SYSROOT_PATH "")
if(CMAKE_OSX_SYSROOT)
  if("x${CMAKE_OSX_SYSROOT}" MATCHES "/")
    # This is a path to the SDK.  Make sure it exists.
    if(NOT IS_DIRECTORY "${CMAKE_OSX_SYSROOT}")
      message(WARNING "Ignoring CMAKE_OSX_SYSROOT value:\n ${CMAKE_OSX_SYSROOT}\n"
        "because the directory does not exist.")
      set(CMAKE_OSX_SYSROOT "")
    endif()
    set(_CMAKE_OSX_SYSROOT_PATH "${CMAKE_OSX_SYSROOT}")
  else()
    _apple_resolve_sdk_path(${CMAKE_OSX_SYSROOT} _sdk_path)
    if(IS_DIRECTORY "${_sdk_path}")
      set(_CMAKE_OSX_SYSROOT_PATH "${_sdk_path}")
      # For non-Xcode generators use the path.
      if(NOT "${CMAKE_GENERATOR}" MATCHES "Xcode")
        set(CMAKE_OSX_SYSROOT "${_CMAKE_OSX_SYSROOT_PATH}")
      endif()
    endif()
  endif()
endif()

This gets triggered from /usr/share/cmake-3.28/Modules/Platform/iOS-Initialize.cmake, which begins:

include(Platform/Darwin-Initialize)

if(NOT _CMAKE_OSX_SYSROOT_PATH MATCHES "/iPhone(OS|Simulator)")
  message(FATAL_ERROR "${CMAKE_OSX_SYSROOT} is not an iOS SDK")
endif()

So what seem to be happening is

  • Setting CMAKE_SYSTEM_NAME (which cmake v1.0.49 guarantees is set) triggers the validation logic in iOS-Initialize.cmake.
  • Then, Darwin-Initialize.cmake tries to determine the SDK from CMAKE_OSX_SYSROOT, or $ENV{SDKROOT} and transform it into a path, but does so incorrectly, and the validation logic fails.

jfgoog avatar May 15 '24 16:05 jfgoog

Note to future someone: Cmake caching makes this one hard to debug. You need to blow away build/aarch64-apple-ios/native/sanitizers between builds.

jfgoog avatar May 15 '24 17:05 jfgoog

@bors r- (manually r- because the tree looks wonky with some PRs that shouldn't be elligble for rollup)

jieyouxu avatar May 26 '24 22:05 jieyouxu

@jfgoog any updates on this? thanks

Dylan-DPC avatar Aug 15 '24 18:08 Dylan-DPC

@jfgoog any updates on this? thanks

I wasn't able to get it to work, and had to move on. I think I put all the stuff I figured out in this CL, so I hope it will be useful to someone else who wants to give it a try.

jfgoog avatar Aug 15 '24 18:08 jfgoog

@Dylan-DPC Should we close PR if author is not interesting in proceeding?

alex-semenyuk avatar Sep 18 '24 15:09 alex-semenyuk

@Dylan-DPC Should we close PR if author is not interesting in proceeding?

@alex-semenyuk yes. Will close this one :)

Dylan-DPC avatar Sep 18 '24 17:09 Dylan-DPC