Skip to content

fix: defer Rust toolchain install to fallback build path only#51

Merged
deucalioncodes merged 3 commits into
mainfrom
fix/lazy-rust-install
May 27, 2026
Merged

fix: defer Rust toolchain install to fallback build path only#51
deucalioncodes merged 3 commits into
mainfrom
fix/lazy-rust-install

Conversation

@deucalioncodes
Copy link
Copy Markdown
Member

Summary

  • Removed the unconditional install_rust_dependencies.sh call from __main__.py that ran on every python3 -m basilisk invocation
  • Added ensure_rust_dependencies(paths) in build_wasm_binary_or_exit.py, called only from build_template_from_source() — the fallback path when the pre-built template WASM is missing and cannot be downloaded
  • Added proper error handling: the install script's return code is now checked (previously ignored)
  • Added unit tests for the new function and its integration point

The 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

  • CI passes (unit tests + existing integration tests)
  • Manual: icp deploy in a clean Docker container skips Rust installation on happy path (template downloaded successfully)
  • Manual: if template download fails, fallback path still installs Rust and builds from source

Made with Cursor

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>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.sh invocation from basilisk/__main__.py.
  • Added ensure_rust_dependencies(paths) and invoked it from build_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 verifying Cargo.toml exists. If the package/template sources are missing/corrupt, this will still spend minutes installing Rust before failing. Suggest checking template_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,
)


deucalioncodes and others added 2 commits May 27, 2026 12:28
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>
@deucalioncodes deucalioncodes merged commit 171a68a into main May 27, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants