RustToolChain.jl is a Julia package that provides Rust toolchains (especially cargo) using Julia's Artifacts system. You can build and run Rust projects directly from Julia without installing Rust on your system.
- π¦ Provides Rust 1.96.1 toolchain
- π¦ Automatic download and management via Julia's Artifacts system
- π₯οΈ Supports multiple platforms and architectures
- π Simple API to execute
cargocommands
- Linux: x86_64 (glibc, musl), aarch64 (glibc, musl), i686 (glibc, musl)
- macOS: x86_64, aarch64
- Windows: x86_64
RustToolChain.jl installs an isolated Rust toolchain (cargo, rustc, and related tools) for you.
It does not provide a C/C++ linker or the Windows SDK.
On Windows this package uses the x86_64-pc-windows-msvc target, so linking still requires Microsoft's MSVC build tools (for example link.exe) and a Windows SDK.
Install these once on the machine before building Rust projects.
Open PowerShell or Command Prompt as Administrator, then run:
winget install -e --id Microsoft.VisualStudio.2022.BuildTools `
--accept-source-agreements `
--accept-package-agreements `
--override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"| Flag / value | Purpose |
|---|---|
Microsoft.VisualStudio.2022.BuildTools |
Installs Visual Studio 2022 Build Tools (no full IDE) |
Microsoft.VisualStudio.Workload.VCTools |
Adds the C++ build tools workload (MSVC + linker); see workload ID docs |
--includeRecommended |
Pulls in recommended components, including MSVC x64/x86 tools and a Windows SDK |
--wait --passive |
Runs a non-interactive install and waits until it finishes |
Notes:
- The same command can also add the C++ workload if Build Tools are already installed without it (
winget install+--overridemodifies the existing product). - After installation, open a new terminal (or reboot if tools are still not found) so environment variables are refreshed.
- Use of Microsoft C++ Build Tools requires a valid Visual Studio license (Community is free for many use cases).
- Download Build Tools for Visual Studio
- Run the installer
- Select the Desktop development with C++ workload
- Complete the install
Without MSVC build tools, cargo build typically fails with errors such as:
note: the msvc targets depend on the msvc linker but `link.exe` was not found
RustToolChain.jl cannot work around this: the MSVC linker and Windows SDK are host system components, not part of the Rust distribution that this package downloads.
- rustup book: MSVC prerequisites β why Rust's
msvctarget needs Visual Studio / Build Tools (and an alternative winget example) - Microsoft Learn: Use command-line parameters to install Visual Studio β official
winget install --id ... --override "--add ..."pattern, plus--wait,--passive, and--includeRecommended - Microsoft Learn: Build Tools workload and component IDs β
Microsoft.VisualStudio.Workload.VCTools("Desktop development with C++") and its recommended components (MSVC, Windows SDK) - Build Tools for Visual Studio download β GUI installer entry point
using Pkg; Pkg.add("RustToolChain")using RustToolChain: cargo
# Execute cargo command
run(`$(cargo()) --version`)
# Build a Rust project
run(`$(cargo()) build`)
# Run a Rust project
run(`$(cargo()) run`)This repository includes a simple example:
git clone https://github.com/AtelierArith/RustToolChain.jl.git
cd RustToolChain.jl
julia --project -e 'using Pkg; Pkg.instantiate()'
cd examples
julia --project run.jlOr from the Julia REPL:
using Pkg
Pkg.activate("examples")
Pkg.instantiate()
include("examples/run.jl")Returns a command object for executing Rust's cargo command.
Returns: Cmd object (usable with Julia's backtick syntax)
Examples:
using RustToolChain: cargo
# Check cargo version
run(`$(cargo()) --version`)
# Create a new Rust project
run(`$(cargo()) new my_project`)
# Build project
run(`$(cargo()) build --release`)This package uses Julia's Artifacts system to automatically download and manage Rust toolchains on Unix-like platforms. On first use, the appropriate Rust toolchain for your platform will be automatically downloaded.
The cargo() and rustc() functions return commands that use the isolated Windows toolchain when no system cargo or rustc is available.
Windows uses a different installation path. Instead of installing the large Rust distribution tarball through Julia Artifacts, RustToolChain.jl downloads rustup-init.exe from https://win.rustup.rs and installs the Rust version recorded in Artifacts.toml with rustup toolchain install --profile default. The installation is isolated under this package's Julia scratchspace by setting package-local RUSTUP_HOME and CARGO_HOME directories. It does not modify the user's PATH or the user's existing Rust installation.
RustToolChain.jl/
βββ src/
β βββ RustToolChain.jl # Main Julia module
βββ examples/
β βββ hello/ # Example Rust project
β βββ run.jl # Julia script demonstrating usage
βββ gen/
β βββ generate_Artifacts_toml.jl # Script to generate Artifacts.toml
βββ test/
β βββ runtests.jl # Julia test script
βββ .github/workflows/
β βββ CI.yml # Continuous integration tests
β βββ bump-rust-stable.yml # Auto-update Rust toolchain
βββ Artifacts.toml # List of artifact dependencies
βββ Project.toml # Julia package manifest
This package automatically checks for new Rust stable releases and creates pull requests to update the toolchain.
Automated Workflow:
- Runs weekly (every Monday at 00:00 UTC)
- Fetches the latest Rust stable version from
https://static.rust-lang.org/dist/channel-rust-stable.toml - Regenerates
Artifacts.tomlwith the new version - Updates the version in
README.md - Creates a pull request if changes are detected
Note on CI for auto-generated PRs:
PRs created by the GitHub Actions workflow may not start the pull_request CI jobs automatically. If the required checks are still missing, trigger CI by pushing an empty commit to the PR branch:
gh pr checkout <PR_NUMBER>
git commit --allow-empty -m "Trigger CI for PR #<PR_NUMBER>"
git pushManual Update:
You can manually regenerate Artifacts.toml for a specific Rust version:
julia --project=gen gen/generate_Artifacts_toml.jl <RUST_VERSION>
# Example:
julia --project=gen gen/generate_Artifacts_toml.jl 1.93.0The script validates the version format (X.Y.Z) and provides clear error messages for invalid input.
Please refer to the LICENSE file in the repository for license information.
- Satoshi Terasaki terasakisatoshi.math@gmail.com