Precompiled.Host (Precompiled v0.10.0)

Copy Markdown View Source

Install signed, verified precompiled dependency builds instead of compiling them.

On by default, against the official API (Precompiled.Config). In a Mix project the mix precompiled.deps task, reached through the project's deps.loadpaths alias, calls run/1 before Mix compiles the dependencies (the Nerves nerves.init hook calls it the same way); install/2 wraps Mix.install/2. Every candidate dependency prints HIT, MISS or FAIL with a reason, and the same list lands in _build/<target>_<env>/lib/.precompiled/report.json.

Summary

Types

What a run did: counts of hits, misses and failures, the bytes installed, the time taken and one printed line per candidate.

What report/1 did. {:sent, id, false} is a new report and its id (what retracting it needs); {:sent, nil, true} is one the source had already received. The rest: dumped, cancelled, no report to send, an invalid contact:, an error, no install project in this runtime, or reporting turned off.

Functions

Mix.install/2 with precompiled builds: resolves deps, installs every matching build into the install project, then calls Mix.install/2, which compiles only the rest. Starts Mix first, as Mix.install/2 does, so it works in a fresh runtime such as Livebook's.

mix precompiled.report for Mix.install/2 and Livebook: sends the report of the most recent install/2 in this runtime's install project, after showing it and asking. Every install in that project overwrites the same report, so after two installs the second one's is sent.

The build-time step: check every dependency Mix is about to compile and install the matching builds. :disabled when turned off, and on the host target unless allow_host: true (what mix precompiled.deps passes); host?: true | false forces either.

Types

report()

@type report() :: %{
  hits: non_neg_integer(),
  misses: non_neg_integer(),
  fails: non_neg_integer(),
  bytes: non_neg_integer(),
  seconds: float(),
  lines: [term()]
}

What a run did: counts of hits, misses and failures, the bytes installed, the time taken and one printed line per candidate.

report_outcome()

@type report_outcome() ::
  {:sent, String.t() | nil, boolean()}
  | :dumped
  | :cancelled
  | :no_report
  | :invalid
  | {:error, String.t() | :internal}
  | :no_install
  | :off

What report/1 did. {:sent, id, false} is a new report and its id (what retracting it needs); {:sent, nil, true} is one the source had already received. The rest: dumped, cancelled, no report to send, an invalid contact:, an error, no install project in this runtime, or reporting turned off.

Functions

install(deps, opts \\ [])

@spec install([term()], keyword()) :: :ok

Mix.install/2 with precompiled builds: resolves deps, installs every matching build into the install project, then calls Mix.install/2, which compiles only the rest. Starts Mix first, as Mix.install/2 does, so it works in a fresh runtime such as Livebook's.

Takes Mix.install/2's options plus :except and :home (see Precompiled.Config). The source is the official API unless the config names another; :source, :root and :content are config only and raise ArgumentError here (see the Trust guide). With PRECOMPILED=0 it is a plain Mix.install/2.

Needs Mix on the device (:mix in extra_applications), a writable MIX_INSTALL_DIR, and Hex.

report(opts \\ [])

@spec report(keyword()) :: report_outcome()

mix precompiled.report for Mix.install/2 and Livebook: sends the report of the most recent install/2 in this runtime's install project, after showing it and asking. Every install in that project overwrites the same report, so after two installs the second one's is sent.

It works only after Mix.install/2 (through install/2) has run in this runtime: the install project is known only then. After a restart, run the notebook's install/2 cell again first; otherwise it returns :no_install and sends nothing.

Options: yes: true skips the question, contact: adds a handle for follow-up questions (at most 100 characters), dump: true prints the exact JSON and dump: path writes it, sending nothing. Without yes: true only y or yes sends; anything else, and a stdin that is not interactive, counts as no.

Livebook has no stdin, so there Precompiled.Host.report() shows the summary and cancels, and Precompiled.Host.report(yes: true) sends. A new report prints its id, the one thing needed to retract it; a report already received prints no id. Never raises for a reporting problem; returns what happened.

run(opts \\ [])

@spec run(keyword()) :: :disabled | :nothing_to_do | {:ok, report()}

The build-time step: check every dependency Mix is about to compile and install the matching builds. :disabled when turned off, and on the host target unless allow_host: true (what mix precompiled.deps passes); host?: true | false forces either.