-
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?
Conversation
Adding initial pass at the differentiation build.
Findmath.cmake performs a platform dependent lookup for the necessary math overlay and adds it as an imported target against which Differentiation links.
469f815
to
66cebdd
Compare
"$<$<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 comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably put the sources under a Sources
directory. While that is not required for CMake to work properly, I think that it would be nice to have the layout be similar to other projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
- Supplemental
- Differentiation
- CMakeLists.txt
- Sources
- AnyDifferentiable.swift
- ...
- Synchronization
- CMakeLists.txt
- Sources
- ...
- cmake/modules
- Differentiation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
math_LIBRARY math_INCLUDE_DIR) | ||
else() | ||
# TODO: Windows | ||
message(FATAL_ERROR "Findmath.cmake module search not implemented for targeted platform\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we can simply default to $ENV{SDKROOT}/usr/lib/swift/windows/${SwiftSupplemental_ARCH_SUBDIR}
.
fe5fc68
to
34fda7d
Compare
34fda7d
to
1598787
Compare
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Do we set the language version for the other libraries?
@@ -0,0 +1,95 @@ | |||
#[=======================================================================[.rst: | |||
Findmath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should consider renaming this. Findmath
makes it sound like this is meant to configure libm
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on board. Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reading the implementation more carefully, it does seem that this is doing some amount of work to locate and setup libm
, which is incorrect. This is target dependent and you should use CMAKE_MATH_LIBS
in the INTERFACE_LINK_DEPENDENCIES
if you need to setup the link to the math library. However, that said, it shouldn't be needed as the swiftmodule should handle the autolinking.
Perhaps FindSwiftMath
is an option if this is meant to be a helper for the _math
Swift module?
@@ -0,0 +1,95 @@ | |||
#[=======================================================================[.rst: | |||
Findmath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reading the implementation more carefully, it does seem that this is doing some amount of work to locate and setup libm
, which is incorrect. This is target dependent and you should use CMAKE_MATH_LIBS
in the INTERFACE_LINK_DEPENDENCIES
if you need to setup the link to the math library. However, that said, it shouldn't be needed as the swiftmodule should handle the autolinking.
Perhaps FindSwiftMath
is an option if this is meant to be a helper for the _math
Swift module?
find_library(math_LIBRARY NAMES m) | ||
if(math_STATIC) | ||
add_library(math STATIC IMPORTED GLOBAL) | ||
else() | ||
add_library(math SHARED IMPORTED GLOBAL) | ||
endif() | ||
set_target_properties(math PROPERTIES | ||
IMPORTED_LOCATION ${math_LIBRARY} | ||
INTERFACE_INCLUDE_DIRECTORIES ${math_INCLUDE_DIR} ${math_GLIBC_DIR}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not entirely correct. As a concrete example, musl does not need to link against libm
but that would still evaluate LINUX
as true. In such a case, you might end up linking against libm
from glibc and have two different libc implementation in the address space, which is UB.
…iation Signed-off-by: Andrew Sukach <[email protected]>
1598787
to
904db9b
Compare
include(AvailabilityMacros) | ||
include(CatalystSupport) | ||
include(EmitSwiftInterface) | ||
include(ResourceEmbedding) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need InstallSwiftInterface
to be able to call install_swift_interface
include(InstallSwiftInterface)
|
||
install(TARGETS swift_Differentiation | ||
EXPORT SwiftSupplementalTargets | ||
COMPONENT SwiftCore_runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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
COMPONENT SwiftCore_runtime | |
COMPONENT ${PROJECT_NAME}_runtime |
Builds differentiation as part of the supplemental libraries and also adds a module for finding the math overlay.