arduino / arduino-cli

Arduino command line tool
https://arduino.github.io/arduino-cli/latest/
GNU General Public License v3.0
4.31k stars 373 forks source link

Support for custom libraries when using `sketch.yaml` #2133

Open dmohns opened 1 year ago

dmohns commented 1 year ago

Describe the request

In a project I am currently using different "kind" of libraries.

  1. Versioned libraries available in via Arduino Library Manager
  2. Non-versioned libraries available via their source code on Github
  3. Non-versioned libraries available via their source code in local subfolder folder of my project (zipped or raw)

To ease collaboration on the project I would like to use a Project Sketch File and provide a set of dependencies that are confirmed working.

Unfortunately, the Project Sketch File only seem to support 1. (versioned libraries available in Arduino Library Manager). Scope of this request is to add functionality to supply Github and local folder libraries to the libraries: attribute on sketch.yam (in some fashion).

Describe the current behavior

Currently, I have been able to compile my project using

arduino-cli compile --fqbn "<FQBN>" --libraries=Library/

However, if I tried to use --profile and --libraries the compile command fails

You cannot use the --libraries flag while compiling with a profile.

Arduino CLI version

arduino-cli Version: nightly-20230329 Commit: b69ed33 Date: 2023-03-29T01:34:59Z

Operating system

macOS

Operating system version

12.6.3

Additional context

No response

Issue checklist

umbynos commented 1 year ago

Seems a duplicate of https://github.com/arduino/arduino-cli/issues/108

jirutka commented 10 months ago

Seems a duplicate of #108

It’s not a duplicate, #108 is just one of the ways it can be implemented (and more complicated than requested here).

dmohns commented 10 months ago

Yeah, just to clarify, this issue is about making sketch.yaml spec more flexible to support libraries from other sources than Arduino Library Manager.

One way that is backwards compatible would be

profiles:
  <PROFILE_NAME>:
    ....
    libraries:
      - <LIB_NAME> (<LIB_VERSION>)

to allow <LIB_VERSION> to be <LIB_VERSION_OR_URL> and take the form of VCS and local urls, for example

profiles:
  my_profile:
    ....
    libraries:
      - ArduinoIoTCloud (1.0.2)
      - HelloWorld (https://github.com/username/HelloWorld.git#v2.13)
      - HelloWorld2 (file://./libraries/HelloWorld2.zip)

Note: Above is just an example. There are other ways to implements this as well, like changing the schema of libraries to be a list of dicts rather list of strings. This would be more powerful and flexible but not be backwards compatible.

eesoymilk commented 8 months ago

I've been trying to install custom libraries through cli for ages now. Is there a workaround for this issue? The cli compile can never seem to find my custom lib in ~/Arduino/libraries.

ubidefeo commented 8 months ago

@eesoymilk can you be more specific? what are your custom libraries? libraries developed by you? do they conform to the libraries specification?

eesoymilk commented 8 months ago

@ubidefeo I'm writing my own library. This is the repo: eesoymilk/AS608-Fingerprint-Arduino.

I believe it does conform to the spec since running arduino-lint only shows 1 warning (no license).

I put this repo directly in my ~/Arduino/libraries of course. I was trying to compile it with arduino-cli and I have a sketch.yaml file right next to the targeted .ino file. I added my library's into the skectch.yaml file in hope that all things works (arduino-cli, neovim lsp, etc.):

libraries:
  - AS608Fingerprint (0.1.0)

However, this is the root cause why arduino-cli compile won't correctly compile. It trys to download my library from the Arduino Library Manager (DNE btw) even though my library is listed in arduino-cli lib list.

In the end, removing my library from sketch.yaml solved this problem and the lsp also works.

dmohns commented 8 months ago

I put this repo directly in my ~/Arduino/libraries of course. I was trying to compile it with arduino-cli and I have a sketch.yaml file right next to the targeted .ino file. I added my library's into the skectch.yaml file in hope that all things works (arduino-cli, neovim lsp, etc.):

libraries:
  - AS608Fingerprint (0.1.0)

However, this is the root cause why arduino-cli compile won't correctly compile. It trys to download my library from the Arduino Library Manager (DNE btw) even though my library is listed in arduino-cli lib list.

You would need to run arduino-cli lib install --git-url https://github.com/eesoymilk/AS608-Fingerprint-Arduino.git then arduino-cli compile should work. Which is very tedious to do if you have more than one external library. You can find an example how we created a Makefile to automate some of this here: https://github.com/EnAccess/OpenSmartMeter/blob/27ad33a244d4f95201a7676a6d8307f7c766d15e/Firmware%20code/smart_energy_meter/Makefile#L23-L33

What you describe is exactly the motivation for why this feature request exists.

But let's keep this discussion about the feature request itself rather than workarounds for individual situations.

tyeth commented 1 month ago

Just bumping this, keen on git urls (with refs) in the version string spot, and adding a related note in case @cmaglie / anyone implements this feature...

As mentioned at the end of #108, it would be nice if profiles could support inheritance from a common build profile (we have 60 common libs to list), and then also share these custom libraries linked via git refs too.

We have 9 git-based libs for users to install, two on non-default untagged branches (using sha ref), and a few build profiles (23 targets but I'm assuming user can switch FQBN target and still use a base build profile) hence the interest in this feature.

egnor commented 1 month ago

Yes, this feature continues to be high priority for me and probably many other users of arduino-cli.

As a note, I believe the workaround mentioned in https://github.com/arduino/arduino-cli/issues/2133#issuecomment-1881136157 no longer works (assuming it once did); when a sketch.yaml file is present, arduino-cli compile seems to disregard any libraries installed locally (via arduino-cli lib install or just plopped in ~/Arduino/libraries). This makes sense to keep things hermetic, but removes workarounds...

hasselmm commented 1 month ago

There also occur warnings when trying to "pin" 3rd-party platform libraries like ESP8266HTTPClient:

Downloading library ESP8266HTTPClient@1.2...
Library ESP8266HTTPClient@1.2 not found...
Error initializing instance: Library 'ESP8266HTTPClient' not found

Arduino-cli still finds ESP8266HTTPClient later on. Still this is confusing. And yes, maybe it doesn't make much sense to pin platform libraries.