Skip to content

[Proposal] Declare library depencies inside sketches #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
philippejadin opened this issue Dec 20, 2018 · 11 comments
Closed

[Proposal] Declare library depencies inside sketches #1011

philippejadin opened this issue Dec 20, 2018 · 11 comments
Assignees
Labels
type: enhancement Proposed improvement

Comments

@philippejadin
Copy link

This proposal is short and addresses a shortcoming for every user : which library do I need to install to make this sketch run?

  • allow to add some markup to sketches to declare the required library and version needed
  • parse this new info on compile, and ask user if he wants to install the needed libraries
  • profit!

Markup proposal, example with the rfid lib :

// require_arduino_lib "MFRC522"
#include <MFRC522.h>

Note that we simply use a comment so nothing changes from the compiler point of view.

Markup proposal specifying the lib version to use :

// require_arduino_lib "MFRC522" "1.4.2"
#include <MFRC522.h>

The rules are as follow :

  • the word require_arduino_lib
  • followed with the quoted library name
  • followed by the quoted version or nothing to install the latest
  • followed by a new line character
  • one library per line
  • inside a comment is allowed (and currently mandatory since there is no compiler support)
@philippejadin
Copy link
Author

Sorry to bump this thread, but really no one is interested by this? It's such a common problem to install the correct library for newbies... I see a lot of potential in my proposal but maybe I missed something :-)

@facchinm
Copy link
Member

facchinm commented Jan 2, 2019

Hi @philippejadin ,
the proposal is interesting; however, there's a lot of infrastructure to be modified before approaching this (first of all, allowing two different versions of the same library to coexist).
In the meantime, there's a less known feature to directly open library manager that could be useful; a link in the form http://librarymanager/all#keywordToSearch (inside a comment) will open the library manager with the right filters and ease the installation at least.

@philippejadin
Copy link
Author

Good to know for the link. I will make a proof of concept and will report back here if I manage to have something interesting.

@s-celles
Copy link

s-celles commented Jan 3, 2019

Looks related to arduino/Arduino#5795

@ericvb
Copy link

ericvb commented Apr 26, 2020

@philippejadin Have you been able to make progress on this?
This would boost the usability of sketches if you could include in the script the dependencies to libraries and the used version.
Everybody would then be able to compile your script without a problem of finding the right libs.

This of course requires that all library versions remain available indefinitely...

@philippejadin
Copy link
Author

Unfortunately all I have done is make a proposal. This must be decided by the core team and implemented by very competent people (which does not include me in both cases :-) )

@philippejadin
Copy link
Author

This being said, I still think that my proposal holds well and is simple enough for users / code writers.
BUT : it must be supported by the IDE, that is the hard part, well worth it imho.

@ericvb
Copy link

ericvb commented Apr 27, 2020

@facchinm Do you know if there is something on the roadmap for this problem?

Your suggestion to use a url link to the librarymanager could already help, but it is very limited.

  • the url link search works not for library names with spaces (also not in the IDE itself)
  • if it should be able to include the required library version
  1. no version set ==> take the latest version and install it
  2. a version set ==> take that version and install it
  3. a minimum version set ==> install at least this minimum version if the lib is already installed on the system or take the latest version if not installed

This latest point could be implemented without requiring a change of the Arduino infrastructure.

@per1234 per1234 transferred this issue from arduino/Arduino Oct 5, 2020
@ianfixes
Copy link

The easiest workaround I know of is to convert your sketch into one of the "examples" for a library. Then you can put the dependencies in library.properties

name=WebServer
version=1.0.0
author=Cristian Maglie <[email protected]>, Pippo Pluto <[email protected]>
maintainer=Cristian Maglie <[email protected]>
sentence=A library that makes coding a Webserver a breeze.
paragraph=Supports HTTP1.1 and you can do GET and POST.
category=Communication
url=http://example.com/
architectures=avr
includes=WebServer.h
depends=ArduinoHttpClient
precompiled=true

note the line depends=ArduinoHttpClient

The library itself can be basically empty, e.g. do-something.cpp from the dummy DoSomething library

@per1234 per1234 reopened this Mar 30, 2021
@tarampampam
Copy link

@philippejadin Maybe #1321 can be helpful for you?

@umbynos
Copy link
Contributor

umbynos commented Oct 12, 2022

Actually this has been implemented in the cli https://arduino.github.io/arduino-cli/latest/sketch-project-file/.

@umbynos umbynos closed this as completed Oct 12, 2022
@umbynos umbynos self-assigned this Oct 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement Proposed improvement
Projects
None yet
Development

No branches or pull requests

10 participants