Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,13 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux")
string(APPEND CMAKE_CXX_FLAGS " -fPIC -ftls-model=initial-exec")
string(APPEND LEANC_EXTRA_CC_FLAGS " -fPIC")
string(APPEND TOOLCHAIN_SHARED_LINKER_FLAGS " -Wl,-rpath=\\$$ORIGIN/..:\\$$ORIGIN")
string(APPEND INIT_SHARED_LINKER_FLAGS " -Wl,-soname=libInit_shared.so")
string(APPEND LEANSHARED_1_LINKER_FLAGS " -Wl,-soname=libleanshared_1.so")
string(APPEND LEANSHARED_2_LINKER_FLAGS " -Wl,-soname=libleanshared_2.so")
string(APPEND LEANSHARED_LINKER_FLAGS " -Wl,-soname=libleanshared.so")
string(
APPEND LAKESHARED_LINKER_FLAGS
" -Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/lean/libLake.a.export -Wl,--no-whole-archive"
" -Wl,--whole-archive ${CMAKE_BINARY_DIR}/lib/lean/libLake.a.export -Wl,--no-whole-archive -Wl,-soname=libLake_shared.so"
)
string(APPEND CMAKE_EXE_LINKER_FLAGS " -Wl,-rpath=$ORIGIN/../lib:$ORIGIN/../lib/lean")
elseif(CMAKE_SYSTEM_NAME MATCHES "Darwin")
Expand Down
5 changes: 5 additions & 0 deletions src/Init/System/Platform.lean
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ Is the current platform [Emscripten](https://emscripten.org/)?
-/
def isEmscripten : Bool := getIsEmscripten ()

/--
Is the current platform Linux?
-/
def isLinux : Bool := !isWindows && !isOSX && !isEmscripten

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kha does this look reasonable? I am assuming that the platform has to be one of [windows, macos, emscripten, linux]. An alternative would be to add a native symbol like the others which checks for the __linux__ macro.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know we have had some users that have built (or at least try to build) Lean on BSD. Thus, it may be best to have a more exact check (especially if this is exclusive to Linux and not other non-macOS Unix-like operating systems).


/--
Gets the LLVM target triple of the current platform, or `""` if this was missing when Lean was
compiled.
Expand Down
22 changes: 17 additions & 5 deletions src/lake/Lake/Build/Module.lean
Original file line number Diff line number Diff line change
Expand Up @@ -213,12 +213,24 @@ def computeModuleDeps
else
dynlibs := dynlibs.push impLib
/-
On MacOS, Lake must be loaded as a plugin for
`import Lake` to work with precompiled modules.
https://github.com/leanprover/lean4/issues/7388
On Linux, dynlibs that use Lake symbols are linked against `libLake_shared.so` (`--as-needed`).
The runtime linker is not able to find `lib/lean/libLake_shared.so` on disk
because we do not set `LD_LIBRARY_PATH`,
and the `DT_RUNPATH` entry on `bin/lean` pointing to `lib/lean`
is ignored when resolving transitive dependencies.
So we load `libLake_shared.so` eagerly *in case it might be needed*
(we don't know whether it is needed because an imported `Lake.*` module
will not be present in `Module.transImports`).
TODO: load as dynlib instead of as plugin,
see https://github.com/leanprover/lean4/pull/14326

MacOS *can* resolve the dylib but needs a plugin to run initializers,
see https://github.com/leanprover/lean4/issues/7388
TODO: remove macOS case once initializers are compiled correctly,
see https://github.com/leanprover/lean4/issues/14359
-/
if Platform.isOSX && !(plugins.isEmpty && dynlibs.isEmpty) then
plugins := plugins.push (← getLakeInstall).sharedDynlib
if (Platform.isLinux || Platform.isOSX) && !(plugins.isEmpty && dynlibs.isEmpty) then
plugins := plugins.insertIdx 0 (← getLakeInstall).sharedDynlib
return {dynlibs, plugins}

structure TransImportEntry where
Expand Down
1 change: 1 addition & 0 deletions tests/lake/tests/precompileModules-importLake/Foo.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Foo.ImportLake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import Lake.Util.Casing
1 change: 1 addition & 0 deletions tests/lake/tests/precompileModules-importLake/clean.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rm -rf .lake lake-manifest.json produced.out
6 changes: 6 additions & 0 deletions tests/lake/tests/precompileModules-importLake/lakefile.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name = "precompileModules-importLake"
precompileModules = true
defaultTargets = ["Foo"]

[[lean_lib]]
name = "Foo"
8 changes: 8 additions & 0 deletions tests/lake/tests/precompileModules-importLake/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
source ../common.sh

./clean.sh

# Test that precompiled modules can import Lake.
# Regression test for https://github.com/leanprover/lean4/issues/9420.
test_run -v build Foo
Loading