facebook / buck

A fast build system that encourages the creation of small, reusable modules over a variety of platforms and languages.
https://buck.build
Apache License 2.0
8.56k stars 1.16k forks source link

Using buck with "embedded" compilers for ARM microcontrollers #2002

Closed lemtronix closed 6 years ago

lemtronix commented 6 years ago

Hi, I'm looking at using buck for sharing c/c++ libraries and providing an easy way to compile projects using embedded toolchains. We use embedded specific compilers--KEIL and IAR (not Visual Studio or GCC)--that build for ARM (and other) microcontrollers.

The issue I'm having is that buck always inserts the compiler flags "-x c++ -gno-record-gcc-switches -c -MD -MF" which iccarm.exe (IAR compiler) doesn't know about. I tried over writing every possible compiler and preprocessor flag in [cxx] for .buckconfig and cxx_binary() in the BUCK file but these flags still show up in the ppandcompile.argsfile. Even when I leave the cppflags, cflags, cxxppflags, etc. empty, the flags mentioned above still show up. Is there a way to turn these flags off?

The -MD and -MF flags are found in CxxInferCapture.java and DefaultCompiler.java and are hardcoded to be added to an ImmutableList. If there isn't an easy way to turn it off I was going to remove the references from these files but this would obviously break compatibility for compilers that need these flags.

In .buckconfig, there's linker_platform and archiver_platform that allows someone to specify LINUX, MACOS, FREEBSD, or WINDOWS. Would it be possible to add something (perhaps EMBEDDED) that would remove these compiler flags by default?

Thoughts or suggestions? Thanks!

cjhopman commented 6 years ago

Can you write a binary that converts g++ flags to something that your compiler understands and then forward to your real compiler? Then you could just specify that binary as your compiler.

lemtronix commented 6 years ago

What I'm attempting to do is cross-compile on Windows to an MCU (embedded ARM Cortex-M0+) using the IAR compiler.

As I dig through the source code, the issue goes beyond simply not having certain flags passed in for the compile step, the link step is also incorrect as well as the information that is entered into the argvar files (i.e. ppandcompile.argsfile and linker.argsfile).

To close the loop on this issue, BUCK currently does not currently support other compilers. It appears that only Visual Studio, GCC, and Xcode are supported at this time.