Skip to content

arduino/arduino-cslt

Repository files navigation

arduino-cslt

arduino-cslt is a convenient wrapper of arduino-cli, it compiles Arduino sketches outputting a precompiled library under sketch-dist/ folder created in the current working directory. 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 to generate an archive of the object files.

Prequisites

In order to run this tool you have to install first the Arduino CLI and have arduino-cli binary in your $PATH, otherwise arduino-cslt won't work. Please use a version of the Arduino CLI that has this change (version > 0.20.2).

Another requirement is gcc-ar (installable with apt-get install gcc) in your $PATH.

Build it

In order to build arduino-cslt just use task go:build

Usage

./arduino-cslt compile -b <fqbn> <sketch_path>

asciicast

For example, running ./arduino-cslt compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino should produce a library with the following structure, in the current working directory:

sketch-dist/
├── libsketch
│   ├── extras
│   │   └── result.json
│   ├── library.properties
│   └── src
│       ├── cortex-m0plus
│       │   └── libsketch.a
│       └── libsketch.h
└── sketch
    └── sketch.ino  <-- the actual sketch we are going to compile with the arduino-cli later

This is an example execution:

$ ./arduino-cslt compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino
INFO[0000] arduino-cli version: git-snapshot            
INFO[0000] GNU ar (GNU Binutils) 2.37                   
INFO[0000] the ino file path is sketch/sketch.ino 
INFO[0000] created sketch/main.cpp 
INFO[0000] replaced setup() and loop() functions in sketch/sketch.ino 
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino -v --format json 
INFO[0000] running: arduino-cli compile -b arduino:samd:mkrwifi1010 sketch/sketch.ino --show-properties 
INFO[0001] removed sketch/main.cpp 
INFO[0001] created sketch/sketch.ino 
INFO[0001] restored sketch/sketch.ino 
INFO[0001] created sketch-dist/libsketch/library.properties
INFO[0001] created sketch-dist/libsketch/src/libsketch.h 
INFO[0001] created sketch-dist/sketch/sketch.ino 
INFO[0001] running: gcc-ar rcs sketch-dist/libsketch/src/cortex-m0plus/libsketch.a /tmp/arduino-sketch-E4D76B1781E9EB73A7B3491CAC68F374/sketch/sketch.ino.cpp.o 
INFO[0001] created sketch-dist/libsketch/src/cortex-m0plus/libsketch.a 
INFO[0001] created sketch-dist/libsketch/extras/result.json

And the content of sketch-dist/libsketch/extras/result.json is:

{
 "coreInfo": {
  "id": "arduino:samd",
  "version": "1.8.12"
 },
 "libsInfo": [
  {
   "name": "WiFiNINA",
   "version": "1.8.13",
   "provides_includes": [
    "WiFiNINA.h"
   ]
  },
  {
   "name": "SPI",
   "version": "1.0",
   "provides_includes": [
    "SPI.h"
   ]
  }
 ]
}

How to compile the precompiled sketch

In order to compile the sketch you have first to install manually the libraries and the core listed in the sketch-dist/<libsketch>/extras/result.json file.

You can install a library with arduino-cli lib install LIBRARY[@VERSION_NUMBER].

You can install a core with arduino-cli core install PACKAGER:ARCH[@VERSION].

After completing that operation you can compile it with:

arduino-cli compile -b <fqbn> sketch-dist/sketch/sketch.ino --library sketch-dist/<libsketch>.

It's important to use the --library flag to include the precompiled library generated with arduino-cslt otherwise the Arduino CLI won't find it.

For example a legit execution looks like this:

$ arduino-cli compile -b arduino:samd:mkrwifi1010 sketch-dist/sketch/sketch.ino --library sketch-dist/libsketch/

Library libsketch has been declared precompiled:
Using precompiled library in sketch-dist/libsketch/src/cortex-m0plus
Sketch uses 14636 bytes (5%) of program storage space. Maximum is 262144 bytes.
Global variables use 3224 bytes (9%) of dynamic memory, leaving 29544 bytes for local variables. Maximum is 32768 bytes.

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors 3

  •  
  •  
  •