blob: d1d2af412e241c1128dfbe19b0867054561ba03f [file]
/-
Copyright (c) 2017 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner, Sebastian Ullrich, Mac Malone
-/
module
prelude
public import Init.Data.ToString
import Lake.Version
namespace Lake
public def usage :=
uiVersionString ++ "
USAGE:
lake [OPTIONS] <COMMAND>
COMMANDS:
new <name> <temp> create a Lean package in a new directory
init <name> <temp> create a Lean package in the current directory
build <targets>... build targets
query <targets>... build targets and output results
exe <exe> <args>... build an exe and run it in Lake's environment
samply <exe> profile an exe with samply and demangle Lean names
check-build check if any default build targets are configured
test test the package using the configured test driver
check-test check if there is a properly configured test driver
lint lint the package
check-lint check if there is a properly configured lint driver
clean remove build outputs
shake minimize imports in source files
comparator judge a solution against a challenge
check check this project against external checker(s)
env <cmd> <args>... execute a command in Lake's environment
lean <file> elaborate a Lean file in Lake's context
update update dependencies and save them to the manifest
pack pack build artifacts into an archive for distribution
unpack unpack build artifacts from an distributed archive
upload <tag> upload build artifacts to a GitHub release
cache manage the Lake cache
script manage and run workspace scripts
scripts shorthand for `lake script list`
run <script> shorthand for `lake script run`
translate-config change language of the package configuration
serve start the Lean language server
BASIC OPTIONS:
--version print version and exit
--help, -h print help of the program or a command and exit
--dir, -d=file use the package configuration in a specific directory
--file, -f=file use a specific file for the package configuration
-K key[=value] set the configuration file option named key
--old only rebuild modified modules (ignore transitive deps)
--rehash, -H hash all files for traces (do not trust `.hash` files)
--update update dependencies on load (e.g., before a build)
--packages=file JSON file of package entries that override the manifest
--reconfigure, -R elaborate configuration files instead of using OLeans
--keep-toolchain do not update toolchain on workspace update
--allow-empty accept bare builds with no default targets configured
--no-build exit immediately if a build target is not up-to-date
--fail-fast stop scheduling new build jobs after the first required failure
--no-cache build packages locally; do not download build caches
--try-cache attempt to download build caches for supported packages
--json, -J output JSON-formatted results (in `lake query`,
`lake check` and `lake comparator`)
--text output results as plain text (in `lake query`)
OUTPUT OPTIONS:
--quiet, -q hide informational logs and the progress indicator
--verbose, -v show trace logs (command invocations) and built targets
--ansi, --no-ansi toggle the use of ANSI escape codes to prettify output
--log-level=lv minimum log level to output on success
(levels: trace, info, warning, error)
--fail-level=lv minimum log level to fail a build (default: error)
--iofail fail build if any I/O or other info is logged
(same as --fail-level=info)
--wfail fail build if warnings are logged
(same as --fail-level=warning)
See `lake help <command>` for more information on a specific command."
def newInitHelp :=
s!"If you are using Lake through Elan (which is standard), you can create a
package with a specific Lean version via the `+` option.
The initial configuration and starter files are based on the template:
std library and executable; default
exe executable only
lib library only
math-lax library only with a Mathlib dependency
math library with Mathlib standards for linting and workflows
Templates can be suffixed with `.lean` or `.toml` to produce a Lean or TOML
version of the configuration file, respectively. The default is TOML."
def helpNew :=
s!"Create a Lean package in a new directory
USAGE:
lake [+<lean-version>] new <name> [<template>][.<language>]
{newInitHelp}"
def helpInit :=
s!"Create a Lean package in the current directory
USAGE:
lake [+<lean-version>] init [<name>] [<template>][.<language>]
{newInitHelp}
You can create a package with current directory's name via `lake init .`
or a bare `lake init`."
def helpBuild :=
"Build targets
USAGE:
lake build [<targets>...] [-o <mappings>] [--package <name>]
A target is specified with a string of the form:
[@[<package>]/][<target>|[+]<module>][:<facet>]
You can also use the source path of a module as a target. For example,
lake build Foo/Bar.lean:o
will build the Lean module (within the workspace) whose source file is
`Foo/Bar.lean` and compile the generated C file into a native object file.
The `@` and `+` markers can be used to disambiguate packages and modules
from file paths or other kinds of targets (e.g., executables or libraries).
LIBRARY FACETS: build the library's ...
elabArts elaboration artifacts (*.olean, *.ilean files)
irArts (default) compilation artifacts (*.ir, *.ir.sig, *.c files)
static static artifact (*.a file)
shared shared artifact (*.so, *.dll, or *.dylib file)
MODULE FACETS: build the module's ...
deps dependencies (e.g., imports, shared libraries, etc.)
elabArts elaboration artifacts (*.olean, *.ilean files)
irArts (default) compilation artifacts (*.ir, *.ir.sig, *.c files)
olean OLean (binary blob of Lean data for importers)
ilean ILean (binary blob of metadata for the Lean LSP server)
c compiled C file
bc compiled LLVM bitcode file
c.o compiled object file (of its C file)
bc.o compiled object file (of its LLVM bitcode file)
o compiled object file (of its configured backend)
dynlib shared library (e.g., for `--load-dynlib`)
TARGET EXAMPLES: build the ...
a default facet(s) of target `a`
@a default target(s) of package `a`
+A default facet(s) of module `A`
@/a default facet(s) of target `a` of the root package
@a/b default facet(s) of target `b` of package `a`
@a/+A:c C file of module `A` of package `a`
:foo facet `foo` of the root package
A bare `lake build` command will build the default target(s) of the root
package. Package dependencies are not updated during a build.
With the Lake cache enabled, Lake can track the targets the build covers
(both those up-to-date and those newly built) and write the input-to-outputs
mappings of each to a file specified by the `-o` option. By default, with `-o`,
Lake will track the targets of the root package, use `--package` to select a
different one. These mappings can then be used to upload the build artifacts
to a remote cache with `lake cache put`. This will only include the artifacts
from the covered targets. Other targets in the package will not be tracked."
def helpQuery :=
"Build targets and output results
USAGE:
lake query [<targets>...]
Builds a set of targets, reporting progress on standard error and outputting
the results on standard out. Target results are output in the same order they
are listed and end with a newline. If `--json` is set, results are formatted as
JSON. Otherwise, they are printed as raw strings. Targets which do not have
output configured will be printed as an empty string or `null`.
See `lake help build` for information on and examples of targets."
def helpCheckBuild :=
"Check if any default build targets are configured
USAGE:
lake check-build
Exits with code 0 if the workspace's root package has any
default targets configured. Errors (with code 1) otherwise.
Does NOT verify that the configured default targets are valid.
It merely verifies that some are specified.
"
def helpUpdate :=
"Update dependencies and save them to the manifest
USAGE:
lake update [<package>...]
ALIAS: lake upgrade
Updates the Lake package manifest (i.e., `lake-manifest.json`),
downloading and upgrading packages as needed. For each new (transitive) git
dependency, the appropriate commit is cloned into a subdirectory of
`packagesDir`. No copy is made of local dependencies.
If a set of packages are specified, said dependencies are upgraded to
the latest version compatible with the package's configuration (or removed if
removed from the configuration). If there are dependencies on multiple versions
of the same package, the version materialized is undefined.
A bare `lake update` will upgrade all dependencies."
def helpTest :=
"Test the workspace's root package using its configured test driver
USAGE:
lake test [-- <args>...]
A test driver can be configured by either setting the 'testDriver'
package configuration option or by tagging a script, executable, or library
`@[test_driver]`. A definition in a dependency can be used as a test driver
by using the `<pkg>/<name>` syntax for the 'testDriver' configuration option.
A script test driver will be run with the package configuration's
`testDriverArgs` plus the CLI `args`. An executable test driver will be
built and then run like a script. A library test driver will just be built.
"
def helpCheckTest :=
"Check if there is a properly configured test driver
USAGE:
lake check-test
Exits with code 0 if the workspace's root package has a properly
configured lint driver. Errors (with code 1) otherwise.
Does NOT verify that the configured test driver actually exists in the
package or its dependencies. It merely verifies that one is specified.
"
def helpLint :=
"Lint the workspace's root package
USAGE:
lake lint [OPTIONS] [<MODULE>...] [-- <args>...]
By default, runs the package's configured lint driver. If `builtinLint` is
set to `true` in the package configuration, builtin lints also run.
Builtin linting (`--builtin-lint`, `--builtin-only`, `--linters`,
`--lint-only`, or `builtinLint = true` in the package configuration) drives a
build of the targeted modules with the requested linter options enabled.
The lint driver path on its own does not trigger a build.
Which environment linters run on a declaration is determined by the linter
options in effect when that declaration was built (e.g. via `set_option` in
the source, or via `--linters`/`--lint-only` below). Both override those
options for the lint build; `--lint-only` additionally restricts the reported
output to exactly the linters its spec enables.
Positional `MODULE` arguments narrow only the builtin lints; if omitted,
the workspace's default target roots are used. The lint driver is invoked
with `lintDriverArgs` from the package config plus any arguments after
`--`; the `MODULE` list is not passed to it.
OPTIONS:
--builtin-lint run builtin environment and text linters
--builtin-only run only builtin linters, skip the lint driver
--linters <spec> override linter options for the lint build; <spec> is a
comma-separated list of linter option names, each
optionally prefixed with `-` to disable it. A name
beginning with `.` is shorthand for the `linter.`
prefix, so `.foo` means `linter.foo`. E.g.
`--linters=.foo,-linter.bar`. Repeatable; later
entries override earlier ones for the same linter
--lint-only <spec> like `--linters`, but report ONLY the linters the spec
positively enables, suppressing every other linter
(including default-on linters that are not named).
Expands `linter.all` and linter sets. Uses the same
`<spec>` syntax as `--linters`; switching between
`--linters` and `--lint-only` replaces the prior spec
--record-exceptions record each linter warning as a
`set_option <linter> false in` exception by editing the
offending source files in place, silencing the warning
for that declaration. Implies `--builtin-lint`.
--code-quality records each linter warning as a code quality check result
and runs the registered code quality checks.
Setting this flag will skip lint driver.
--checks <mods> comma-separated list of workspace modules providing
package code quality checks; they are imported
alongside each linted module (implies --code-quality)
A lint driver can be configured by either setting the `lintDriver` package
configuration option or by tagging a script or executable `@[lint_driver]`.
A definition in a dependency can be used as a lint driver by using the
`<pkg>/<name>` syntax for the 'lintDriver' configuration option.
A script lint driver will be run with the package configuration's
`lintDriverArgs` plus the CLI `args`. An executable lint driver will be
built and then run like a script.
"
def helpCheckLint :=
"Check if there is a properly configured lint driver
USAGE:
lake check-lint
Exits with code 0 if the workspace's root package has a properly
configured lint driver. Errors (with code 1) otherwise.
Does NOT verify that the configured lint driver actually exists in the
package or its dependencies. It merely verifies that one is specified.
"
def helpPack :=
"Pack build artifacts into an archive for distribution
USAGE:
lake pack [<file.tgz>]
Packs the root package's `buildDir` into a gzip tar archive using `tar`.
If a path for the archive is not specified, creates an archive in the package's
Lake directory (`.lake`) named according to its `buildArchive` setting.
Does NOT build any artifacts. It just packs the existing ones."
def helpUnpack :=
"Unpack build artifacts from a distributed archive
USAGE:
lake unpack [<file.tgz>]
Unpack build artifacts from the gzip tar archive `file.tgz` into the root
package's `buildDir`. If a path for the archive is not specified, uses the
the package's `buildArchive` in its Lake directory (`.lake`)."
def helpUpload :=
"Upload build artifacts to a GitHub release
USAGE:
lake upload <tag>
Packs the root package's `buildDir` into a `tar.gz` archive using `tar` and
then uploads the asset to the pre-existing GitHub release `tag` using `gh`."
def helpClean :=
"Remove build outputs
USAGE:
lake clean [<package>...]
If no package is specified, deletes the build directories of every package in
the workspace. Otherwise, just deletes those of the specified packages."
def helpShake :=
"Minimize imports in Lean source files
USAGE:
lake shake [OPTIONS] [<MODULE>...]
Checks the current project for unused imports by analyzing generated `.olean`
files to deduce required imports and ensuring that every import contributes
some constant or other elaboration dependency.
ARGUMENTS:
<MODULE> A module path like `Mathlib`. All files transitively
reachable from the provided module(s) will be checked.
If not specified, uses the package's default targets.
OPTIONS:
--force Skip the `lake build --no-build` sanity check
--keep-implied Preserve imports implied by other imports
--keep-prefix Prefer parent module imports over specific submodules
--keep-public Preserve all `public` imports for API stability
--add-public Add new imports as `public` if they were in the
original public closure
--add-downstream <MODULE>
Add the module as an `import` to every checked
module that does not reach it yet, except where
that would create an import cycle
--add-public-downstream <MODULE>
Like `--add-downstream`, but add the module as a
`public import` wherever it is not reached through
public imports yet. As these are passed on to
importing modules, this adds far fewer imports.
Only one of these two options can be used, once
--explain Show which constants require each import
--fix Apply suggested fixes directly to source files
--gh-style Output in GitHub problem matcher format
ANNOTATIONS:
Source files can contain special comments to control shake behavior:
* `module -- shake: keep-downstream`
Preserves this module in all downstream modules
* `module -- shake: keep-all`
Preserves all existing imports in this module
* `import X -- shake: keep`
Preserves this specific import"
def helpComparator :=
"Judge a solution against a challenge
USAGE:
lake comparator [--config <FILE>] [--challenge-from-export <FILE>]
[--solution-from-export <FILE>] [--paranoid]
[--inadvisably-no-sandbox] [--json]
Establishes that every named theorem in a solution Lean file proves the same
statement as in a challenge Lean file, uses no axiom outside the permitted
list, and is accepted by the kernel.
Note, that comparator has no way to figure out whether the statements in
the challenge file properly correspond to the meaning intended by their author.
It can only establish that the statements as written down are correct with
a very high degree of certainty.
REQUIREMENTS:
Comparator is only able to provide these guarantees under the following
assumptions:
1. Everything (transitively) imported by the challenge file is trusted.
2. `lakefile.toml`/`lakefile.lean` and `lake-manifest.json` as well as
all the dependencies they require are trusted.
3. The project operates from a clean build, that is, there is no
pre-existing `.lake` directory.
4. You have `bubblewrap` installed for sandboxing the, potentially
dangerous, build of the solution. `bubblewrap` is currently only
available on Linux systems so comparator can only be safely
used on Linux.
5. You are not running `lake comparator` as a privileged user.
6. The lean default kernel, or with `--paranoid` at least one of
the used kernels, does not have a soundness issue that causes
it to accept an incorrect proof.
7. The solution file does not make use of unknown exploits against
other software or hardware on the machine you are running this on.
OPTIONS:
--config=<file> JSON file describing the challenge (see below)
(default: `comparator.json` in the current
directory)
--challenge-from-export=<file>
judge this export as the challenge, instead of
building and exporting `challenge_module`
--solution-from-export=<file>
judge this export as the solution, instead of
building and exporting `solution_module`
--paranoid also run all external checkers bundled with Lean
besides Lean's own kernel: `leanchecker-paranoid`,
`lean4lean`, `nanoda`, `con-leche` and `con-ron`
--inadvisably-no-sandbox disable the built-in sandbox. This can compromise
the result fully and is only advised for expert
users.
--json print a JSON report of every step instead of
progress
CONFIGURATION:
The challenge author writes the file and distributes it with the project, so
that a solver need only point `lake comparator` at it:
{
\"challenge_module\": \"Challenge\",
\"solution_module\": \"Solution\",
\"theorem_names\": [\"imo2024_p1\"],
\"definition_names\": [],
\"permitted_axioms\": [\"propext\", \"Quot.sound\", \"Classical.choice\"],
\"external_kernels\": {\"nanoda\": [\"nanoda_bin\"]}
}
`challenge_module`, `solution_module`, `theorem_names` and
`permitted_axioms` are required; the rest may be omitted.
`definition_names` lists the challenge's definition holes, each of which the
challenge has to define as `sorry`.
`permitted_axioms` is deliberately not defaulted: it is what the verdict
means, so the challenge author states it. The three above are the ones
`#print axioms` treats as a clean proof.
`external_kernels` names additional checkers to run over the export, each as
the command to execute; the solution must satisfy every one of them as well
as Lean's own kernel. `enable_nanoda: true` is still accepted and is
equivalent to a \"nanoda\" entry of [\"nanoda_bin\"]; name the command in
`external_kernels` instead to run it from elsewhere.
EXIT CODES:
0 accepted
1 rejected: statement mismatch, forbidden axiom, kernel
rejection, or a build that did not succeed
2 could not start: `bwrap` or the manifest is missing,
or the configuration is missing, unreadable or
malformed
JSON REPORT:
With `--json` comparator only prints one final JSON report to stdout
instead of continous progress. An example output looks as follows:
{\"version\": \"0.1.0\",
\"sandboxed\": true,
\"report\":
{\"resolve_dependencies\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"},
\"kernel_reports\":
{\"Lean default\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"}},
\"export_solution\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"},
\"export_challenge\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"},
\"config\":
{\"theorem_names\": [\"comm\"],
\"solution_module\": \"Solution\",
\"permitted_axioms\": [\"propext\", \"Quot.sound\", \"Classical.choice\"],
\"definition_names\": null,
\"challenge_module\": \"Challenge\"},
\"compare_statements\":
{\"output\": {\"str\": {\"string\": \"\"}}, \"judgement\": \"success\"},
\"check_axioms\": {\"output\": {\"str\": {\"string\": \"\"}}, \"judgement\": \"success\"},
\"build_solution\":
{\"output\":
{\"proc\":
{\"stdout\": \"Build completed successfully (4 jobs).\\n\", \"stderr\": \"\"}},
\"judgement\": \"success\"},
\"build_challenge\":
{\"output\":
{\"proc\":
{\"stdout\": \"Build completed successfully (4 jobs).\\n\", \"stderr\": \"\"}},
\"judgement\": \"success\"}},
\"judgement\": \"accepted\"}
EXPORTS:
The `--*-from-export` options take an NDJSON export as generated by
`leanexport` instead of building and exporting either the challenge or the
solution. Note that this option does not check that the provided export
matches the challenge or solution in the project this command is being run
in. This is useful for several scenarios:
- Using export files built in virtual machines for extra isolation.
- Using export files built by third parties, e.g. because they require
extensive computational resources to generate.
- Using export files generated through means other than a standard
`lake build`.
ENVIRONMENT:
COMPARATOR_BWRAP sandbox executable (default: `bwrap` on PATH)
The exporter is always the `leanexport` of this toolchain, and deliberately
not configurable: the export format has to match the compiler that produced
the `.olean` files being exported.
HARDENING:
`comparator` uses `bwrap` for sandboxing. `/` is bound read-only and the home directories are then
covered, so the code being judged builds against the system it expects and reads none of the
invoking user's files. Only `.lake` is writable. Only dependency resolution has a network, because
it has to fetch git dependencies; the build, the export and any external kernels run in an empty
network namespace."
def helpCheck :=
"Check this project against external checker(s)
USAGE:
lake check [--from-export <FILE>] [--paranoid] [--inadvisably-no-sandbox]
[--json]
Builds the default build targets, exports them, and replays the result through
the kernel, erroring on any use of non-standard axioms.
The project is untrusted input: its configuration is evaluated, and its code
built and exported, inside a `bwrap` sandbox, and none of its `.olean` files
is ever loaded into Lake's own address space. `bubblewrap` is required, and
needs either unprivileged user namespaces or to be installed setuid root.
The project has to carry a `lake-manifest.json`, because dependencies are
resolved inside the sandbox and it cannot write to the project directory.
Building the project once is enough to write one.
OPTIONS:
--from-export=<file> check this export, instead of building and
exporting the project (see below)
--paranoid also run all external checkers bundled with Lean
besides Lean's own kernel: `leanchecker-paranoid`,
`lean4lean`, `nanoda`, `con-leche` and `con-ron`
--inadvisably-no-sandbox disable the built-in sandbox. This can compromise
the result fully and is only advised for expert
users.
--json print a JSON report of every step instead of
progress
EXPORTS:
The `--from-export` option takes an NDJSON export as generated by
`leanexport` instead of building and exporting the entire project. Note that
using this option only establishes that the export file is accepted and
nothing about the project this command is being run in. This is useful for
several scenarios:
- Using export files built in virtual machines for extra isolation.
- Using export files built by third parties, e.g. because they require
extensive computational resources to generate.
- Using export files generated through means other than a standard
`lake build`.
EXIT CODES:
0 every selected checker accepts the project and it uses
only the permitted axioms
1 a checker rejects it, an axiom is not permitted, or a
build did not succeed
2 could not start: `bwrap` is missing, the project has
no `lake-manifest.json`, or it has no default targets
JSON REPORT:
With `--json` check only prints one final JSON report to stdout
instead of continous progress. An example output looks as follows:
{\"version\": \"0.1.0\",
\"sandboxed\": true,
\"report\":
{\"resolve_dependencies\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"},
\"kernel_reports\":
{\"Lean default\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"}},
\"check_axioms\":
{\"output\":
{\"str\": {\"string\": \"Uses axioms: propext, Classical.choice, Quot.sound\"}},
\"judgement\": \"success\"},
\"build_report\":
{\"output\": {\"proc\": {\"stdout\": \"\", \"stderr\": \"\"}}, \"judgement\": \"success\"}},
\"judgement\": \"accepted\"}
ENVIRONMENT:
COMPARATOR_BWRAP sandbox executable (default: `bwrap` on PATH)
The exporter is always the `leanexport` of this toolchain, and deliberately
not configurable: the export format has to match the compiler that produced
the `.olean` files being exported.
HARDENING:
The sandbox bounds writes and the network exactly as `lake comparator`'s
does, and its limits apply here too. See the HARDENING section of
`lake help comparator`.
See `lake help comparator` to judge a solution against a challenge instead."
def helpCacheCli :=
"Manage the Lake cache
USAGE:
lake cache <COMMAND>
COMMANDS:
get [<mappings>] download build outputs into the local Lake cache
put <mappings> upload build outputs to a remote cache
add <mappings> add input-to-output mappings to the Lake cache
clean removes ALL from the local Lake cache
services print configured remote cache services
STAGING COMMANDS:
stage <map> <dir> copy build outputs from the cache to a directory
unstage <dir> cache build outputs from a staging directory
put-staged <dir> upload build outputs from a staging directory
See `lake cache help <command>` for more information on a specific command."
def helpCacheGet :=
"Download build outputs from a remote service into the Lake cache
USAGE:
lake cache get [<mappings>]
OPTIONS:
--max-revs=<n> backtrack up to n revisions (default: 100)
--rev=<commit-hash> lookup artifacts only for set revision
--package=<name> fetch outputs for set package
--service=<name> fetch outputs from set cache service
--repo=<github-repo> GitHub repository of the package or its fork
--platform=<target-triple> with Reservoir or --repo, set the platform
--toolchain=<name> with Reservoir or --repo, set the toolchain
--scope=<remote-scope> verbatim scope for a custom endpoint
--mappings-only only download mappings, delay artifacts
--force-download redownload existing files
Downloads build outputs for packages in the workspace from a remote cache
service. The cache service used can be specified via the `--service` option.
Otherwise, Lake will use the configured default or, if none, Reservoir. See
`lake cache services` for more information on how to configure services.
By default, Lake will use Reservoir to download outputs for each
dependency in the workspace (in order). Non-Reservoir dependencies will be
skipped. If instead an input-to-outputs mappings file, `--scope`, or `--repo`
is provided, Lake will default to downloading build outputs for the root
package. In either case, if `--package` is specified, Lake will switch to
only downloading outputs for it.
To determine what to download, Lake searches for input-to-output mappings for
a given build of a package via the cache service. This mapping is identified
by a Git revision and prefixed with a scope derived from the package's name,
GitHub repository, Lean toolchain, and current platform. The exact configuration
can be customized using options.
For Reservoir, setting `--repo` will cause Lake to lookup outputs for the
package by a repository name, rather than the package's. This can be used to
download outputs for a fork of the Reservoir package (if such artifacts are
available). The `--platform` and `--toolchain` options can be used to download
artifacts for a different platform/toolchain configuration than Lake detects.
For a custom endpoint, the full prefix Lake uses can be set via `--scope`.
If `--rev` is not set, Lake uses the package's current revision to lookup
artifacts. If no mappings are found, Lake will backtrack the Git history up to
`--max-revs`, looking for a revision with mappings. If `--max-revs` is 0, Lake
will search the repository's entire history (or as far as Git will allow).
By default, Lake will download both the input-to-output mappings and the
output artifacts for a package. By using `--mappings-only`, Lake will only
download the mappings and delay downloading artifacts until they are needed.
If a download for an artifact fails or the download process for a whole
package fails, Lake will report this and continue on to the next. Once done,
if any download failed, Lake will exit with a nonzero status code."
def helpCachePut :=
"Upload build outputs from the Lake cache to a remote service
USAGE:
lake cache put <mappings>
OPTIONS:
--package=<name> upload for set package
--service=<name> upload to set cache service
--scope=<remote-scope> upload under set scope verbatim
--repo=<github-repo> scope w/ repository + toolchain & platform
--toolchain=<name> with --repo, sets the toolchain
--platform=<target-triple> with --repo, sets the platform
Uploads the input-to-output mappings contained in the specified file along
with the corresponding output artifacts to a remote cache. The cache service
used can be specified via the `--service` option. If not specified, Lake will
use the system default, or error if none is configured. See the help page of
`lake cache services` for more information on how to configure services.
Files are uploaded using the AWS Signature Version 4 authentication protocol
via `curl`. Thus, the service should generally be an S3-compatible bucket.
The authentication key is set via the `LAKE_CACHE_KEY` environment variable.
Since Lake does not currently use cryptographically secure hashes for
artifacts and outputs, uploads to the cache are prefixed with a scope to
avoid clashes. This is controlled by `--scope` or `--repo`. With `--repo`,
Lake will produce a scope by augmenting the repository with toolchain and
platform information as it deems necessary. With `--scope`, Lake will use
the specified scope verbatim.
Artifacts are uploaded to the artifact endpoint with a file name derived
from their Lake content hash (and prefixed by the repository or scope).
The mappings file is uploaded to the revision endpoint with a file name
derived from the package's current Git revision (and prefixed by the
full scope). As such, the command will warn if the work tree currently
has changes."
def helpCacheAdd :=
"Add input-to-output mappings to the Lake cache
USAGE:
lake cache add <mappings>
OPTIONS:
--package=<name> add mappings to set package
--service=<name> cache service to fetch from on demand
--scope=<remote-scope> the prefix of artifacts within the service
--repo=<github-repo> for Reservoir, a GitHub repository scope
--no-overwrite do not overwrite existing mappings
Reads a list of input-to-output mappings from the provided file and adds
them to the local Lake cache. Mappings already in the cache are overwritten
unless `--no-overwrite` is specified. Mappings are added for the root package
unless `--package` is specified.
If `--service` is provided, the output artifacts can then be fetched lazily
from that service during a Lake build. The service must either be `reservoir`
or be configured through the Lake system configuration (see the help page of
`lake cache services` for details).
Since Lake does not currently use cryptographically secure hashes for
artifacts and outputs, artifacts in a cache service are prefixed with a scope
to avoid clashes. For Reservoir, this scope can either be a package (set via
`--scope`) or a repository (set via `--repo`). For S3 services, both options
are synonymous."
def helpCacheStage :=
"Copy build outputs from the cache to a staging directory
USAGE:
lake cache stage <mappings> <staging-directory> [--force-overwrite]
Creates the staging directory and copies the mappings file to it. Then,
it copies all artifacts described within the mappings file from the cache to
the staging directory. Artifacts in the staging directory are not overwritten
unless `--force-overwrite` is specified. Errors if any of the artifacts
described cannot be found in the cache."
def helpCacheUnstage :=
"Cache build outputs from a staging directory
USAGE:
lake cache unstage <staging-directory> [--force-overwrite]
Copies the mappings and artifacts stored in staging directory (e.g., via
`lake cache stage`) back into the cache.
Reads the mappings file located at `outputs.jsonl` within the staging
directory and writes the mappings to the Lake cache. Then, it copies the
described artifacts from the staging directory into the cache. Mappings and
artifacts already in the cache are not overwritten unless `--force-overwrite`
is specified."
def helpCachePutStaged :=
"Upload build outputs from a staging directory to a remote service
USAGE:
lake cache put-staged <staging-directory>
OPTIONS:
--rev=<commit-hash> upload for set revision
--service=<name> upload to set cache service
--scope=<remote-scope> upload under set scope verbatim
--repo=<github-repo> scope w/ repository + toolchain & platform
--toolchain=<name> with --repo, set the toolchain
--platform=<target-triple> with --repo, set the platform
Works like `lake cache put` but uploads outputs from the staging directory
instead of the Lake cache.
Does not configure the workspace and thus does not execute arbitrary user
code. However, because of this, the package's platform and toolchain settings
will not be automatically detected for `--repo` and must be specified manually
via `--platform` and `--toolchain` (if needed). Similarly, the source revision
the outputs correspond to must be manually specified via `--rev`."
def helpCacheClean :=
"Removes ALL files from the local Lake cache
USAGE:
lake cache clean
Deletes the configured Lake cache directory. If a workspace configuration
exists, this will delete the cache directory it uses. Otherwise, it will
delete the default Lake cache directory for the system."
def helpCacheServices :=
"Print configured remote cache services
USAGE:
lake cache services
Prints the name of each configured remote cache services (one per line).
Additional services can be added by modifying the system Lake configuration.
The exact location of the this configuration file is system dependent and can
be set by `LAKE_CONFIG`, but it is usually located at `~/.lake/config.toml`.
The configuration of the system cache could look something like the following:
cache.defaultService = \"my-s3\"
cache.defaultUploadService = \"my-s3\"
[[cache.service]]
name = \"my-s3\"
kind = \"s3\"
artifactEndpoint = \"https://my-s3.com/a0\"
revisionEndpoint = \"https://my-s3.com/r0\"
If no `cache.defaultService` is configured, Lake will use Reservoir by default."
def helpScriptCli :=
"Manage Lake scripts
USAGE:
lake script <COMMAND>
COMMANDS:
list list available scripts
run <script> run a script
doc <script> print the docstring of a given script
See `lake script help <command>` for more information on a specific command."
def helpScriptList :=
"List available scripts
USAGE:
lake script list
ALIAS: lake scripts
This command prints the list of all available scripts in the workspace."
def helpScriptRun :=
"Run a script
USAGE:
lake script run [[<package>/]<script>] [<args>...]
ALIAS: lake run
This command runs the `script` of the workspace (or the specific `package`),
passing `args` to it.
A bare `lake run` command will run the default script(s) of the root package
(with no arguments)."
def helpScriptDoc :=
"Print a script's docstring
USAGE:
lake script doc [<package>/]<script>
Print the docstring of `script` in the workspace or the specific `package`."
def helpServe :=
"Start the Lean language server
USAGE:
lake serve [-- <args>...]
Run the language server of the Lean installation (i.e., via `lean --server`)
with the package configuration's `moreServerArgs` field and `args`.
"
def helpEnv :=
"Execute a command in Lake's environment
USAGE:
lake env [<cmd>] [<args>...]
Spawns a new process executing `cmd` with the given `args` and with
the environment set based on the detected Lean/Lake installations and
the workspace configuration (if it exists).
Specifically, this command sets the following environment variables:
LAKE set to the detected Lake executable
LAKE_HOME set to the detected Lake home
LEAN_SYSROOT set to the detected Lean toolchain directory
LEAN_AR set to the detected Lean `ar` binary
LEAN_CC set to the detected `cc` (if not using the bundled one)
LEAN_PATH adds Lake's and the workspace's Lean library dirs
LEAN_SRC_PATH adds Lake's and the workspace's source dirs
PATH adds Lean's, Lake's, and the workspace's binary dirs
PATH adds Lean's and the workspace's library dirs (Windows)
DYLD_LIBRARY_PATH adds Lean's and the workspace's library dirs (MacOS)
LD_LIBRARY_PATH adds Lean's and the workspace's library dirs (other)
A bare `lake env` will print out the variables set and their values,
using the form NAME=VALUE like the POSIX `env` command."
def helpExe :=
"Build an executable target and run it in Lake's environment
USAGE:
lake exe <exe-target> [<args>...]
ALIAS: lake exec
Looks for the executable target in the workspace (see `lake help build` to
learn how to specify targets), builds it if it is out of date, and then runs
it with the given `args` in Lake's environment (see `lake help env` for how
the environment is set up)."
def helpSamply :=
"Profile an executable target with samply and demangle Lean names
USAGE:
lake samply [OPTIONS] <exe-target> [-- [<samply-args>...] [-- <exe-args>...]]
Builds the executable target, records a CPU profile using samply, symbolicates
the raw addresses, demangles Lean compiler names, and writes a Firefox Profiler
JSON file.
OPTIONS:
-o FILE output path (default: ./profile-demangled.json.gz)
--raw save the raw profile without serving (default: ./profile-raw.json.gz)
--no-serve write output file and exit without serving it
Anything after `--` is forwarded verbatim to `samply record`. An inner `--`
separates samply's own flags from the profiled executable's arguments, e.g.:
lake samply mergeSort # no samply or exe args
lake samply mergeSort -- --rate 2000 # only samply args
lake samply mergeSort -- -- 10 # only exe args
lake samply mergeSort -- --rate 2000 -- 10 # both
Run `samply record --help` to see samply's flags.
REQUIREMENTS:
samply cargo install samply
curl, gzip standard on most Linux/macOS systems
Open the output file in Firefox Profiler at https://profiler.firefox.com/from-file/"
def helpLean :=
"Elaborate a Lean file in the context of the Lake workspace
USAGE:
lake lean <file> [-- <args>...]
Build the imports of the given file and then runs `lean` on it using
the workspace's root package's additional Lean arguments and the given args
(in that order). The `lean` process is executed in Lake's environment like
`lake env lean` (see `lake help env` for how the environment is set up)."
def helpTranslateConfig :=
"Translate a Lake configuration file into a different language
USAGE:
lake translate-config <lang> [<out-file>]
Translates the loaded package's configuration into another of
Lake's supported configuration languages (i.e., either `lean` or `toml`).
The produced file is written to `out-file` or, if not provided, the path of
the configuration file with the new language's extension. If the output file
already exists, Lake will error.
Translation is lossy. It does not preserve comments or formatting and
non-declarative configuration will be discarded."
public def helpScript : (cmd : String) → String
| "list" => helpScriptList
| "run" => helpScriptRun
| "doc" => helpScriptDoc
| _ => helpScriptCli
public def helpCache : (cmd : String) → String
| "get" => helpCacheGet
| "put" => helpCachePut
| "add" => helpCacheAdd
| "stage" => helpCacheStage
| "unstage" => helpCacheUnstage
| "put-staged" => helpCachePutStaged
| "clean" => helpCacheClean
| "services" => helpCacheServices
| _ => helpCacheCli
public def help : (cmd : String) → String
| "new" => helpNew
| "init" => helpInit
| "build" => helpBuild
| "check-build" => helpCheckBuild
| "query" => helpQuery
| "update" | "upgrade" => helpUpdate
| "pack" => helpPack
| "unpack" => helpUnpack
| "upload" => helpUpload
| "cache" => helpCacheCli
| "test" => helpTest
| "check-test" => helpCheckTest
| "lint" => helpLint
| "check-lint" => helpCheckLint
| "clean" => helpClean
| "shake" => helpShake
| "comparator" => helpComparator
| "check" => helpCheck
| "script" => helpScriptCli
| "scripts" => helpScriptList
| "run" => helpScriptRun
| "serve" => helpServe
| "env" => helpEnv
| "exe" | "exec" => helpExe
| "samply" => helpSamply
| "lean" => helpLean
| "translate-config" => helpTranslateConfig
| _ => usage