Skip to content

Commit c3d9d0d

Browse files
authored
feat: lake: restoreAllArtifacts (#10576)
This PR adds a new package configuration option: `restoreAllArtifacts`. When set to `true` and the Lake local artifact cache is enabled, Lake will copy all cached artifacts into the build directory. This ensures they are available for external consumers who expect build results to be in the build directory.
1 parent e98d7dd commit c3d9d0d

File tree

8 files changed

+52
-21
lines changed

8 files changed

+52
-21
lines changed

src/lake/Lake/Build/Common.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ public def buildArtifactUnlessUpToDate
562562
else
563563
return some art
564564
if (← pkg.isArtifactCacheEnabled) then
565-
if let some art ← fetchArt? restore then
565+
if let some art ← fetchArt? (restore || pkg.restoreAllArtifacts) then
566566
setTrace art.trace
567567
if let some outputsRef := pkg.outputsRef? then
568568
outputsRef.insert inputHash art.hash

src/lake/Lake/Build/Module.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ private def Module.recBuildLean (mod : Module) : FetchM (Job ModuleOutputArtifac
710710
return none
711711
let arts ← id do
712712
if (← mod.pkg.isArtifactCacheEnabled) then
713-
if let some arts ← fetchArtsFromCache? false then
713+
if let some arts ← fetchArtsFromCache? mod.pkg.restoreAllArtifacts then
714714
return arts
715715
else
716716
unless (← savedTrace.replayIfUpToDate (oldTrace := srcTrace.mtime) mod depTrace) do

src/lake/Lake/Config/Package.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ public def nativeLibDir (self : Package) : FilePath :=
344344
@[inline] public def enableArtifactCache? (self : Package) : Option Bool :=
345345
self.config.enableArtifactCache?
346346

347+
/-- The package's `restoreAllArtifacts` configuration. -/
348+
@[inline] public def restoreAllArtifacts (self : Package) : Bool :=
349+
self.config.restoreAllArtifacts
350+
347351
/-- The directory within the Lake cache were package-scoped files are stored. -/
348352
public def cacheScope (self : Package) :=
349353
self.name.toString (escape := false)

src/lake/Lake/Config/PackageConfig.lean

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ public configuration PackageConfig (p : Name) (n : Name) extends WorkspaceConfig
295295
-/
296296
enableArtifactCache?, enableArtifactCache : Option Bool := none
297297
/--
298+
Whether, when the local artifact cache is enabled, Lake should copy all cached
299+
artifacts into the build directory. This ensures the build results are available
300+
to external consumers who expect them in the build directory.
301+
302+
Defaults to `false`.
303+
-/
304+
restoreAllArtifacts : Bool := false
305+
/--
298306
Whether native libraries (of this package) should be prefixed with `lib` on Windows.
299307
300308
Unlike Unix, Windows does not require native libraries to start with `lib` and,

src/lake/tests/cache/lakefile.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Lake
2+
open System Lake DSL
3+
4+
package test where
5+
enableArtifactCache := true
6+
restoreAllArtifacts := get_config? restoreAll |>.isSome
7+
8+
lean_lib Test
9+
10+
lean_lib Module where
11+
leanOptions := #[⟨`experimental.module, true⟩]
12+
13+
lean_lib Ignored
14+
15+
lean_exe test where
16+
root := `Main

src/lake/tests/cache/lakefile.toml

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/lake/tests/cache/online-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env bash
1+
gi#!/usr/bin/env bash
22
source ../common.sh
33

44
./clean.sh

src/lake/tests/cache/test.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ test_exp "$cache_art" != "$local_art"
5555
test_cmd cmp -s "$cache_art" "$local_art"
5656

5757
# Verify supported artifacts end up in the cache directory
58-
test_run build test:exe Test:static Test:shared +Test:o.export +Test:o.noexport
58+
test_run build \
59+
test:exe Test:static Test:shared +Test:o.export +Test:o.noexport +Module
5960
test_cached() {
6061
target="$1"; shift
6162
art="$($LAKE query $target)"
@@ -71,7 +72,6 @@ test_cached +Test:dynlib !
7172
test_cached +Test:olean
7273
test_cached +Test:ilean !
7374
test_cached +Test:c
74-
test_run build +Module
7575
test_cached +Module:olean
7676
test_cached +Module:olean.server
7777
test_cached +Module:olean.private
@@ -134,5 +134,24 @@ test_cmd_eq 3 wc -l < .lake/outputs.jsonl
134134
test_run build Test:static -o .lake/outputs.jsonl
135135
test_cmd_eq 6 wc -l < .lake/outputs.jsonl
136136

137+
# Verify all artifacts end up in the cache directory with `restoreAllArtifacts`
138+
test_cmd cp -r "$CACHE_DIR" .lake/cache-backup
139+
test_cmd rm -rf "$CACHE_DIR"
140+
test_run build -R -KrestoreAll=true \
141+
test:exe Test:static Test:shared +Test:o.export +Test:o.noexport +Module
142+
test_cached test:exe !
143+
test_cached Test:static !
144+
test_cached Test:shared !
145+
test_cached +Test:o.export !
146+
test_cached +Test:o.noexport !
147+
test_cached +Test:dynlib !
148+
test_cached +Test:olean !
149+
test_cached +Test:ilean !
150+
test_cached +Test:c !
151+
test_cached +Module:olean !
152+
test_cached +Module:olean.server !
153+
test_cached +Module:olean.private !
154+
test_cached +Module:ir !
155+
137156
# Cleanup
138157
rm -f produced.out Ignored.lean

0 commit comments

Comments
 (0)