Skip to content

feat: lake: build by source path#7909

Merged
tydeu merged 9 commits intoleanprover:masterfrom
tydeu:lake/build-mod-path
Apr 15, 2025
Merged

feat: lake: build by source path#7909
tydeu merged 9 commits intoleanprover:masterfrom
tydeu:lake/build-mod-path

Conversation

@tydeu
Copy link
Copy Markdown
Member

@tydeu tydeu commented Apr 11, 2025

This PR adds Lake support for building modules given their source file path. This is made use of in both the CLI and the sever.

As a target specifier, lake build Foo/Bar.lean will now look for a module in the workspace whose source file is Foo/Bar.lean and build it. Facets are support via lake build Foo/Bar.lean:o. As such, : is an illegal character in such file names (which is reasonable considering its use in search paths like PATH on Linux).

In the server, lake setup-file Foo/Bar.lean will now try to lookup a module for the source and and build its dependencies, ignoring the imports specified. This allows Lake to return more specific configuration for the module requested (e.g., library-specific dynlibs and plugins). If the path cannot be found in the workspace, Lake will fallback to its previous behavior.

Finally, like setup-file, lake lean Foo/Bar.lean will try to lookup a module for the source path and use its more specific configuration if possible.

Closes #2756.

@tydeu tydeu added the changelog-lake Lake label Apr 11, 2025
@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 Apr 11, 2025
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 11, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 11, 2025
@ghost ghost added the breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan label Apr 11, 2025
@ghost
Copy link
Copy Markdown

ghost commented Apr 11, 2025

Mathlib CI status (docs):

ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 11, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 11, 2025
@ghost ghost added builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Apr 11, 2025
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 12, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 12, 2025
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 12, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 12, 2025
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 12, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 12, 2025
@tydeu tydeu marked this pull request as ready for review April 15, 2025 18:21
@tydeu tydeu added this pull request to the merge queue Apr 15, 2025
@tydeu tydeu removed this pull request from the merge queue due to a manual request Apr 15, 2025
@tydeu tydeu force-pushed the lake/build-mod-path branch from a1f97e8 to dfce48d Compare April 15, 2025 18:54
@tydeu tydeu enabled auto-merge April 15, 2025 19:09
@tydeu tydeu added this pull request to the merge queue Apr 15, 2025
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Apr 15, 2025
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Apr 15, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Apr 15, 2025
@tydeu tydeu added this pull request to the merge queue Apr 15, 2025
Merged via the queue into leanprover:master with commit 7d26c7c Apr 15, 2025
16 checks passed
@tydeu tydeu deleted the lake/build-mod-path branch April 16, 2025 01:44
github-merge-queue bot pushed a commit that referenced this pull request Apr 19, 2025
This PR fixes bugs in #7809 and #7909 that were not caught partially
because the `badImport` test had been disabled.

**Bugs Fixed:**

* Building by path no longer drops top-level logs.
* "bad import" errors are once again printed.
* Transitively imported precompiled modules are once again loaded during
elaboration.
github-merge-queue bot pushed a commit that referenced this pull request May 1, 2025
This PR makes Lake tests much more verbose in output. It also fixes some
bugs that had been missed due to disabled tests. Most significantly, the
target specifier `@pkg` (e.g., in `lake build`) is now always
interpreted as a package. It was previously ambiguously interpreted due
to changes in #7909.
github-merge-queue bot pushed a commit that referenced this pull request Jun 23, 2025
This PR adds support to the server for the new module setup process by
changing how `lake setup-file` is used.

In the new server setup, `lake setup-file` is invoked with the file name
of the edited module passed as a CLI argument and with the parsed header
passed to standard input in JSON form. Standard input is used to avoid
potentially exceeding the CLI length limits on Windows. Lake will build
the module's imports along with any other dependencies and then return
the module's workspace configuration via JSON (now in the form of
`ModuleSetup`). The server then post-processes this configuration a bit
and returns it back to the Lean language processor.

The server's header is currently only fully respected by Lake for
external modules (files that are not part of any workspace library). For
workspace modules, the saved module header is currently used to build
imports (as has been done since #7909). A follow-up Lake PR will align
both cases to follow the server's header.

Lean search paths (e.g., `LEAN_PATH`, `LEAN_SRC_PATH`) are no longer
negotiated between the server and Lake. These environment variables are
already configured during sever setup by `lake serve` and do not change
on a per-file basis. Lake can also pre-resolve the `.olean` files of
imports via the `importArts` field of `ModuleSetup`, limiting the
potential utility of communicating `LEAN_PATH`.
wkrozowski pushed a commit to wkrozowski/lean4 that referenced this pull request Jun 24, 2025
This PR adds support to the server for the new module setup process by
changing how `lake setup-file` is used.

In the new server setup, `lake setup-file` is invoked with the file name
of the edited module passed as a CLI argument and with the parsed header
passed to standard input in JSON form. Standard input is used to avoid
potentially exceeding the CLI length limits on Windows. Lake will build
the module's imports along with any other dependencies and then return
the module's workspace configuration via JSON (now in the form of
`ModuleSetup`). The server then post-processes this configuration a bit
and returns it back to the Lean language processor.

The server's header is currently only fully respected by Lake for
external modules (files that are not part of any workspace library). For
workspace modules, the saved module header is currently used to build
imports (as has been done since leanprover#7909). A follow-up Lake PR will align
both cases to follow the server's header.

Lean search paths (e.g., `LEAN_PATH`, `LEAN_SRC_PATH`) are no longer
negotiated between the server and Lake. These environment variables are
already configured during sever setup by `lake serve` and do not change
on a per-file basis. Lake can also pre-resolve the `.olean` files of
imports via the `importArts` field of `ModuleSetup`, limiting the
potential utility of communicating `LEAN_PATH`.
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 changelog-lake Lake toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lake build Foo/Bar.lean

1 participant