Skip to content

Commit 9b6c9c4

Browse files
authored
[skip changelog] Document library dependency version constraints (#1786)
Arduino libraries may specify dependencies on other libraries in their metadata. The Arduino Library Manager offers the option to install these dependencies when the user installs the library. By default, the latest version of the dependency is installed. However, libraries may be compatible or tested working only with specific versions of a dependency. In this case, the library developer may wish to specify a particular version or version range of the dependency. Arduino CLI and the Arduino Library index system has had support for such dependency version constraints for the last 2.5 years, but it was never documented so has only been used by the few library developers who discovered it via other means. The dependencies version constraint system is hereby fully documented in the Arduino library specification. This will allow meaningful benefit to finally come from the work done to add this valuable capability.
1 parent 124c35d commit 9b6c9c4

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

Diff for: docs/library-specification.md

+53-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ otherwise below, **all fields are required**. The available fields are:
7474
install the dependencies during installation of the library.
7575
[`arduino-cli lib install`](commands/arduino-cli_lib_install.md) will automatically install the dependencies. Since
7676
spaces are allowed in the `name` of a library, but not commas, you can refer to libraries containing spaces in the
77-
name without ambiguity for example:<br> `depends=Very long library name, Another library with long-name`
77+
name without ambiguity for example:<br> `depends=Very long library name, Another library with long-name`<br>
78+
[Version constraints](#version-constraints) for the dependency may be specified in parentheses after the name:<br>
79+
`depends=ArduinoHttpClient (>=1.0.0)`
7880
- **dot_a_linkage** - **(available from Arduino IDE 1.6.0 / arduino-builder 1.0.0-beta13)** (optional) when set to
7981
`true`, the library will be compiled using a .a (archive) file. First, all source files are compiled into .o files as
8082
normal. Then instead of including all .o
@@ -117,6 +119,56 @@ includes=WebServer.h
117119
depends=ArduinoHttpClient
118120
```
119121

122+
#### Version constraints
123+
124+
**(available from Arduino IDE 2.0.0-beta.3/Arduino CLI 0.7.0)**
125+
126+
By default, the latest version of a dependency specified in the `depends` field of
127+
[`library.properties`](#libraryproperties-file-format) is installed along with the library. Specifying an exact version
128+
or range of versions is also supported.
129+
130+
The following operators are available:
131+
132+
<!-- code tags used below to reconcile mismatch between Prettier and Python-Markdown handling of pipe characters -->
133+
134+
| | |
135+
| ----------------- | ----------------------------- |
136+
| `=` | equal to |
137+
| `>` | greater than |
138+
| `>=` | greater than or equal to |
139+
| `<` | less than |
140+
| `<=` | less than or equal to |
141+
| `!` | NOT [<sup>1</sup>](#not-note) |
142+
| `&&` | AND |
143+
| <code>\|\|</code> | OR |
144+
| `(`, `)` | constraint group |
145+
146+
<a id="not-note"></a> <sup>1</sup> Available from Arduino IDE 2.0.0-rc7/Arduino CLI 0.22.0
147+
148+
##### Examples
149+
150+
If the library "ArduinoHttpClient" has the following releases:
151+
152+
- `0.1.0`
153+
- `1.0.0`
154+
- `2.0.0`
155+
- `2.1.0`
156+
157+
The version of it installed as a dependency would be as follows:
158+
159+
| `depends` field value | Installs<br> version |
160+
| --------------------------------------------------------------- | -------------------- |
161+
| `ArduinoHttpClient` | `2.1.0` |
162+
| `ArduinoHttpClient (=1.0.0)` | `1.0.0` |
163+
| `ArduinoHttpClient (>1.0.0)` | `2.1.0` |
164+
| `ArduinoHttpClient (>=1.0.0)` | `2.1.0` |
165+
| `ArduinoHttpClient (<2.0.0)` | `1.0.0` |
166+
| `ArduinoHttpClient (<=2.0.0)` | `2.0.0` |
167+
| `ArduinoHttpClient (!=1.0.0)` | `2.1.0` |
168+
| `ArduinoHttpClient (>1.0.0 && <2.1.0)` | `2.0.0` |
169+
| <code>ArduinoHttpClient (<1.0.0 \|\| >2.0.0)</code> | `2.1.0` |
170+
| <code>ArduinoHttpClient ((>0.1.0 && <2.0.0) \|\| >2.1.0)</code> | `1.0.0` |
171+
120172
### Layout of folders and files
121173

122174
Each folder has a specific purpose (sources, examples, documentation, etc). Folders not covered in this specification

0 commit comments

Comments
 (0)