Skip to content

Conversation

@justice-adams-apple
Copy link
Contributor

Add FindSwiftPlatformOverlay module responsible for finding the platform overlays for the supplemental libraries

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#ToDo: Handle the static MUSL SDK case
#TODO(swiftlang/swift#????): Handle the static MUSL SDK case

Can you fill in an issue identifier that has the context on what exactly needs to be done here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 197 to 215
Copy link
Member

Choose a reason for hiding this comment

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

Seems like a generator expression should allow us to fold the two branches into one:

list(APPEND swiftAndroid_INCLUDE_DIR_HINTS
  "${Swift_SDKROOT}/usr/lib/swift$<$<BOOL:${SwiftPlatformOverlay_USE_STATIC_LIBS}>:_static>/swift/android
  ...

Copy link
Member

@etcwilde etcwilde Jul 8, 2025

Choose a reason for hiding this comment

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

I don't believe that find_library or find_path accept generator expressions as its HINTS since it's run well before the is instantiated.

It turns out that find_library does actually grab a pointer to the global generator from the makefile, so I learned something new today.

cmFindLibraryHelper::cmFindLibraryHelper(cmMakefile* mf,
                                         cmFindBase const* base,
                                         cmFindCommonDebugState* debugState)
  : Makefile(mf)
  , FindBase(base)
  , DebugState(debugState)
{
  this->GG = this->Makefile->GetGlobalGenerator();

  // Collect the list of library name prefixes/suffixes to try.
  std::string const& prefixes_list = get_prefixes(this->Makefile);
  std::string const& suffixes_list = get_suffixes(this->Makefile);

  this->Prefixes.assign(prefixes_list, cmList::EmptyElements::Yes);
  this->Suffixes.assign(suffixes_list, cmList::EmptyElements::Yes);
  this->RegexFromList(this->PrefixRegexStr, this->Prefixes,
                      cmSystemTools::DirCase::Sensitive);
  this->RegexFromList(this->ICasePrefixRegexStr, this->Prefixes,
                      cmSystemTools::DirCase::Insensitive);
  this->RegexFromList(this->SuffixRegexStr, this->Suffixes,
                      cmSystemTools::DirCase::Sensitive);
  this->RegexFromList(this->ICaseSuffixRegexStr, this->Suffixes,
                      cmSystemTools::DirCase::Insensitive);

  // Check whether to use OpenBSD-style library version comparisons.
  this->IsOpenBSD = this->Makefile->GetState()->GetGlobalPropertyAsBool(
    "FIND_LIBRARY_USE_OPENBSD_VERSIONING");
}

That's so that it can call cmGlobalGenerator::GetDirectoryContent, but I don't see it calling cmGeneratorExpression::Expand anywhere in the evaluation.

Copy link
Member

Choose a reason for hiding this comment

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

What is this? The project name is SwiftOverlay:

https://github.com/swiftlang/swift/blob/9ae27d7a2fe547768c1637ecc06791f63f55aa61/Runtimes/Overlay/CMakeLists.txt#L30C1-L30C21

This will need to align with the Find-module name, (SwiftPlatformOverlay). This will be consistent across all of the platforms.

We should be able to move this bit to the top of the file just like with FindSwiftCore.cmake.

if(SwiftPlatformOverlay_DIR)
  if(SwiftPlatformOverlay_FIND_REQUIRED)
    list(APPEND args REQUIRED)
  endif()
  if(SwiftPlatformOverlay_FIND_QUIETLY)
    list(APPEND args QUIET)
  endif()
  find_package(SwiftPlatformOverlay CONFIG ${args})
  return()
endif()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I renamed the package to FindSwiftOverlay and moved the check for SwiftOverlay_Dir to the top of the module

Copy link
Member

Choose a reason for hiding this comment

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

This is part of the platform overlay package. This should be exported by the SwiftPlatformOverlay module.

@justice-adams-apple
Copy link
Contributor Author

@swift-ci smoke test

@justice-adams-apple
Copy link
Contributor Author

@swift-ci smoke test macOS

endif()

if(SwiftOverlay_DIR)
find_package(SwiftOverlay CONFIG)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it still makes sense to propagate of the QUIET and REQUIRED keywords like find_dependency does (since find_package does not do that, at least from a quick skim of the source code)

Suggested change
find_package(SwiftOverlay CONFIG)
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED)
list(APPEND args REQUIRED)
endif()
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY)
list(APPEND args QUIET)
endif()
find_package(SwiftOverlay CONFIG ${args})

Comment on lines 75 to 76
include(FindPackageHandleStandardArgs)
include(PlatformInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Nitpick) I would suggest to move this after if(SwiftOverlay_DIR), so it matches the structure of FindSwiftCore (and we avoid loading those modules if we have a config file)

Comment on lines 110 to 79
# If the swiftGlibc_DIR_FLAG is specified, look there instead. The cmake-generated
# config file is more accurate
if(swiftGlibc_DIR)
if(swiftGlibc_FIND_REQUIRED)
list(APPEND args REQUIRED)
endif()
if(swiftGlibc_FIND_QUIETLY)
list(APPEND args QUIET)
endif()
find_package(swiftGlibc NO_MODULE ${args})
# Look in the SDK
else()
Copy link
Contributor

@edymtt edymtt Jul 21, 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 this is needed -- I expect swiftGlibc to be exported as part of the Overlay build system, so the call to find_package(SwiftOverlay ...) should take care of this.

