@@ -79,24 +79,24 @@ def CURLBIN :=
7979 -- change file name if we ever need a more recent version to trigger re-download
8080 IO.CACHEDIR / s! "curl-{ CURLVERSION} "
8181
82- /-- leantar version at https://github.com/digama0/leangz -/
83- def LEANTARVERSION :=
84- "0.1.17"
85-
8682def EXE := if System.Platform.isWindows then ".exe" else ""
8783
88- def LEANTARBIN :=
89- -- change file name if we ever need a more recent version to trigger re-download
90- IO.CACHEDIR / s! "leantar-{ LEANTARVERSION}{ EXE} "
91-
9284def LAKEPACKAGESDIR : FilePath :=
9385 ".lake" / "packages"
9486
9587def getCurl : IO String := do
9688 return if (← CURLBIN.pathExists) then CURLBIN.toString else "curl"
9789
98- def getLeanTar : IO String := do
99- return if (← LEANTARBIN.pathExists) then LEANTARBIN.toString else "leantar"
90+ /-- Path to the `leantar` binary bundled with the Lean toolchain.
91+ This has been bundled since `nightly-2026-03-09` (lean4#12822). -/
92+ private initialize leantarSysrootBin : String ← do
93+ let out ← IO.Process.output { cmd := "lean" , args := #["--print-prefix" ] }
94+ if out.exitCode == 0 then
95+ let path : FilePath := out.stdout.trimAscii.toString / "bin" / s! "leantar{ EXE} "
96+ if ← path.pathExists then return path.toString
97+ throw <| IO.userError "leantar not found in Lean sysroot. This toolchain may predate nightly-2026-03-09."
98+
99+ def getLeanTar : IO String := return leantarSysrootBin
100100
101101/-- Spawn a `leantar` process for decompression, writing the given JSON config to its stdin.
102102 Returns the process exit code. -/
@@ -208,7 +208,9 @@ def validateCurl : IO Bool := do
208208 match (← runCmd "curl" #["--version" ]).splitOn " " with
209209 | "curl" :: v :: _ => match v.splitOn "." with
210210 | maj :: min :: _ =>
211- let version := (maj.toNat!, min.toNat!)
211+ let some majN := String.toNat? maj | throw <| IO.userError "Invalidly formatted version of `curl`"
212+ let some minN := String.toNat? min | throw <| IO.userError "Invalidly formatted version of `curl`"
213+ let version := (majN, minN)
212214 let _ := @lexOrd
213215 let _ := @leOfOrd
214216 if version >= (7 , 81 ) then return true
@@ -232,45 +234,6 @@ def validateCurl : IO Bool := do
232234 | _ => throw <| IO.userError "Invalidly formatted version of `curl`"
233235 | _ => throw <| IO.userError "Invalidly formatted response from `curl --version`"
234236
235- def Version := Nat × Nat × Nat
236- deriving Inhabited, DecidableEq
237-
238- instance : Ord Version := let _ := @lexOrd; lexOrd
239- instance : LE Version := leOfOrd
240-
241- def parseVersion (s : String) : Option Version := do
242- let [maj, min, patch] := s.splitOn "." | none
243- some (maj.toNat!, min.toNat!, patch.toNat!)
244-
245- def validateLeanTar : IO Unit := do
246- if (← LEANTARBIN.pathExists) then return
247- if let some version ← some <$> runCmd "leantar" #["--version" ] <|> pure none then
248- let "leantar" :: v :: _ := version.splitOn " "
249- | throw <| IO.userError "Invalidly formatted response from `leantar --version`"
250- let some v := parseVersion v | throw <| IO.userError "Invalidly formatted version of `leantar`"
251- -- currently we need exactly one version of leantar, change this to reflect compatibility
252- if v = (parseVersion LEANTARVERSION).get! then return
253- let win := System.Platform.getIsWindows ()
254- let target ← if win then
255- pure "x86_64-pc-windows-msvc"
256- else
257- let mut arch ← (·.trimAscii.copy) <$> runCmd "uname" #["-m" ] false
258- if arch = "arm64" then arch := "aarch64"
259- unless arch ∈ ["x86_64" , "aarch64" ] do
260- throw <| IO.userError s! "unsupported architecture { arch} "
261- pure <|
262- if System.Platform.getIsOSX () then s! "{ arch} -apple-darwin"
263- else s! "{ arch} -unknown-linux-musl"
264- IO.println s! "installing leantar { LEANTARVERSION} "
265- IO.FS.createDirAll IO.CACHEDIR
266- let ext := if win then "zip" else "tar.gz"
267- let _ ← runCmd "curl" (stderrAsErr := false ) #[
268- s! "https://github.com/digama0/leangz/releases/download/v{ LEANTARVERSION} /leantar-v{ LEANTARVERSION} -{ target} .{ ext} " ,
269- "-L" , "-o" , s! "{ LEANTARBIN} .{ ext} " ]
270- let _ ← runCmd "tar" #["-xf" , s! "{ LEANTARBIN} .{ ext} " ,
271- "-C" , IO.CACHEDIR.toString, "--strip-components=1" ]
272- IO.FS.rename (IO.CACHEDIR / s! "leantar{ EXE} " ).toString LEANTARBIN.toString
273-
274237/-- Recursively gets all files from a directory with a certain extension -/
275238partial def getFilesWithExtension
276239 (fp : FilePath) (extension : String) (acc : Array FilePath := #[]) :
0 commit comments