while cross compiling llvm I see a NATIVE component being built which has bin dir, can someone please explain what this NATIVE component is.
Is NATIVE component built for the machine on which cross compiling happens or for the machine for which cross compiling happens?
from what I have learnt so far, host is the machine where cross compilation takes place, I am using cygwin on windows, and target is the machine where built binaries are supposed to run, linux in my case. I have installed cross compilers for linux on windows.
please correct me if I am wrong here.
Also my build fails in the end with error
No rule to make target 'NATIVE/bin/llvm-min-tblgen.exe', needed by 'include/llvm/TargetParser/RISCVTargetParserDef.inc
but I see llvm-min-tblgen in my NATIVE dir present in my build dir,
$ ls NATIVE/bin/.
llvm-lit.py llvm-min-tblgen
I don’t see a .exe extension to the llvm-min-tblgen executable generated, is it because of that?
I am using windows cmake to cross compile, because it resolves many issues that I see while using cygwin cmake, especially the path ones.
The NATIVE component is built for the machine on which the cross compiling is happening. The reason for it, is that when you build LLVM, it needs to build and execute some code generation tools (llvm-tblgen and llvm-min-tblgen among others).
Yes, I would believe so. I think the reason here is that there is a mismatch in setting up and using the NATIVE tools, whether they are expected to have an .exe suffix on cygwin or not.
@mstorsjo : The NATIVE component is built for the machine on which the cross compiling is happening. The reason for it, is that when you build LLVM, it needs to build and execute some code generation tools (llvm-tblgen and llvm-min-tblgen among others).
does this need to be carried out using clang only, cause I have used cross compilers and eventually the native build is also being built with cross compilers and hence the executable is unable to run on current machine which is the host and which is windows in my case.
Please correct me if I am wrong here, since I need a native build and that cannot be built with cross compilers, I need to have a native build using Visual Studio for windows and point cmake to this NATIVE build while cross compilation using LLVM_NATIVE_TOOL_DIR?
The idea is that the LLVM build internally sets up the NATIVE build, where it is meant to use the system default compiler, using whatever defaults cmake uses if you don’t pass it anything extra.
I think the main mixup comes from this:
So you’re running a cygwin environment, but using a native windows cmake within it - I presume it’s possible this is one source for the confusion.
No, normally you should not need to do this. The intent is that cmake automatically configures and builds the necessary tools only, within the NATIVE directory. It looks like this has worked in your case. The issue is just that the configuration of the NATIVE directory doesn’t quite match what the surrounding build expects.
I don’t know if this is an issue with LLVM’s cmake files, specifically when building within cygwin, or if this is an issue with your particular configuration with mismatched tools.
By manually doing a separate native build and pointing towards it with LLVM_NATIVE_TOOL_DIR, yes, then you should be able to avoid the whole issue. But normally one should not need that.
thank you @mstorsjo. In my case even the native build was being built with cross compilers and this might have been due to Cygwin and windows cmake I used as you mentioned. I am unable to use Cygwin cmake cause it sees paths in cygwin format as /cygdrive/c/ and appends similarly while generating makefiles. This is causing issue with cross compiler which is meant for windows->linux cross compilation. Thanks again, for answering my doubts and suggesting a solution.
Actually, if that’s what is happening, it’s probably not so much about the mixing of cygwin and windows cmake, but more about your environment, and/or how you are configuring your cross compilation setup.
If your cross compilers are available with default names like cc or gcc, it’s possible that cmake, when trying to configure the default build for the NATIVE subdirectory, ends up picking such a compiler.
It might be possible to override it by configuring your outer (cross) LLVM build with a flag like -DCROSS_TOOLCHAIN_FLAGS_NATIVE='-DCMAKE_C_COMPILER=path/to/your/real/windows/compiler/cc.exe;-DCMAKE_CXX_COMPILER=similar/path'. When the outer, cross LLVM build configures the inner NATIVE build, it would then pass those two cmake parameters to that build, letting it find the right compilers.