Skip to content

Commit

Permalink
fix: lake: computation of precompiled libs
Browse files Browse the repository at this point in the history
  • Loading branch information
tydeu committed Jun 26, 2024
1 parent e3578c2 commit a051669
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 22 deletions.
13 changes: 9 additions & 4 deletions src/lake/Lake/Build/Module.lean
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ def Module.recBuildDeps (mod : Module) : FetchM (BuildJob (SearchPath × Array F
if imp.name = mod.name then
logError s!"{mod.leanFile}: module imports itself"
imp.olean.fetch
let precompileImports ← try mod.precompileImports.fetch
let precompileImports ←
try
if mod.shouldPrecompile then
mod.transImports.fetch
else
mod.precompileImports.fetch
catch errPos => return Job.error (← takeLogFrom errPos)
let modLibJobs ← precompileImports.mapM (·.dynlib.fetch)
let pkgs := precompileImports.foldl (·.insert ·.pkg)
OrdPackageSet.empty |>.insert mod.pkg |>.toArray
let (externJobs, libDirs) ← recBuildExternDynlibs pkgs
let pkgs := precompileImports.foldl (·.insert ·.pkg) OrdPackageSet.empty
let pkgs := if mod.shouldPrecompile then pkgs.insert mod.pkg else pkgs
let (externJobs, libDirs) ← recBuildExternDynlibs pkgs.toArray
let externDynlibsJob ← BuildJob.collectArray externJobs
let modDynlibsJob ← BuildJob.collectArray modLibJobs

Expand Down
3 changes: 2 additions & 1 deletion src/lake/examples/ffi/app/lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ require ffi from ".."/"lib"
lean_exe app where
root := `Main

lean_lib Test
lean_lib Test where
precompileModules := true
7 changes: 3 additions & 4 deletions src/lake/examples/ffi/lib/lakefile.lean
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import Lake
open System Lake DSL

package ffi {
package ffi where
srcDir := "lean"
precompileModules := true
}

lean_lib FFI

@[default_target] lean_exe test where
@[default_target]
lean_exe test where
root := `Main

target ffi.o pkg : FilePath := do
Expand Down
10 changes: 0 additions & 10 deletions src/lake/examples/ffi/package.sh

This file was deleted.

16 changes: 13 additions & 3 deletions src/lake/examples/ffi/test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
set -ex
#!/usr/bin/env bash
set -euxo pipefail

LAKE=${LAKE:-../../.lake/build/bin/lake}

./clean.sh
./package.sh

# Tests that a non-precmpiled build does not load anything as a dynlib
# https://github.com/leanprover/lean4/issues/4565
$LAKE -d app build -v | (grep --color load-dynlib && exit 1 || true)
$LAKE -d lib build -v | (grep --color load-dynlib && exit 1 || true)

./app/.lake/build/bin/app
./lib/.lake/build/bin/test

${LAKE:-../../.lake/build/bin/lake} -d app build -v Test
# Tests the successful precompilation of an `extern_lib`
# Also tests a module with `precompileModules` always precompiles its imports
$LAKE -d app build Test

0 comments on commit a051669

Please sign in to comment.