# `NBPR.Buildroot.Builder`
[🔗](https://github.com/jimsynz/nbpr/blob/v0.7.0/lib/nbpr/buildroot/builder.ex#L1)

Source-builds an NBPR package artefact tarball end-to-end.

Driven from both `Mix.Tasks.Nbpr.Build` (CLI) and `Mix.Tasks.Nbpr.Fetch`'s
fallback path (when no prebuilt artefact is published for the active
(system, system_version, build_opts) tuple).

Pipeline:

  1. Discover `deps/nerves_system_br/` and read the pinned BR version.
  2. Ensure the patched BR source tree at
     `$NERVES_DATA_DIR/nbpr/buildroot/<version>/`.
  3. Render a defconfig that layers the package + its `build_opts` on top
     of the active system's `nerves_defconfig`.
  4. Run BR (`<pkg>-dirclean && <pkg>`) against a stable per-(system,
     BR-version) output dir, in Docker on non-Linux hosts.
  5. Filter per-package output via BR's files-list (runtime-only).
  6. Pack into the canonical artefact tarball at `output_dir/`.

Returns the absolute path to the produced tarball.

# `build!`

```elixir
@spec build!(NBPR.Package.t(), NBPR.Artifact.build_inputs(), Path.t()) :: Path.t()
```

Builds the artefact for `pkg` against `inputs.system_app`/`system_version`,
with `inputs.build_opts` applied. Writes the tarball into `output_dir` and
returns its absolute path.

`inputs` is the standard `t:NBPR.Artifact.build_inputs/0` map (the same one
used for cache-key/manifest computation in the fetch path).

# `ensure_libc_supported!`

```elixir
@spec ensure_libc_supported!(NBPR.Package.t(), Path.t(), atom()) :: :ok
```

Raises when `pkg` declares the system's libc unsupported.

Refuses the combination before Buildroot spends ten minutes proving it in a
compile error. The prebuild matrix already leaves these out of CI, so this
guard is for a consumer whose `mix firmware` falls through to a source
build.

# `libc_of_system`

```elixir
@spec libc_of_system(Path.t()) :: NBPR.Package.libc()
```

The C library a system's toolchain targets, read from its `nerves_defconfig`.

Buildroot's own kconfig is the source of truth here rather than the
toolchain's name, since that's what decides which libc the package is
actually compiled against. Anything that isn't explicitly musl is treated as
glibc, which is every Nerves system bar `x86_64`.

# `stable_output_dir`

```elixir
@spec stable_output_dir(atom(), String.t()) :: Path.t()
```

Returns the stable per-(system, BR-version) BR output dir. Reusing across
builds keeps the toolchain extraction, host-skeleton, and unchanged packages
cached; `make olddefconfig` reconciles defconfig drift.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
