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

Conversation

kinke
Copy link
Member

@kinke kinke commented Feb 7, 2021

No description provided.

@kinke kinke force-pushed the cmake_misc branch 2 times, most recently from ea1fe0f to a7f9cf7 Compare February 7, 2021 10:47
@Geod24
Copy link
Contributor

Geod24 commented Feb 7, 2021

I gave this a try on Mac OSX, the LLVM detection works fine but the first run complained about ldmd2:

geod24@geod24mbp2018 ~/projects/dlang/ldc/build-test (git)-[remotes/kinke/cmake_misc] % cmake ..
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found host D compiler /usr/local/bin/ldmd2, with default flags ''
-- Host D compiler ID: LDMD
-- Host D compiler version: LDC - the LLVM D compiler (1.24.0)
-- Host D compiler front-end version: 2094
-- LLVM_NATIVE_ARCH: X86
-- Found LLVM: /usr/local/Cellar/llvm/11.0.1 (found suitable version "11.0.1", minimum required is "6.0")
-- Found mlir-tblgen: /usr/local/Cellar/llvm/11.0.1/bin/mlir-tblgen
-- -- Building LDC with MLIR support (/usr/local/Cellar/llvm/11.0.1)
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Checking for module 'LLVMSPIRVLib'
--   No package 'LLVMSPIRVLib' found
-- -- Building LDC without SPIR-V support: not found
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG
-- Performing Test SUPPORTS_FVISIBILITY_INLINES_HIDDEN_FLAG - Success
-- LDC version identifier: 1.25.0-git-a7f9cf7-dirty
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): ON
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): ON
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
CMake Error at cmake/Modules/ExtractDMDSystemLinker.cmake:41 (message):
  Failed to link empty D program using '/usr/local/bin/ldmd2 -wi'
Call Stack (most recent call first):
  CMakeLists.txt:642 (include)


-- Configuring incomplete, errors occurred!
See also "/Users/geod24/projects/dlang/ldc/build-test/CMakeFiles/CMakeOutput.log".
See also "/Users/geod24/projects/dlang/ldc/build-test/CMakeFiles/CMakeError.log".

When I re-ran it, without changing anything, it passed:

1 geod24@geod24mbp2018 ~/projects/dlang/ldc/build-test (git)-[remotes/kinke/cmake_misc] % cmake ..                                                                                                                                         :(
-- Found host D compiler /usr/local/bin/ldmd2, with default flags ''
-- Host D compiler ID: LDMD
-- Host D compiler version: LDC - the LLVM D compiler (1.24.0)
-- Host D compiler front-end version: 2094
-- LLVM_NATIVE_ARCH: X86
-- Found mlir-tblgen: /usr/local/Cellar/llvm/11.0.1/bin/mlir-tblgen
-- -- Building LDC with MLIR support (/usr/local/Cellar/llvm/11.0.1)
-- Checking for module 'LLVMSPIRVLib'
--   No package 'LLVMSPIRVLib' found
-- -- Building LDC without SPIR-V support: not found
-- LDC version identifier: 1.25.0-git-a7f9cf7-dirty
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): ON
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): ON
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
-- Host D compiler linker program: /usr/bin/cc
-- Host D compiler linker flags: -L/usr/local/Cellar/ldc/1.24.0/lib;-lphobos2-ldc;-ldruntime-ldc;-ldl;-lpthread;-lm;-m64
-- -- Including LTO linker plugin (LDC_INSTALL_LTOPLUGIN): ON (/usr/local/Cellar/llvm/11.0.1/lib/libLTO.dylib)
-- -- Including LLVM compiler-rt libraries (LDC_INSTALL_LLVM_RUNTIME_LIBS): ON
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.asan_osx_dynamic.dylib --> libldc_rt.asan.dylib
/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/geod24/projects/dlang/ldc/build-test/lib/libldc_rt.asan.dylib (for architecture x86_64)
/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/geod24/projects/dlang/ldc/build-test/lib/libldc_rt.asan.dylib (for architecture arm64)
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.tsan_osx_dynamic.dylib --> libldc_rt.tsan.dylib
/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/geod24/projects/dlang/ldc/build-test/lib/libldc_rt.tsan.dylib (for architecture x86_64)
/Library/Developer/CommandLineTools/usr/bin/install_name_tool: warning: changes being made to the file will invalidate the code signature in: /Users/geod24/projects/dlang/ldc/build-test/lib/libldc_rt.tsan.dylib (for architecture arm64)
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.osx.a --> libldc_rt.builtins.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.profile_osx.a --> libldc_rt.profile.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.fuzzer_osx.a --> libldc_rt.fuzzer.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.xray_osx.a --> libldc_rt.xray.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.xray-basic_osx.a --> libldc_rt.xray-basic.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.xray-fdr_osx.a --> libldc_rt.xray-fdr.a
-- --  - /usr/local/Cellar/llvm/11.0.1/lib/clang/11.0.1/lib/darwin/libclang_rt.xray-profiling_osx.a --> libldc_rt.xray-profiling.a
-- Using path for Intrinsics.td: /usr/local/Cellar/llvm/11.0.1/include
-- The ASM compiler identification is Clang
-- Found assembler: /Library/Developer/CommandLineTools/usr/bin/cc
-- -- LDC runtime configuration:
-- --  - Building 32/64-bit libraries (MULTILIB): OFF
-- --  - Building shared libraries (BUILD_SHARED_LIBS): BOTH
-- --  - Building LTO libraries (BUILD_LTO_LIBS): OFF
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Use custom passes in jit: ON
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/geod24/projects/dlang/ldc/build-test

