fix: defer Rust toolchain install to fallback build path only#51
Merged
Conversation
The Rust toolchain (rustup, wasm32-wasip1, wasi2ic, candid-extractor) is only needed when building the CPython canister template from source. The default path downloads a pre-built template WASM and injects Python with pure-Python tooling — no Rust required. Move install_rust_dependencies.sh invocation from the unconditional __main__.py startup into build_template_from_source(), which only runs when the pre-built template is missing and cannot be downloaded. This eliminates minutes of unnecessary Rust installation on first deploy in Docker/CI. Also adds proper error handling for install script failures (previously the return code was ignored). Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Pull request overview
Defers Rust toolchain/build-dependency installation so it only runs when Basilisk must fall back to building the CPython template WASM from source (instead of on every python3 -m basilisk invocation), improving first-run deploy times for the common “download prebuilt template” path.
Changes:
- Removed the unconditional
install_rust_dependencies.shinvocation frombasilisk/__main__.py. - Added
ensure_rust_dependencies(paths)and invoked it frombuild_template_from_source()(fallback build path) with return-code checking. - Added unit tests covering the new function call and its integration point.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
basilisk/build_wasm_binary_or_exit.py |
Adds lazy Rust dependency installation for the template-from-source fallback path. |
basilisk/__main__.py |
Removes eager Rust installer invocation on every CLI run. |
tests/test_lazy_rust_install.py |
Adds tests validating installer invocation behavior and integration with the fallback build path. |
Comments suppressed due to low confidence (1)
basilisk/build_wasm_binary_or_exit.py:364
ensure_rust_dependencies(paths)runs before verifyingCargo.tomlexists. If the package/template sources are missing/corrupt, this will still spend minutes installing Rust before failing. Suggest checkingtemplate_cargo_toml(and any other required source files) first, then installing Rust only once the fallback build is actually possible.
ensure_rust_dependencies(paths)
compiler_dir = os.path.dirname(basilisk.__file__) + "/compiler"
template_cargo_toml = f"{compiler_dir}/cpython_canister_template/Cargo.toml"
if not os.path.exists(template_cargo_toml):
print(red(f"Template Cargo.toml not found at {template_cargo_toml}"))
sys.exit(1)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+31
to
+36
| result = subprocess.run( | ||
| [install_script, basilisk.__version__, basilisk.__rust_version__], | ||
| check=False, | ||
| ) | ||
| if result.returncode != 0: | ||
| print(red("Failed to install Basilisk Rust build dependencies.")) |
| check=False, | ||
| ) | ||
|
|
||
|
|
Co-authored-by: Cursor <cursoragent@cursor.com>
Add visual separators and emoji prefix to make errors stand out in icp-cli output. Update ic-basilisk message to point to requirements.txt. Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Summary
install_rust_dependencies.shcall from__main__.pythat ran on everypython3 -m basiliskinvocationensure_rust_dependencies(paths)inbuild_wasm_binary_or_exit.py, called only frombuild_template_from_source()— the fallback path when the pre-built template WASM is missing and cannot be downloadedThe default build path (download pre-built template + Python WASM injection) does not use cargo, wasi2ic, or candid-extractor. Deferring Rust installation to the fallback path eliminates minutes of unnecessary setup on first deploy in Docker/CI.
Test plan
icp deployin a clean Docker container skips Rust installation on happy path (template downloaded successfully)Made with Cursor