-
-
Notifications
You must be signed in to change notification settings - Fork 268
Support ldc2.conf as a directory #4954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
2b069b0
6ac0db0
20494ea
6a4223a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,23 +17,14 @@ project(ldc) | |
|
||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules") | ||
|
||
include(LdcCommon) | ||
|
||
include(FindDCompiler) | ||
include(CheckCXXCompilerFlag) | ||
include(CheckDSourceCompiles) | ||
include(CheckLinkFlag) | ||
include(BuildDExecutable) | ||
|
||
# Helper function | ||
function(append value) | ||
foreach(variable ${ARGN}) | ||
if(${variable} STREQUAL "") | ||
set(${variable} "${value}" PARENT_SCOPE) | ||
else() | ||
set(${variable} "${${variable}} ${value}" PARENT_SCOPE) | ||
endif() | ||
endforeach(variable) | ||
endfunction() | ||
|
||
# | ||
# Locate LLVM. | ||
# | ||
|
@@ -128,20 +119,9 @@ set(DMDFE_PATCH_VERSION 0) | |
|
||
set(DMD_VERSION ${DMDFE_MAJOR_VERSION}.${DMDFE_MINOR_VERSION}.${DMDFE_PATCH_VERSION}) | ||
|
||
# Generally, we want to install everything into CMAKE_INSTALL_PREFIX, but when | ||
# it is /usr, put the config files into /etc to meet common practice. | ||
if(NOT DEFINED SYSCONF_INSTALL_DIR) | ||
if(CMAKE_INSTALL_PREFIX STREQUAL "/usr") | ||
set(SYSCONF_INSTALL_DIR "/etc") | ||
else() | ||
set(SYSCONF_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/etc") | ||
endif() | ||
endif() | ||
|
||
set(D_VERSION ${DMDFE_MAJOR_VERSION} CACHE STRING "D language version") | ||
set(PROGRAM_PREFIX "" CACHE STRING "Prepended to ldc/ldmd binary names") | ||
set(PROGRAM_SUFFIX "" CACHE STRING "Appended to ldc/ldmd binary names") | ||
set(CONF_INST_DIR ${SYSCONF_INSTALL_DIR} CACHE PATH "Directory ldc2.conf is installed to") | ||
set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/include/d CACHE PATH "Path to install D modules to") | ||
|
||
# Note: LIB_SUFFIX should perhaps be renamed to LDC_LIBDIR_SUFFIX. | ||
|
@@ -923,10 +903,6 @@ if(NOT DEFINED COMPILER_RT_LIBDIR_CONFIG) | |
set(COMPILER_RT_LIBDIR_CONFIG "${COMPILER_RT_LIBDIR}") | ||
endif() | ||
endif() | ||
if(DEFINED COMPILER_RT_LIBDIR_CONFIG) | ||
message(STATUS "Adding ${COMPILER_RT_LIBDIR_CONFIG} to lib-dirs in configuration file") | ||
set(OPTIONAL_COMPILER_RT_DIR "\n \"${COMPILER_RT_LIBDIR_CONFIG}\", // compiler-rt directory") | ||
endif() | ||
|
||
# | ||
# Auxiliary build and test utils. | ||
|
@@ -974,6 +950,59 @@ endif() | |
# | ||
add_subdirectory(tools) | ||
|
||
# | ||
# Compiler ldc2.conf configuration | ||
# | ||
|
||
set(switches) | ||
|
||
# LLVM 16: Disable function specializations by default. | ||
# They cause miscompiles of e.g. the frontend for some targets (macOS x86_64 and Windows x64). | ||
if(LDC_LLVM_VER GREATER 1599 AND LDC_LLVM_VER LESS 1700) | ||
list(APPEND switches "-func-specialization-size-threshold=1000000000") | ||
endif() | ||
|
||
if(DEFINED COMPILER_RT_LIBDIR_CONFIG) | ||
message(STATUS "Adding ${COMPILER_RT_LIBDIR_CONFIG} to lib-dirs in configuration file") | ||
endif() | ||
|
||
list(APPEND switches "-defaultlib=phobos2-ldc,druntime-ldc") | ||
|
||
makeConfSection(NAME "35-ldc-compiler" SECTION "default" | ||
BUILD | ||
SWITCHES ${switches} | ||
# -defaultlib is configure in runtime/CMakeLists.txt | ||
POST_SWITCHES | ||
"-I${PROJECT_SOURCE_DIR}/runtime/druntime/src" | ||
"-I${PROJECT_BINARY_DIR}/import" | ||
"-I${PROJECT_SOURCE_DIR}/runtime/phobos" | ||
"-I${PROJECT_SOURCE_DIR}/runtime/jit-rt/d" | ||
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG} | ||
|
||
INSTALL | ||
SWITCHES ${switches} | ||
POST_SWITCHES "-I${INCLUDE_INSTALL_DIR}" | ||
LIB_DIRS ${COMPILER_RT_LIBDIR_CONFIG} | ||
) | ||
|
||
set(wasm_switches) | ||
list(APPEND wasm_switches -defaultlib=) | ||
# Default wasm stack is only 64kb, this is rather small, let's bump it to 1mb | ||
list(APPEND wasm_switches -L-z -Lstack-size=1048576) | ||
# Protect from stack overflow overwriting global memory | ||
list(APPEND wasm_switches -L--stack-first) | ||
if(LDC_WITH_LLD) | ||
list(APPEND wasm_switches -link-internally) | ||
endif() | ||
# LLD 8+ requires (new) `--export-dynamic` for WebAssembly (https://github.com/ldc-developers/ldc/issues/3023). | ||
list(APPEND wasm_switches -L--export-dynamic) | ||
|
||
makeConfSection(NAME "40-ldc-wasm" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should decrease the order of this - these are just some wasm defaults. The main 'problem' is that we disable linking druntime and Phobos via With the much greater flexibility now, we could add 2 wasm sections, and e.g. restrict the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [just an idea for a follow-up PR perhaps, not here] |
||
SECTION "^wasm(32|64)-" | ||
SWITCHES ${wasm_switches} | ||
LIB_DIRS OVERRIDE | ||
) | ||
|
||
# | ||
# Test and runtime targets. Note that enable_testing() is order-sensitive! | ||
# | ||
|
@@ -1006,6 +1035,15 @@ option(LDC_BUILD_RUNTIME "Build the runtime libraries" ${_LDC_BUILD_RUNTIME_DEFA | |
|
||
if(LDC_BUILD_RUNTIME) | ||
add_subdirectory(runtime) | ||
|
||
# POST_BUILD can't be used for targets in a different directory so | ||
# runtime/CMakeLists.txt can't directly add the commands. | ||
if(_LDC_POST_BUILD_COMMANDS) | ||
add_custom_command(TARGET ${LDC_EXE} POST_BUILD | ||
${_LDC_POST_BUILD_COMMANDS} | ||
BYPRODUCTS ${_LDC_POST_BUILD_BYPRODUCTS} | ||
) | ||
endif() | ||
else() | ||
message(STATUS "NOT building the runtime libraries (LDC_BUILD_RUNTIME=OFF)") | ||
endif() | ||
|
@@ -1045,6 +1083,11 @@ if(${BUILD_SHARED}) | |
install(TARGETS ${LDC_LIB} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}) | ||
endif() | ||
|
||
# Add some documentation to the installed config files | ||
if(NOT DONT_INSTALL_CONF) | ||
install(FILES "ldc2.conf.header" DESTINATION "${CONF_INST_DIR}/ldc2.conf" RENAME 00-docs.conf) | ||
endif() | ||
kinke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux") | ||
if(NOT DEFINED BASH_COMPLETION_COMPLETIONSDIR) | ||
find_package(bash-completion QUIET) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Common functionality shared by the compiler and the runtime build system. | ||
kinke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function(append value) | ||
foreach(variable ${ARGN}) | ||
if(${variable} STREQUAL "") | ||
set(${variable} "${value}" PARENT_SCOPE) | ||
else() | ||
set(${variable} "${${variable}} ${value}" PARENT_SCOPE) | ||
endif() | ||
endforeach(variable) | ||
endfunction() | ||
|
||
include(LdcConfig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably remove the
30-ldc-runtime-lib.conf
file - AFAIK, that containsdefault: …
with the x86_64 macOS libs. The special thing about the macOS universal package is that it's used by 2 compilers - the native x86_64 and native arm64 ones, merged into the universalbin/ldc2
executable. That's why we don't have a cleardefault
target, and have these x86_64/arm64 sections instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I've accidentally removed the
rm
line that I've added while editing the file :(There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm somewhat unsatisfied with the
30-ldc-runtime
and31-ldc-runtime
inconsistent naming scheme but I guess I can't do anything unless the triple situation changesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can tweak the naming scheme anytime. E.g., the current 30 config part is more than just the runtime libs, at least for the iOS configs - when cross-compiling, we normally need to tweak the used C compiler for linking and preprocessing too, either via
-gcc
or adding extra-Xcc
flags. So I'd see this as target-specific group, where I think coupling both OS and arch makes sense (i.e., no need for a 30 OS group, and a separate 40 arch group or so).Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
E.g.:
The compiler-rt path would logically belong to the target group, but is only known when building the compiler. We could e.g. create a
70-compiler-rt.conf
as part of the compiler build, appending the compiler-rt libdir fordefault
(i.e., all targets). So that a user can append a better one earlier in the 50-target group, and/or fix up the section name in70-compiler-rt.conf
to only apply to the default target (by matching its triple).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or what would also work:
51-target-compiler-rt.conf
, appending the lib-dir fordefault
. And the overrides in 55 then reset lib-dirs anyway.