Skip to content

Commit

Permalink
Entitle macOS executables while building (#92967)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkoritzinsky authored Oct 10, 2023
1 parent 5b7ab04 commit 4f77a1b
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 12 deletions.
File renamed without changes.
File renamed without changes.
13 changes: 13 additions & 0 deletions eng/native/functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,16 @@ function(add_library_clr targetName kind)
strip_symbols(${ARGV0} symbolFile)
endif()
endfunction()

# Adhoc sign targetName with the entitlements in entitlementsFile.
function(adhoc_sign_with_entitlements targetName entitlementsFile)
# Add a dependency from a source file for the target on the entitlements file to ensure that the target is rebuilt if only the entitlements file changes.
get_target_property(sources ${targetName} SOURCES)
list(GET sources 0 firstSource)
set_source_files_properties(${firstSource} PROPERTIES OBJECT_DEPENDS ${entitlementsFile})

add_custom_command(
TARGET ${targetName}
POST_BUILD
COMMAND codesign -s - -f --entitlements ${entitlementsFile} $<TARGET_FILE:${targetName}>)
endfunction()
5 changes: 1 addition & 4 deletions eng/pipelines/common/macos-sign-with-entitlements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ steps:
installationPath: '$(Agent.TempDirectory)/dotnet'

- ${{ each file in parameters.filesToSign }}:
- script: codesign -s - -f --entitlements ${{ file.entitlementsFile }} ${{ file.path }}/${{ file.name }}
displayName: 'Add entitlements to ${{ file.name }}'

- task: CopyFiles@2
displayName: 'Copy entitled file ${{ file.name }}'
inputs:
Expand Down Expand Up @@ -49,7 +46,7 @@ steps:
"toolName": "sign",
"toolVersion": "1.0"
}
]
]
SessionTimeout: ${{ parameters.timeoutInMinutes }}
MaxConcurrency: '50'
MaxRetryAttempts: '5'
Expand Down
2 changes: 0 additions & 2 deletions eng/pipelines/coreclr/templates/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,8 @@ jobs:
filesToSign:
- name: createdump
path: $(buildProductRootFolderPath)
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/createdump-entitlements.plist
- name: corerun
path: $(buildProductRootFolderPath)
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/entitlements.plist

- task: CopyFiles@2
displayName: 'Copy signed createdump to sharedFramework'
Expand Down
1 change: 0 additions & 1 deletion eng/pipelines/installer/jobs/build-job.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ jobs:
displayName: Collect vslogs on exit
condition: always()


- ${{ if in(parameters.osGroup, 'osx', 'ios', 'tvos') }}:
- script: |
du -sh $(Build.SourcesDirectory)/*
Expand Down
4 changes: 0 additions & 4 deletions eng/pipelines/runtime-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,16 +149,12 @@ extends:
filesToSign:
- name: createdump
path: $(Build.SourcesDirectory)/artifacts/bin/coreclr/$(osGroup).$(archType).$(_BuildConfig)
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/createdump-entitlements.plist
- name: corerun
path: $(Build.SourcesDirectory)/artifacts/bin/coreclr/$(osGroup).$(archType).$(_BuildConfig)
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/entitlements.plist
- name: dotnet
path: $(Build.SourcesDirectory)/artifacts/bin/$(osGroup)-$(archType).$(_BuildConfig)/corehost
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/entitlements.plist
- name: apphost
path: $(Build.SourcesDirectory)/artifacts/bin/$(osGroup)-$(archType).$(_BuildConfig)/corehost
entitlementsFile: $(Build.SourcesDirectory)/eng/pipelines/common/entitlements.plist

- task: CopyFiles@2
displayName: 'Copy signed createdump to sharedFramework'
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/debug/createdump/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,8 @@ endif(CLR_CMAKE_HOST_OSX)

endif(CLR_CMAKE_HOST_WIN32)

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(createdump "${CLR_ENG_NATIVE_DIR}/createdump-entitlements.plist")
endif()

install_clr(TARGETS createdump DESTINATIONS . sharedFramework COMPONENT runtime)
6 changes: 5 additions & 1 deletion src/coreclr/hosts/corerun/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ else(CLR_CMAKE_HOST_WIN32)
endif()
endif(CLR_CMAKE_HOST_WIN32)

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(corerun "${CLR_ENG_NATIVE_DIR}/entitlements.plist")
endif()

install_clr(TARGETS corerun DESTINATIONS . COMPONENT hosts)

# If there's a dynamic ASAN runtime, then install it in the directory where we put our executable.
if (NOT "${ASAN_RUNTIME}" STREQUAL "")
install(FILES ${ASAN_RUNTIME} DESTINATION .)
endif()
endif()
8 changes: 8 additions & 0 deletions src/libraries/sendtohelixhelp.proj
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@
</HelixPostCommands>
</PropertyGroup>

<!-- ad-hoc sign createdump on the helix machine to allow us to collect dumps -->
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetOS)' == 'osx'">
<HelixPreCommands>
$(HelixPreCommands);
find $HELIX_CORRELATION_PAYLOAD -name createdump | xargs -n 1 codesign -s - -f --preserve-metadata=entitlements
</HelixPreCommands>
</PropertyGroup>

<Error Condition="'$(NeedsWorkload)' == 'true' and '$(TestUsingWorkloads)' == 'true' and ('$(SdkWithWorkloadForTestingPath)' == '' or !Exists($(SdkWithWorkloadForTestingPath)))"
Text="Could not find workload at %24(SdkWithWorkloadForTestingPath)=$(SdkWithWorkloadForTestingPath)" />

Expand Down
4 changes: 4 additions & 0 deletions src/native/corehost/apphost/standalone/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ endif()
if (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
target_link_libraries(apphost PRIVATE shell32.lib)
endif()

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(apphost "${CLR_ENG_NATIVE_DIR}/entitlements.plist")
endif()
4 changes: 4 additions & 0 deletions src/native/corehost/dotnet/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ list(APPEND SOURCES
)

include(../exe.cmake)

if (CLR_CMAKE_HOST_APPLE)
adhoc_sign_with_entitlements(dotnet "${CLR_ENG_NATIVE_DIR}/entitlements.plist")
endif()
5 changes: 5 additions & 0 deletions src/tests/Common/helixpublishwitharcade.proj
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,11 @@
</ItemGroup>
</Target>

<!-- Adhoc-sign createdump so we can use it in our tests -->
<PropertyGroup Condition="'$(RuntimeFlavor)' == 'CoreCLR' and '$(TargetOS)' == 'osx'">
<HelixPreCommands>$(HelixPreCommands);codesign -s - -f --preserve-metadata=entitlements $HELIX_CORRELATION_PAYLOAD/createdump</HelixPreCommands>
</PropertyGroup>

<PropertyGroup>
<SigningCommand Condition="'$(TargetOS)' == 'iOS' or '$(TargetOS)' == 'tvOS'">
<![CDATA[
Expand Down

0 comments on commit 4f77a1b

Please sign in to comment.