CLI documentation is very incomplete

02 Jul 2018

I'm getting started using the mbed-cli, and it seems like either this is a very primitive tool, or else there's just no documentation beyond the bare basics.

The docs explain how to create a new project and compile. Great. But they don't explain how to control what source files get compiled, what compiler/linker settings are used, or any of the other nitty-gritty of building a nontrivial project. (By contrast, the last build system I learned, Espressif's ESP-IDF, has a pretty polished and well-documented build system(1) based on 'make', and an upcoming one using CMake.)

I've got a medium-large source base that lives in multiple directories, with some files that are platform-specific, and has three or four submodules. Issues I'm running into right off the bat:

  • The only way to specify what directories source files are in is to use the `-source` flag to `mbed compile`. So this crucial part of the build configuration is ephemeral, not recorded in a file. I can work around this by creating a shellscript with the command line in it and then committing that to Git.
  • Every source file in a source directory gets compiled. But many of my directories contain platform-specific files that should only be compiled for iOS or Linux or whatever, or which enable features I don't need. (And I don't have control over the layout, because I'm using 3rd party submodules.)
  • I don't see any way to tweak compiler or linker settings. From past experience, I know I'm going to need to do this. I may need to disable certain warnings, or enable language features like RTTI. Sometimes I need to do this for individual files, like 3rd party code that would otherwise trigger warnings.

Are these supported features that just aren't documented? Or is the mbed-cli only meant for very simple projects?

(1) https://esp-idf.readthedocs.io/en/latest/api-guides/build-system.html

03 Jul 2018

Hi,

what I am missing is what documentation you have already read. This docs https://os.mbed.com/docs/v5.9/tools/working-with-mbed-cli.html should answer your question.

You can specify sources by source or use default - all in root dir. Use keywords like TOOLCHAIN_/TARGET_NAME for folder names (see the directory structure in Mbed OS for examples). Or use mbedignore file to ignore files/directories. This should answer also the second item.

Check toolchain profiles for those settings. You can create your own one if needed.

03 Jul 2018

Yes, I read that page (several times).

You can specify sources by source or use default - all in root dir.

I did figure that out, though it took some careful reading to find it — it's mentioned very briefly, in the middle of a list of command-line arguments. It's a pretty important point, so IMHO it should at least be a section "Adding source files" or "Configuring source code location" or something.

I would really, really, like this to be something that could be put in a config file in the project root directory. For example, I'm going to have to list about eight source directories, so the command line will get rather lengthy. (Unless the build system recurses into subdirectories automatically? That will cut it down a bit.)

Use keywords like TOOLCHAIN_/TARGET_NAME for folder names (see the directory structure in Mbed OS for examples).

In the OS source there are source subdirectories with names like "TARGET_CORTEX"; is that what you mean? I'm not asking about how to restrict files to a particular embedded platform, rather how to control what gets compiled at all by mbed.

Or use mbedignore file to ignore files/directories. This should answer also the second item.

Ah, I see, there are a bunch of invisible `.mbedignore` files in the mbed.os source. They seem to have the same syntax as `.gitignore` files, i.e. one globbed path per line. I think I can work with this, especially since I can put one in my own repo and have it control what gets compiled in submodules whose file layout I can't change.

Check toolchain profiles for those settings. You can create your own one if needed.

Sorry, I don't know what this means. What/where are toolchain profiles?

Thanks for the help! It looks like you work on mbed; could you please request that the docs team add the above info to the web page?

03 Jul 2018

I've now managed to point the CLI at my source directories and weed out the subdirectories it should ignore.

Unfortunately the result is that it compiles none of my code — it builds mbed.os, then the linker complains about a missing "main" function. My guess is that it doesn't recognize the ".cc" suffix for C++ source code.

Short of renaming all of my and my co-workers' source files (not likely), how can I work around this?

03 Jul 2018

I hacked tools/toolchains/init.py and added several checks for "ext == '.cc'" and "ext == '.hh'", working around the previous problem.

Now I get this:

[Error] c++0x_warning.h@32,2: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.

Our code requires C++11. Do I need to hack the toolchain files further to add "-std=c++11" to the GCC command line?

03 Jul 2018

Now I've figured out profiles, and made my own customized copy of the GCC debug.json.

It would have saved me about a day of work, so far, if someone had documented all this stuff :(

Latest roadblock: No support for C++ threads/mutexes/locks. I know that the RTOS component has equivalents ... time to write a bunch of glue code.

04 Jul 2018

I shared the feedback with tools and docs team.

.cc and .hh support - feel free to send a pull request (I would expect that one to be already there however have seen it that often to be used).

We do not support C++1x yet. We used to have toolchain limitations that are currently being resolved (we still need to update our tools to their latest version).

06 Jul 2018

Thanks, Martin! By "we do not support C++1x yet", do you mean "code compiled with C++1x will break", or just "we haven't fully tested with C++1x yet"? If it's the former, I'll need to give up on mbed.os for the time being, unfortunately.

06 Jul 2018

I've filed a pull request for the .cc/.hh support: https://github.com/ARMmbed/mbed-os/pull/7437

09 Jul 2018

we haven't fully tested with C++1x yet

We haven't fully tested but have seen users using it (mainly C++11 that I noticed )

Thanks for the pull request!