Building specific library depending on the architecture

Hi all,

I’ve recently discovered Platformio and just loved it! Great work!

I wanted to build a library where a hal.c file depends on the architecture. Basically the structure of my code looks like this:


The idea is to build mylib.a using a different hal depending on the target.

I managed to make it work using rather agressive #ifdef around the whole hal.c file and using specific -D in the build_flags. But I find this solution not so satisfying and it still produces empty hal.o file which are still included in the lib.
You can find the whole example here:

I’ve also tried using src_filter but it it seems that all hal.o file are still compiled (but the linking seems to work though?):

And finally I’ve tried using extra_script, the correct way to do it I guess but did not manage to achieve anything. I was hoping to modify the lib dependencies to only keep the good hal.

Any help would be greatly appreciated :slight_smile:

I’ve just updated docs and added support for dynamic srcFilter. See

Please note that you need the latest PIO Core: Redirecting...

That’s perfect! Thanks for your reactivity!

1 Like