Multiple copies

Unless I am greatly mistaken, a new copy of a library is downloaded and installed for each project that uses it. This seems to me to be an unnecessary use of both bandwidth and drive space.
I know they are both as cheap as chips these days, but that’s beside the point: is there some sensible way of avoiding doing that?

Before we jump at optimization: Is it relevant at all?

How does the used bandwidth compare to the size of a typical web page? Could we really save a relevant amount of bandwidth?

How does the disk space used by the downloaded source file compare to the size of the object and library files generated during the build? How does it compare to the size needed for tooling (compilers, linkers etc.)? Could we really save a relevant amount of disk space?

The saving need to be worth the additional effort and complexity.

Arduino IDE seems to manage, and at the same time keep things simple.

As to the other point, it amounts to saying “Let’s burn energy just because it’s easier.”
The amounts of energy here may be trivial, but it’s a bad habit and may be multiplied many millions of times over if people are doing it across the world.

And also, we don’t all always have a good connection to the internet, and especially not at rush hour.

Arduino IDE has a different approach where sharing is easy and having separate versions of a library is hard. In PlatformIO, it’s the other way round. The additional complexity does not come for the approach itself, but from implementing and supporting multiple approaches concurrently. It would also increase the Arduino complexity if it had to implement both its own and the PlatformIO approach.

When you start optimizing, you need to have a goal such as reducing disk space usage. And then you should put your effort into those areas that will make the biggest difference for reducing disk space usage. That’s the proper approach. I doubt that separate library downloads will be the area with the biggest effect.

Aside from that, PlatformIO can indeed store libraries globally (see pio lib install — PlatformIO latest documentation). Note however that it is not recommended as it has several disadvantages (projects are no longer self-contained, updating a library affects other projects etc.).

1 Like

EDITED: lib_extra_dirs, not lib_extra_dir!

If you want “global” libraries, you can create a top level directory with a separate sub directory for each library, containing the sources and headers.

In each project that needs to share a library, simply put the top level directory as the parameter to lib_extra_dirs. You don’t then need to have the libraries listed anywhere else in the ini file. Just include the appropriate headers – just like the Arduino IDE.

I use this when testing libraries before publishing them separately.

HTH

Cheers,
Norm.

Presumably that needs the path to the directory?

Yes, just the top level directory though. Even if you have 20 separate sub-directories under it, you only need the top level one. Oh sorry, a typo, it’s lib_extra_dirs plural.

Cheers,
Norm.

There used to just be a button to install globally. It was awesome. It was removed for some reason.

Yes, it was removed as it caused problems. If two libraries were installed globally and had the same name but different platforms, say Arduino and ESP32, then the compiler/linker would pick up the wrong one, or a mixture of the two and cause problems.

It’s simple to install the libraries under a “global” directory and just use LIB_EXTRA_DIRS to point at the global one, to have the same effect as installing globally – but for your Arduino projects you could have something like lib_extra_dirs - /home/norman/pio/global/arduino and for ESP32, lib_extra_dirs - /home/norman/pio/global/esp32. Whereas previously, globally installed libraries all went into the same top level directory.

So we can still have global libraries, but we can now separate them to separate frameworks/platforms/whatever we want!

Cheers,
Norm.

1 Like