Skip to content
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

CMake: Revise status output for important build options & fix misc. annoyances #3654

Merged
merged 9 commits into from
Feb 10, 2021
2 changes: 1 addition & 1 deletion .azure-pipelines/posix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ steps:
set -ex
cd ../build
ctest -j$PARALLEL_JOBS --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest"
displayName: Run defaultlib unittests & druntime stand-alone tests
displayName: Run defaultlib unittests & druntime integration tests
condition: and(succeededOrFailed(), ne(variables['CI_OS'], 'android'))

# Install & make portable
Expand Down
9 changes: 4 additions & 5 deletions .azure-pipelines/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ steps:
curl -L -o ldc2.7z http://github.com/ldc-developers/ldc/releases/download/v%HOST_LDC_VERSION%/ldc2-%HOST_LDC_VERSION%-windows-multilib.7z 2>&1
7z x ldc2.7z > nul
mv ldc2-%HOST_LDC_VERSION%-windows-multilib host-ldc
:: Download & extract GNU make (for dmd-testsuite & druntime stand-alone tests)
:: Download & extract GNU make (for druntime integration tests)
curl -L -o make.7z https://dl.dropboxusercontent.com/s/4y36f5ydgrk4p5g/make-4.2.1.7z?dl=0 2>&1
mkdir gnu
cd gnu
Expand All @@ -68,8 +68,7 @@ steps:
- script: |
echo on
cd ..
:: git's usr/bin required to make GNU `find` precede MS one in C:\Windows\System32
set PATH=C:\Program Files\LLVM\bin;%CD%\ninja;%CD%\gnu;C:\Program Files\Git\usr\bin;%PATH%
set PATH=C:\Program Files\LLVM\bin;%CD%\ninja;%CD%\gnu;%PATH%
call "%VSINSTALLDIR%Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
echo on
cmake --version
Expand All @@ -86,7 +85,7 @@ steps:
- script: |
echo on
cd ..
set PATH=C:\Program Files\LLVM\bin;%CD%\ninja;%CD%\gnu;C:\Program Files\Git\usr\bin;%PATH%
set PATH=C:\Program Files\LLVM\bin;%CD%\ninja;%CD%\gnu;%PATH%
call "%VSINSTALLDIR%Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
echo on
set INSTALL_DIR=%CD%/install
Expand Down Expand Up @@ -132,7 +131,7 @@ steps:
call "%VSINSTALLDIR%Common7\Tools\VsDevCmd.bat" -arch=%ARCH%
cd build
ctest -j4 --output-on-failure -E "dmd-testsuite|lit-tests|ldc2-unittest"
displayName: Run defaultlib unittests & druntime stand-alone tests
displayName: Run defaultlib unittests & druntime integration tests
condition: succeededOrFailed()

# Install, make portable and copy curl & MinGW-w64-based libs
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ commonSteps: &commonSteps
fi
DMD_TESTSUITE_MAKE_ARGS=-j$PARALLELISM ctest -V -R dmd-testsuite
- run:
name: Run defaultlib unittests & druntime stand-alone tests
name: Run defaultlib unittests & druntime integration tests
when: always
command: cd ../build && ctest -j$PARALLELISM --output-on-failure -E "dmd-testsuite|ldc2-unittest|lit-tests"

Expand Down
2 changes: 1 addition & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ common_steps_template: &COMMON_STEPS_TEMPLATE
cd $CIRRUS_WORKING_DIR/../build
DMD_TESTSUITE_MAKE_ARGS=-j$PARALLELISM ctest -V -R dmd-testsuite
run_defaultlib_tests_script: |
# Run defaultlib unittests & druntime stand-alone tests
# Run defaultlib unittests & druntime integration tests
cd $CIRRUS_WORKING_DIR/../build
ctest -j$PARALLELISM --output-on-failure -E "dmd-testsuite|ldc2-unittest|lit-tests"

Expand Down
48 changes: 21 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ project(ldc)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules")

