Skip to content

Commit d9b6a82

Browse files
authored
Merge pull request #79337 from compnerd/manifesting-destiny
Runtimes: attempt to embed a SxS manifest for swiftCore
2 parents 6dc18c0 + 509c385 commit d9b6a82

File tree

4 files changed

+69
-32
lines changed

4 files changed

+69
-32
lines changed

Runtimes/Core/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ include(DefaultSettings)
8282
include(EmitSwiftInterface)
8383
include(PlatformInfo)
8484
include(gyb)
85-
include(Plist)
85+
include(ResourceEmbedding)
8686

8787
check_symbol_exists("asl_log" "asl.h" SwiftCore_HAS_ASL)
8888
check_symbol_exists("dladdr" "dlfcn.h" SwiftCore_HAS_DLADDR)

Runtimes/Core/cmake/modules/Plist.cmake

-31
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
function(generate_plist project_name project_version target)
2+
set(PLIST_INFO_PLIST "Info.plist")
3+
set(PLIST_INFO_NAME "${project_name}")
4+
5+
# Underscores aren't permitted in the bundle identifier.
6+
string(REPLACE "_" "" PLIST_INFO_UTI "com.apple.dt.runtime.${PLIST_INFO_NAME}")
7+
set(PLIST_INFO_VERSION "${project_version}")
8+
set(PLIST_INFO_BUILD_VERSION "${project_version}")
9+
10+
set(PLIST_INFO_PLIST_OUT "${PLIST_INFO_PLIST}")
11+
set(PLIST_INFO_PLIST_IN "${PROJECT_SOURCE_DIR}/${PLIST_INFO_PLIST}.in")
12+
13+
if(APPLE)
14+
target_link_options(${target} PRIVATE
15+
"SHELL:-Xlinker -sectcreate -Xlinker __TEXT -Xlinker __info_plist -Xlinker ${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
16+
endif()
17+
18+
configure_file(
19+
"${PLIST_INFO_PLIST_IN}"
20+
"${PLIST_INFO_PLIST_OUT}"
21+
@ONLY
22+
NEWLINE_STYLE UNIX)
23+
24+
set_property(TARGET ${target} APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/${PLIST_INFO_PLIST_OUT}")
25+
26+
# If Application Extensions are enabled, pass the linker flag marking
27+
# the dylib as safe.
28+
if (CXX_SUPPORTS_FAPPLICATION_EXTENSION AND (NOT DISABLE_APPLICATION_EXTENSION))
29+
list(APPEND link_flags "-Wl,-application_extension")
30+
endif()
31+
endfunction()
32+
33+
if(NOT DEFINED CMAKE_MT)
34+
find_program(CMAKE_MT NAMES mt llvm-mt)
35+
endif()
36+
37+
function(embed_manifest target)
38+
get_target_property(_EM_TARGET_TYPE ${target} TYPE)
39+
if(NOT "${_EM_TARGET_TYPE}" MATCHES "SHARED_LIBRARY|EXECUTABLE")
40+
return()
41+
endif()
42+
43+
get_target_property(_EM_BINARY_DIR ${target} BINARY_DIR)
44+
get_target_property(_EM_NAME ${target} NAME)
45+
46+
# Evaluate variables
47+
file(CONFIGURE
48+
OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in
49+
CONTENT [[<?xml version="1.0" encoding="utf-8" standalone="yes"?>
50+
<assembly manifestversion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
51+
<assemblyIdentity
52+
name="$<TARGET_NAME:@target@>"
53+
processorArchitecture="@CMAKE_SYSTEM_PROCESSOR@"
54+
type="win32"
55+
version="@PROJECT_VERSION@" />
56+
<file name="$<TARGET_FILE_NAME:@target@>" />
57+
</assembly>]])
58+
# Evaluate generator expression
59+
file(GENERATE
60+
OUTPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest
61+
INPUT ${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest.in)
62+
63+
if(WIN32)
64+
add_custom_command(TARGET ${target} POST_BUILD
65+
COMMAND ${CMAKE_MT} -nologo -manifest "${_EM_BINARY_DIR}/${_EM_NAME}-${PROJECT_VERSION}.1.manifest" "-outputresource:$<TARGET_FILE:${target}>;#1")
66+
endif()
67+
endfunction()

Runtimes/Core/core/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ install_swift_interface(swiftCore)
335335

336336
# Configure plist creation for Darwin platforms.
337337
generate_plist("${CMAKE_PROJECT_NAME}" "${CMAKE_PROJECT_VERSION}" swiftCore)
338+
embed_manifest(swiftCore)
338339

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

0 commit comments

Comments
 (0)