Skip to content
Merged
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
21 changes: 11 additions & 10 deletions lakefile.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ open Lake DSL

package Blake3

/- Precompiled so the C/Rust FFI symbols are auto-loaded into elaborating
processes -- batch builds and language-server workers alike. Without this,
any consumer that reaches the FFI at elaboration time (`#eval`, or
`native_decide` over a hash) fails outright with "Could not find native
implementation of external declaration", and cannot fix it from their side.
The cost is one shared-library link per lib, measured at ~0.3s on a cold
build of a consumer that links an executable, and nothing on rebuilds. -/
@[default_target]
lean_lib Blake3
lean_lib Blake3 where
precompileModules := true

@[test_driver]
lean_exe Blake3Test
Expand Down Expand Up @@ -78,6 +86,7 @@ target blake3_c pkg : System.FilePath := do
buildStaticLib (pkg.staticLibDir / name) oFileJobs

lean_lib Blake3C where
precompileModules := true
roots := #[`Blake3.C]
moreLinkObjs := #[blake3_c]

Expand All @@ -88,15 +97,7 @@ target blake3_rs pkg : System.FilePath := do
inputBinFile $ pkg.dir / "rust" / "target" / "release" / libName

lean_lib Blake3Rust where
precompileModules := true
roots := #[`Blake3.Rust]
moreLinkObjs := #[blake3_rs]

/-- The `blake3-rs` shared library. Produced by the same `cargo build` as
`blake3_rs`; this target selects the `cdylib` output for downstream tooling
that loads the raw `rs_blake3_*` symbols at runtime rather than linking them
statically — e.g. supplying the BLAKE3 backend to Lean's native evaluator for
`native_decide` proofs. -/
target blake3_rs_shared pkg : System.FilePath := do
proc { cmd := "cargo", args := #["build", "--release"], cwd := pkg.dir / "rust" } (quiet := true)
inputBinFile $ pkg.dir / "rust" / "target" / "release" / nameToSharedLib "blake3_rs"

9 changes: 4 additions & 5 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ version = "0.1.0"
edition = "2024"

[lib]
# `staticlib` is linked into final Lean executables. `cdylib` additionally
# builds a position-independent shared object exporting the raw `rs_blake3_*`
# symbols, so they can be loaded at runtime — e.g. by Lean's native evaluator
# for `native_decide` proofs elaborated before any executable is linked.
crate-type = ["staticlib", "cdylib"]
# Linked into the precompiled Lean shared libraries and into final
# executables. A `cdylib` is not needed: `precompileModules` bundles these
# symbols into each lib's shared object, which Lake loads for importers.
crate-type = ["staticlib"]

[dependencies]
blake3 = "1.8.7"
Expand Down