Skip to content

[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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sookach
Copy link
Contributor

@sookach sookach commented May 1, 2025

Builds differentiation as part of the supplemental libraries and also adds a module for finding the math overlay.

etcwilde and others added 2 commits May 1, 2025 13:46
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.
@sookach sookach force-pushed the pr/runtimes-differentiation branch from 469f815 to 66cebdd Compare May 1, 2025 20:48
"$<$<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)
Copy link
Member

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.

Copy link
Contributor

@edymtt edymtt May 5, 2025

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

Copy link
Member

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")
Copy link
Member

@compnerd compnerd May 1, 2025

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}.

@sookach sookach force-pushed the pr/runtimes-differentiation branch from 34fda7d to 1598787 Compare May 7, 2025 01:37
@sookach sookach requested a review from edymtt May 7, 2025 01:39
VERSION 6.1.0${BUILD_NUMBER})

set(CMAKE_POSITION_INDEPENDENT_CODE YES)
set(CMAKE_Swift_LANGUAGE_VERSION 5)
Copy link
Member

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
Copy link
Member

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.

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'm on board. Any suggestions?

Copy link
Member

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
Copy link
Member

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?

Comment on lines 81 to 89
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})
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 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.

@sookach sookach force-pushed the pr/runtimes-differentiation branch from 1598787 to 904db9b Compare May 12, 2025 22:22
include(AvailabilityMacros)
include(CatalystSupport)
include(EmitSwiftInterface)
include(ResourceEmbedding)
Copy link
Contributor

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
Copy link
Contributor

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

Suggested change
COMPONENT SwiftCore_runtime
COMPONENT ${PROJECT_NAME}_runtime

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.

4 participants