forked from leanprover-community/mathlib4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlakefile.lean
161 lines (136 loc) · 5.08 KB
/
lakefile.lean
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import Lake
open Lake DSL
/-!
## Mathlib dependencies on upstream projects
-/
require "leanprover-community" / "batteries" @ git "main"
require "leanprover-community" / "Qq" @ git "master"
require "leanprover-community" / "aesop" @ git "master"
require "leanprover-community" / "proofwidgets" @ git "v0.0.41"
require "leanprover-community" / "importGraph" @ git "main"
/-!
## Options for building mathlib
-/
/-- These options are used
* as `leanOptions`, prefixed by `` `weak``, so that `lake build` uses them;
* as `moreServerArgs`, to set their default value in mathlib
(as well as `Archive`, `Counterexamples` and `test`).
-/
abbrev mathlibOnlyLinters : Array LeanOption := #[
⟨`linter.hashCommand, true⟩,
⟨`linter.missingEnd, true⟩,
⟨`linter.cdot, true⟩,
⟨`linter.dollarSyntax, true⟩,
⟨`linter.style.lambdaSyntax, true⟩,
⟨`linter.longLine, true⟩,
⟨`linter.oldObtain, true,⟩,
⟨`linter.refine, true⟩,
⟨`linter.setOption, true⟩
]
/-- These options are passed as `leanOptions` to building mathlib, as well as the
`Archive` and `Counterexamples`. (`tests` omits the first two options.) -/
abbrev mathlibLeanOptions := #[
⟨`pp.unicode.fun, true⟩, -- pretty-prints `fun a ↦ b`
⟨`autoImplicit, false⟩
] ++ -- options that are used in `lake build`
mathlibOnlyLinters.map fun s ↦ { s with name := `weak ++ s.name }
package mathlib where
leanOptions := mathlibLeanOptions
-- Mathlib also enforces these linter options, which are not active by default.
moreServerOptions := mathlibOnlyLinters
-- These are additional settings which do not affect the lake hash,
-- so they can be enabled in CI and disabled locally or vice versa.
-- Warning: Do not put any options here that actually change the olean files,
-- or inconsistent behavior may result
-- weakLeanArgs := #[]
/-!
## Mathlib libraries
-/
@[default_target]
lean_lib Mathlib
-- NB. When adding further libraries, check if they should be excluded from `getLeanLibs` in
-- `scripts/mk_all.lean`.
lean_lib Cache
lean_lib LongestPole
lean_lib Archive where
leanOptions := mathlibLeanOptions
moreServerOptions := mathlibOnlyLinters
lean_lib Counterexamples where
leanOptions := mathlibLeanOptions
moreServerOptions := mathlibOnlyLinters
/-- Additional documentation in the form of modules that only contain module docstrings. -/
lean_lib docs where
roots := #[`docs]
/-!
## Executables provided by Mathlib
-/
/-- `lake exe cache get` retrieves precompiled `.olean` files from a central server. -/
lean_exe cache where
root := `Cache.Main
/-- `lake exe check-yaml` verifies that all declarations referred to in `docs/*.yaml` files exist. -/
lean_exe «check-yaml» where
srcDir := "scripts"
supportInterpreter := true
/-- `lake exe mk_all` constructs the files containing all imports for a project. -/
lean_exe mk_all where
srcDir := "scripts"
supportInterpreter := true
-- Executables which import `Lake` must set `-lLake`.
weakLinkArgs := #["-lLake"]
/-- `lake exe shake` checks files for unnecessary imports. -/
lean_exe shake where
root := `Shake.Main
supportInterpreter := true
/-- `lake exe lint-style` runs text-based style linters. -/
lean_exe «lint-style» where
srcDir := "scripts"
/--
`lake exe pole` queries the Mathlib speedcenter for build times for the current commit,
and then calculates the longest pole
(i.e. the sequence of files you would be waiting for during a infinite parallelism build).
-/
lean_exe pole where
root := `LongestPole.Main
supportInterpreter := true
-- Executables which import `Lake` must set `-lLake`.
weakLinkArgs := #["-lLake"]
/--
`lake exe test` is a thin wrapper around `lake exe batteries/test`, until
https://github.com/leanprover/lean4/issues/4121 is resolved.
You can also use it as e.g. `lake exe test conv eval_elab` to only run the named tests.
-/
@[test_driver]
lean_exe test where
-- We could add the above `leanOptions` and `moreServerOptions`: currently, these do not take
-- effect as `test` is a `lean_exe`. With a `lean_lib`, it would work...
srcDir := "scripts"
/-!
## Other configuration
-/
/--
When a package depending on Mathlib updates its dependencies,
update its toolchain to match Mathlib's and fetch the new cache.
-/
post_update pkg do
let rootPkg ← getRootPackage
if rootPkg.name = pkg.name then
return -- do not run in Mathlib itself
/-
Once Lake updates the toolchains,
this toolchain copy will be unnecessary.
https://github.com/leanprover/lean4/issues/2752
-/
let wsToolchainFile := rootPkg.dir / "lean-toolchain"
let mathlibToolchain := ← IO.FS.readFile <| pkg.dir / "lean-toolchain"
IO.FS.writeFile wsToolchainFile mathlibToolchain
if (← IO.getEnv "MATHLIB_NO_CACHE_ON_UPDATE") != some "1" then
/-
Instead of building and running cache via the Lake API,
spawn a new `lake` since the toolchain may have changed.
-/
let exitCode ← IO.Process.spawn {
cmd := "elan"
args := #["run", "--install", mathlibToolchain.trim, "lake", "exe", "cache", "get"]
} >>= (·.wait)
if exitCode ≠ 0 then
logError s!"{pkg.name}: failed to fetch cache"