embeddedartistry / project-skeleton

A C & C++ project skeleton for new Embedded Artistry projects
Apache License 2.0
21 stars 3 forks source link

Always building "APP_native" + "APP" #16

Closed haydenridd closed 1 year ago

haydenridd commented 1 year ago

Question

Would it make more sense to only build executable APP when cross compiling? Currently the behavior of make without any arguments will build both APP and APP_native using the native compiler. This is because meson.get_compiler('lang', native: false) will just fetch the native compiler since when not cross compiling native compiler = host compiler.

Generally speaking once you get into adding custom linker scripts, startup assembly source, etc. to an MCU host, this means that make by default will lead to errors when it tries to compile/link APP using the native compiler instead of arm-none-eabi-... or what have you.

This could be pretty easily gated using:

if meson.is_cross_build()
    APP = executable('APP', ...)
endif

APP_native = executable('APP_native', ...)

This would lead to the behavior:

To me this makes more intuitive sense but curious to get yall's thoughts...

phillipjohnston commented 1 year ago

No problem I see structuring the build that way.

I do tend to keep both variants in my own projects. For example, on my development machine, the non-native variant might pull in drivers that would talk to sensors/etc through USB debug adapters, while the native variant would be a pure simulator setup.

phillipjohnston commented 1 year ago

(That type of setup is dependent on structuring your code and build in a way that supports it, though.)

haydenridd commented 1 year ago

Oh very interesting! So in your setup you would have:

Non cross compiled build:

Cross compiled build:

Tests build native for all cases

phillipjohnston commented 1 year ago

Yep. That's what I aim for.

haydenridd commented 1 year ago

Nice! That makes sense then why you have both variants for both x-compiling and regular. Appreciate the explanation!