8000 feat: lake: `require` overhaul by tydeu · Pull Request #3174 · leanprover/lean4 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: lake: require overhaul #3174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

tydeu
Copy link
Member
@tydeu tydeu commented Jan 13, 2024

This PR contains major changes to require DSL, the Lake manifest format, types of dependencies, and the how packages and targets are named. These changes overlap in significant ways, hence why there were all done as part of one PR. However, due to its complexity, it may be worthwhile to break significant parts of it up into smaller PRs. What follows is a summary of the major components of the current PR.

This PR depends on leanprover/reservoir#18 being merged (and its tests will need to be update once it is).

require Docstrings

Lake now supports docstrings on require commands:

/-- this is a docstring for a require statement -/
require std from ...

Closes #2898.

require ... if ... & Locked Conditional Dependencies

To specify conditional dependencies, the previous approach of, e.g.:

meta if get_config? doc = some "on" then
require «doc-gen4» from git "https://github.com/leanprover/doc-gen4" @ "main"

has been replaced with:

require «doc-gen4» if get_config? doc = some "on"
  from git "https://github.com/leanprover/doc-gen4" @ "main"

This replacement is backwards-compatible. Lake will intelligently expand meta if .. require ... to require ... if .. with a deprecation warning asking the user to update their configuration file accordingly.

The advantage of this change is that require statements are no longer conditionally elaborated. Instead, conditional dependencies are always part of a package's configuration. They just have settings indicating whether they are conditional and whether the dependency is enabled in a given configuration.

Lake makes use of the information to ensure the manifest always contains a complete record of all possible package dependencies locked to a specific version. That is, lake update will materialize and lock all dependencies -- even those not enabled. Other commands (e.g., lake build) will just materialize / use the packages enabled with the set configuration. This helps ensure reproducible builds across different configurations.

GitHub Dependency Source

Packages which are required from GitHub can now state this explicitly via new require syntax and a new source type rather than reusing the standard git source. For example,

require aesop from github "leanprover" / "aesop"

