# Rust

> RustBuild builds a Cargo crate and links it with plinto's own pinned C toolchain, never the machine's.

**RustBuild builds a Cargo crate with the Rust your group pins and, on Linux, links it with plinto's own C toolchain, so the machine needs no compiler and every build links the same way.**

Build system: `RustBuild`
Start one: `plinto create rust-service HelloApp` (or `rust-lib`)
Ships as: a binary in an archive, for Linux back to Debian 11

## The project {#project}

`src/lib.rs` makes a library, and a crate that names its binary's root, `main = src/main.rs`, a program; a crate can be both. Integration tests are `tst/<name>.rs`. Crates use edition 2024.

```conf file=plinto.conf
{
  name = HelloApp
  version = 1.0
  build = RustBuild
  main = src/main.rs   # a program: what `plinto run` starts

  build-dependencies: {
    RustBuild = 1.0
    Rust = 1.98
  }
  dependencies: {
    Serde: { version = 1.0.229, features = [derive] }
  }
}
```

`main` can name another file, such as `src/server.rs`. `args = [--port, 8080]` is what the program starts with, for `plinto run` and once packaged.

**Not yet:**
build scripts (`build.rs`) don't run.

## The C toolchain {#c-toolchain}

On Linux, the `Rust` package brings `Gcc` and `Glibc` as packages, and RustBuild links with those only, never with the machine's `cc`. Each build says which:

```text
using Rust 1.98.1, linking with Gcc 15.2.0, Glibc 2.31
```

A binary needs a Linux whose glibc is at least as new as the one it was linked with: with Glibc 2.31, Debian 11's, as groups start, it runs on Debian 11 and newer. On macOS, Rust links with the system's toolchain.

## Builds and releases {#releases}

`plinto build` and `plinto run` use Cargo's dev profile; a release is optimized and stripped of debug information. A program's release is `HelloApp-1.0-bin-<platform>.tar.gz`, built for the machine it builds on.

## Crates {#libraries}

```sh
$ plinto import crate serde@1.0.229 --features derive
```

The features an import turns on decide which optional crates it brings, and a project turns on those it needs, as `features = [derive]` above.

- [Go](go.md): static binaries too
- [Check a release](../guides/check-a-release.md): build it again and compare
- [Packages](../concepts/packages.md#imports): imports, for every language
