lean4-htt/tests/pkg/frontend/Frontend/Compile.lean
Mac Malone c9c3366521
feat: lake: support plugins (#7001)
This PR adds support for plugins to Lake. Precompiled modules are now
loaded as plugins rather than via `--load-dynlib`.

Additional plugins can be added through an experimental `plugins`
configuration option. The syntax for specifying this is not yet
convenient, and will be improved in future changes. A parallel `dynlibs`
configuration option has been added for specifying additional dynamic
libraries to build and pass to `--load-dynlib`.

This PR also changes the default directory for `.olean`, `.ilean`, and
module dynamic libraries (i.e., `leanLibDir`) to `lib/lean` instead of
the previous default of `lib`. This avoids potential name clashes
between single module shared libraries and the shared libraries of a
full `lean_lib`.

On non-Windows systems, module dynamic libraries are no longer linked to
their imports or external symbols. Symbols from those libraries are left
unresolved until load time. This avoids nesting these dependencies
within the shared library and means Lake no longer needs to augment the
shared library path to allow Lean to resolve such nested dependencies on
load.
2025-02-14 04:57:31 +00:00

28 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Lean.Elab.Frontend
open Lean Elab
unsafe def processInput (input : String) (initializers := false) :
IO (Environment × List Message) := do
let fileName := "<input>"
let inputCtx := Parser.mkInputContext input fileName
if initializers then enableInitializersExecution
let (header, parserState, messages) ← Parser.parseHeader inputCtx
let (env, messages) ← processHeader header {} messages inputCtx
let s ← IO.processCommands inputCtx parserState (Command.mkState env messages {}) <&> Frontend.State.commandState
pure (s.env, s.messages.toList)
open System in
def findLean (mod : Name) : IO FilePath := do
let olean ← findOLean mod
-- Remove a ".lake/build/lib/lean" substring from the path.
let lean := olean.toString.replace (toString (FilePath.mk ".lake" / "build" / "lib" / "lean") ++ FilePath.pathSeparator.toString) ""
return FilePath.mk lean |>.withExtension "lean"
/-- Read the source code of the named module. -/
def moduleSource (mod : Name) : IO String := do
IO.FS.readFile (← findLean mod)
unsafe def compileModule (mod : Name) (initializers := false) :
IO (Environment × List Message) := do
processInput (← moduleSource mod) initializers