Skip to content

Commit 14ae0a6

Browse files
[compiler-rt] Check codesign in path before using
Fixes an issue discovered with Nix where codesign is executed but Nix cannot use codesign without faults. Use `find_program` in CMake to ensure it is in `$PATH`.
1 parent 57ccd42 commit 14ae0a6

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler-rt/cmake/Modules/AddCompilerRT.cmake

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ function(add_compiler_rt_runtime name type)
388388
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
389389
set_target_properties(${libname} PROPERTIES IMPORT_SUFFIX ".lib")
390390
endif()
391-
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*")
391+
find_program(CODESIGN codesign)
392+
if (APPLE AND NOT CMAKE_LINKER MATCHES ".*lld.*" AND CODESIGN)
392393
# Apple's linker signs the resulting dylib with an ad-hoc code signature in
393394
# most situations, except:
394395
# 1. Versions of ld64 prior to ld64-609 in Xcode 12 predate this behavior.
@@ -403,7 +404,7 @@ function(add_compiler_rt_runtime name type)
403404
# argument and looking for `invalid argument "linker-signed"` in its output.
404405
# FIXME: Remove this once all supported toolchains support `-o linker-signed`.
405406
execute_process(
406-
COMMAND sh -c "codesign -f -s - -o linker-signed this-does-not-exist 2>&1 | grep -q linker-signed"
407+
COMMAND sh -c "${CODESIGN} -f -s - -o linker-signed this-does-not-exist 2>&1 | grep -q linker-signed"
407408
RESULT_VARIABLE CODESIGN_SUPPORTS_LINKER_SIGNED
408409
)
409410

@@ -414,7 +415,7 @@ function(add_compiler_rt_runtime name type)
414415

415416
add_custom_command(TARGET ${libname}
416417
POST_BUILD
417-
COMMAND codesign --sign - ${EXTRA_CODESIGN_ARGUMENTS} $<TARGET_FILE:${libname}>
418+
COMMAND ${CODESIGN} --sign - ${EXTRA_CODESIGN_ARGUMENTS} $<TARGET_FILE:${libname}>
418419
WORKING_DIRECTORY ${COMPILER_RT_OUTPUT_LIBRARY_DIR}
419420
COMMAND_EXPAND_LISTS
420421
)

0 commit comments

Comments
 (0)