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.95.0 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
Windows users need to run the following in an Administrator PowerShell to install the required build tools:
winget install -e --id Microsoft.VisualStudio.2022.BuildTools `
--accept-source-agreements `
--accept-package-agreements `
--override "--wait --passive --add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"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