Skip to content

Commit 2244172

Browse files
committed
CMake: Install imports when installing the compiler, not the runtime
1 parent 5b317d2 commit 2244172

File tree

7 files changed

+60
-55
lines changed

7 files changed

+60
-55
lines changed

.github/actions/5-install/action.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ runs:
2222
# * bin/: executables
2323
# * lib/: LTO plugin and compiler-rt libs only
2424
# * etc/bash_completion.d/
25+
# * import/: missing ldc/gccbuiltins_*.di
2526
ninja -C build-cross install
2627
2728
# install the cross-compiled libs to populate:
2829
# * lib/: runtime library artifacts
2930
# * etc/ldc2.conf
30-
# * import/: missing ldc/gccbuiltins_*.di
3131
ninja -C build-cross-libs install
3232
3333
# copy gccbuiltins from bootstrap compiler
34-
cp bootstrap-ldc/runtime/import/ldc/gccbuiltins_*.di install/import/ldc/
34+
cp bootstrap-ldc/import/ldc/gccbuiltins_*.di install/import/ldc/
3535
fi
3636
3737
cp ldc/LICENSE install/

CMakeLists.txt

+48
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ set(D_VERSION ${DMDFE_MAJOR_VERSION} CACHE STRING "D language version")
138138
set(PROGRAM_PREFIX "" CACHE STRING "Prepended to ldc/ldmd binary names")
139139
set(PROGRAM_SUFFIX "" CACHE STRING "Appended to ldc/ldmd binary names")
140140
set(CONF_INST_DIR ${SYSCONF_INSTALL_DIR} CACHE PATH "Directory ldc2.conf is installed to")
141+
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
141142

142143
# Note: LIB_SUFFIX should perhaps be renamed to LDC_LIBDIR_SUFFIX.
143144
set(LIB_SUFFIX "" CACHE STRING "Appended to the library installation directory. Set to '64' to install libraries into ${PREFIX}/lib64.")
@@ -910,6 +911,42 @@ endif()
910911
#
911912
add_subdirectory(utils)
912913

