Skip to content

Commit 1ea44ce

Browse files
umbynosper1234
andauthored
The tool now generate a precompiled library that can be linked later with the libs and the core (#2)
* WIP continue from lib folder generation * WIP 🎉 it works! Still needs some code reorganization, update doc etc.. * update README.md, reorganize the code, remove `main.cpp` and restore `sketch.ino` after the compile, minor fixes * apply suggestions from code review * Apply suggestions from code review Co-authored-by: per1234 <[email protected]> * add asciinema screencast Co-authored-by: per1234 <[email protected]>
1 parent 3906685 commit 1ea44ce

File tree

3 files changed

+359
-55
lines changed

3 files changed

+359
-55
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
cslt-tool
22
.vscode
3-
build/
3+
lib*

README.md

+79-20
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,59 @@
11
# cslt-tool
22

3-
cslt-tool is a convenient wrapper of [arduino-cli](https://github.com/arduino/arduino-cli), it compiles Arduino sketches outputting object files and a json file in a `build/` directory
4-
The json contains information regarding libraries and core to use in order to build the sketch. The result is achieved by parsing the verbose output of `arduino-cli`.
3+
`cslt-tool` is a convenient wrapper of [arduino-cli](https://github.com/arduino/arduino-cli), it compiles Arduino sketches outputting a precompiled library in the current working directory.
4+
It generates a json file in the `extras/` folder that contains information regarding libraries and core to use in order to build the sketch. The result is achieved by parsing the verbose output of `arduino-cli` and by using [GNU ar](https://sourceware.org/binutils/docs/binutils/ar.html) to generate an archive of the object files.
55

6-
## Requisites
7-
In order to run this tool you have to install first the [arduino-cli](https://github.com/arduino/arduino-cli) and have `arduino-cli` binary in your path, otherwise `cslt-tool` won't work.
8-
Please use a version of the cli that has [this](https://github.com/arduino/arduino-cli/pull/1608) change, version > 0.20.2
6+
## Prequisites
7+
In order to run this tool you have to install first the [Arduino CLI](https://github.com/arduino/arduino-cli) and have `arduino-cli` binary in your `$PATH`, otherwise `cslt-tool` won't work.
8+
Please use a version of the Arduino CLI that has [this](https://github.com/arduino/arduino-cli/pull/1608) change (version > 0.20.2).
9+
10+
Another requirement is [`gcc-ar`](https://sourceware.org/binutils/docs/binutils/ar.html) (installable with `apt-get install gcc`) in your `$PATH`.
911

1012
## Build it
11-
In order to build it just use `go build`
13+
In order to build `cslt-tool` just use `go build`
1214

1315
## Usage
1416
`./cslt-tool compile -b <fqbn> <sketch_path>`
1517

16-
This is an example execution:
17-
``` bash
18-
$ ./cslt-tool compile -b arduino:samd:mkrwan1310 /home/umberto/getdeveui
19-
INFO[0001] arduino-cli version: git-snapshot
20-
INFO[0001] running: arduino-cli compile -b arduino:samd:mkrwan1310 /home/umberto/getdeveui -v --format json
21-
INFO[0002] copied file to /home/umberto/Nextcloud/8tb/Lavoro/cslt-tool/build/getdeveui.ino.cpp.o
22-
INFO[0002] created new file in: /home/umberto/Nextcloud/8tb/Lavoro/cslt-tool/build/result.json
18+
[![asciicast](https://asciinema.org/a/463342.svg)](https://asciinema.org/a/463342)
19+
20+
For example, running `./cslt-tool compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino` should produce a library with the following structure, in the current working directory:
2321
```
24-
The structure of the `build` forder is the following:
22+
libsketch/
23+
├── examples
24+
│ └── sketch
25+
│ └── sketch.ino <-- the actual sketch we are going to compile with the arduino-cli later
26+
├── extras
27+
│ └── result.json
28+
├── library.properties
29+
└── src
30+
├── cortex-m0plus
31+
│ └── libsketch.a
32+
└── libsketch.h
2533
```
26-
build/
27-
├── getdeveui.ino.cpp.o
28-
└── result.json
34+
35+
This is an example execution:
2936
```
30-
And the content of `build/result.json` is:
37+
$ ./cslt-tool compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino
38+
INFO[0000] arduino-cli version: git-snapshot
39+
INFO[0000] GNU ar (GNU Binutils) 2.37
40+
INFO[0000] the ino file path is sketch/sketch.ino
41+
INFO[0000] created sketch/main.cpp
42+
INFO[0000] replaced setup() and loop() functions in sketch/sketch.ino
43+
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino -v --format json
44+
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino --show-properties
45+
INFO[0001] removed sketch/main.cpp
46+
INFO[0001] created sketch/sketch.ino
47+
INFO[0001] restored sketch/sketch.ino
48+
INFO[0001] created libsketch/library.properties
49+
INFO[0001] created libsketch/src/libsketch.h
50+
INFO[0001] created libsketch/examples/sketch/sketch.ino
51+
INFO[0001] running: gcc-ar rcs libsketch/src/cortex-m0plus/libsketch.a /tmp/arduino-sketch-E4D76B1781E9EB73A7B3491CAC68F374/sketch/sketch.ino.cpp.o
52+
INFO[0001] created libsketch/src/cortex-m0plus/libsketch.a
53+
INFO[0001] created libsketch/extras/result.json
54+
```
55+
56+
And the content of `libsketch/extras/result.json` is:
3157
```json
3258
{
3359
"coreInfo": {
@@ -36,9 +62,42 @@ And the content of `build/result.json` is:
3662
},
3763
"libsInfo": [
3864
{
39-
"name": "MKRWAN",
40-
"version": "1.1.0"
65+
"name": "WiFiNINA",
66+
"version": "1.8.13",
67+
"provides_includes": [
68+
"WiFiNINA.h"
69+
]
70+
},
71+
{
72+
"name": "SPI",
73+
"version": "1.0",
74+
"provides_includes": [
75+
"SPI.h"
76+
]
4177
}
4278
]
4379
}
80+
```
81+
82+
## How to compile the precompiled sketch
83+
In order to compile the sketch you have first to install manually the libraries and the core listed in the `<libsketch>/extras/result.json` file.
84+
85+
You can install a library with [`arduino-cli lib install LIBRARY[@VERSION_NUMBER]`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_lib_install/).
86+
87+
You can install a core with [`arduino-cli core install PACKAGER:ARCH[@VERSION]`](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_core_install/).
88+
89+
After completing that operation you can compile it with:
90+
91+
`arduino-cli compile -b <fqbn> <libsketch>/examples/sketch/sketch.ino --library <libsketch>`.
92+
93+
It's important to use the `--library` flag to include the precompiled library generated with cslt-tool otherwise the Arduino CLI won't find it.
94+
95+
For example a legit execution looks like this:
96+
```
97+
$ arduino-cli compile -b arduino:samd:mkrwifi1010 libsketch/examples/sketch/sketch.ino --library libsketch/
98+
99+
Library libsketch has been declared precompiled:
100+
Using precompiled library in libsketch/src/cortex-m0plus
101+
Sketch uses 14636 bytes (5%) of program storage space. Maximum is 262144 bytes.
102+
Global variables use 3224 bytes (9%) of dynamic memory, leaving 29544 bytes for local variables. Maximum is 32768 bytes.
44103
```

0 commit comments

Comments
 (0)