Skip to main content

Libraries

A library is code that's built once and used by many projects, such as the Raspberry Pi library, which gives a program the board's pins and devices.

Adding one​

In IntelliJ, choose Tools | Nylon | Add Nylon Library…, or right-click in the project view. It lists the libraries you can add, with the boards each one works on. Pick one and a version, and it adds one line to your build.markup.code:

build.markup.code
(+dependencies : RepositoryDependency coordinate={"com.grandtheorem:raspberry-pi:0.1.0"} /)

New Project offers the same list, so you can choose libraries as the project is made.

A library you've built yourself comes in the same way: Add Nylon Library from File… adds a FileDependency, and Add Nylon Library from Git… a GitDependency (Build files).

Using it​

Import what you use from the library's namespace. import a.b.C brings in one type, and import namespace a.b everything in a namespace:

namespace robot

import grandtheorem.rpi.Pi

entrypoint main() {
Pi.statusLed().on()
}

What a library brings with it​

A library brings the libraries it needs. The Build HAT library needs the Raspberry Pi library, so adding build-hat brings raspberry-pi too, and your program can import from both.

A library needs the exact versions it was built against. If you name a version yourself that a library you use doesn't allow, the build says so and names the version it needs.

The published libraries​

LibraryCoordinateNamespace
Raspberry Picom.grandtheorem:raspberry-pi:0.1.0grandtheorem.rpi
Build HATcom.grandtheorem:build-hat:0.1.0grandtheorem.buildhat

They come from the library repository at downloads.grandtheorem.com, which IntelliJ calls "central".

Fetching and checking​

The first build that needs a library downloads it, along with a SHA-256 digest published beside it. The build keeps the library only if the two match. Otherwise it stops and says why.

A library is kept in ~/.nylon/libraries once it's fetched, and never downloaded again, so builds work offline after the first. Set NYLON_HOME to keep it somewhere else.