-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Runtimes][CMake] Build Differentiation in new style. #81239
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,96 @@ | ||||||
cmake_minimum_required(VERSION 3.29) | ||||||
|
||||||
if($ENV{BUILD_NUMBER}) | ||||||
math(EXPR BUILD_NUMBER "$ENV{BUILD_NUMBER} % 65535") | ||||||
set(BUILD_NUMBER ".${BUILD_NUMBER}") | ||||||
endif() | ||||||
project(SwiftDifferentiation | ||||||
LANGUAGES Swift C | ||||||
VERSION 6.1.0${BUILD_NUMBER}) | ||||||
|
||||||
set(CMAKE_POSITION_INDEPENDENT_CODE YES) | ||||||
set(CMAKE_Swift_LANGUAGE_VERSION 5) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we set the language version for the other libraries? |
||||||
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../cmake/modules") | ||||||
|
||||||
if(NOT PROJECT_IS_TOP_LEVEL) | ||||||
message(SEND_ERROR "Swift Differentiation must build as a standalone project") | ||||||
endif() | ||||||
|
||||||
set(${PROJECT_NAME}_SWIFTC_SOURCE_DIR | ||||||
"${PROJECT_SOURCE_DIR}/../../../" | ||||||
CACHE FILEPATH "Path to the root source directory of the Swift compiler") | ||||||
|
||||||
find_package(SwiftCore) | ||||||
find_package(SwiftMath) | ||||||
|
||||||
include(gyb) | ||||||
sookach marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
include(AvailabilityMacros) | ||||||
include(CatalystSupport) | ||||||
include(EmitSwiftInterface) | ||||||
include(ResourceEmbedding) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We also need
|
||||||
|
||||||
option(${PROJECT_NAME}_ENABLE_VECTOR_TYPES "Enable vector support" | ||||||
${SwiftCore_ENABLE_VECTOR_TYPES}) | ||||||
|
||||||
option(${PROJECT_NAME}_ENABLE_LIBRARY_EVOLUTION "Enable library evolution" | ||||||
${SwiftCore_ENABLE_LIBRARY_EVOLUTION}) | ||||||
|
||||||
add_compile_options( | ||||||
$<$<COMPILE_LANGUAGE:Swift>:-explicit-module-build> | ||||||
$<$<COMPILE_LANGUAGE:Swift>:-nostdlibimport> | ||||||
$<$<COMPILE_LANGUAGE:Swift>:-parse-stdlib> | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-library-level api>" | ||||||
$<$<COMPILE_LANGUAGE:Swift>:-enforce-exclusivity=unchecked> | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-target-min-inlining-version min>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NoncopyableGenerics2>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SuppressedAssociatedTypes>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature SE427NoInferenceOnExtension>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature NonescapableTypes>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature LifetimeDependence>" | ||||||
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-experimental-feature MemberImportVisibility>" | ||||||
$<$<AND:$<BOOL:${SwiftDifferentiation_ENABLE_LIBRARY_EVOLUTION}>,$<COMPILE_LANGUAGE:Swift>>:-enable-library-evolution>) | ||||||
|
||||||
if(SwiftDifferentiation_ENABLE_VECTOR_TYPES) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably put the sources under a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I understand correctly your point -- are you suggesting to have a directory structure in which the sources are not mingled with the CMake code? For example
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You would still have the intermingled CMakeLists.txt, but the idea is that we could have the same structure across all the libraries. I think that @etcwilde suggested that we do that subsequently, which I am fine with. |
||||||
gyb_expand(SIMDDifferentiation.swift.gyb SIMDDifferentiation.swift) | ||||||
endif() | ||||||
gyb_expand(TgmathDerivatives.swift.gyb TgmathDerivatives.swift) | ||||||
gyb_expand(FloatingPointDifferentiation.swift.gyb | ||||||
FloatingPointDifferentiation.swift) | ||||||
|
||||||
add_library(swift_Differentiation | ||||||
AnyDifferentiable.swift | ||||||
ArrayDifferentiation.swift | ||||||
Differentiable.swift | ||||||
DifferentialOperators.swift | ||||||
DifferentiationUtilities.swift | ||||||
OptionalDifferentiation.swift | ||||||
$<$<BOOL:${SwiftDifferentiation_ENABLE_VECTOR_TYPES}>:SIMDDifferentiation.swift> | ||||||
TgmathDerivatives.swift | ||||||
FloatingPointDifferentiation.swift | ||||||
linker-support/magic-symbols-for-install-name.c) | ||||||
|
||||||
set_target_properties(swift_Differentiation PROPERTIES | ||||||
Swift_MODULE_NAME _Differentiation) | ||||||
|
||||||
if(APPLE AND BUILD_SHARED_LIBS) | ||||||
target_link_options(swift_Differentiation PRIVATE "SHELL:-Xlinker -headerpad_max_install_names") | ||||||
endif() | ||||||
|
||||||
target_link_libraries(swift_Differentiation PRIVATE swiftCore SwiftMath) | ||||||
|
||||||
set(${PROJECT_NAME}_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}/${Supplemental_ARCH_SUBDIR}>" CACHE STRING "") | ||||||
set(${PROJECT_NAME}_INSTALL_SWIFTMODULEDIR "${CMAKE_INSTALL_LIBDIR}/swift$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:_static>$<$<BOOL:${Supplemental_INSTALL_NESTED_SUBDIR}>:/${Supplemental_PLATFORM_SUBDIR}>" CACHE STRING "") | ||||||
|
||||||
install(TARGETS swift_Differentiation | ||||||
EXPORT SwiftSupplementalTargets | ||||||
COMPONENT SwiftCore_runtime | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would suggest to match the same name we are using in #81310
Suggested change
|
||||||
ARCHIVE DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" | ||||||
LIBRARY DESTINATION "${${PROJECT_NAME}_INSTALL_LIBDIR}" | ||||||
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") | ||||||
emit_swift_interface(swift_Differentiation) | ||||||
install_swift_interface(swift_Differentiation) | ||||||
|
||||||
# Configure plist creation for Darwin platforms. | ||||||
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swift_Differentiation) | ||||||
embed_manifest(swift_Differentiation) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#[=======================================================================[.rst: | ||
FindSwiftMath | ||
------------ | ||
|
||
Find the Swift `_math` module interface, deferring to mathConfig.cmake when | ||
requested. | ||
|
||
This module locates the Swift `_math` module, which provides standard math | ||
functions to Swift code. The module looks for the `_math.swiftinterface` file | ||
in the SDK and sets up an imported target for use in CMake. | ||
Imported Targets | ||
^^^^^^^^^^^^^^^^ | ||
|
||
The following :prop_tgt:`IMPORTED` TARGETS may be defined: | ||
|
||
``math`` | ||
|
||
Hint Variables | ||
^^^^^^^^^^^^^^ | ||
|
||
``swift_SDKROOT`` | ||
Set the path to the Swift SDK installation. | ||
This only affects Linux and Windows builds. | ||
Apple builds always use the library provided by the SDK. | ||
|
||
Result Variables | ||
^^^^^^^^^^^^^^^^ | ||
|
||
The module may set the following variables if `SwiftMath_DIR` is not set. | ||
|
||
``SwiftMath_FOUND`` | ||
true if the `_math` module interface (and required library) were found. | ||
|
||
``SwiftMath_INCLUDE_DIR`` | ||
The directory containing the `_math.swiftinterface` file | ||
|
||
``SwiftMath_LIBRARIES`` OR ``SwiftMath_IMPLIB`` | ||
the libraries to be linked | ||
|
||
#]=======================================================================] | ||
|
||
# If the math_DIR is specified, look there instead. The cmake-generated | ||
# config file is more accurate, but requires that the SDK has one available. | ||
if(SwiftMath_DIR) | ||
if(SwiftMath_FIND_REQUIRED) | ||
list(APPEND args REQUIRED) | ||
endif() | ||
if(SwiftMath_FIND_QUIETLY) | ||
list(APPEND args QUIET) | ||
endif() | ||
find_package(SwiftMath NO_MODULE ${args}) | ||
return() | ||
endif() | ||
|
||
include(FindPackageHandleStandardArgs) | ||
include(PlatformInfo) | ||
|
||
if(APPLE) | ||
find_path(SwiftMath_INCLUDE_DIR | ||
NAMES _math.swiftmodule | ||
PATHS ${CMAKE_OSX_SYSROOT}/usr/lib/swift) | ||
find_path(SwiftMath_IMPLIB | ||
NAMES libm.tbd | ||
PATHS usr/lib) | ||
add_library(SwiftMath SHARED IMPORTED GLOBAL) | ||
set_target_properties(SwiftMath PROPERTIES | ||
IMPORTED_IMPLIB ${SwiftMath_IMPLIB} | ||
INTERFACE_INCLUDE_DIRECTORIES ${SwiftMath_INCLUDE_DIR}) | ||
find_package_handle_standard_args(SwiftMath DEFAULT_MSG | ||
SwiftMath_IMPLIB SwiftMath_INCLUDE_DIR) | ||
elseif(LINUX) | ||
find_path(SwiftMath_INCLUDE_DIR | ||
glibc.modulemap | ||
PATHS ${Swift_SDKROOT}/usr/lib/swift/linux/${SwiftSupplemental_ARCH_SUBDIR}) | ||
find_path(SwiftMath_GLIBC_DIR | ||
Glibc.swiftmodule | ||
PATHS ${Swift_SDKROOT}/usr/lib/swift/linux) | ||
add_library(SwiftMath INTERFACE IMPORTED GLOBAL) | ||
set_target_properties(SwiftMath PROPERTIES | ||
INTERFACE_INCLUDE_DIRECTORIES ${SwiftMath_INCLUDE_DIR} ${SwiftMath_GLIBC_DIR}) | ||
find_package_handle_standard_args(SwiftMath DEFAULT_MSG SwiftMath_INCLUDE_DIR) | ||
else() | ||
# TODO: Windows | ||
message(FATAL_ERROR "FindSwiftMath.cmake module search not implemented for targeted platform\n") | ||
endif() |
Uh oh!
There was an error while loading. Please reload this page.