Skip to content

Commit a7c6eee

Browse files
committed
[darwin][compiler-rt] produce a separate builtins library for device simulators
This lets darwin's compiler-rt builtins add an arm64 slice to the simulator builtins library
1 parent 0009aa7 commit a7c6eee

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

compiler-rt/cmake/Modules/CompilerRTDarwinUtils.cmake

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,15 @@ macro(darwin_add_builtin_library name suffix)
286286
endforeach(cflag)
287287
endif()
288288

289+
if ("${LIB_OS}" MATCHES ".*sim$")
290+
# Pass an explicit -simulator environment to the -target option to ensure
291+
# that we don't rely on the architecture to infer whether we're building
292+
# for the simulator.
293+
string(REGEX REPLACE "sim" "" base_os "${LIB_OS}")
294+
list(APPEND builtin_cflags
295+
-target "${LIB_ARCH}-apple-${base_os}${DARWIN_${LIBOS}_BUILTIN_MIN_VER}-simulator")
296+
endif()
297+
289298
set_target_compile_flags(${libname}
290299
${sysroot_flag}
291300
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
@@ -412,15 +421,33 @@ macro(darwin_add_builtin_libraries)
412421
endif()
413422
endforeach()
414423

415-
# We put the x86 sim slices into the archives for their base OS
416424
foreach (os ${ARGN})
425+
# We put the x86 sim slices into the archives for their base OS
426+
# FIXME: Stop doing that in upstream Phab review (blocked by swift side
427+
# support as well).
417428
if(NOT ${os} MATCHES ".*sim$")
429+
set(sim_flags ${${os}sim_builtins_lipo_flags})
430+
# Do not include the arm64 slice in the `lipo` invocation for the device
431+
# libclang_rt.<os>.a . This ensures that `lipo` uses the device arm64
432+
# slice in libclang_rt.<os>.a. The simulator arm64 slice is present only
433+
# in libclang_rt.<os>sim.a .
434+
if (NOT "${sim_flags}" STREQUAL "")
435+
string(REGEX REPLACE ";-arch;arm64.*" "" sim_flags "${sim_flags}")
436+
message(STATUS "adjusted simulator flags for non-sim builtin lib: ${sim_flags}")
437+
endif()
418438
darwin_lipo_libs(clang_rt.${os}
419439
PARENT_TARGET builtins
420-
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags}
440+
LIPO_FLAGS ${${os}_builtins_lipo_flags} ${sim_flags}
421441
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
422442
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
423443
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
444+
else()
445+
darwin_lipo_libs(clang_rt.${os}
446+
PARENT_TARGET builtins
447+
LIPO_FLAGS ${${os}_builtins_lipo_flags}
448+
DEPENDS ${${os}_builtins_libs}
449+
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
450+
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR})
424451
endif()
425452
endforeach()
426453
darwin_add_embedded_builtin_libraries()

0 commit comments

Comments
 (0)