-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
osx: error: unable to create target: 'Unable to find target for this triple (no targets are registered)' #5055
Comments
What if you try to download zig from the website and try with that? |
great, here's what works:
here's what doesn't work: brew zig
here's what doesn't work: cross compile from nim
|
@timotheecour about the last one which doesn't work (about cross-compiling) |
This is a homebrew issue and you should file it on the homebrew issue tracker |
The next step to troubleshooting this one is to try to reproduce it without nim |
will do; EDIT: Homebrew/homebrew-core#53198
will do but please keep this issue open for now :) |
Of course :) Generally we keep issues open in the zig issue tracker for upstream/downstream issues, even if we're waiting on a third party to change something. |
@andrewrk it appears instructions to build from source in https://github.com/ziglang/zig don't work and have the same issue, which is why the homebrew formuala also fails: https://github.com/Homebrew/homebrew-core/blob/master/Formula/zig.rb so this seems like a zig issue, not a homebrew issue:
/tmp/d01/Users/timothee/git_clone/zig/build/bin/zig build-exe --c-source /Users/timothee/git_clone//nim//timn/src/timn/examples/thelloc.c --library c |
@andrewrk update:
however, when I don't use pre-built llvm+friends (obviously a non-starter for many cases including homebrew), nothing i tried works:
but even after fixing those paths nothing works:
if I manually copy those 3 missing libs from build output to release dir (as hinted here http://lists.llvm.org/pipermail/llvm-bugs/2017-June/056284.html), and rerun building zig, it now gives:
which is odd building without
|
EDIT: finally i can build from source a working zig, but via gcc only: gcc: worksI follow instructions from https://github.com/ziglang/zig/blob/master/ci/azure/macos_script#L18 (with HAVE_CACHE="false" to avoid prebuilt libs) and change
and then it works both with and without clang: gives non-working zigthis is painful though as it requires building llvm+friends from source using gcc; isn't there a way to use clang? if not I don't see how this could be packaged in homebrew easily (which builds llvm via clang) EDIT: i tried this:
and it does build zig, but then has same issue as top post |
This is a problem with homebrew's LLVM/Clang. It's missing targets. There is nothing zig can do about this. What your system is claiming to fulfill Zig's dependency actually does not fulfill Zig's dependency. And so the homebrew zig package as well, is broken. Zig is not intended to be linked against an LLVM/Clang that is missing targets. Your options are to build llvm/clang/lld from source, download a prebuilt tarball, or convince homebrew to improve their packages. |
@andrewrk
I don't think this is the case, and I think it's a bug with zig instead.
this actually means there are 0 targets (not just missing ones but 0). However, when I instrument zig code, I find that:
proof: see lldb stacktrace here: https://gist.github.com/timotheecour/cce51bf06f3b12b1db2b15f4cdc31ef5
no, as I explained here #5055 (comment) I have tried building llvm/clang/lld from source using clang as compiler (using same approach as I did for building llvm/clang/lld from source using gcc as compiler), and that gave exactly same errors |
This diff makes zig link against libLLVM.dylib, just like the (working) clang-10 binary from the brew package. diff --git a/cmake/Findclang.cmake b/cmake/Findclang.cmake
index 5f5bef820..534d740c0 100644
--- a/cmake/Findclang.cmake
+++ b/cmake/Findclang.cmake
@@ -18,7 +18,7 @@ find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
)
if(ZIG_PREFER_CLANG_CPP_DYLIB)
- find_library(CLANG_CPP_DYLIB
+ find_library(CLANG_LIBRARIES
NAMES
clang-cpp-10.0
clang-cpp100
@@ -31,9 +31,7 @@ if(ZIG_PREFER_CLANG_CPP_DYLIB)
)
endif()
-if(CLANG_CPP_DYLIB)
- set(CLANG_LIBRARIES ${CLANG_CPP_DYLIB})
-else()
+if(NOT CLANG_LIBRARIES)
macro(FIND_AND_ADD_CLANG_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
diff --git a/cmake/Findllvm.cmake b/cmake/Findllvm.cmake
index 7d6a4b04d..5228710dc 100644
--- a/cmake/Findllvm.cmake
+++ b/cmake/Findllvm.cmake
@@ -7,7 +7,30 @@
# LLVM_LIBRARIES
# LLVM_LIBDIRS
-if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
+find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
+ PATHS
+ /usr/lib/llvm/10/include
+ /usr/lib/llvm-10/include
+ /usr/lib/llvm-10.0/include
+ /usr/local/llvm10/include
+ /usr/local/llvm100/include
+ /mingw64/include
+)
+
+if(ZIG_PREFER_CLANG_CPP_DYLIB)
+ find_library(LLVM_LIBRARIES
+ NAMES
+ LLVM-10.0
+ LLVM-10
+ LLVM-100
+ LLVM
+ PATHS
+ ${LLVM_LIBDIRS}
+ /usr/lib/llvm-10/lib
+ /usr/local/llvm10/lib
+ /usr/local/llvm100/lib
+ )
+elseif("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-10 llvm-config-10.0 llvm-config100 llvm-config10 llvm-config
PATHS
@@ -106,11 +129,6 @@ if("${ZIG_TARGET_TRIPLE}" STREQUAL "native")
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
- execute_process(
- COMMAND ${LLVM_CONFIG_EXE} --includedir
- OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
- OUTPUT_STRIP_TRAILING_WHITESPACE)
-
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
if(NOT LLVM_LIBRARIES)
@@ -124,15 +142,6 @@ else()
# to support more complicated setups. We also assume the experimental target
# AVR is enabled.
- find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
- PATHS
- /usr/lib/llvm/10/include
- /usr/lib/llvm-10/include
- /usr/lib/llvm-10.0/include
- /usr/local/llvm100/include
- /usr/local/llvm10/include
- /mingw64/include)
-
macro(FIND_AND_ADD_LLVM_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_} However this causes, at runtime,
Because of static linking LLD combined with dynamic linking LLVM+Clang. The brew package does not provide a dynamic library for LLD, so Zig cannot solve this. Upstream LLVM needs to fix it, and homebrew needs to do one of these things:
Welcome to C++ dependency hell. I cannot reproduce your problem, following the directions to build from source. It works for me when I build everything from source. My new suggestion is now reverting all the way back to #4799 (comment). @Bo98, the ball is back in your court. I'm sending zig users to the homebrew issue tracker. |
I gave homebrew a suggestion of how to fix this: Homebrew/homebrew-core#53198 (comment) |
@andrewrk
here's what doesn't work yet
=> clearly, '-static-libgcc' should be somthg else
=> makes life easy and wouldn't break things like
are you referring to
|
I'm happy to apply whatever workaround is needed in the zig formula until upstream makes changes. Just to answer some points:
Ah, I did not realise Zig used LLD. I wouldn't have suggested using shared libraries at all for that case since, for some reason, LLD isn't available as a shared library at the moment.
Neither does upstream. I argue they should, but that's out of my hands.
Not really trivial to do. The proper fix would be upstream providing a LLD shared library.
This would unfortunately just shift the problem. Some users would ask for Polly support to come back.
Yeah, upstream adjusting llvm-config seems like this is the easiest approach in the short term for 10.0.1. This is more a missing feature as llvm-config hasn't even reported Clang libraries ever before, let alone anything else like Polly, but there's no reason why it shouldn't. If we are going to rely on llvm-config even more though instead of CMake, I will need to also patch the bugs it has on macOS. Hopefully that will make it for 10.0.1 too. Any patching of llvm-config is likely to be non-trivial and involve several patches so it would likely end up being a case of waiting for 10.0.1 for the case of llvm-config. However, in the meantime before 10.0.1 arrives, I'm happy to apply some of the workarounds mentioned to the Homebrew formula. I'll revisit this tomorrow. |
LLVM 11 was released today and I just merged the llvm11 branch into master. |
Summary of this issue
on OSX 10.15.2 (19C57)
brew install zig
zig version
0.6.0
zig build-exe --c-source thelloc.c --library c
likewise if I do
nim c -f --cc:zig hello.nim
(which was my original use case, see nim-lang/Nim#13757)note
which clang
/usr/bin/clang
clang -v
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
brew test zig
works but that doesnt' helpI also tried specifying a target explicitly via
-target ...
but nothing workedThe text was updated successfully, but these errors were encountered: