rizsotto / Bear

Bear is a tool that generates a compilation database for clang tooling.
GNU General Public License v3.0
4.83k stars 313 forks source link

Bear generates empty compile_commands.json when using VBCC frontend #547

Closed rsvensson closed 1 year ago

rsvensson commented 1 year ago

Describe the bug I've set up VBCC as a cross-compiler for m68k targets, and want to use Bear to generate compile_commands.json for use with clangd/emacs lsp-mode. The compiler works just fine, but it's using a frontend to simplify the compilation for the user which compiles the code into an assembler file, assembles that into object code, and then links that into an executable. Here's what the frontend spits out when using the verbose output for a simple hello world C file:

vc frontend for vbcc (c) in 1995-2020 by Volker Barthelmann
vbccm68k -quiet "hello.c" -o= "/tmp/fileiwzGa1.asm" -hunkdebug  -O=1 -I"$VBCC"/targets/m68k-atari/include
vasmm68k_mot -quiet -Faout -mid=0 -nowarn=62 "/tmp/fileiwzGa1.asm" -o "/tmp/fileiwzGa1.o"
vlink -EB -bataritos -tos-textbased -x -Bstatic -Cvbcc -nostdlib "$VBCC"/targets/m68k-ata/lib/startup.o "/tmp/fileiwzGa1.o"   -s -L"$VBCC"/targets/m68k-atari/lib -lvc -o hello.tos
rm -f "/tmp/fileiwzGa1.asm"
rm -f "/tmp/fileiwzGa1.o"

I've tried to create a config file pointing to both the vc, vbccm68k, and vasmm68k_mot executables but it didn't help. If I add the full path of vc to a CC environment variable before running Bear it does add some arguments, directory, file, output to the compile_commands.json, but not any includes so it doesn't help me much. I've also tried creating a symlink to /usr/lib/bear/wrapper as both /usr/lib/bear/wrapper.d/vc and /usr/lib/bear/wrapper.d/vbccm68k without any luck.

Is there anything else I could be doing to get this going?

To Reproduce

  1. Install VBCC compiler with m68k target files.
  2. Create a simple hello world C file.
  3. Run bear -- vc -o hello hello.c, or bear -- make with a makefile.
  4. Observe how compile_commands.json is empty.

Bear log file for the above repro steps: bear.log

Expected behavior Bear should correctly pick up any include files and libraries that are used to compile the application and list them in compile_commands.json

Environment:

rsvensson commented 1 year ago

Just after posting this I thought of putting the path to the actual vbccm68k executable as my CC environment variable instead of the vc frontend, and then it worked just fine and added the includes. Doh. So ignore this I guess. I do wonder if there is a way to not have to specify that every time? Shouldn't the /usr/lib/bear/wrapper.d/vbccm68k link handle that theoretically?

rizsotto commented 1 year ago

@rsvensson I am happy that you could sort it out.

I can explain why it is a bit of trouble to use cross compilers... The two main things (that Bear does) are: intercept the executions and recognize them. When you put a link into the wrapper directory, that helps to intercept. To help recognize it, you need to create a config file and list the compiler in the compilation.compilers_to_recognize section.

When you specify the CC environment, that instruct Bear that this executable needs to be recognized.

On linux the interception works well without create a new wrapper executable. But still needs help to recognize the compiler calls.

rsvensson commented 1 year ago

Thanks for your explanation!

Hmm but I did create a config file like that and tried to add both vc and vbccm68k to the compilers_to_recognize list. That did not help me in this case unfortunately, although it's possible I did something wrong. I don't have that config file saved anymore unfortunately. But it's not a big deal to specify the CC env var. I don't need to run Bear often enough to where it would be annoying.

Thanks for making this great piece of software btw!