Suggested change
# If the swiftGlibc_DIR_FLAG is specified, look there instead. The cmake-generated
# config file is more accurate
if(swiftGlibc_DIR)
if(swiftGlibc_FIND_REQUIRED)
list(APPEND args REQUIRED)
endif()
if(swiftGlibc_FIND_QUIETLY)
list(APPEND args QUIET)
endif()
find_package(swiftGlibc NO_MODULE ${args})
# Look in the SDK
else()

(the matching endif() should be deleted as well)

"${Swift_SDKROOT}/usr/lib/swift"
"$ENV{SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}"
"$ENV{SDKROOT}/usr/lib/swift")
list(APPEND swiftCRT_NAMES swiftCRT.lib)
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to change the name whether we are looking for dynamic or static libraries
(please double check with what we did for FindSwiftCore)

Suggested change
list(APPEND swiftCRT_NAMES swiftCRT.lib)
if(SwiftOverlay_USE_STATIC_LIBS)
list(APPEND swiftCRT_NAMES libswiftCRT.lib)
else()
list(APPEND swiftCRT_NAMES swiftCRT.lib)
endif()

"${Swift_SDKROOT}/usr/lib/swift"
"$ENV{SDKROOT}/usr/lib/swift/${${PROJECT_NAME}_PLATFORM_SUBDIR}/${${PROJECT_NAME}_ARCH_SUBDIR}"
"$ENV{SDKROOT}/usr/lib/swift")
list(APPEND swiftWinSDK_NAMES swiftWinSDK.lib)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same feedback as swiftCRT

@justice-adams-apple justice-adams-apple force-pushed the jadams/add-find-platform-overlay branch from 4a02999 to 0cb933a Compare July 22, 2025 21:32
@justice-adams-apple
Copy link
Contributor Author

@swift-ci smoke test macOS

@justice-adams-apple
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Contributor

@edymtt edymtt left a comment

Choose a reason for hiding this comment

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

Looks good to me -- of all my comments, the only important one before merging is about lines 144-148

FindSwiftOverlay
------------

Find SwiftOverlay, deferring to the associated <Overlay>Config.cmake when requested.
Copy link
Contributor

Choose a reason for hiding this comment

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

(Can be done in a follow up PR) At the moment we can defer only to the config file for the SwiftOverlay project

Suggested change
Find SwiftOverlay, deferring to the associated <Overlay>Config.cmake when requested.
Find SwiftOverlay, deferring to the associated SwiftOverlayConfig.cmake when requested.

This affects Linux, Android, and Windows builds.
Apple builds always use the overlay provided by the SDK.

Result Variables
Copy link
Contributor

Choose a reason for hiding this comment

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

(Can be done in a follow up PR) This section refers to variables that are not considered (swiftDarwin_DIR et al) or not set by find_package  and our search logic (swiftDarwin_DIR_FOUND et all)

The section would need to either be reworked, or possibly removed all together (to nudge users toward using the target)

Comment on lines 144 to 104
if(SwiftOverlay_USE_STATIC_LIBS)
list(APPEND swiftCRT_NAMES libswiftWinSDK.lib)
else()
list(APPEND swiftCRT_NAMES swiftWinSDK.lib)
endif()
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of the variable does not match the overlay we are searching

Suggested change
if(SwiftOverlay_USE_STATIC_LIBS)
list(APPEND swiftCRT_NAMES libswiftWinSDK.lib)
else()
list(APPEND swiftCRT_NAMES swiftWinSDK.lib)
endif()
if(SwiftOverlay_USE_STATIC_LIBS)
list(APPEND swiftWinSDK_NAMES libswiftWinSDK.lib)
else()
list(APPEND swiftWinSDK_NAMES swiftWinSDK.lib)
endif()

Comment on lines 193 to 194
" Build the Overlays for your platform and set the appropriate `<OverlayTarget>_DIR` variable to"
" the directory containing <OverlayTarget>Config.cmake\n")
Copy link
Contributor

Choose a reason for hiding this comment

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

(Can be done in a later PR) I believe we want to suggest the SwiftOverlay project is the place to build additional overlays

Suggested change
" Build the Overlays for your platform and set the appropriate `<OverlayTarget>_DIR` variable to"
" the directory containing <OverlayTarget>Config.cmake\n")
" Build the Overlays for your platform and set the appropriate `SwiftOverlay_DIR` variable to"
" the directory containing SwiftOverlayConfig.cmake\n")


# Setup SwiftOverlay interface library and link it against the explicit
# overlay targets
add_library(SwiftOverlay INTERFACE)
Copy link
Contributor

Choose a reason for hiding this comment

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

(Can be done in a follow up PR) I would use the same camel case convention we use for the other targets -- that is, start the name with a lower case letter

Suggested change
add_library(SwiftOverlay INTERFACE)
add_library(swiftOverlay INTERFACE)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@edymtt I' would probably tackle this in a another PR, but a bit confused, I see the target in the Overlay project is called SwiftOverlay and the FindSwiftCore defines SwiftCore so I was going off that. Might be overlooking something

@justice-adams-apple justice-adams-apple force-pushed the jadams/add-find-platform-overlay branch from 0cb933a to 86821e4 Compare July 30, 2025 20:08
@justice-adams-apple
Copy link
Contributor Author

@swift-ci smoke test

@justice-adams-apple justice-adams-apple merged commit 573607f into main Aug 4, 2025
3 checks passed
@justice-adams-apple justice-adams-apple deleted the jadams/add-find-platform-overlay branch August 4, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants