cquery icon indicating copy to clipboard operation
cquery copied to clipboard

Support cross compiling / No std builds

Open athei opened this issue 7 years ago • 11 comments

When using cquery for cross compilation I have the problem that it adds the pathes of the system compiler to the include path and not the ones of the cross compiler. To fix this I propose the following changes:

  • If the --sysroot flag is detected for a file the built-in specs of that cross compiler should be used instead of the system compiler ones.

  • If -nostdlib flag is detected no std lib include pathes should be added.

athei avatar Jul 04 '18 09:07 athei

If supporting something like this is not complicated than SGTM, but there is a limit to what the auto-setup logic can do without completely re-implementing clang command line parsing.

jacobdufault avatar Jul 06 '18 15:07 jacobdufault

If you use gcc to cross-compile then include paths of the system compiler are not the only problem you will find. cquery uses libclang in order to compile translation units and for clang to work in cross-compilation you need additional flags as not only --sysroot flag is required - you also need --target and --gcc-toolchain. cquery may parse files properly but it will definitely report a lot of errors from your headers.

ghost avatar Jul 09 '18 09:07 ghost

I use cquery mainly for embedded kernel development. It works better than any other tool even with the wrong target and sysroot. I just set some endian defines. Of course I have many errors but I do not care as long as jumping to definition/references works.

I agree that it is problematic to duplicate all the clang command line parsing. What about extracting all the information from the command compiler binary by asking it for its machine and sysroot without looking at the other flags. The only thing is the -nostd thing that cannot be extracted from that.

athei avatar Jul 13 '18 14:07 athei

I agree that it is problematic to duplicate all the clang command line parsing. What about extracting all the information from the command compiler binary by asking it for its machine and sysroot without looking at the other flags. The only thing is the -nostd thing that cannot be extracted from that.

We currently extract system include headers in this manner.

@athei if you have your cross compiler be an path (ie, /bin/cross-gcc) in your compile_commands.json cquery will query that compiler for system includes first.

jacobdufault avatar Jul 13 '18 15:07 jacobdufault

Nice! I create the compile_commands.json without the command only with arguments. I will fix my script.

Still, this is only headers, --target and --gcc-toolchain is still missing, right?

athei avatar Jul 13 '18 16:07 athei

I don't recall if cquery looks at command, the first value of arguments is supposed to be a compiler, ie, for me it is

"command": "/work/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/apps/apps/app_lifetime_monitor.o.d -DV8_DEPRECATION_WARNINGS -DDCHECK_ALWAYS_ON=1 -DUSE_UDEV -DUSE_AURA=1..."

The compiler (clang++) is a path.

jacobdufault avatar Jul 13 '18 18:07 jacobdufault

For figuring out the system headers, cquery does take into account --gcc-toolchains, --sysroot and -nostdlib.

https://github.com/cquery-project/cquery/blob/master/src/project.cc#L123-L128

bstaletic avatar Jul 27 '18 19:07 bstaletic

But only when supplied as extra arguments and not when supplied in compile_commands.json, right?

athei avatar Jul 27 '18 20:07 athei

I don't recall if cquery looks at command, the first value of arguments is supposed to be a compiler, ie,

I tried that (with --check). Unfortunately it cquery ignores the command. It would help alot if it would use it.

athei avatar Jul 30 '18 05:07 athei

For figuring out the system headers, cquery does take into account --gcc-toolchains, --sysroot and -nostdlib.

At least for me this does not work. I have -nostdinc in my arguments and at the end -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include -isystem/usr/local/include -isystem/usr/lib/gcc/x86_64-linux-gnu/7/include-fixed -isystem/usr/include/x86_64-linux-gnu -isystem/usr/include is added. I see them both at the same time using --check.

athei avatar Jul 30 '18 05:07 athei