Skip to content

Commit 6515654

Browse files
committed
update README.md, reorganize the code, remove main.cpp and restore sketch.ino after the compile, minor fixes
1 parent a5e3bd9 commit 6515654

File tree

3 files changed

+258
-157
lines changed

3 files changed

+258
-157
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
cslt-tool
22
.vscode
3-
build/
3+
lib*

README.md

Lines changed: 77 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,57 @@
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 `extra/` 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 o have [`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+
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:
2319
```
24-
The structure of the `build` forder is the following:
20+
libsketch/
21+
├── examples
22+
│ └── sketch
23+
│ └── sketch.ino <-- the actual sketch we are going to compile with the arduino-cli later
24+
├── extra
25+
│ └── result.json
26+
├── library.properties
27+
└── src
28+
├── cortex-m0plus
29+
│ └── libsketch.a
30+
└── libsketch.h
2531
```
26-
build/
27-
├── getdeveui.ino.cpp.o
28-
└── result.json
32+
33+
This is an example execution:
34+
``` bash
35+
$ ./cslt-tool compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino
36+
INFO[0000] arduino-cli version: git-snapshot
37+
INFO[0000] GNU ar (GNU Binutils) 2.37
38+
INFO[0000] the ino file path is sketch/sketch.ino
39+
INFO[0000] created sketch/main.cpp
40+
INFO[0000] replaced setup() and loop() functions in sketch/sketch.ino
41+
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino -v --format json
42+
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino --show-properties
43+
INFO[0001] removed sketch/main.cpp
44+
INFO[0001] created sketch/sketch.ino
45+
INFO[0001] restored sketch/sketch.ino
46+
INFO[0001] created libsketch/library.properties
47+
INFO[0001] created libsketch/src/libsketch.h
48+
INFO[0001] created libsketch/examples/sketch/sketch.ino
49+
INFO[0001] running: gcc-ar rcs libsketch/src/cortex-m0plus/libsketch.a /tmp/arduino-sketch-E4D76B1781E9EB73A7B3491CAC68F374/sketch/sketch.ino.cpp.o
50+
INFO[0001] created libsketch/src/cortex-m0plus/libsketch.a
51+
INFO[0001] created libsketch/extra/result.json
2952
```
30-
And the content of `build/result.json` is:
53+
54+
And the content of `libsketch/extra/result.json` is:
3155
```json
3256
{
3357
"coreInfo": {
@@ -36,9 +60,42 @@ And the content of `build/result.json` is:
3660
},
3761
"libsInfo": [
3862
{
39-
"name": "MKRWAN",
40-
"version": "1.1.0"
63+
"name": "WiFiNINA",
64+
"version": "1.8.13",
65+
"provides_includes": [
66+
"WiFiNINA.h"
67+
]
68+
},
69+
{
70+
"name": "SPI",
71+
"version": "1.0",
72+
"provides_includes": [
73+
"SPI.h"
74+
]
4175
}
4276
]
4377
}
78+
```
79+
80+
## How to compile the precompiled sketch
81+
In order to compile the sketch you have first to install manually the libraries and the core listed in the `<libsketch>/extra/result.json` file.
82+
83+
You can install a library with `arduino-cli lib install LIBRARY[@VERSION_NUMBER]`.
84+
85+
You can install a core with `arduino-cli core install PACKAGER:ARCH[@VERSION]`.
86+
87+
After completing that operation you can compile it with:
88+
89+
`arduino-cli compile -b <fqbn> <libsketch>/examples/sketch/sketch.ino --library <libsketch>`.
90+
91+
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.
92+
93+
For example a legit execution looks like this:
94+
``` bash
95+
$ arduino-cli compile -b arduino:samd:mkrwifi1010 libsketch/examples/sketch/sketch.ino --library libsketch/
96+
97+
Library libsketch has been declared precompiled:
98+
Using precompiled library in libsketch/src/cortex-m0plus
99+
Sketch uses 14636 bytes (5%) of program storage space. Maximum is 262144 bytes.
100+
Global variables use 3224 bytes (9%) of dynamic memory, leaving 29544 bytes for local variables. Maximum is 32768 bytes.
44101
```

0 commit comments

Comments
 (0)