PlatformIO Community

Exclude specific libraries from building


#1

Hi,

I’m working on a project where two different target environments use two different libraries, in this case one target needs Adafruit_ILI9341 (for wemos_d1) and the other needs ILI9341_t3 (for teensy31) and these are specified in my platformio.ini file.

Unfortunately, when I build for the demos_d1 environment, the teensy library tries to build but fails.

How can I express that specific libraries should only be built for specific environments?

Thanks!


#2

You need lib_deps + lib_ignore depending on a situation.
See http://docs.platformio.org/en/stable/librarymanager/ldf.html


#3

Ah, lib_ignore, I totally missed that. Thanks, Ivan!


#4

Sorry, I’m missing something.

When I use lib_ignore it does successfully ignore the specified libraries and doesn’t install them in .piolibdeps

but…

If I build another environment that uses the ignored library and then try to build again, it fails as it tries to build the ignored library.


#5

Hm… Could you share platformio.ini?


#6

Sure thing:

[platformio]
env_default = teensy31

[common]
libs =
  Time
  SerialFlash 
  SparkFun APDS9960 RGB and Gesture Sensor
  Blackketter/Adafruit_FT6206_Library
  Blackketter/Audio
  Blackketter/Clock
  Blackketter/Preferences

teensylibs =
  Blackketter/ILI9341_t3

esplibs =
  Links2004/Adafruit_ILI9341
  Adafruit GFX Library

[env:teensy31]
platform = teensy
framework = arduino
board = teensy31
build_flags = -O -DTEENSY31 -UUSB_SERIAL -DARDUINO_ARCH_AVR -DUSB_SERIAL_HID -DLAYOUT_US_ENGLISH -I./src
board_f_cpu = 96000000
lib_deps = ${common.libs} ${common.teensylibs}
lib_ignore = ${common.esplibs}

[env:teensy36]
platform = teensy
framework = arduino
board = teensy36
build_flags = -O -UUSB_SERIAL -DARDUINO_ARCH_AVR -DUSB_SERIAL_HID -DLAYOUT_US_ENGLISH -I./src
board_f_cpu = 120000000
lib_deps = ${common.libs} ${common.teensylibs}
lib_ignore = ${common.esplibs}

[env:d1_mini]
platform = espressif8266
framework = arduino
board = d1_mini
lib_deps = ${common.libs} ${common.esplibs}
lib_ignore = ${common.teensylibs}

#7

Wow! Excellent using of dynamic variables and project dependencies. Looks, that our efforts for PlatformIO 3.0 have a big benefit.

Please check docs http://docs.platformio.org/en/stable/projectconf.html#projectconf-lib-ignore

The correct value for this option is library name (not folder name).

The “Links2004/Adafruit_ILI9341” is not a library name. Check pio lib list for the names.


#8

Thanks, I see. That fixed it.

It does seem strange that libraries can be installed with a broader syntax than they can be ignored. This seems to have the side effect that when you want to use two libraries that have the same name (for example, two different forks or git revisions) in two different environments, that means that they get reinstalled each time you switch.

It also means that I need to refer to a given library using two different syntaxes in the .ini file, but that’s not a huge deal.

BTW: PlatformIO 3.0 is awesome and you are my hero, Ivan. Keep up the great work!


#9

I didn’t find a better solution. All package managers work with the ONE registry. PlatformIO allows using multiple ways how to install a library. What is more, a user can put library manually to one of Library Storages. We propose to use external extra library storages. See http://docs.platformio.org/en/stable/librarymanager/ldf.html#storage

The only one thing that is common between these libraries is NAME. We support 3-rd party manifests, Arduino.properties, ARM mbed module.json and etc.

In this case, “Installation” process live on the one planet, where the Library Dependency Finder lives in another.

Thanks!!! I can’t wait when PIO Remote will be announced. It’s amazing with unique features in the market!!!


#10

Darn. I was hoping that if I used the link to a github archive zip in lib_deps that if I then used the whole identical URL in lib_ignore it would be ignored.

So, for now I can just add the library as a lib_deps entry in all the targets that can build it, and leave it out of those that can’t.


#11

Ahhhh. Nevermind. I delved into the mysteries of .piolibdeps and discovered that if I use the commit-id of the archive, I can use it in lib_ignore too. That will work!

The only reason I’m going to all this trouble is so those who build our project on Windows don’t get a complaint about the lack of git. For some reason they get annoyed with us.


#12

You can ignore libraries by their names. You should see their names in dependency graph


#13

I wanted to eliminate the dependency on git to build our project, so I changed all lib_deps to use the link to the .zip archives instead, which use the name of the branch (master) as the filename. For example:

lib_deps https : // github . com/trinamic/TMC26XStepper/archive/master.zip

(URLs split up to allow more “links in post” for my n00bness)

When this form is used the line lib_ignore TMC26XStepper fails to prevent this library from being compiled.

During my troubleshooting I noticed in the case of one library the subfolder created inside .piolibdeps was named master with no hash added. I discovered if I used lib_ignore master then that specific library would be ignored.

It was then I realized I could use the commit hashes instead. For example…

lib_deps
https : // github . com/lincomatic/LiquidTWI2/archive/30aa480.zip
https : // github . com/ameyer/Arduino-L6470/archive/3cd0993.zip
https : // github . com/trinamic/TMC26XStepper/archive/c1921b4.zip

And then lib_ignore c1921b4 works! It prevents TMC26XStepper from being compiled.

I don’t know why lib_ignore TMC26XStepper fails to prevent the library from being compiled, but it does. We couldn’t get our Travis CI to pass whatsoever until I went through the process I just outlined.

I can only assume that when PlatformIO sees a link to a .zip file, it doesn’t take the extra notice that it’s a Github archive link and pick out the TMC26XStepper segment of the path as the ID of the library.

Was this ever a known issue? I believe I already patched up our .travis.yml file to use the latest version of PlatformIO. Also, I had the same problem within Visual Studio Code using 3.5.2b2.


#14

See example here

Also, please take a look at <name> at http://docs.platformio.org/en/latest/userguide/lib/cmd_install.html#cmd-lib-install

P.S: Have you tried lib_ldf_mode = chain+?


#15

Hello,
is there a way to exclude files from within a library tree?
and is it possible to compile .c files as .cpp?

Thanks.


#16

Yes, you need library.json and build.srcfilter field.