Build

The build process is almost similar to Arduino Build Process.

A number of things have to happen for your Arduino code to get onto the Arduino board. First, plugin performs some small transformations to make sure that the code is correct C or C++ (two common programming languages). It then gets passed to a compiler (avr-gcc), which turns the human readable code into machine readable instructions (or object files). Then, your code gets combined with (linked against), the standard Arduino libraries that provide basic functions like digitalWrite() or Serial.print(). The result is a single hex file, which contains the specific bytes that need to be written to the program memory of the chip on the Arduino board. This file is then uploaded to the board: transmitted over the USB or serial connection via the bootloader already on the chip or with external programming hardware.

Preparation

TODO: reference cli command when it's done

Multi-file sketches

A sketch can contain one .ino or .pde file and multiple files with extensions of .c, .cpp and .h. Before your sketch is compiled, .ino or .pde file is transformed to form the "main sketch file". Files with .c, .cpp or extensions are compiled separately. To use files with a .h extension, you need to #include it (using "double quotes" not angle brackets).

Transformations to the main sketch file

cuwire performs a few transformations to your main sketch file before passing it to the compiler.

First, #include "Arduino.h" is added just before first program statement. This header file (found in <ARDUINO>/hardware/cores/<CORE>/) includes all the defintions needed for the standard Arduino core.

Next, cuwire searches for function definitions within your main sketch file and creates declarations (prototypes) for them. These are inserted just after Arduino.h. This means that if you want to use a custom type as a function argument, you should declare it within a separate header file. Also, this generation isn't perfect: it won't create prototypes for functions that have default argument values, or which are declared within a namespace or class.

Arduino IDE and Stino plugin for SublimeText works slightly different. Arduino IDE append every file without extension to the main sketch file, Stino does the same for all files with .ino or .pde extension. This is bad practice, cuwire doesn't support that. If you want to build a modular app, please use .c* and .h files, this behavior is supported in every IDE.

  • Build process

First, plugin reads boards.txt and platform.txt within <ARDUINO_APP>/hardware and <USER_DOCUMENTS>/Arduino/hardware folders to generate recipes for build and upload.