-
Notifications
You must be signed in to change notification settings - Fork 5
/
lakefile.lean
82 lines (71 loc) · 2.98 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
/-
Copyright (c) 2024 Lean FRO LLC. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Author: David Thrane Christiansen
-/
import Lake
open Lake DSL
open System (FilePath)
require verso from git "https://github.com/leanprover/verso.git"@"main"
require subverso from git "https://github.com/leanprover/subverso.git"@"main"
package "verso-manual" where
-- building the C code cost much more than the optimizations save
moreLeancArgs := #["-O0"]
-- work around clang emitting invalid linker optimization hints that lld rejects
moreLinkArgs :=
if System.Platform.isOSX then
#["-Wl,-ignore_optimization_hints"]
else #[]
lean_lib Manual where
def inputTextFile' (path : FilePath) : SpawnM (BuildJob FilePath) :=
Job.async do (path, ·) <$> computeTrace (TextFilePath.mk path)
def figureDir : FilePath := "figures"
def figureOutDir : FilePath := "static/figures"
def ensureDir (dir : System.FilePath) : IO Unit := do
if !(← dir.pathExists) then
IO.FS.createDirAll dir
if !(← dir.isDir) then
throw (↑ s!"Not a directory: {dir}")
/-- Ensure that the subverso-extract-mod executable is available -/
target subversoExtractMod : FilePath := do
if let some pkg := ← findPackage? `subverso then
if let some exe := pkg.findLeanExe? `«subverso-extract-mod» then
exe.recBuildExe
else
failure
else
failure
target figures : Array FilePath := do
let files := (← figureDir.readDir).filterMap fun f =>
match f.path.extension with
| some "tex" => some f.path
| _ => none
let files := files.qsort (toString · < toString ·)
let srcs ← BuildJob.collectArray (← liftM <| files.mapM inputTextFile')
let traceFile := figureDir.join "lake.trace"
liftM <| srcs.bindSync fun srcInfo depTrace => do
buildUnlessUpToDate traceFile depTrace traceFile do
for src in srcInfo do
let some f := src.fileStem
| continue
proc { cmd := "lualatex", args := #[f], cwd := some figureDir} (quiet := true)
proc { cmd := "lualatex", args := #[f], cwd := some figureDir} (quiet := true)
proc { cmd := "lualatex", args := #[f], cwd := some figureDir} (quiet := true)
proc { cmd := "lualatex", args := #[f], cwd := some figureDir} (quiet := true)
proc { cmd := "pdftocairo", args := #["-svg", s!"{f}.pdf", s!"{f}.svg"], cwd := some figureDir} (quiet := true)
ensureDir "static"
ensureDir figureOutDir
for fmt in ["pdf", "svg"] do
let built := s!"{f}.{fmt}"
IO.println s!"Generated: {figureOutDir.join built}"
IO.FS.withFile (figureDir.join built) .read fun h =>
IO.FS.withFile (figureOutDir.join built) .write fun h' => do
let mut buf ← h.read 1024
while !buf.isEmpty do
h'.write buf
buf ← h.read 1024
pure (srcInfo, depTrace)
@[default_target]
lean_exe "generate-manual" where
extraDepTargets := #[`figures, `subversoExtractMod]
root := `Main