@@ -289,6 +289,15 @@ macro(darwin_add_builtin_library name suffix)
289
289
endforeach (cflag)
290
290
endif ()
291
291
292
+ if ("${LIB_OS} " MATCHES ".*sim$" )
293
+ # Pass an explicit -simulator environment to the -target option to ensure
294
+ # that we don't rely on the architecture to infer whether we're building
295
+ # for the simulator.
296
+ string (REGEX REPLACE "sim" "" base_os "${LIB_OS} " )
297
+ list (APPEND builtin_cflags
298
+ -target "${LIB_ARCH} -apple-${base_os} ${DARWIN_${LIBOS} _BUILTIN_MIN_VER}-simulator" )
299
+ endif ()
300
+
292
301
set_target_compile_flags(${libname}
293
302
${sysroot_flag}
294
303
${DARWIN_${LIB_OS} _BUILTIN_MIN_VER_FLAG}
@@ -449,15 +458,33 @@ macro(darwin_add_builtin_libraries)
449
458
endif ()
450
459
endforeach ()
451
460
452
- # We put the x86 sim slices into the archives for their base OS
453
461
foreach (os ${ARGN} )
462
+ # We put the x86 sim slices into the archives for their base OS
463
+ # FIXME: Stop doing that in upstream Phab review (blocked by swift side
464
+ # support as well).
454
465
if (NOT ${os} MATCHES ".*sim$" )
466
+ set (sim_flags ${${os} sim_builtins_lipo_flags})
467
+ # Do not include the arm64 slice in the `lipo` invocation for the device
468
+ # libclang_rt.<os>.a . This ensures that `lipo` uses the device arm64
469
+ # slice in libclang_rt.<os>.a. The simulator arm64 slice is present only
470
+ # in libclang_rt.<os>sim.a .
471
+ if (NOT "${sim_flags} " STREQUAL "" )
472
+ string (REGEX REPLACE ";-arch;arm64.*" "" sim_flags "${sim_flags} " )
473
+ message (STATUS "adjusted simulator flags for non-sim builtin lib: ${sim_flags} " )
474
+ endif ()
455
475
darwin_lipo_libs(clang_rt.${os}
456
476
PARENT_TARGET builtins
457
- LIPO_FLAGS ${${os} _builtins_lipo_flags} ${${os} sim_builtins_lipo_flags }
477
+ LIPO_FLAGS ${${os} _builtins_lipo_flags} ${sim_flags }
458
478
DEPENDS ${${os} _builtins_libs} ${${os} sim_builtins_libs}
459
479
OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
460
480
INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR} )
481
+ else ()
482
+ darwin_lipo_libs(clang_rt.${os}
483
+ PARENT_TARGET builtins
484
+ LIPO_FLAGS ${${os} _builtins_lipo_flags}
485
+ DEPENDS ${${os} _builtins_libs}
486
+ OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR}
487
+ INSTALL_DIR ${COMPILER_RT_LIBRARY_INSTALL_DIR} )
461
488
endif ()
462
489
endforeach ()
463
490
darwin_add_embedded_builtin_libraries()
0 commit comments