914+
# auto-generate ldc/gccbuiltins_*.di headers, depending on LLVM version and enabled LLVM backends
915+
set(GCCBUILTINS "")
916+
if(TARGET gen_gccbuiltins)
917+
file(MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/import/ldc")
918+
919+
function(gen_gccbuiltins name)
920+
set(module "${PROJECT_BINARY_DIR}/import/ldc/gccbuiltins_${name}.di")
921+
if (GCCBUILTINS STREQUAL "")
922+
set(GCCBUILTINS "${module}" PARENT_SCOPE)
923+
else()
924+
set(GCCBUILTINS "${GCCBUILTINS};${module}" PARENT_SCOPE)
925+
endif()
926+
add_custom_command(
927+
OUTPUT ${module}
928+
COMMAND gen_gccbuiltins ${module} "${name}"
929+
DEPENDS gen_gccbuiltins
930+
)
931+
endfunction()
932+
933+
set(target_arch "AArch64;AMDGPU;ARM;Mips;RISCV;NVPTX;PowerPC;SystemZ;X86")
934+
set(target_name "aarch64;amdgcn;arm;mips;riscv;nvvm;ppc;s390;x86")
935+
936+
foreach(target ${LLVM_TARGETS_TO_BUILD})
937+
list(FIND target_arch ${target} idx)
938+
if(idx GREATER -1)
939+
list(GET target_name ${idx} name)
940+
gen_gccbuiltins(${name})
941+
endif()
942+
endforeach()
943+
944+
add_custom_target(gccbuiltins DEPENDS ${GCCBUILTINS})
945+
946+
# make sure they are generated when building the compiler (as link-time dependency)
947+
add_dependencies(${LDC_EXE} gccbuiltins)
948+
endif()
949+
913950
#
914951
# Auxiliary tools.
915952
#
@@ -992,6 +1029,17 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
9921029
install(DIRECTORY packaging/bash_completion.d/ DESTINATION ${BASH_COMPLETION_COMPLETIONSDIR})
9931030
endif()
9941031

1032+
# imports/includes
1033+
install(FILES runtime/druntime/src/object.d runtime/druntime/src/__importc_builtins.di runtime/druntime/src/importc.h DESTINATION ${INCLUDE_INSTALL_DIR})
1034+
foreach(p core etc ldc)
1035+
install(DIRECTORY runtime/druntime/src/${p} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
1036+
install(DIRECTORY runtime/druntime/src/${p} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.di")
1037+
endforeach()
1038+
install(DIRECTORY runtime/phobos/std DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
1039+
install(DIRECTORY runtime/phobos/etc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
1040+
install(DIRECTORY runtime/jit-rt/d/ldc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
1041+
install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc)
1042+
9951043
#
9961044
# Packaging
9971045
#

ldc2.conf.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ default:
2323
// default switches appended after all explicit command-line switches
2424
post-switches = [
2525
"-I@RUNTIME_DIR@/src",
26-
"-I@LDC_BUILD_IMPORT_DIR@",
26+
"-I@LDC_GCCBUILTINS_IMPORT_DIR@",
2727
"-I@JITRT_DIR@/d",
2828
];
2929
// default directories to be searched for libraries when linking

ldc2_phobos.conf.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ default:
2323
// default switches appended after all explicit command-line switches
2424
post-switches = [
2525
"-I@RUNTIME_DIR@/src",
26-
"-I@LDC_BUILD_IMPORT_DIR@",
26+
"-I@LDC_GCCBUILTINS_IMPORT_DIR@",
2727
"-I@JITRT_DIR@/d",
2828
"-I@PHOBOS2_DIR@",
2929
];

runtime/CMakeLists.txt

+7-48
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ endif()
3535

3636
set(MULTILIB OFF CACHE BOOL "Build both 32/64 bit runtime libraries")
3737
set(BUILD_LTO_LIBS OFF CACHE BOOL "Also build the runtime as LLVM bitcode libraries for LTO")
38-
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to")
3938
set(BUILD_SHARED_LIBS AUTO CACHE STRING "Whether to build the runtime as a shared library (ON|OFF|BOTH)")
4039
set(D_FLAGS -w;-de;-preview=dip1000;-preview=dtorfields;-preview=fieldwise CACHE STRING "Runtime D compiler flags, separated by ';'")
4140
set(D_EXTRA_FLAGS "" CACHE STRING "Runtime extra D compiler flags, separated by ';'")
@@ -301,8 +300,11 @@ endif()
301300
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023).
302301
set(WASM_DEFAULT_LDC_SWITCHES "${WASM_DEFAULT_LDC_SWITCHES}\n \"-L--export-dynamic\",")
303302

304-
# Directory filled with auto-generated import files
305-
set(LDC_BUILD_IMPORT_DIR "${PROJECT_BINARY_DIR}/import")
303+
# Note: normally inherited from LDC CMake parent build, and only needed for ldc2_install.conf
304+
set(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/d" CACHE PATH "Path the D modules are installed to")
305+
306+
# Note: default value only works if embedded in LDC CMake parent build, but only needed for ImportC (__importc_builtins.di) and non-install ldc2.conf
307+
set(LDC_GCCBUILTINS_IMPORT_DIR "${CMAKE_BINARY_DIR}/import" CACHE PATH "Directory filled with auto-generated ldc/gccbuiltins_*.di files")
306308

307309
# Generate .conf files
308310
if(LDC_EXE)
@@ -369,36 +371,6 @@ install(FILES ${install_conf_path} DESTINATION ${CONF_INST_DIR} RENAME ${CONFIG_
369371
# druntime/Phobos compilation helpers.
370372
#
371373

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

450422
# dc_deps can only contain paths, otherwise cmake will ignore the dependency.
451423
# See: https://github.com/ldc-developers/ldc/pull/4743#issuecomment-2323156173
452-
set(dc_deps ${LDC_EXE_FULL} ${GCCBUILTINS})
424+
set(dc_deps ${LDC_EXE_FULL})
453425
if(TARGET add-multilib-section)
454426
# Make sure the config files are available before invoking LDC.
455427
set(dc_deps ${dc_deps} add-multilib-section)
@@ -564,7 +536,7 @@ macro(compile_druntime d_flags lib_suffix path_suffix emit_bc all_at_once single
564536
endif()
565537
dc("${DRUNTIME_D}"
566538
"${RUNTIME_DIR}/src"
567-
"-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src;-I${LDC_BUILD_IMPORT_DIR}"
539+
"-conf=;${d_flags};${DRUNTIME_EXTRA_FLAGS};-I${RUNTIME_DIR}/src"
568540
"${PROJECT_BINARY_DIR}/objects${target_suffix}"
569541
"${emit_bc}"
570542
"${all_at_once}"
@@ -900,19 +872,6 @@ foreach(libname ${libs_to_install})
900872
endif()
901873
endforeach()
902874

903-
set(DRUNTIME_PACKAGES core etc ldc)
904-
905-
install(FILES ${RUNTIME_DIR}/src/object.d ${RUNTIME_DIR}/src/__importc_builtins.di ${RUNTIME_DIR}/src/importc.h DESTINATION ${INCLUDE_INSTALL_DIR})
906-
foreach(p ${DRUNTIME_PACKAGES})
907-
install(DIRECTORY ${RUNTIME_DIR}/src/${p} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
908-
install(DIRECTORY ${RUNTIME_DIR}/src/${p} DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.di")
909-
endforeach()
910-
if(PHOBOS2_DIR)
911-
install(DIRECTORY ${PHOBOS2_DIR}/std DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
912-
install(DIRECTORY ${PHOBOS2_DIR}/etc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
913-
endif()
914-
install(FILES ${GCCBUILTINS} DESTINATION ${INCLUDE_INSTALL_DIR}/ldc)
915-
916875

917876
#
918877
# Test targets.

runtime/jit-rt/DefineBuildJitRT.cmake

-3
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ if(LDC_DYNAMIC_COMPILE)
8989
list(APPEND ${outlist_targets} "ldc-jit-rt${target_suffix}")
9090
set(${outlist_targets} ${${outlist_targets}} PARENT_SCOPE)
9191
endfunction()
92-
93-
# Install D interface files
94-
install(DIRECTORY ${JITRT_DIR}/d/ldc DESTINATION ${INCLUDE_INSTALL_DIR} FILES_MATCHING PATTERN "*.d")
9592
else()
9693
function(build_jit_runtime d_flags c_flags ld_flags path_suffix outlist_targets)
9794
endfunction()

runtime/ldc-build-runtime.d.in

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ void runCMake() {
159159
"-DDMDFE_MINOR_VERSION=@DMDFE_MINOR_VERSION@",
160160
"-DDMDFE_PATCH_VERSION=@DMDFE_PATCH_VERSION@",
161161
"-DLDC_WITH_LLD=@LDC_WITH_LLD@",
162+
"-DINCLUDE_INSTALL_DIR=@INCLUDE_INSTALL_DIR@",
162163
];
163164

164165
if (config.targetSystem.length) args ~= "-DTARGET_SYSTEM=" ~ config.targetSystem.join(";");

0 commit comments

Comments
 (0)