-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlakefile.lean
More file actions
155 lines (130 loc) · 4.91 KB
/
lakefile.lean
File metadata and controls
155 lines (130 loc) · 4.91 KB
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
import Lake
open Lake DSL System
package «xeus-lean» where
-- add package configuration options here
lean_lib REPL where
srcDir := "src"
lean_lib ReplFFI where
srcDir := "src"
-- Display.lean provides the #html / #latex / #md / #svg rich-display
-- commands. It is declared as its own lib so that `import Display` from
-- WasmRepl.lean (and user cells) resolves to src/Display.lean.
lean_lib Display where
srcDir := "src"
lean_lib WasmRepl where
srcDir := "src"
lean_exe repl where
root := `REPL.Main
supportInterpreter := true
lean_exe testmain where
root := `TestMain
srcDir := "src"
@[default_target]
lean_exe xlean where
root := `XeusKernel
supportInterpreter := true
srcDir := "src"
-- Link with the xeus FFI static library built by cmake
-- Platform-specific link arguments
moreLinkArgs :=
if System.Platform.isWindows then
#["./build-cmake/libxeus_ffi.a",
"-L./build-cmake/_deps/xeus-build",
"-L./build-cmake/_deps/xeus-zmq-build",
"-lxeus", "-lxeus-zmq", "-lstdc++"]
else if System.Platform.isOSX then
#["./build-cmake/libxeus_ffi.a",
"-L./build-cmake/_deps/xeus-build",
"-L./build-cmake/_deps/xeus-zmq-build",
"-Wl,-rpath,@executable_path/../../../build-cmake/_deps/xeus-build",
"-Wl,-rpath,@executable_path/../../../build-cmake/_deps/xeus-zmq-build",
"-lxeus", "-lxeus-zmq", "-lstdc++"]
else -- Linux
-- FFI library must be built with leanc (Lean's clang/libc++) for ABI
-- compatibility. Lean's linker uses its own sysroot and libc++, so
-- libstdc++ and GCC runtime are not needed.
-- All deps built from source via FetchContent; do NOT add system lib
-- paths like -L/usr/lib/x86_64-linux-gnu because leanc uses --sysroot
-- with its own bundled glibc, and system glibc conflicts (__libc_csu_init).
-- glibc_isoc23_compat.o provides __isoc23_strtoull etc. shims: system
-- clang++ compiles against glibc 2.38+ which redirects strtoull→C23
-- variants, but leanc's older glibc lacks them.
#["-L./build-cmake/_deps/xeus-build",
"-L./build-cmake/_deps/xeus-zmq-build",
"-L./build-cmake/_deps/libzmq-build/lib",
"-Wl,--start-group",
"./build-cmake/libxeus_ffi.a",
"./build-cmake/glibc_isoc23_compat.o",
"-lxeus", "-lxeus-zmq", "-lzmq",
"-Wl,--end-group",
"-lpthread", "-lm", "-ldl"]
/-- Script to build xlean via cmake -/
script buildXlean do
-- First build the Lean libraries
IO.println "Building Lean libraries..."
let lakeResult ← IO.Process.output {
cmd := "lake"
args := #["build", "REPL"]
}
if lakeResult.exitCode != 0 then
IO.eprint lakeResult.stderr
throw <| IO.userError "Failed to build Lean libraries"
let buildDir := "build-cmake"
-- Create build directory if it doesn't exist
let buildPath : FilePath := buildDir
if !(← buildPath.pathExists) then
IO.FS.createDirAll buildDir
-- Run cmake configure to build C++ FFI library
IO.println "Configuring CMake to build C++ FFI library..."
let configResult ← IO.Process.output {
cmd := "cmake"
args := #["-S", ".", "-B", buildDir, "-DXEUS_LEAN_BUILD_FFI_ONLY=ON"]
}
if configResult.exitCode != 0 then
IO.eprint configResult.stderr
throw <| IO.userError "CMake configuration failed"
-- Build the C++ FFI library
IO.println "Building C++ FFI library..."
let buildResult ← IO.Process.output {
cmd := "cmake"
args := #["--build", buildDir, "--target", "xeus_ffi"]
}
if buildResult.exitCode != 0 then
IO.eprint buildResult.stderr
throw <| IO.userError "CMake build of FFI library failed"
-- Now build the Lean executable that links with the FFI library
IO.println "Building xlean executable (Lean + FFI)..."
let xleanResult ← IO.Process.output {
cmd := "lake"
args := #["build", "xlean"]
}
if xleanResult.exitCode != 0 then
IO.eprint xleanResult.stderr
throw <| IO.userError "Failed to build xlean executable"
IO.println "xlean built successfully at .lake/build/bin/xlean"
return 0
/-- Script to install xlean kernel to Jupyter -/
script installKernel do
-- Build first
let _ ← buildXlean []
-- Copy kernel spec to Jupyter
let homeDir ← IO.getEnv "HOME"
let jupyterDir := homeDir.getD "~" ++ "/Library/Jupyter/kernels/xlean"
IO.FS.createDirAll jupyterDir
let currentDir ← IO.currentDir
-- Create kernel.json content
let kernelJson :=
"{" ++ "\n" ++
" \"display_name\": \"Lean 4\"," ++ "\n" ++
" \"argv\": [" ++ "\n" ++
s!" \"{currentDir}/.lake/build/bin/xlean\"," ++ "\n" ++
" \"{connection_file}\"" ++ "\n" ++
" ]," ++ "\n" ++
" \"language\": \"lean\"," ++ "\n" ++
" \"interrupt_mode\": \"signal\"," ++ "\n" ++
" \"env\": {}" ++ "\n" ++
"}"
-- Write kernel.json
IO.FS.writeFile (jupyterDir ++ "/kernel.json") kernelJson
IO.println s!"Installed xlean kernel to {jupyterDir}"
return 0