While Lake could deduce this from some URLs, making this explicit avoids heuristic errors and allows Lake to better provide GitHub-specific features. For instance, Lake now respects a LAKE_GITHUB_URL environment variable to point Lake to a different URL (other than https://github.com) from which to clone GitHub packages. This should help enable, for example, GitHub mirrors in restricted internet contexts and compatibility with Enterprise editions of GitHub.

Reservoir Registry Dependency

Adds a new registry package source which fetches package metadata from a API endpoint (e.g., Reservoir's) and clones a Git package using the information provided. To require such a dependency, the new syntax is:

require <scope> / <pkg-name> [@ <rev>] -- e.g., require "leanprover" / "doc-gen4"

Unlike with Git dependencies, Lake can make use of the richer information provided by the registry to determine the default branch of the package. This means for repositories of packages like std which have a default branch that is not master, Lake will now use said default branch (e.g., in std's case, main).

Also, as with GitHub dependencies, Lake supports configuring the registry endpoint via an environment variable: LAKE_RESERVIOR_URL. Thus, any server providing a similar interface to Reservoir can be used as the registry. Further configuration options paralleling those of Cargo's Alternative Registries and Source Replacement will come in future PRs.

Simple Package & Target Names

To implement Reservoir dependencies, an important detail was to have the package names specified in the require statement match those of the package being required. Previously, a mismatch was just warning, but experience has shown this should be a error (as things break otherwise). Reservoir gets its package names from the lake-manifest.json of the indexed package, thus it is important the name listed there matches and is easily machine-readable.

Before this PR, this name was naively produced via a toJSON on the package's name : Name field. However, this can produce names with escapes that are hard for non-Lean machines to read. These escapes can be removed via setting escape := false in Name.toString, but this makes the name not round-trip if it contains multiple components. To avoid this, Packages are now forced to have simple names (i.e., a Name with a single string component). For consistency's sake, this PR also changes targets (e.g., lean_lib, lean_exe, and target) to have simple names as well.

It is important note that this is a major API refactor with potential for breakage in complex configuration files. I have tried to minimized the places were breakage could occur, but they still exist. For instance, targets identified to by a multipart name literal will no longer exist and produce an error. Unfortunately, the simple FFI example in Lake used such a target:

extern_lib libleanffi pkg := do
  let name := nameToStaticLib "leanffi"
  let ffiO ←pkg.target ``ffi.o
  buildStaticLib (pkg.nativeLibDir / name) #[ffiO]

It needed to be changed to:

extern_lib libleanffi pkg := do
  let name := nameToStaticLib "leanffi"
  let ffiO ← ffi.o.fetch
  buildStaticLib (pkg.nativeLibDir / name) #[ffiO]

There are several such cases in the larger Lean ecosystem as well (e.g., loogle). This is likely because they followed the naming pattern of the example.

@tydeu tydeu added the WIP This is work in progress, and only a PR for the sake of CI or sharing. No review yet. label Jan 13, 2024
@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Jan 13, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 13, 2024
@tydeu tydeu force-pushed the lake/require-overhaul branch from 62ee6c4 to 36512d7 Compare January 13, 2024 01:58
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 13, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator
leanprover-community-mathlib4-bot commented Jan 13, 2024

Mathlib CI status (docs):

  • 🟡 Mathlib branch lean-pr-testing-3174 build against this PR was cancelled. (2024-01-13 02:17:37) View Log
  • 🟡 Mathlib branch lean-pr-testing-3174 build against this PR was cancelled. (2024-01-16 20:29:59) View Log
  • ✅ Mathlib branch lean-pr-testing-3174 has successfully built against this PR. (2024-01-16 21:45:11) View Log
  • ✅ Mathlib branch lean-pr-testing-3174 has successfully built against this PR. (2024-01-17 02:34:43) View Log
  • ❗ Std CI can not be attempted yet, as the nightly-testing-2024-01-26 tag does not exist there yet. We will retry when you push more commits. If you rebase your branch onto nightly-with-mathlib, Std CI should run now. (2024-01-27 07:18:31)

@leanprover-community-mathlib4-bot leanprover-community-mathlib4-bot added the builds-mathlib CI has verified that Mathlib builds against this PR label Jan 13, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 13, 2024
@leanprover-community-mathlib4-bot
Copy link
Collaborator

Mathlib CI status (docs):

@tydeu tydeu force-pushed the lake/require-overhaul branch from 36512d7 to 199aaa9 Compare January 16, 2024 19:28
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 16, 2024
@tydeu tydeu force-pushed the lake/require-overhaul branch from 199aaa9 to d3abba5 Compare January 16, 2024 20:11
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 16, 2024
leanprover-community-mathlib4-bot added a commit to leanprover-community/mathlib4 that referenced this pull request Jan 17, 2024
@tydeu tydeu force-pushed the lake/require-overhaul branch from c94e8c7 to a892c70 Compare January 23, 2024 22:31
@tydeu tydeu force-pushed the lake/require-overhaul branch 2 times, most recently from 0c0e55b to 3b1bc72 Compare January 26, 2024 20:26
github-merge-queue bot pushed a commit that referenced this pull request May 24, 2024
Switches the manifest format to use `major.minor.patch` semantic
versions. Major version increments indicate breaking changes (e.g., new
required fields and semantic changes to existing fields). Minor version
increments (after `0.x`) indicate backwards-compatible extensions (e.g.,
adding optional fields, removing fields). This change is backwards
compatible. Lake will still successfully read old manifest with numeric
versions. It will treat the numeric version `N` as semantic version
`0.N.0`. Lake will also accept manifest versions with `-` suffixes
(e.g., `x.y.z-foo`) and then ignore the suffix.

This change also includes the general cleanup/refactoring of the
manifest code and data structures that was part of #3174.
github-merge-queue bot pushed a commit that referenced this pull request Jun 29, 2024
Adds a new type of `require` which fetches package metadata from a
registry API endpoint (i.e., Reservoir) and then clones a Git package
using the information provided. To require such a dependency, the new
syntax is:

```lean
require <scope> / <pkg-name> [@ "git#<rev>"] -- e.g., require "leanprover" / "doc-gen4"
```

Or in TOML:

```toml
[[require]]
name = "<pkg-name>"
scope = "<scope>"
rev = "<rev>"
```

Unlike with Git dependencies, Lake can make use of the richer
information provided by the registry to determine the default branch of
the package. This means for repositories of packages like `doc-gen4`
which have a default branch that is not `master`, Lake will now use said
default branch (e.g., in `doc-gen4`'s case, `main`).

Lake also supports configuring the registry endpoint via an environment
variable: `RESERVIOR_API_URL`. Thus, any server providing a similar
interface to Reservoir can be used as the registry. Further
configuration options paralleling those of Cargo's [Alternative
Registries](https://doc.rust-lang.org/cargo/reference/registries.html)
and [Source
Replacement](https://doc.rust-lang.org/cargo/reference/source-replacement.html)
will come in the future.

Updated and split from #3174.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builds-mathlib CI has verified that Mathlib builds against this PR toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN WIP This is work in progress, and only a PR for the sake of CI or sharing. No review yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow doc-strings on require statements in lakefile.lean
2 participants
0