Packages (roadmap #35)
A package is a directory with a lib.tr (its public definitions, as for any module) and, if it has dependencies of its own, a trine.toml. A project lists the packages it uses in [dependencies] of its trine.toml, and imports each one by its bare name:
# trine.toml
[package]
name = "app"
[dependencies]
geometry = { path = "../geometry" } # a directory on disk (35a)
shapes = { git = "https://github.com/me/shapes", rev = "v1.2" } # a git repository (35b)
# main.tr
import "shapes"
fn main():
print(shapes.area(3, 4))
Git dependencies and trine.lock (35b)
rev is a tag, a branch or a commit (default: HEAD). The first build:
- fetches the repository into a mirror in the shared cache (below);
- resolves
revto a commit and checks that commit out, without.gitand without line-ending conversion, into the cache under the hash of its files; - writes
trine.lockbeside the project'strine.toml:
[[package]]
name = "shapes"
git = "https://github.com/me/shapes"
rev = "v1.2"
commit = "9e819af4457a4c260b495f27e73c8b8eae872cc2"
hash = "sha256:45f95f9eda8b…"
**Commit trine.lock.** Every later build, on any machine, uses exactly that commit, even if the tag has since moved, and checks the files against the hash: if a repository's history was rewritten (the same commit id, other files), the build stops and says so. Packages a package depends on are pinned in the same lock file: one lock file per project.
trine build main.tr --locked(orTRINE_LOCKED=1): add nothing to the lock; a dependency that isn't in it is an error. Use it in CI and release builds.trine update [names...]: resolve the named dependencies (all, when none are named) again, rewrite the lock file and report what moved (updated shapes v1.2: b5b788484aa0 -> 9e819af4457a). It also drops entries nothing uses any more.- The content hash is sha256 over the package's files in path order, each as its relative path (with
/), its length and its bytes; hidden files and directories (.git,.trine) are left out. It is the same on every platform. - Messages name package files
shapes@v1.2/lib.tr:4:9, not paths in the cache, and no cache path reaches the generated C, so a build doesn't depend on where the cache is. - Git must be on the PATH. Credentials are git's own (SSH keys, credential helpers); trine never lets git prompt.
trine.tomlandtrine.lockcome with a project, so they are checked before git sees them:gitis anhttps://,http://,ssh://,git://orfile://URL,user@host:pathor a local path (never something starting with-, nor aname::transport helper);revcan't start with-; a lock entry'scommitis a full hex commit id and itshashissha256:and 64 hex digits, or the lock file is reported damaged (SECURITY.md).
The shared cache (35c)
$TRINE_HOME, else %LOCALAPPDATA%\trine on Windows, $XDG_CACHE_HOME/trine or ~/.cache/trine elsewhere:
git/: bare mirrors of the repositories, one per URL.pkgs/<hash>/: package checkouts, named by their content hash (shared by every project that uses the same files).build/<key>: native executables, keyed by sha256 of the generated C, the runtime headers, the C compiler (its path and--version) and its flags. The same program built the same way in any project is copied, not compiled (TRINE_NO_BUILD_CACHE=1turns this off; PGO builds don't use it).
Everything in the cache can be deleted at any time; it is fetched or built again.
Reproducible builds
The executable depends only on the sources (the project's and the locked packages'), the compiler and the flags. A clean checkout with an empty cache builds a byte-identical executable when built the same way (the main file named by the same relative path: it is the program's name in its error messages). A test does exactly this: two git packages and an app, locked, the upstream tag moved, a fresh clone built --locked with a fresh cache.
Not yet: version ranges and a registry (packages are pinned commits); trine add.