braydenanderson2014 / C-Arduino-Libraries

This repository contains C++ and Arduino Libraries that are lightweight and easy to use. All libraries were created/mimicked by me and chatgpt.
Apache License 2.0
13 stars 0 forks source link

Platformio version has dependency for "arduino" which is spurious #79

Closed trevorbattle closed 2 weeks ago

trevorbattle commented 3 weeks ago

When adding this library with Platformio, it tries to load a dependency for arduino, and gives a warning.

Library Manager: Installing braydenanderson2014/Hashtable
Unpacking  [####################################]  100%
Library Manager: Hashtable@1.1.3-BETA has been installed!
Library Manager: Resolving dependencies...
Library Manager: Installing Arduino @ *
Library Manager: Warning! More than one package has been found by Arduino @ * requirements:
Library Manager:  - mbed-aluqard/arduino@0.0.0+sha.3b83fc30bbdf
Library Manager:  - mbed-eduardog26/Arduino@0.0.0+sha.abbc3308dfa1
Library Manager:  - mbed-thechrisyd/Arduino@0.0.0+sha.272d0276d474
Library Manager:  - mbed-rahulsitaram/Arduino@0.0.0+sha.d0b32a4209f0
Library Manager:  - mbed-gastonfeng/arduino@0.0.0-alpha+sha.b000674ff8b3
Library Manager:  - mbed-team2/Arduino@0.0.0+sha.d96590319bcf
Library Manager: Please specify detailed REQUIREMENTS using package owner and version (shown above) to avoid name conflicts
braydenanderson2014 commented 2 weeks ago

It will always throw a warning unless you specify an Arduino library because all the code depends on Arduino.h. The warning can usually be ignored as the compiler usually selects one anyway and it hasn't had any problems. I've never specified an Arduino.h library and have been fine.

trevorbattle commented 2 weeks ago

This does not seem to be what "other libraries do" when they require Arduino.

On my pretty-vanilla installation, this chases down anything called "arduino" and finds six unrelated candidates:

Library Manager: Installing Arduino @ *
Library Manager: Warning! More than one package has been found by Arduino @ * requirements:
Library Manager:  - mbed-aluqard/arduino@0.0.0+sha.3b83fc30bbdf
Library Manager:  - mbed-eduardog26/Arduino@0.0.0+sha.abbc3308dfa1
Library Manager:  - mbed-thechrisyd/Arduino@0.0.0+sha.272d0276d474
Library Manager:  - mbed-rahulsitaram/Arduino@0.0.0+sha.d0b32a4209f0
Library Manager:  - mbed-gastonfeng/arduino@0.0.0-alpha+sha.b000674ff8b3
Library Manager:  - mbed-team2/Arduino@0.0.0+sha.d96590319bcf
Library Manager: Please specify detailed REQUIREMENTS using package owner and version (shown above) to avoid name conflicts
Unpacking  [####################################]  100%
Library Manager: arduino@0.0.0+sha.3b83fc30bbdf has been installed!

Which seems to install: https://registry.platformio.org/libraries/mbed-aluqard/arduino It ends up working because the spurious library is silently ignored, but it is always downloaded as if it was a dependency.

I also know that other platformio libraries do not need to specify "arduino".

braydenanderson2014 commented 2 weeks ago

Most other libraries probably specified an exact arduino library to use. The reason why I didn’t is I’ve never used any of them and since it was not required I chose to not force a version. But the warning is to be expected and can safely be ignored. The code will work regardless. But if you care enough all you have to do to fix it is go into the library.json file for the library and put the author of one of those arduino libraries name in front of the Hashtable.

Example:

mbed-aluqard/arduino@ *

Or

mbed-eduardog26/Arduino@ 0.0.0

The compiler will no longer throw a fit unless you download any other libraries with the same issue. Which all my libraries do. But as I stated, it will work perfectly fine without specifying an exact arduino library. You’ll just have that warning pop up every time.

You can also specify a version within your platformio.ini

trevorbattle commented 2 weeks ago

Ok, maybe I can be clearer. This isn't about ambiguity of dependencies, that dependency is just not needed and actually ends up doing something unwanted and potentially bad.

If you load: https://registry.platformio.org/libraries/braydenanderson2014/Hashtable it lists "arduino" as one dependency, SimpleVector as the other. You won't see "arduino" in any other platformio library dependencies, including ones that require Arduino.

Since that isn't really a platformio library, the only matches it finds are pretty obscure. And worse, all six matches for that dependency (see above) are for the (defunct) mbed architecture, regardless of the architecture the user is compiling for. At best that's harmless, at worse it might break if it gets compiled in.

So when building HashTable, Platformio picks one of those six mbed-arduino libraries semi-randomly, but none of them are correct. There are no library dependencies on platformio that match "arduino" that should be pulled in to compile HashTable.

As for the requirement for the Arduino.h file, in Platformio, setting framework to "Arduino" installs the correct Arduino.h for the user's platform, in my current case, esp32, so you get the file installed by the framework chosen, in my current case:

`/home/user/.platformio/packages/framework-arduinoespressif32/cores/esp32/Arduino.h'

The contents are very architecture specific so having an mbed one called into my esp32 project is... undesirable.

As for "going into the library.json file", yes, but that is transient. We would have to stop using platformio for your library and include a local copy, frozen at this version, that we also have to distribute to compile properly elsewhere. If I just send my code normally to somebody else, they will get the same result as above when their Platformio loads your library.