Skip to content

Commit b85e1aa

Browse files
committed
Generate gccbuiltins headers as part of root CMakeLists.txt
Even though they are header files they are tied to the version of llvm ldc2 is being built against. Their generation script depends on llvm. They are missing when building the runtime and the compiler separately. For these reasons build and install them as part of the ldc2 compiler. Signed-off-by: Andrei Horodniceanu <[email protected]>
1 parent 1480310 commit b85e1aa

File tree

3 files changed

+40
-33
lines changed

3 files changed

+40
-33
lines changed

CMakeLists.txt

+38
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,44 @@ add_subdirectory(utils)
890890
#
891891
add_subdirectory(tools)
892892

893+
#
894+
# GCC builtins.
895+
#
896+
if(TARGET gen_gccbuiltins)
897+
set(build_import_dir "${PROJECT_BINARY_DIR}/runtime/import")
898+
899+
file(MAKE_DIRECTORY "${build_import_dir}/ldc")
900+
901+
function(gen_gccbuiltins name)
902+
set(module "${build_import_dir}/ldc/gccbuiltins_${name}.di")
903+
list(APPEND gccbuiltins "${module}")
904+
set(gccbuiltins "${gccbuiltins}" PARENT_SCOPE)
905+
add_custom_command(
906+
OUTPUT ${module}
907+
COMMAND gen_gccbuiltins ${module} "${name}"
908+
DEPENDS gen_gccbuiltins
909+
)
910+
endfunction()
911+
912+
set(target_arch "AArch64;AMDGPU;ARM;Mips;RISCV;NVPTX;PowerPC;SystemZ;X86")
913+
set(target_name "aarch64;amdgcn;arm;mips;riscv;nvvm;ppc;s390;x86")
914+
915+
foreach(target ${LLVM_TARGETS_TO_BUILD})
916+
list(FIND target_arch ${target} idx)
917+
if(idx GREATER -1)
918+
list(GET target_name ${idx} name)
919+
gen_gccbuiltins(${name})
920+
endif()
921+
endforeach()
922+
makeConfSection(NAME "35-ldc-compiler-gccbuiltins" SECTION "default"
923+
BUILD POST_SWITCHES "-I${build_import_dir}"
924+
)
925+
add_custom_target(gen_gccbuiltins_headers DEPENDS ${gccbuiltins})
926+
add_dependencies(${LDC_EXE} gen_gccbuiltins_headers)
927+
928+
install(FILES ${gccbuiltins} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc)
929+
endif()
930+
893931
#
894932
# Compiler ldc2.conf configuration
895933
#

cmake/Modules/LdcCommon.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ endif()
270270

271271
set(CONF_INST_DIR ${SYSCONF_INSTALL_DIR} CACHE PATH "Directory ldc.conf is installed to")
272272
option(CONF_PREFER_DIR "Prefer installing ldc2.conf as a directory")
273+
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
273274

274275
defineIfUnset(LDC2_BUILD_CONF "${CMAKE_BINARY_DIR}/bin/ldc2.conf")
275276
defineIfUnset(LDC2_INSTALL_CONF "${CMAKE_BINARY_DIR}/bin/ldc2_install.conf")

runtime/CMakeLists.txt

+1-33
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ endif()
2424

2525
set(MULTILIB OFF CACHE BOOL "Build both 32/64 bit runtime libraries")
2626
set(BUILD_LTO_LIBS OFF CACHE BOOL "Also build the runtime as LLVM bitcode libraries for LTO")
27-
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
2827
set(BUILD_SHARED_LIBS AUTO CACHE STRING "Whether to build the runtime as a shared library (ON|OFF|BOTH)")
2928
set(D_FLAGS -w;-de;-preview=dip1000;-preview=dtorfields;-preview=fieldwise CACHE STRING "Runtime D compiler flags, separated by ';'")
3029
set(D_EXTRA_FLAGS "" CACHE STRING "Runtime extra D compiler flags, separated by ';'")
@@ -373,36 +372,6 @@ endif()
373372
# druntime/Phobos compilation helpers.
374373
#
375374

376-
set(GCCBUILTINS "")
377-
if(TARGET gen_gccbuiltins)
378-
file(MAKE_DIRECTORY "${LDC_BUILD_IMPORT_DIR}/ldc")
379-
380-
function(gen_gccbuiltins name)
381-
set(module "${LDC_BUILD_IMPORT_DIR}/ldc/gccbuiltins_${name}.di")
382-
if (GCCBUILTINS STREQUAL "")
383-
set(GCCBUILTINS "${module}" PARENT_SCOPE)
384-
else()
385-
set(GCCBUILTINS "${GCCBUILTINS};${module}" PARENT_SCOPE)
386-
endif()
387-
add_custom_command(
388-
OUTPUT ${module}
389-
COMMAND gen_gccbuiltins ${module} "${name}"
390-
DEPENDS gen_gccbuiltins
391-
)
392-
endfunction()
393-
394-
set(target_arch "AArch64;AMDGPU;ARM;Mips;RISCV;NVPTX;PowerPC;SystemZ;X86")
395-
set(target_name "aarch64;amdgcn;arm;mips;riscv;nvvm;ppc;s390;x86")
396-
397-
foreach(target ${LLVM_TARGETS_TO_BUILD})
398-
list(FIND target_arch ${target} idx)
399-
if(idx GREATER -1)
400-
list(GET target_name ${idx} name)
401-
gen_gccbuiltins(${name})
402-
endif()
403-
endforeach()
404-
endif()
405-
406375
# Always build zlib and other C parts of the runtime in release mode, regardless
407376
# of what the user chose for LDC itself. Also add other C_FLAGS here.
408377
# 1) Set up CMAKE_C_FLAGS_RELEASE
@@ -453,7 +422,7 @@ macro(dc src_files src_basedir d_flags output_basedir emit_bc all_at_once single
453422

454423
# dc_deps can only contain paths, otherwise cmake will ignore the dependency.
455424
# See: https://github.com/ldc-developers/ldc/pull/4743#issuecomment-2323156173
456-
set(dc_deps ${LDC_EXE_FULL} ${GCCBUILTINS})
425+
set(dc_deps ${LDC_EXE_FULL})
457426

458427
set(relative_src_files "")
459428
set(new_o "")
@@ -911,7 +880,6 @@ if(PHOBOS2_DIR)
911880
install(DIRECTORY ${PHOBOS2_DIR}/std DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
912881
install(DIRECTORY ${PHOBOS2_DIR}/etc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
913882
endif()
914-
install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc)
915883

916884

917885
#

0 commit comments

Comments
 (0)