Skip to content

Runtimes: attempt to embed a SxS manifest for swiftCore #79337

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

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Runtimes/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ include(DefaultSettings)
include(EmitSwiftInterface)
include(PlatformInfo)
include(gyb)
include(Plist)
include(ResourceEmbedding)

check_symbol_exists("asl_log" "asl.h" SwiftCore_HAS_ASL)
check_symbol_exists("dladdr" "dlfcn.h" SwiftCore_HAS_DLADDR)
Expand Down
31 changes: 0 additions & 31 deletions Runtimes/Core/cmake/modules/Plist.cmake

This file was deleted.

67 changes: 67 additions & 0 deletions Runtimes/Core/cmake/modules/ResourceEmbedding.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
function(generate_plist project_name project_version target)
set(PLIST_INFO_PLIST "Info.plist")
set(PLIST_INFO_NAME "${project_name}")

# Underscores aren't permitted in the bundle identifier.
string(REPLACE "_" "" PLIST_INFO_UTI "com.apple.dt.runtime.${PLIST_INFO_NAME}")
set(PLIST_INFO_VERSION "${project_version}")
set(PLIST_INFO_BUILD_VERSION "${project_version}")

set(PLIST_INFO_PLIST_OUT "${PLIST_INFO_PLIST}")
set(PLIST_INFO_PLIST_IN "${PROJECT_SOURCE_DIR}/${PLIST_INFO_PLIST}.in")

if(APPLE)
target_link_options(${target} PRIVATE
"SHELL:-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker ${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
endif()

configure_file(
"${PLIST_INFO_PLIST_IN}"
"${PLIST_INFO_PLIST_OUT}"
@ONLY
NEWLINE_STYLE UNIX)

set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")

# If Application Extensions are enabled, pass the linker flag marking
# the dylib as safe.
if (CXX_SUPPORTS_FAPPLICATION_EXTENSION AND (NOT DISABLE_APPLICATION_EXTENSION))
list(APPEND link_flags "-Wl,-application_extension")
endif()
endfunction()

if(NOT DEFINED CMAKE_MT)
find_program(CMAKE_MT NAMES mt llvm-mt)
endif()

function(embed_manifest target)
get_target_property(_EM_TARGET_TYPE ${target} TYPE)
if(NOT "${_EM_TARGET_TYPE}" MATCHES "SHARED_LIBRARY|EXECUTABLE")
return()
endif()

get_target_property(_EM_BINARY_DIR ${target} BINARY_DIR)
get_target_property(_EM_NAME ${target} NAME)

# Evaluate variables
file(CONFIGURE
OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in
CONTENT [[<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity
name="$<TARGET_NAME:@target@>"
processorArchitecture="@CMAKE_SYSTEM_PROCESSOR@"
type="win32"
version="@PROJECT_VERSION@" />
<file name="$<TARGET_FILE_NAME:@target@>" />
</assembly>]])
# Evaluate generator expression
file(GENERATE
OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest
INPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in)

if(WIN32)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND ${CMAKE_MT} -nologo -manifest "${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest" "-outputresource:$<TARGET_FILE:${target}>;#1")
endif()
endfunction()
1 change: 1 addition & 0 deletions Runtimes/Core/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,7 @@ install_swift_interface(swiftCore)

# Configure plist creation for Darwin platforms.
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftCore)
embed_manifest(swiftCore)

include("${SwiftCore_VENDOR_MODULE_DIR}/swiftCore.cmake" OPTIONAL)

Expand Down