@kinke
Copy link
Member Author

kinke commented Feb 7, 2021

Thx for testing; please re-test again from scratch, as that error should now show the compiler stderr output for troubleshooting.

@Geod24
Copy link
Contributor

Geod24 commented Feb 7, 2021

-- LDC version identifier: 1.25.0-git-fbc3161
-- -- Building LDC with dynamic compilation support (LDC_DYNAMIC_COMPILE): ON
-- -- Building LDC with integrated LLD linker (LDC_WITH_LLD): ON
-- -- Building LDC with plugin support (LDC_ENABLE_PLUGINS): ON
CMake Error at cmake/Modules/ExtractDMDSystemLinker.cmake:41 (message):
  Failed to link empty D program using '/usr/local/bin/ldmd2 -wi':

  ld: library not found for -ldl

  clang: error: linker command failed with exit code 1 (use -v to see
  invocation)

  Error: /Library/Developer/CommandLineTools/usr/bin/cc failed with status: 1
Call Stack (most recent call first):
  CMakeLists.txt:642 (include)


-- Configuring incomplete, errors occurred!
See also "/Users/geod24/projects/dlang/ldc/build-test/CMakeFiles/CMakeOutput.log".
See also "/Users/geod24/projects/dlang/ldc/build-test/CMakeFiles/CMakeError.log".

@kinke
Copy link
Member Author

kinke commented Feb 7, 2021

Hmm, that would mean a trivial /usr/local/bin/ldmd2 -wi -v hello.d fails to link, with the src file containing void main() {}. Can you investigate a bit (verify that your installation isn't broken)? Possibly outputting ${stdout} too so that it should become clear which config file it uses and how it invokes clang.

@Geod24
Copy link
Contributor

Geod24 commented Feb 7, 2021

Hum, the issue is that CMake is trying to pull in libdl which doesn't exist on Mac (see e.g. https://reviews.llvm.org/D43168).
On the first run, cmake detects the Developer tools (aka clang) and clang just errors out. When re-running cmake, it picks up /usr/bin/cc, which is a compatibility layer (acts like GCC) and either just ignores -ldl or links an empty lib.

However, I don't know why -ldl is used. DFLAGS, LDFLAGS, LINK_FLAGS are empty.

@kinke
Copy link
Member Author

kinke commented Feb 7, 2021

Hmm, the compiler explicitly adds it for Darwin:

ldc/driver/linker-gcc.cpp

Lines 650 to 658 in 4bee4e6

// 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:
case llvm::Triple::DragonFly:

Edit: But we don't use it for the runtime libs (shared libs and test runners):

set(C_SYSTEM_LIBS m pthread)

Comment on lines +43 to 46
set(linkdl "")
if("${TARGET_SYSTEM}" MATCHES "Linux")
set(linkdl "LINKDL=-L-ldl")
endif()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for cross-compilation with our own TARGET_SYSTEM semantics.

@kinke kinke changed the title CMake: Revise status output for important build options etc. CMake: Revise status output for important build options & fix misc. annoyances Feb 8, 2021
@kinke
Copy link
Member Author

kinke commented Feb 8, 2021

@Geod24: Have you tested the latest version by chance?

Previously, it would print a *warning* but continue execution, running
into some string-replace *error* due to an undefined variable later on,
obfuscating this presumably rather common error.
…tion tests)

dmd-testsuite doesn't depend on it anymore, and GNU make is probably
rather exotic on Windows dev boxes (doesn't come with git).
This should fix concurrency errors/warnings like this, from Azure
CI Windows:

mv: cannot stat 'D:/a/1/build/runtime/objects/object.bc': No such file or directory
... many more ...
It's apparently not required to link with dl{open,close} and e.g.
not set in CMAKE_DL_LIBS for Darwin targets.
@kinke kinke merged commit ddb97aa into ldc-developers:master Feb 10, 2021
@kinke kinke deleted the cmake_misc branch February 10, 2021 20:36
@Geod24
Copy link
Contributor

Geod24 commented Feb 21, 2021

@kinke : Sorry missed the notification. Haven't tested recently (since it needed to be compiled with a different host).
Will update the Alpine / Homebrew package and let you know if I find any issue.

@kinke
Copy link
Member Author

kinke commented Feb 21, 2021

No worries; thx for updating and note that you might be affected by #3673 as package maintainer (if so, then hopefully positively :)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants