@@ -286,6 +286,15 @@ macro(darwin_add_builtin_library name suffix)
286
286
endforeach (cflag )
287
287
endif ()
288
288
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
+
289
298
set_target_compile_flags (${libname}
290
299
${sysroot_flag}
291
300
${DARWIN_${LIB_OS}_BUILTIN_MIN_VER_FLAG}
@@ -412,15 +421,33 @@ macro(darwin_add_builtin_libraries)
412
421
endif ()
413
422
endforeach ()
414
423
415
- # We put the x86 sim slices into the archives for their base OS
416
424
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).
417
428
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 ()
418
438
darwin_lipo_libs (clang_rt.${os}
419
439
PARENT_TARGET builtins
420
- LIPO_FLAGS ${${os}_builtins_lipo_flags} ${${os}sim_builtins_lipo_flags }
440
+ LIPO_FLAGS ${${os}_builtins_lipo_flags} ${sim_flags }
421
441
DEPENDS ${${os}_builtins_libs} ${${os}sim_builtins_libs}
422
442
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
423
443
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} )
424
451
endif ()
425
452
endforeach ()
426
453
darwin_add_embedded_builtin_libraries ()
0 commit comments