Skip to content

Commit 99153c8

Browse files
authored
[CMake][Fuchsia] Build libc++ on top libc for baremetal (#99009)
This is mostly a proof of concept requiring a number of workarounds, but demonstrates that it is feasible.
1 parent f58cfac commit 99153c8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
325325
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
326326
set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
327327
foreach(lang C;CXX;ASM)
328-
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb -Wno-atomic-alignment" CACHE STRING "")
328+
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
329+
# These should be addressed and removed over time.
330+
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -mthumb -Wno-atomic-alignment -D'vfprintf(stream, format, vlist)=vprintf(format, vlist)' -D'fprintf(stream, format, ...)=printf(format)' -D'timeval=struct timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' -D_LIBCPP_PRINT=1" CACHE STRING "")
329331
endforeach()
330332
foreach(type SHARED;MODULE;EXE)
331333
set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
@@ -335,7 +337,7 @@ foreach(target armv6m-unknown-eabi;armv7m-unknown-eabi;armv8m.main-unknown-eabi)
335337
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
336338
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
337339
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
338-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
340+
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
339341
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
340342
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
341343
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")
@@ -373,7 +375,9 @@ foreach(target riscv32-unknown-elf)
373375
set(RUNTIMES_${target}_CMAKE_BUILD_TYPE MinSizeRel CACHE STRING "")
374376
set(RUNTIMES_${target}_CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY CACHE STRING "")
375377
foreach(lang C;CXX;ASM)
376-
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f" CACHE STRING "")
378+
# TODO: The preprocessor defines workaround various issues in libc and libc++ integration.
379+
# These should be addressed and removed over time.
380+
set(RUNTIMES_${target}_CMAKE_${lang}_FLAGS "--target=${target} -march=rv32imafc -mabi=ilp32f -D'vfprintf(stream, format, vlist)=vprintf(format, vlist)' -D'fprintf(stream, format, ...)=printf(format)' -D'timeval=struct timeval{int tv_sec; int tv_usec;}' -D'gettimeofday(tv, tz)' -D_LIBCPP_PRINT=1" CACHE STRING "")
377381
endforeach()
378382
foreach(type SHARED;MODULE;EXE)
379383
set(RUNTIMES_${target}_CMAKE_${type}_LINKER_FLAGS "-fuse-ld=lld" CACHE STRING "")
@@ -383,7 +387,7 @@ foreach(target riscv32-unknown-elf)
383387
set(RUNTIMES_${target}_LIBCXX_ABI_VERSION 2 CACHE STRING "")
384388
set(RUNTIMES_${target}_LIBCXX_CXX_ABI none CACHE STRING "")
385389
set(RUNTIMES_${target}_LIBCXX_ENABLE_SHARED OFF CACHE BOOL "")
386-
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC OFF CACHE BOOL "")
390+
set(RUNTIMES_${target}_LIBCXX_ENABLE_STATIC ON CACHE BOOL "")
387391
set(RUNTIMES_${target}_LIBCXX_ENABLE_FILESYSTEM OFF CACHE BOOL "")
388392
set(RUNTIMES_${target}_LIBCXX_ENABLE_RANDOM_DEVICE OFF CACHE BOOL "")
389393
set(RUNTIMES_${target}_LIBCXX_ENABLE_LOCALIZATION OFF CACHE BOOL "")

0 commit comments

Comments
 (0)