make precompileModules opt-in via precompile option - #47
Open
johnchandlerburnham wants to merge 1 commit into
Open
make precompileModules opt-in via precompile option#47johnchandlerburnham wants to merge 1 commit into
precompile option#47johnchandlerburnham wants to merge 1 commit into
Conversation
Downstream packages that run Blake3 hashing inside `#eval` at
elaboration time (e.g. Verso blog posts) need the FFI symbols loaded
into the elaborating process — in batch `lake build` and in
language-server file workers alike. Lake's mechanism for this is
`precompileModules`: the lib's shared library (which bundles the
moreLinkObjs native objects) is then built and auto-loaded for
importers, the same pattern MD4Lean uses.
Rather than forcing every consumer to pay the native-compile cost,
gate it behind a require option, off by default:
[[require]]
name = "Blake3"
git = "..."
rev = "..."
options = {precompile = "on"}
or in a lakefile.lean:
require Blake3 from git "..." @ "..."
with NameMap.empty.insert `precompile "on"
With no option passed, behavior is identical to before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Consumers that call Blake3 inside
#evalat elaboration time — e.g. Versoblog posts with executable code examples — need the FFI symbols loaded into
the elaborating process, both in batch
lake buildand in language-serverfile workers. Without that, the interpreter fails with
Could not find native implementation of external declaration 'Blake3.C.hasherInit', and there isno reliable way to fix this purely from the consumer side (
--load-dynlibvia
moreGlobalServerArgscrash-loops LSP workers, and module-level dynlibsdon't bundle
moreLinkObjsobjects).Lake's mechanism for this is
precompileModules: the lib's shared library —which does bundle the
moreLinkObjsnative objects — is built andautomatically loaded for importers, in batch builds via injected
--load-dynliband in the language server vialake setup-file'sdynlibs/plugins. This is the same pattern MD4Lean uses for its md4c FFI.Rather than forcing the native-compile cost on every consumer, this PR gates
it behind a require option, off by default — with no option passed,
get_config? precompileisnoneand behavior is byte-identical to today(ix unaffected). Consumers opt in with:
or in a
lakefile.lean:The option is applied to all three libs (
Blake3,Blake3C,Blake3Rust)for symmetry; only libs a consumer actually builds/imports are affected.
Validated end-to-end in
argument-website(with this exactget_config?gating applied to the dependency checkout):
lake setup-fileon a postimporting
Blake3.ClistslibBlake3_Blake3C.so/libBlake3_Blake3.soforeditor workers, and a scripted LSP session evaluating
#eval Blake3.C.hash …live produces correct digests with zero missing-native errors.
Note for consumers: require
optionstake effect at dependencymaterialization, so run
lake update Blake3after adding them — a plainrebuild is not enough. (Lake also silently ignores unknown require keys in
TOML, so a typo in
optionsfails without a diagnostic.)