include(FindDCompiler)
include(CheckIncludeFile)
include(CheckIncludeFileCXX)
include(CheckLibraryExists)
include(CheckCXXCompilerFlag)
include(CheckDSourceCompiles)
include(CheckLinkFlag)
Expand Down Expand Up @@ -51,14 +48,14 @@ endforeach()
# Set MLIR support variables if it is found. Only try for LLVM >= 10.0.
if(NOT (LDC_LLVM_VER LESS 1000))
include(FindMLIR)
message(STATUS "Building LDC with MLIR support: ${MLIR_FOUND}")
if(MLIR_FOUND)
message(STATUS "Using MLIR installation directory: ${MLIR_ROOT_DIR}")
message(STATUS "-- Building LDC with MLIR support (${MLIR_ROOT_DIR})")
include_directories(${MLIR_INCLUDE_DIR})
add_definitions("-DLDC_MLIR_ENABLED")

set(LLVM_LIBRARIES "${MLIR_LIBRARIES}" ${LLVM_LIBRARIES})
endif() #if MLIR_FOUND
else()
message(STATUS "-- Building LDC without MLIR support: not found")
endif()
endif()

# Check and adapt for LLVMSPIRVLib (Khronos SPIRV-LLVM-Translator)
Expand Down Expand Up @@ -95,8 +92,10 @@ if(NOT LLVM_SPIRV_FOUND)
endif()
endif()
if(LLVM_SPIRV_FOUND)
message(STATUS "Building with SPIR-V support")
message(STATUS "-- Building LDC with SPIR-V support")
add_definitions("-DLDC_LLVM_SUPPORTED_TARGET_SPIRV=1")
else()
message(STATUS "-- Building LDC without SPIR-V support: not found")
endif()

#
Expand Down Expand Up @@ -180,10 +179,10 @@ endif()

if(MSVC)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "Let D host compiler output 64bit object files")
message(STATUS "Let D host compiler output 64-bit object files")
append("-m64" DFLAGS_BASE)
else()
message(STATUS "Let D host compiler output 32bit COFF object files")
message(STATUS "Let D host compiler output 32-bit COFF object files")
if(${D_COMPILER_ID} STREQUAL "DigitalMars")
append("-m32mscoff" DFLAGS_BASE)
else()
Expand Down Expand Up @@ -453,7 +452,7 @@ option(LDC_DYNAMIC_COMPILE_USE_CUSTOM_PASSES "Use custom LDC passes in jit" ON)
if(LDC_DYNAMIC_COMPILE STREQUAL "AUTO")
set(LDC_DYNAMIC_COMPILE ON)
endif()
message(STATUS "Building LDC with dynamic compilation support: ${LDC_DYNAMIC_COMPILE} (LDC_DYNAMIC_COMPILE=${LDC_DYNAMIC_COMPILE})")
message(STATUS "-- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): ${LDC_DYNAMIC_COMPILE}")
if(LDC_DYNAMIC_COMPILE)
add_definitions(-DLDC_DYNAMIC_COMPILE)
add_definitions(-DLDC_DYNAMIC_COMPILE_API_VERSION=3)
Expand Down Expand Up @@ -494,11 +493,12 @@ endif()
if(LDC_WITH_LLD)
append("-DLDC_WITH_LLD" LDC_CXXFLAGS)
endif()
message(STATUS "Building LDC with integrated LLD: ${LDC_WITH_LLD} (LDC_WITH_LLD=${LDC_WITH_LLD})")
message(STATUS "-- Building LDC with integrated LLD linker (LDC_WITH_LLD): ${LDC_WITH_LLD}")

