-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
CMake: Improve usage of llvm-config (esp. for consistent static/shared linking)
#12136
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
Conversation
|
IIUC, |
de26be4 to
bc1c5e2
Compare
|
Any extra steps I need to take to make sure this doesn't break zig-bootstrap? Or will the CI already cover that? |
|
I have only shared libraries, and before bc1c5e2 it worked fine. -- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.10.0-dev.3013+e867127a6
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBinaryFormat.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBitstreamReader.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRemarks.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMCore.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBitReader.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDebugInfoCodeView.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMC.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMCParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMTextAPI.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMObject.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDebugInfoDWARF.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMProfileData.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAnalysis.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBitWriter.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMTransformUtils.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAggressiveInstCombine.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMInstCombine.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMScalarOpts.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMTarget.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMFuzzMutate.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMFileCheck.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMInterfaceStub.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMIRReader.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSelectionDAG.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDebugInfoMSF.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAsmPrinter.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMIRParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMGlobalISel.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDWARFLinker.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMExtensions.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMFrontendOpenACC.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMFrontendOpenMP.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMInstrumentation.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLinker.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVectorize.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMipo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMObjCARCOpts.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMCoroutines.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMCFGuard.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPasses.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLTO.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMCDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMCA.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMObjectYAML.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMOption.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDebugInfoGSYM.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDebugInfoPDB.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSymbolize.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDWP.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMOrcShared.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMOrcTargetProcess.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRuntimeDyld.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMExecutionEngine.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMInterpreter.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMJITLink.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMCJIT.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMOrcJIT.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMXCoreInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMXCoreDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMXCoreCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMXCoreDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAVRInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAVRDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAVRCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAVRAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAVRDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyUtils.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWebAssemblyDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSystemZInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSystemZDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSystemZCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSystemZAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSystemZDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRISCVInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRISCVDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRISCVCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRISCVAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMRISCVDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSparcInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSparcDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSparcCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSparcAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMSparcDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64Info.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64Utils.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64Desc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64CodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64AsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAArch64Disassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMSP430Info.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMSP430Desc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMSP430CodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMSP430AsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMSP430Disassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMHexagonInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMHexagonDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMHexagonAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMHexagonCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMHexagonDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLanaiInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLanaiDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLanaiAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLanaiCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLanaiDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVEInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVEDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVECodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVEAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMVEDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMipsInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMipsDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMipsCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMipsAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMMipsDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMNVPTXInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMNVPTXDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMNVPTXCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPowerPCInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPowerPCDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPowerPCCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPowerPCAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMPowerPCDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBPFInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBPFDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBPFCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBPFAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMBPFDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86Info.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86Desc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86CodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86AsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86Disassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMX86TargetMCA.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMUtils.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMARMDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUInfo.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUUtils.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUDesc.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUCodeGen.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUAsmParser.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUDisassembler.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMAMDGPUTargetMCA.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLineEditor.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMCoverage.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMDlltoolDriver.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMLibDriver.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMXRay.a
llvm-config: error: missing: /usr/lib/llvm/14/lib64/libLLVMWindowsManifest.a
-- Found llvm: /usr/lib/llvm/14/lib64/libLLVM-14.so (Required is at least version "14")
-- Found clang: /usr/lib/llvm/14/lib64/libclang-cpp.so.14 (Required is at least version "14")
-- Could NOT find lld (missing: LLD_LIBRARIES LLD_INCLUDE_DIRS) (Required is at least version "14")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LLD_INCLUDE_DIRS (ADVANCED)
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
used as include directory in directory /home/bratishkaerik/zig
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of
"embedded_softfloat":
"LLD_INCLUDE_DIRS-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "zigcpp":
"LLD_INCLUDE_DIRS-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "opt_c_util":
"LLD_INCLUDE_DIRS-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "zigstage1":
"LLD_INCLUDE_DIRS-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "zig0":
"LLD_INCLUDE_DIRS-NOTFOUND"
CMake Error in CMakeLists.txt:
Found relative path while evaluating include directories of "zig":
"LLD_INCLUDE_DIRS-NOTFOUND"
-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly. |
|
Thanks for the report. I'll look into it. Can you also share the output before this change, for comparison? |
-- The C compiler identification is GNU 11.3.0
-- The CXX compiler identification is GNU 11.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /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: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.10.0-dev.3013+e867127a6
-- Found llvm: /usr/lib/llvm/14/lib64/libLLVM-14.so (Required is at least version "14")
-- Found clang: /usr/lib/llvm/14/lib64/libclang-cpp.so (Required is at least version "14")
-- Found lld: /usr/lib64/liblldMinGW.so;/usr/lib64/liblldELF.so;/usr/lib64/liblldCOFF.so;/usr/lib64/liblldWasm.so;/usr/lib64/liblldMachO.so;/usr/lib64/liblldCommon.so (Required is at least version "14")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /home/bratishkaerik/zig/build |
|
I tried this on M1 Mac and successfully built stage1 and stage2 without the zlib-workaround. Behaviour tests worked as well. However, building stage3 currently crashes. This started to happen on master too, today. So it may be unrelated. |
Do you mean #12069? IDK how but I can build stage1 without this workaround (both static and shared zlib installed) (IIUC llvm-config can't choose between static and shared form on affected systems?) |
Yes, #12069. Interesting! I had this problem on ARM Mac and Intel Mac, other people reported it on Arch Linux and NixOS. What are you running? |
Gentoo Linux, tried https://packages.gentoo.org/packages/sys-libs/zlib (shared library) with |
The stage 3 problems may be related to #12133. I have to rework that PR a bit, but it'd be helpful to know if it makes any difference for you as-is |
bc1c5e2 to
1079cb7
Compare
|
Notice:
But it surely does. It's a bit confusing. Besides this, thank you so much! |
|
Thanks for the helpful reports! Can you share the output of |
Empty line. Maybe |
The commit just pushed should report the error received from llvm-config. Would you mind trying it once more? |
|
|
That error message should have said "LLVM 14.x found at /usr/lib/llvm/14/bin/llvm-config does not support linking as a static library". Fixed now Regarding the failure itself: Are the files reported missing present elsewhere in If not, then CMake might just be correctly informing you that there is no static version of LLVM that it can find to link against. |
Oh! Now I can sleep in peace :)
Only shared. #12136 (comment) |
b4216d7 to
3371470
Compare
|
Pushed a change to build This is the first time we'll be building and installing a shared library as part of the Zig build process, so hopefully I got all of the details right (especially |
warning: FileNotFound: /home/bratishkaerik/zig/build/zigcpp/libzigcpp.a
thread 25859 panic: attempt to unwrap error: FileNotFound
/home/bratishkaerik/zig/lib/std/process.zig:373:46: 0x5654b62bed41 in std.process.getEnvVarOwned (zig1)
const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
^
/home/bratishkaerik/zig/lib/std/process.zig:373:46: 0x5654b62bed41 in std.process.getEnvVarOwned (zig1)
const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
^
/home/bratishkaerik/zig/lib/std/process.zig:373:46: 0x5654b62bed41 in std.process.getEnvVarOwned (zig1)
const result = os.getenv(key) orelse return error.EnvironmentVariableNotFound;
^
/home/bratishkaerik/zig/lib/std/os.zig:3068:19: 0x5654b62d5019 in std.os.readlinkZ (zig1)
.INVAL => return error.NotLink,
^
/home/bratishkaerik/zig/lib/std/zig/system/NativeTargetInfo.zig:419:26: 0x5654b655d5d8 in std.zig.system.NativeTargetInfo.glibcVerFromSO (zig1)
error.NotLink => return error.GnuLibCVersionUnavailable,
^
/home/bratishkaerik/zig/lib/std/os.zig:2749:19: 0x5654b62463c0 in std.os.mkdiratZ (zig1)
.EXIST => return error.PathAlreadyExists,
^
/home/bratishkaerik/zig/lib/std/os.zig:2709:9: 0x5654b6246276 in std.os.mkdirat (zig1)
return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1327:9: 0x5654b6246186 in std.fs.Dir.makeDir (zig1)
try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
^
/home/bratishkaerik/zig/lib/std/os.zig:2749:19: 0x5654b62463c0 in std.os.mkdiratZ (zig1)
.EXIST => return error.PathAlreadyExists,
^
/home/bratishkaerik/zig/lib/std/os.zig:2709:9: 0x5654b6246276 in std.os.mkdirat (zig1)
return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1327:9: 0x5654b6246186 in std.fs.Dir.makeDir (zig1)
try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
^
/home/bratishkaerik/zig/lib/std/os.zig:2749:19: 0x5654b62463c0 in std.os.mkdiratZ (zig1)
.EXIST => return error.PathAlreadyExists,
^
/home/bratishkaerik/zig/lib/std/os.zig:2709:9: 0x5654b6246276 in std.os.mkdirat (zig1)
return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1327:9: 0x5654b6246186 in std.fs.Dir.makeDir (zig1)
try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
^
/home/bratishkaerik/zig/lib/std/os.zig:2749:19: 0x5654b62463c0 in std.os.mkdiratZ (zig1)
.EXIST => return error.PathAlreadyExists,
^
/home/bratishkaerik/zig/lib/std/os.zig:2709:9: 0x5654b6246276 in std.os.mkdirat (zig1)
return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1327:9: 0x5654b6246186 in std.fs.Dir.makeDir (zig1)
try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
^
/home/bratishkaerik/zig/lib/std/os.zig:2749:19: 0x5654b62463c0 in std.os.mkdiratZ (zig1)
.EXIST => return error.PathAlreadyExists,
^
/home/bratishkaerik/zig/lib/std/os.zig:2709:9: 0x5654b6246276 in std.os.mkdirat (zig1)
return mkdiratZ(dir_fd, &sub_dir_path_c, mode);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1327:9: 0x5654b6246186 in std.fs.Dir.makeDir (zig1)
try os.mkdirat(self.fd, sub_path, default_new_dir_mode);
^
/home/bratishkaerik/zig/lib/std/os.zig:1680:23: 0x5654b6535810 in std.os.openatZ (zig1)
.NOENT => return error.FileNotFound,
^
/home/bratishkaerik/zig/lib/std/fs.zig:1076:13: 0x5654b623f8b6 in std.fs.Dir.openFileZ (zig1)
try os.openatZ(self.fd, sub_path, os_flags, 0);
^
/home/bratishkaerik/zig/lib/std/fs.zig:1003:9: 0x5654b623bd0e in std.fs.Dir.openFile (zig1)
return self.openFileZ(&path_c, flags);
^
/home/bratishkaerik/zig/src/Cache.zig:539:22: 0x5654b623d6da in Cache.Manifest.populateFileHash (zig1)
const file = try fs.cwd().openFile(ch_file.path.?, .{});
^
/home/bratishkaerik/zig/src/Cache.zig:476:21: 0x5654b622940d in Cache.Manifest.hit (zig1)
return err;
^
/home/bratishkaerik/zig/src/Compilation.zig:2130:13: 0x5654b6321549 in Compilation.update (zig1)
return err;
^
/home/bratishkaerik/zig/src/main.zig:3294:5: 0x5654b62b13ed in main.updateModule (zig1)
try comp.update();
^
/home/bratishkaerik/zig/src/main.zig:2985:21: 0x5654b620c84b in main.buildOutputType (zig1)
else => |e| return e,
^
/home/bratishkaerik/zig/src/main.zig:219:9: 0x5654b61b8e23 in main.mainArgs (zig1)
return buildOutputType(gpa, arena, args, .{ .build = .Exe });
^
???:?:?: 0x5654b61ba7ab in ??? (/home/bratishkaerik/zig/src/stage1/stage1.cpp)
/home/bratishkaerik/zig/src/stage1.zig:48:43: 0x5654b61b8938 in main (zig1)
stage2.mainArgs(gpa, arena, args) catch unreachable;
^
error: zig...
error: The following command terminated unexpectedly:
/home/bratishkaerik/zig/build/zig build-exe /home/bratishkaerik/zig/src/main.zig -lc /home/bratishkaerik/zig/build/zigcpp/libzigcpp.a /usr/lib/llvm/14/lib64/libclang-cpp.so.14 /usr/lib64/liblldMinGW.so /usr/lib64/liblldELF.so /usr/lib64/liblldCOFF.so /usr/lib64/liblldWasm.so /usr/lib64/liblldMachO.so /usr/lib64/liblldCommon.so /usr/lib/llvm/14/lib64/libLLVM-14.so /usr/lib/gcc/x86_64-pc-linux-gnu/11.3.0/libstdc++.a -lunwind --cache-dir /home/bratishkaerik/zig/zig-cache --global-cache-dir /home/bratishkaerik/.cache/zig --name zig --pkg-begin build_options /home/bratishkaerik/zig/zig-cache/options/0ghZFRJv5yPSIQOmN7jArYzqIPaxipxNPztZSGsd95d9FUsuBk1sFGWFiIl23teH --pkg-end -I /usr/include -fno-build-id --enable-cache
error: the following build command failed with exit code 6:
/home/bratishkaerik/zig/zig-cache/o/9e99760733e35b737bbb023007fc4485/build /home/bratishkaerik/zig/build/zig /home/bratishkaerik/zig /home/bratishkaerik/zig/zig-cache /home/bratishkaerik/.cache/zig -p stage2 -Dstatic-llvm=false -Denable-llvm=true |
diff --git a/build.zig b/build.zig
index 31347f8e7..27c3931ac 100644
--- a/build.zig
+++ b/build.zig
@@ -59,6 +59,7 @@ pub fn build(b: *Builder) !void {
const skip_run_translated_c = b.option(bool, "skip-run-translated-c", "Main test suite skips run-translated-c tests") orelse false;
const skip_stage2_tests = b.option(bool, "skip-stage2-tests", "Main test suite skips self-hosted compiler tests") orelse false;
const skip_install_lib_files = b.option(bool, "skip-install-lib-files", "Do not copy lib/ files to installation prefix") orelse false;
+ const skip_rpath = b.option(bool, "skip-rpath", "Do not set DT_RUNPATH (useful for package maintainers)") orelse false;
const only_install_lib_files = b.option(bool, "lib-files-only", "Only install library files") orelse false;
@@ -331,8 +332,23 @@ pub fn build(b: *Builder) !void {
b.addSearchPrefix(cfg.cmake_prefix_path);
}
+ const zig_cpp_lib_name = b.fmt("{s}zigcpp{s}", .{ exe.target.libPrefix(), exe.target.dynamicLibSuffix() });
+
+ const zig_cpp_lib_location = fs.path.join(b.allocator, &[_][]const u8{ cfg.cmake_binary_dir, "zigcpp", zig_cpp_lib_name }) catch unreachable;
+
+ exe.addObjectFile(zig_cpp_lib_location);
+ test_cases.addObjectFile(zig_cpp_lib_location);
+
+ if (!skip_rpath) {
+ switch (exe.target.getOsTag()) {
+ .macos => exe.addRPath("@loader_path/../lib"),
+ else => exe.addRPath("$ORIGIN/../lib"),
+ }
+ }
+
try addCmakeCfgOptionsToExe(b, cfg, exe, use_zig_libcxx);
try addCmakeCfgOptionsToExe(b, cfg, test_cases, use_zig_libcxx);
+ b.installLibFile(zig_cpp_lib_location, zig_cpp_lib_name);
} else {
// Here we are -Denable-llvm but no cmake integration.
try addStaticLlvmOptionsToExe(exe);
@@ -534,11 +550,6 @@ fn addCmakeCfgOptionsToExe(
exe: *std.build.LibExeObjStep,
use_zig_libcxx: bool,
) !void {
- exe.addObjectFile(fs.path.join(b.allocator, &[_][]const u8{
- cfg.cmake_binary_dir,
- "zigcpp",
- b.fmt("{s}{s}{s}", .{ exe.target.libPrefix(), "zigcpp", exe.target.staticLibSuffix() }),
- }) catch unreachable);
assert(cfg.lld_include_dir.len != 0);
exe.addIncludePath(cfg.lld_include_dir);
addCMakeLibraryList(exe, cfg.clang_libraries);You can pass |
|
Everything from https://github.com/ziglang/zig/wiki/Building-Zig-From-Source builds and works fine: stage1Option B
$ stage1/bin/zig build -p stage1-from-prebuilt -Dstage1 -Domit-stage2 --zig-lib-dir /home/bratishkaerik/zig/lib/ --search-prefix /usr/lib/llvm/14/ -Dstatic-llvm=false -Dskip-rpath=true -Drelease=true && strip stage1-from-prebuilt/bin/zig
LLD Link... warning(link): unexpected LLD stderr:
ld.lld: warning: linking module flags 'Dwarf Version': IDs have conflicting values ('i32 5' from /home/bratishkaerik/zig/zig-cache/o/310992a639b0dffe65c963fb2461b00e/analyze.o with 'i32 4' from ld-temp.o)
$ stage1-from-prebuilt/bin/zig version
0.10.0-dev.3024+47c58cba5
$ stage1-from-prebuilt/bin/zig build --help
[1] 11387 segmentation fault stage1-from-prebuilt/bin/zig build --helpComparing sizes (all in release modes, without rpath and stripped)stage1Option AOption Bstage2stage3Comparing sizes (all in debug modes, without rpath and not stripped)stage1Option AOption Bstage2stage3Oh, I also noticed that with this pull request we can build stage2/stage3 without patch (IIUC only when using new shared library) from #11137 (but bug still persist) |
3371470 to
9d2e1b0
Compare
|
@BratishkaErik Thanks for all of the thorough testing, I really appreciate it. Pushed support for stage2 (+3) Most important difference w.r.t. your change is that I did not make RPATH configurable. |
scanelf: rpath_security_checks(): Security problem NULL DT_RUNPATH in zigcpp/libzigcpp.soI guess libzigcpp.so doesn't need RPATH? diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2ae8e3d18..6dcd76d6c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -907,6 +907,7 @@ endif()
set_target_properties(zigcpp PROPERTIES
COMPILE_FLAGS ${EXE_CFLAGS}
+ SKIP_BUILD_RPATH On
)
target_link_libraries(zigcpp LINK_PUBLIC |
9d2e1b0 to
7b3c870
Compare
Good catch! Updated now, thank you. |
I haven't quite managed to grok the common recommendation not to "mix" static/shared libraries, to be honest - At the end of the day, static libraries are just (collections of) object files, and saying not to mix them with shared libraries would suggest it's also wrong to mix object files with shared libraries - But that's a linker's entire job. The concrete problem I've seen is not C++ UB - It's that this part of the C standard (http://port70.net/~nsz/c/c11/n1570.html#6.2.2p2) no longer holds up when statically linking the same objects (e.g. I'm also no expert in C++ or linkers. There's a high chance there's more complexity I'm missing here, so I'm all ears if any of the above is wrong.
Tell me about it 😰 |
Same as the LLD situation basically - There are concerns about mixing shared/static stepping on C++ UB, but I don't personally have a specific bug/standard I can point to that says why this would have to be shared Happy to revert, if you'd prefer. My priority is that we don't statically link |
This is indeed the concrete problem that I am thinking of (which you have addressed in #12085), and that is my mistake for confusing things by saying "C++ UB". I think that I have gotten this problem mixed up with the Static Initialization Order Fiasco.
I am firmly convinced that making these files dynamically linked is the wrong way to go, and would indeed request a revert on that particular change.
I share this priority with you. |
|
Great, sounds like a plan. Thanks for the input - I needed a Core Team POV on this one. |
This commit reworks the LLVM/Clang/LLD discovery process for CMake. The
biggest changes are that:
1. We search for LLVM from most preferred directory to least, skipping
any `llvm-config` that is the wrong version, or that doesn't
support the requested link mode ("static" or "shared").
2. `ZIG_PREFER_CLANG_CPP_DYLIB` has been renamed to `ZIG_SHARED_LLVM`,
to better align with `ZIG_STATIC_LLVM`.
3. We only search for LLVM in the same directory alongside LLVM.
4. LLVM's link mode is forwarded to Clang, so that we can look for the
appropriate shared/static libraries.
5. We use `--link-static` when querying `--system-libs` from llvm-config,
so that this will include libz and other dependencies for
statically linking LLD
This change relaxes the restriction added in the prior commit that LLD should be alongside LLVM. This also leaves unresolved the issue of making sure the link mode (static or shared) of LLD matches that of LLVM/Clang. That would be an unfortunate restriction, since LLD seems to be provided only as a static lib on some distros.
This is currently unused, but it will be needed soon so that we can avoid linking static libc++ if LLVM/Clang is configured as a shared library.
7b3c870 to
5337934
Compare
|
Sorry for coming late to the party, but unlike master this branch does not work with guix, does not find the clang include dir and libs. They have different hash than llvm include dirs, so I have no idea how to handle this. Does it work with nixos? |
… CMAKE_FRAMEWORK_PATH On some systems (esp. systems that use unique hashed file-paths for library-versions like Nix), we can't expect LLVM and Clang to share lib/bin directories. The best we can do is find the matching clang libraries in the CMAKE_LIBRARY_PATH provided by the environment
62487e3 to
abc1ae5
Compare
Thanks for the heads up - I've relaxed the way we look for Clang so that it respects I think this is enough to get things operational on Nix-like OS's again (tested on a local install of NixOS) |
|
This one works indeed, thanks. Only #12153 left, but as far as I understand Andrew that stays this way for a while. |
|
Thank you @topolarity, this looks like it was an ordeal in order to implement. I think this is the best we can do with what we've got. That Really appreciate your diligence on this one. |
-DZIG_SHARED_LLVM See ziglang/zig#12136 Signed-off-by: BratishkaErik <[email protected]>
…stage2, minor fix stage1 installation (cmake_src_install) already does this -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Signed-off-by: Eric Joldasov <[email protected]>
…stage2, minor fix stage1 installation (cmake_src_install) already does this -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Signed-off-by: Eric Joldasov <[email protected]>
…stage2, critical fix stage1 installation (cmake_src_install) already does this -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Closes: https://bugs.gentoo.org/864247 Co-authored-by: Rahim Usubov <[email protected]> Signed-off-by: Eric Joldasov <[email protected]>
…stage2, critical fix stage1 installation (cmake_src_install) already does this -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Closes: https://bugs.gentoo.org/864247 Co-authored-by: Rahim Usubov <[email protected]> Signed-off-by: Eric Joldasov <[email protected]>
cmake_src_install already installs lib/, so we should skip this in stage2 -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Closes: https://bugs.gentoo.org/864247 Closes: gentoo#26779 Co-authored-by: Rahim Usubov <[email protected]> Signed-off-by: Eric Joldasov <[email protected]>
cmake_src_install already installs lib/, so we should skip this in stage2 -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Closes: https://bugs.gentoo.org/864247 Closes: gentoo#26779 Co-authored-by: Rahim Usubov <[email protected]> Signed-off-by: Eric Joldasov <[email protected]>
cmake_src_install already installs lib/, so we should skip this in stage2 -DZIG_PREFER_CLANG_CPP_DYLIB has been renamed to -DZIG_SHARED_LLVM, see ziglang/zig#12136 Closes: https://bugs.gentoo.org/864247 Closes: #26779 Co-authored-by: Rahim Usubov <[email protected]> Signed-off-by: Eric Joldasov <[email protected]> Signed-off-by: Jakov Smolić <[email protected]>
| ) | ||
| if(ZIG_USE_LLVM_CONFIG) | ||
| while(1) | ||
| unset(LLVM_CONFIG_EXE CACHE) |
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.
What's the goal here, why unset LLVM_CONFIG_EXE, what if we want to -DLLVM_CONFIG_EXE=<some/path/to/llvm-config> ?
This commit reworks the LLVM/Clang/LLD discovery process for CMake.
llvm-configreally wraps two sets of libraries that exist in parallel in an installation: shared and static. Building LLVM according to the wiki gives you only static libs. However, building with-DLLVM_BUILD_LLVM_DYLIB=ON -DLLVM_LINK_LLVM_DYLIB=ONmeans that your LLVM/Clang installation with have both sets of libraries (which is usually the case for system-provided LLVM/Clang).In that case, llvm-config reports entirely different libraries and dependencies for
--link-staticversus--link-sharedThis include several changes to handle this better:
llvm-configfrom most preferred directory to least, skipping any candidate that is the wrong version or doesn't support the requested link mode ("static" or "shared")-DZIG_PREFER_CLANG_CPP_DYLIBhas been renamed to-DZIG_SHARED_LLVM, to better align with-DZIG_STATIC_LLVM.CMAKE_LIBRARY_PATH)llvm-configto find include directories