From 2722e7aa4fe6ae27d7be5ffa67140d11a7dc1b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Fri, 14 Apr 2023 21:55:19 +0200 Subject: [PATCH] Fix MacCatalyst .framework build This got broken by https://github.com/dotnet/runtime/pull/83903 and wasn't noticed on the PR because we don't build .frameworks unless you pass `/p:BuildDarwinFrameworks=true`. For .frameworks we need to use a different install command and we also don't need to codesign them, it actually causes an error trying to do so: > /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release: code object is not signed at all > In subcomponent: /Users/alexander/dev/runtime/artifacts/obj/mono/maccatalyst.x64.Release/mono/mini/Mono.release.framework/Versions/C/Mono.release.dwarf --- eng/native/functions.cmake | 43 ++++++++++++++++++++++---------------- src/mono/mono.proj | 10 +++++++-- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/eng/native/functions.cmake b/eng/native/functions.cmake index 89ae649ebd9d58..5b8e47c0a43c4b 100644 --- a/eng/native/functions.cmake +++ b/eng/native/functions.cmake @@ -401,10 +401,12 @@ function(strip_symbols targetName outputFilename) set(strip_command ${STRIP} -no_code_signature_warning -S ${strip_source_file}) - # codesign release build - string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWERCASE_CMAKE_BUILD_TYPE) - if (LOWERCASE_CMAKE_BUILD_TYPE STREQUAL release) - set(strip_command ${strip_command} && codesign -f -s - ${strip_source_file}) + if (CLR_CMAKE_TARGET_OSX) + # codesign release build + string(TOLOWER "${CMAKE_BUILD_TYPE}" LOWERCASE_CMAKE_BUILD_TYPE) + if (LOWERCASE_CMAKE_BUILD_TYPE STREQUAL release) + set(strip_command ${strip_command} && codesign -f -s - ${strip_source_file}) + endif () endif () execute_process( @@ -421,9 +423,9 @@ function(strip_symbols targetName outputFilename) TARGET ${targetName} POST_BUILD VERBATIM + COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" COMMAND ${DSYMUTIL} ${DSYMUTIL_OPTS} ${strip_source_file} COMMAND ${strip_command} - COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" ) else (CLR_CMAKE_TARGET_APPLE) @@ -431,36 +433,41 @@ function(strip_symbols targetName outputFilename) TARGET ${targetName} POST_BUILD VERBATIM + COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" COMMAND ${CMAKE_OBJCOPY} --only-keep-debug ${strip_source_file} ${strip_destination_file} COMMAND ${CMAKE_OBJCOPY} --strip-debug --strip-unneeded ${strip_source_file} COMMAND ${CMAKE_OBJCOPY} --add-gnu-debuglink=${strip_destination_file} ${strip_source_file} - COMMAND sh -c "echo Stripping symbols from $(basename '${strip_source_file}') into $(basename '${strip_destination_file}')" ) endif (CLR_CMAKE_TARGET_APPLE) endif(CLR_CMAKE_HOST_UNIX) endfunction() function(install_with_stripped_symbols targetName kind destination) + get_property(target_is_framework TARGET ${targetName} PROPERTY "FRAMEWORK") if(NOT CLR_CMAKE_KEEP_NATIVE_SYMBOLS) strip_symbols(${targetName} symbol_file) - if (NOT "${symbol_file}" STREQUAL "") + if (NOT "${symbol_file}" STREQUAL "" AND NOT target_is_framework) install_symbol_file(${symbol_file} ${destination} ${ARGN}) endif() endif() - if (CLR_CMAKE_TARGET_APPLE AND ("${kind}" STREQUAL "TARGETS")) - # We want to avoid the kind=TARGET install behaviors which corrupt code signatures on osx-arm64 - set(kind PROGRAMS) - endif() - - if ("${kind}" STREQUAL "TARGETS") - set(install_source ${targetName}) - elseif("${kind}" STREQUAL "PROGRAMS") - set(install_source $) + if (target_is_framework) + install(TARGETS ${targetName} FRAMEWORK DESTINATION ${destination} ${ARGN}) else() - message(FATAL_ERROR "The `kind` argument has to be either TARGETS or PROGRAMS, ${kind} was provided instead") + if (CLR_CMAKE_TARGET_APPLE AND ("${kind}" STREQUAL "TARGETS")) + # We want to avoid the kind=TARGET install behaviors which corrupt code signatures on osx-arm64 + set(kind PROGRAMS) + endif() + + if ("${kind}" STREQUAL "TARGETS") + set(install_source ${targetName}) + elseif("${kind}" STREQUAL "PROGRAMS") + set(install_source $) + else() + message(FATAL_ERROR "The `kind` argument has to be either TARGETS or PROGRAMS, ${kind} was provided instead") + endif() + install(${kind} ${install_source} DESTINATION ${destination} ${ARGN}) endif() - install(${kind} ${install_source} DESTINATION ${destination} ${ARGN}) endfunction() function(install_symbol_file symbol_file destination_path) diff --git a/src/mono/mono.proj b/src/mono/mono.proj index 96c23f094b281e..f0a7d7e6ab82c1 100644 --- a/src/mono/mono.proj +++ b/src/mono/mono.proj @@ -981,7 +981,10 @@ <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.release.framework') and Exists('$(MonoObjDir)out\lib\Mono.release.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.release.framework\Versions\Current\Mono.release"> $(RuntimeBinDir)\Mono.release.framework\Mono - <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.release.framework')" Include="$(MonoObjDir)out\lib\Mono.release.framework\Mono.release.dwarf"> + <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.release.framework') and !Exists('$(MonoObjDir)out\lib\Mono.release.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.release.framework\Mono.release.dwarf"> + $(RuntimeBinDir)\Mono.release.framework\Mono.dwarf + + <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.release.framework') and Exists('$(MonoObjDir)out\lib\Mono.release.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.release.framework\Versions\Current\Mono.release.dwarf"> $(RuntimeBinDir)\Mono.release.framework\Mono.dwarf <_MonoRuntimeArtifacts Condition="'$(MonoComponentsStatic)' != 'true' and Exists('$(MonoObjDir)out\lib\Mono.debug.framework')" Include="@(_MonoRuntimeComponentsSharedFilePath)"> @@ -993,7 +996,10 @@ <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.debug.framework') and Exists('$(MonoObjDir)out\lib\Mono.debug.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.debug.framework\Versions\Current\Mono.debug"> $(RuntimeBinDir)\Mono.debug.framework\Mono - <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.debug.framework')" Include="$(MonoObjDir)out\lib\Mono.debug.framework\Mono.debug.dwarf"> + <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.debug.framework') and !Exists('$(MonoObjDir)out\lib\Mono.debug.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.debug.framework\Mono.debug.dwarf"> + $(RuntimeBinDir)\Mono.debug.framework\Mono.dwarf + + <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.debug.framework') and Exists('$(MonoObjDir)out\lib\Mono.debug.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.debug.framework\Versions\Current\Mono.debug.dwarf"> $(RuntimeBinDir)\Mono.debug.framework\Mono.dwarf <_MonoRuntimeArtifacts Condition="Exists('$(MonoObjDir)out\lib\Mono.release.framework') and !Exists('$(MonoObjDir)out\lib\Mono.release.framework\Versions')" Include="$(MonoObjDir)out\lib\Mono.release.framework\Info.plist">