Skip to content

Commit c8290bd

Browse files
authored
fix: lake: import Lake w/ precompiled modules on MacOS (#8383)
This PR fixes the use of `import Lake` with precompiled modules, which was previously broken on MacOS. Closes #7388.
1 parent b7b9589 commit c8290bd

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

src/lake/Lake/Build/Module.lean

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ def computeModuleDeps
186186
plugins := plugins.push impLib
187187
else
188188
dynlibs := dynlibs.push impLib
189+
/-
190+
On MacOS, Lake must be loaded as a plugin for
191+
`import Lake` to work with precompiled modules.
192+
https://github.com/leanprover/lean4/issues/7388
193+
-/
194+
if Platform.isOSX && !(plugins.isEmpty && dynlibs.isEmpty) then
195+
plugins := plugins.push (← getLakeInstall).sharedDynlib
189196
return {dynlibs, plugins}
190197

191198
/--

src/lake/Lake/Config/InstallPath.lean

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ prelude
88
import Init.Control.Option
99
import Init.Data.Option.Coe
1010
import Lean.Compiler.FFI
11+
import Lake.Config.Dynlib
1112
import Lake.Util.NativeLib
1213
import Lake.Config.Defaults
1314

@@ -114,19 +115,26 @@ structure LakeInstall where
114115
srcDir := home
115116
binDir := home / defaultBuildDir / defaultBinDir
116117
libDir := home / defaultBuildDir / defaultLeanLibDir
117-
sharedLib := libDir / nameToSharedLib "Lake"
118+
sharedDynlib : Dynlib := {
119+
name := "Lake"
120+
path := libDir / nameToSharedLib "Lake"
121+
}
118122
lake := binDir / lakeExe
119123
deriving Inhabited, Repr
120124

125+
@[inline] def LakeInstall.sharedLib (self : LakeInstall) : FilePath :=
126+
self.sharedDynlib.path
127+
121128
/-- Construct a Lake installation co-located with the specified Lean installation. -/
122129
def LakeInstall.ofLean (lean : LeanInstall) : LakeInstall where
123130
home := lean.sysroot
124131
srcDir := lean.srcDir / "lake"
125132
binDir := lean.binDir
126133
libDir := lean.leanLibDir
127-
sharedLib :=
134+
sharedDynlib :=
128135
let lib := s!"libLake_shared.{sharedLibExt}"
129-
if Platform.isWindows then lean.binDir / lib else lean.leanLibDir / lib
136+
let path := if Platform.isWindows then lean.binDir / lib else lean.leanLibDir / lib
137+
{name := "Lake_shared", path}
130138
lake := lean.binDir / lakeExe
131139

132140
/-! ## Detection Functions -/
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import Lake
2+
import Foo

src/lake/tests/precompileLink/lakefile.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ lean_lib FooDepDep
1414
lean_exe orderTest
1515

1616
lean_lib Downstream
17+
18+
lean_lib LakeTest

src/lake/tests/precompileLink/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ source ../common.sh
33

44
./clean.sh
55

6+
# Test that precompilation works with a Lake import
7+
# https://github.com/leanprover/lean4/issues/7388
8+
test_run -v build LakeTest
9+
610
# Test that the link & load order of precompiled libraries is correct
711
# https://github.com/leanprover/lean4/issues/7790
812
test_run -v exe orderTest

0 commit comments

Comments
 (0)