# if llvm was built with assertions we have to do the same
# as there are some headers with differing behavior based on NDEBUG
if(LLVM_ENABLE_ASSERTIONS)
message(STATUS "-- Building LDC with enabled assertions (inherited from LLVM build)")
append("-UNDEBUG" EXTRA_CXXFLAGS)
# avoid MSVC warning D9025 about "-DNDEBUG ... -UNDEBUG"
string(REGEX REPLACE "(^| )[/-]D *NDEBUG( |$)" "\\1-UNDEBUG\\2" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
Expand Down Expand Up @@ -626,7 +626,7 @@ if(LDC_ENABLE_PLUGINS)
endif()
endif()
endif()
message(STATUS "Building LDC with plugin support: ${LDC_ENABLE_PLUGINS} (LDC_ENABLE_PLUGINS=${LDC_ENABLE_PLUGINS})")
message(STATUS "-- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ${LDC_ENABLE_PLUGINS}")

if(NOT DEFINED LDC_LINK_MANUALLY)
if(MSVC)
Expand Down Expand Up @@ -666,17 +666,10 @@ endif()
#
# LDMD
#
include(CheckSymbolExists)
CHECK_SYMBOL_EXISTS(_SC_ARG_MAX "unistd.h" HAVE_SC_ARG_MAX)
if (HAVE_SC_ARG_MAX)
append("-DHAVE_SC_ARG_MAX" CMAKE_CXX_FLAGS)
endif()

set_source_files_properties(driver/args.cpp driver/exe_path.cpp driver/ldmd.cpp driver/response.cpp PROPERTIES
COMPILE_FLAGS "${LLVM_CXXFLAGS} ${LDC_CXXFLAGS}"
COMPILE_DEFINITIONS LDC_EXE_NAME="${LDC_EXE_NAME}"
)

add_library(LDMD_CXX_LIB ${LDC_LIB_TYPE} driver/args.cpp driver/exe_path.cpp driver/ldmd.cpp driver/response.cpp driver/args.h driver/exe_path.h)
set_target_properties(
LDMD_CXX_LIB PROPERTIES
Expand Down Expand Up @@ -725,12 +718,14 @@ if (LDC_INSTALL_LTOPLUGIN)
set(LDC_LTO_BINARY_NAME LLVMgold-ldc.so)
endif()
if(EXISTS ${LLVM_LTO_BINARY})
message(STATUS "Also installing LTO binary: ${LLVM_LTO_BINARY} (LDC_INSTALL_LTOPLUGIN=${LDC_INSTALL_LTOPLUGIN})")
message(STATUS "-- Including LTO linker plugin (LDC_INSTALL_LTOPLUGIN): ON (${LLVM_LTO_BINARY})")
copy_and_rename_file(${LLVM_LTO_BINARY} ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/${LDC_LTO_BINARY_NAME})
install(PROGRAMS ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/${LDC_LTO_BINARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
else()
message(STATUS "Not found: ${LLVM_LTO_BINARY}")
message(STATUS "-- Including LTO linker plugin (LDC_INSTALL_LTOPLUGIN): OFF (cannot find ${LLVM_LTO_BINARY})")
endif()
else()
message(STATUS "-- Including LTO linker plugin (LDC_INSTALL_LTOPLUGIN): ${LDC_INSTALL_LTOPLUGIN}")
endif()

#
Expand All @@ -746,19 +741,18 @@ set(LDC_INSTALL_LLVM_RUNTIME_LIBS ${LDC_INSTALL_LLVM_RUNTIME_LIBS_DEFAULT} CACHE
function(copy_compilerrt_lib llvm_lib_name ldc_lib_name fixup_dylib)
set(llvm_lib_path ${LLVM_LIBRARY_DIRS}/clang/${LLVM_VERSION_BASE_STRING}/lib/${llvm_lib_name})
if(EXISTS ${llvm_lib_path})
message(STATUS "Copying runtime library: ${llvm_lib_path} --> ${ldc_lib_name}")
message(STATUS "-- - ${llvm_lib_path} --> ${ldc_lib_name}")
set(ldc_lib_path ${PROJECT_BINARY_DIR}/lib${LIB_SUFFIX}/${ldc_lib_name})
copy_and_rename_file(${llvm_lib_path} ${ldc_lib_path})
if (fixup_dylib)
execute_process(COMMAND install_name_tool -id @rpath/${ldc_lib_name} ${ldc_lib_path})
endif()
install(FILES ${ldc_lib_path} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX})
else()
message(STATUS "Not found: ${llvm_lib_path}")
message(STATUS "-- - not found: ${llvm_lib_path}")
endif()
endfunction()
include(CheckTypeSize)
check_type_size(void* ptr_size)
message(STATUS "-- Including LLVM compiler-rt libraries (LDC_INSTALL_LLVM_RUNTIME_LIBS): ${LDC_INSTALL_LLVM_RUNTIME_LIBS}")
if (LDC_INSTALL_LLVM_RUNTIME_LIBS)
# Locate LLVM sanitizer runtime libraries, and copy them to our lib folder

Expand Down Expand Up @@ -791,7 +785,7 @@ if (LDC_INSTALL_LLVM_RUNTIME_LIBS)
endif()
elseif(WIN32)
set(compilerrt_arch_suffix "x86_64")
if(${ptr_size} EQUAL 4)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(compilerrt_arch_suffix "i386")
endif()
copy_compilerrt_lib("windows/clang_rt.asan-${compilerrt_arch_suffix}.lib" "ldc_rt.asan.lib" FALSE)
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/ExtractDMDSystemLinker.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ execute_process(
ERROR_STRIP_TRAILING_WHITESPACE
)

if(result_code)
message(FATAL_ERROR "Failed to link empty D program using '${D_COMPILER} ${cmdflags}'")
if(NOT "${result_code}" STREQUAL "0")
message(FATAL_ERROR "Failed to link empty D program using '${D_COMPILER} ${D_COMPILER_FLAGS} ${DFLAGS_BASE}':\n${stderr}")
endif()

if("${D_COMPILER_ID}" STREQUAL "GDMD")
Expand Down
62 changes: 37 additions & 25 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ find_program(LLVM_CONFIG
PATHS ${LLVM_ROOT_DIR}/bin NO_DEFAULT_PATH
DOC "Path to llvm-config tool.")
find_program(LLVM_CONFIG NAMES ${llvm_config_names})
if(APPLE)
# extra fallbacks for MacPorts & Homebrew
find_program(LLVM_CONFIG
NAMES ${llvm_config_names}
PATHS /opt/local/libexec/llvm-11/bin /opt/local/libexec/llvm-10/bin /opt/local/libexec/llvm-9.0/bin
/opt/local/libexec/llvm-8.0/bin /opt/local/libexec/llvm-7.0/bin /opt/local/libexec/llvm-6.0/bin
/opt/local/libexec/llvm/bin
/usr/local/opt/llvm@11/bin /usr/local/opt/llvm@10/bin /usr/local/opt/llvm@9/bin
/usr/local/opt/llvm@8/bin /usr/local/opt/llvm@7/bin /usr/local/opt/llvm@6/bin
/usr/local/opt/llvm/bin
NO_DEFAULT_PATH)
endif()

# Prints a warning/failure message depending on the required/quiet flags. Copied
# from FindPackageHandleStandardArgs.cmake because it doesn't seem to be exposed.
Expand All @@ -50,15 +62,15 @@ macro(_LLVM_FAIL _msg)
message(FATAL_ERROR "${_msg}")
else()
if(NOT LLVM_FIND_QUIETLY)
message(STATUS "${_msg}")
message(WARNING "${_msg}")
endif()
endif()
endmacro()


if(NOT LLVM_CONFIG)
if(NOT LLVM_FIND_QUIETLY)
message(WARNING "Could not find llvm-config (LLVM >= ${LLVM_FIND_VERSION}). Try manually setting LLVM_CONFIG to the llvm-config executable of the installation to use.")
_LLVM_FAIL("No LLVM installation (>= ${LLVM_FIND_VERSION}) found. Try manually setting the 'LLVM_ROOT_DIR' or 'LLVM_CONFIG' variables.")
endif()
else()
macro(llvm_set var flag)
Expand Down Expand Up @@ -138,35 +150,35 @@ else()
string(REGEX MATCH "set\\(LLVM_NATIVE_ARCH (.+)\\)" LLVM_NATIVE_ARCH "${LLVM_NATIVE_ARCH}")
set(LLVM_NATIVE_ARCH ${CMAKE_MATCH_1})
message(STATUS "LLVM_NATIVE_ARCH: ${LLVM_NATIVE_ARCH}")
endif()

# On CMake builds of LLVM, the output of llvm-config --cxxflags does not
# include -fno-rtti, leading to linker errors. Be sure to add it.
if(NOT MSVC AND (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")))
if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti")
# On CMake builds of LLVM, the output of llvm-config --cxxflags does not
# include -fno-rtti, leading to linker errors. Be sure to add it.
if(NOT MSVC AND (CMAKE_COMPILER_IS_GNUCXX OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")))
if(NOT ${LLVM_CXXFLAGS} MATCHES "-fno-rtti")
set(LLVM_CXXFLAGS "${LLVM_CXXFLAGS} -fno-rtti")
endif()
endif()
endif()

# Remove some clang-specific flags for gcc.
if(CMAKE_COMPILER_IS_GNUCXX)
string(REPLACE "-Wcovered-switch-default " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
string(REPLACE "-Wstring-conversion " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
string(REPLACE "-fcolor-diagnostics " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
# this requires more recent gcc versions (not supported by 4.9)
string(REPLACE "-Werror=unguarded-availability-new " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
endif()
# Remove some clang-specific flags for gcc.
if(CMAKE_COMPILER_IS_GNUCXX)
string(REPLACE "-Wcovered-switch-default " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
string(REPLACE "-Wstring-conversion " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
string(REPLACE "-fcolor-diagnostics " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
# this requires more recent gcc versions (not supported by 4.9)
string(REPLACE "-Werror=unguarded-availability-new " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
endif()

# Remove gcc-specific flags for clang.
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
string(REPLACE "-Wno-maybe-uninitialized " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
endif()
# Remove gcc-specific flags for clang.
if(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
string(REPLACE "-Wno-maybe-uninitialized " "" LLVM_CXXFLAGS ${LLVM_CXXFLAGS})
endif()

string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "([0-9]+).*" "\\1" LLVM_VERSION_MAJOR "${LLVM_VERSION_STRING}" )
string(REGEX REPLACE "[0-9]+\\.([0-9]+).*[A-Za-z]*" "\\1" LLVM_VERSION_MINOR "${LLVM_VERSION_STRING}" )

if (${LLVM_VERSION_STRING} VERSION_LESS ${LLVM_FIND_VERSION})
message(FATAL_ERROR "Unsupported LLVM version found ${LLVM_VERSION_STRING}. At least version ${LLVM_FIND_VERSION} is required.")
if (${LLVM_VERSION_STRING} VERSION_LESS ${LLVM_FIND_VERSION})
_LLVM_FAIL("Unsupported LLVM version ${LLVM_VERSION_STRING} found (${LLVM_CONFIG}). At least version ${LLVM_FIND_VERSION} is required. You can also set variables 'LLVM_ROOT_DIR' or 'LLVM_CONFIG' to use a different LLVM installation.")
endif()
endif()

# Use the default CMake facilities for handling QUIET/REQUIRED.
Expand Down
4 changes: 0 additions & 4 deletions driver/ldmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@
#include <sys/stat.h>
#endif

#ifdef HAVE_SC_ARG_MAX
#include <unistd.h>
#endif

namespace ls = llvm::sys;

// We reuse DMD's response file parsing routine for maximum compatibility - it
Expand Down
3 changes: 1 addition & 2 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,11 +647,10 @@ void ArgsBuilder::addDefaultPlatformLibs() {
args.push_back("-lunwind"); // for druntime backtrace
}
args.push_back("-lrt");
args.push_back("-ldl");
// fallthrough
case llvm::Triple::Darwin:
case llvm::Triple::MacOSX:
args.push_back("-ldl");
// fallthrough
case llvm::Triple::FreeBSD:
case llvm::Triple::NetBSD:
case llvm::Triple::OpenBSD:
Expand Down
1 change: 1 addition & 0 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl, const bool willDefine) {
// this can e.g. happen for special __xtoHash member functions
Logger::println("Function hasn't had sema3 run yet, running it now.");
const bool semaSuccess = fdecl->functionSemantic3();
(void)semaSuccess;
assert(semaSuccess);
Module::runDeferredSemantic3();
}
Expand Down
3 changes: 1 addition & 2 deletions gen/toir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1093,10 +1093,9 @@ class ToElemVisitor : public Visitor {
// evaluate the base expression but delay getting its pointer until the
// potential bounds have been evaluated
DValue *v = toElem(e->e1);
auto getBasePointer = [e, v, etype]() {
auto getBasePointer = [v, etype]() {
if (etype->ty == Tpointer) {
// pointer slicing
assert(e->lwr);
return DtoRVal(v);
} else {
// array slice
Expand Down
Loading