Skip to content

Commit e83b768

Browse files
authored
feat: lake: reintroduce lean --setup basics (leanprover#8846)
This PR reintroduces the basics of `lean --setup` integration into Lake without the module computation which is still undergoing performance debugging in leanprover#8787. Partially reverts leanprover#8736 and partially reimplements leanprover#8447.
1 parent 6240cd5 commit e83b768

File tree

10 files changed

+270
-112
lines changed

10 files changed

+270
-112
lines changed

src/lake/Lake/Build/Actions.lean

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Gabriel Ebner, Sebastian Ullrich, Mac Malone, Siddharth Bhat
55
-/
66
prelude
7+
import Lean.Setup
8+
import Lean.Data.Json
79
import Lake.Config.Dynlib
810
import Lake.Util.Proc
911
import Lake.Util.NativeLib
@@ -21,29 +23,30 @@ namespace Lake
2123

2224
def compileLeanModule
2325
(leanFile relLeanFile : FilePath)
24-
(oleanFile? ileanFile? cFile? bcFile?: Option FilePath)
25-
(leanPath : SearchPath := []) (rootDir : FilePath := ".")
26-
(dynlibs plugins : Array Dynlib := #[])
27-
(leanArgs : Array String := #[]) (lean : FilePath := "lean")
26+
(setup : ModuleSetup) (setupFile : FilePath)
27+
(arts : ModuleArtifacts)
28+
(leanArgs : Array String := #[])
29+
(leanPath : SearchPath := [])
30+
(rootDir : FilePath := ".")
31+
(lean : FilePath := "lean")
2832
: LogIO Unit := do
2933
let mut args := leanArgs ++
3034
#[leanFile.toString, "-R", rootDir.toString]
31-
if let some oleanFile := oleanFile? then
35+
if let some oleanFile := arts.olean? then
3236
createParentDirs oleanFile
3337
args := args ++ #["-o", oleanFile.toString]
34-
if let some ileanFile := ileanFile? then
38+
if let some ileanFile := arts.ilean? then
3539
createParentDirs ileanFile
3640
args := args ++ #["-i", ileanFile.toString]
37-
if let some cFile := cFile? then
41+
if let some cFile := arts.c? then
3842
createParentDirs cFile
3943
args := args ++ #["-c", cFile.toString]
40-
if let some bcFile := bcFile? then
44+
if let some bcFile := arts.bc? then
4145
createParentDirs bcFile
4246
args := args ++ #["-b", bcFile.toString]
43-
for dynlib in dynlibs do
44-
args := args ++ #["--load-dynlib", dynlib.path.toString]
45-
for plugin in plugins do
46-
args := args ++ #["--plugin", plugin.path.toString]
47+
createParentDirs setupFile
48+
IO.FS.writeFile setupFile (toJson setup).pretty
49+
args := args ++ #["--setup", setupFile.toString]
4750
args := args.push "--json"
4851
withLogErrorPos do
4952
let out ← rawProc {

src/lake/Lake/Build/Facets.lean

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,54 @@ instance (facet : ModuleFacet α) : FamilyDef FacetOut facet.name α :=
4343
instance [FamilyOut FacetOut facet α] : CoeDep Name facet (ModuleFacet α) :=
4444
⟨facet, FamilyOut.fam_eq⟩
4545

46+
/-- A module's source file path plus its parsed header. -/
47+
structure ModuleInput where
48+
path : FilePath
49+
header : ModuleHeader
50+
51+
/--
52+
The module's processed Lean source file.
53+
Combines tracing the file with parsing its header.
54+
-/
55+
builtin_facet input : Module => ModuleInput
56+
57+
/-- The module's Lean source file. -/
58+
builtin_facet lean : Module => FilePath
59+
60+
/-- The parsed module header of the module's source file. -/
61+
builtin_facet header : Module => ModuleHeader
62+
63+
/--
64+
The facet which builds all of a module's dependencies
65+
(i.e., transitive local imports and `--load-dynlib` shared libraries).
66+
Returns the list of shared libraries to load along with their search path.
67+
-/
68+
builtin_facet setup : Module => ModuleSetup
69+
4670
/--
4771
The facet which builds all of a module's dependencies
4872
(i.e., transitive local imports and `--load-dynlib` shared libraries).
4973
Returns the list of shared libraries to load along with their search path.
5074
-/
51-
builtin_facet deps : Module => ModuleDeps
75+
builtin_facet deps : Module => Opaque
5276

5377
/--
5478
The core build facet of a Lean file.
5579
Elaborates the Lean file via `lean` and produces all the Lean artifacts
5680
of the module (i.e., `olean`, `ilean`, `c`).
5781
Its trace just includes its dependencies.
5882
-/
59-
builtin_facet leanArts : Module => Unit
83+
builtin_facet leanArts : Module => ModuleArtifacts
6084

6185
/-- The `olean` file produced by `lean`. -/
6286
builtin_facet olean : Module => FilePath
6387

88+
/-- The `olean.server` file produced by `lean` (with the module system enabled). -/
89+
builtin_facet oleanServerFacet @ olean.server : Module => FilePath
90+
91+
/-- The `olean.private` file produced by `lean` (with the module system enabled). -/
92+
builtin_facet oleanPrivateFacet @ olean.private : Module => FilePath
93+
6494
/-- The `ilean` file produced by `lean`. -/
6595
builtin_facet ilean : Module => FilePath
6696

src/lake/Lake/Build/Info.lean

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,15 @@ abbrev BuildInfo.moduleFacet (module : Module) (facet : Name) : BuildInfo :=
178178

179179
namespace Module
180180

181+
@[inherit_doc inputFacet] abbrev input (self : Module) :=
182+
self.facetCore inputFacet
183+
184+
@[inherit_doc leanFacet] abbrev lean (self : Module) :=
185+
self.facetCore leanFacet
186+
187+
@[inherit_doc headerFacet] abbrev header (self : Module) :=
188+
self.facetCore headerFacet
189+
181190
@[inherit_doc importsFacet] abbrev imports (self : Module) :=
182191
self.facetCore importsFacet
183192

@@ -187,15 +196,24 @@ namespace Module
187196
@[inherit_doc precompileImportsFacet] abbrev precompileImports (self : Module) :=
188197
self.facetCore precompileImportsFacet
189198

199+
@[inherit_doc setupFacet] abbrev setup (self : Module) :=
200+
self.facetCore setupFacet
201+
190202
@[inherit_doc depsFacet] abbrev deps (self : Module) :=
191203
self.facetCore depsFacet
192204

193-
@[inherit_doc leanArtsFacet] abbrev leanArts (self : Module) :=
205+
@[inherit_doc leanArtsFacet] abbrev leanArts (self : Module) :=
194206
self.facetCore leanArtsFacet
195207

196208
@[inherit_doc oleanFacet] abbrev olean (self : Module) :=
197209
self.facetCore oleanFacet
198210

211+
@[inherit_doc oleanServerFacet] abbrev oleanServer (self : Module) :=
212+
self.facetCore oleanServerFacet
213+
214+
@[inherit_doc oleanPrivateFacet] abbrev oleanPrivate (self : Module) :=
215+
self.facetCore oleanPrivateFacet
216+
199217
@[inherit_doc ileanFacet] abbrev ilean (self : Module) :=
200218
self.facetCore ileanFacet
201219

src/lake/Lake/Build/Job/Monad.lean

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,6 @@ def collectList (jobs : List (Job α)) (traceCaption := "<collection>") : Job (L
237237
def collectArray (jobs : Array (Job α)) (traceCaption := "<collection>") : Job (Array α) :=
238238
jobs.foldl (zipWith Array.push) (traceRoot (Array.mkEmpty jobs.size) traceCaption)
239239

240-
/-- Merge a `NameMap` of jobs into one, collecting their outputs into an `NameMap`. -/
241-
def collectNameMap (jobs : NameMap (Job α)) (traceCaption := "<collection>") : Job (NameMap α) :=
242-
jobs.fold (fun s k v => s.zipWith (·.insert k) v) (traceRoot {} traceCaption)
243-
244240
end Job
245241

246242
/-! ## BuildJob (deprecated) -/

0 commit comments

Comments
 (0)