Skip to content

Commit

Permalink
feat: rust in core (#3219)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdx authored Nov 27, 2024
1 parent 424a8f8 commit de3a209
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 42 deletions.
11 changes: 11 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ indexmap = { version = "2", features = ["serde"] }
indicatif = { version = "0.17", features = ["default", "improved_unicode"] }
indoc = "2"
itertools = "0.13"
junction = "1"
log = "0.4"
md-5 = "0.10"
num_cpus = "1"
Expand Down
61 changes: 25 additions & 36 deletions docs/lang/rust.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,40 @@
# Rust

Rust is not currently offered as a core plugin. In fact, I don't think you
should actually use mise for rust development. Rust has an official version
manager called [`rustup`](https://rustup.rs/) that is better than what any of
the current mise plugins offer.
Rust/cargo can be installed which uses rustup under the hood. mise will install rustup if it is not
already installed and add the requested targets. By default, mise uses the default location of rustup/cargo
(`~/.rustup` and `~/.cargo`), but you can change this by setting the `MISE_RUSTUP_HOME` and `MISE_CARGO_HOME`
environment variables if you'd like to isolate mise's rustup/cargo from your other rustup/cargo installations.

You install [rustup](https://rustup.rs/) with the following:
Unlike most tools, these won't exist inside of `~/.local/share/mise/installs` because they are managed by rustup.
All mise does is set the `RUST_TOOLCHAIN` environment variable to the requested version and rustup will
automatically install it if it doesn't exist.

```sh
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

That said, rust is still one of the most popular languages to use in mise.
A lot of users have success with it so if you'd like to keep all of your
languages configured the same, don't feel like using mise is a bad idea either. Especially if you're only a casual rust user.
## Usage

If you're a relatively heavy rust user making use of things like channel
overrides, components, and cross-compiling, then I think you really should
just be using rustup though. The experience will be better.
Use the latest stable version of rust:

If one day we could figure out a way to provide an equivalent experience with
mise, we could revisit this. We have discussed potentially using mise as a
"front-end" to rustup where there is one rustup install that mise just manages
so you could do something like this:

```toml
[tools]
rust = "nightly"
```sh
mise use -g rust
cargo build
```

Where that would basically be equivalent to:
Use the latest beta version of rust:

```sh
rustup override set nightly
mise use -g rust@beta
cargo build
```

Frankly though, this isn't high on my priority list. Use rustup. It's great.
Use a specific version of rust:

Kudos for writing rust too btw, I've really enjoyed it so far—this is my first rust project.

## Default crates
```sh
mise use -g rust@1.82
cargo build
```

mise can automatically install a default set of creates right after installing a new rust version.
To enable this feature, provide a `$HOME/.default-cargo-crates` file that lists one crate per line, for
example:
## Settings

```text
cargo-edit
stylua
```
<script setup>
import Settings from '/components/settings.vue';
</script>
<Settings child="rust" :level="3" />
2 changes: 1 addition & 1 deletion docs/registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ editLink: false
| rstash | [asdf:carlduevel/asdf-rstash](https://github.com/carlduevel/asdf-rstash) |
| ruby | [core:ruby](https://mise.jdx.dev/lang/ruby.html) |
| ruff | [ubi:astral-sh/ruff](https://github.com/astral-sh/ruff) [asdf:simhem/asdf-ruff](https://github.com/simhem/asdf-ruff) |
| rust | [asdf:code-lever/asdf-rust](https://github.com/code-lever/asdf-rust) |
| rust | [core:rust](https://mise.jdx.dev/lang/rust.html) [asdf:code-lever/asdf-rust](https://github.com/code-lever/asdf-rust) |
| rust-analyzer | [aqua:rust-lang/rust-analyzer](https://github.com/rust-lang/rust-analyzer) [asdf:Xyven1/asdf-rust-analyzer](https://github.com/Xyven1/asdf-rust-analyzer) |
| rustic | [ubi:rustic-rs/rustic](https://github.com/rustic-rs/rustic) |
| rye | [aqua:astral-sh/rye](https://github.com/astral-sh/rye) [asdf:Azuki-bar/asdf-rye](https://github.com/Azuki-bar/asdf-rye) |
Expand Down
6 changes: 6 additions & 0 deletions e2e-win/rust.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Describe 'node' {
It 'executes rust 1.82.0' {
mise x rust@1.82.0 -- rustc -V | Should -BeLike "rustc 1.82.0*"
}
}
6 changes: 6 additions & 0 deletions e2e/plugins/core/test_rust
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash

export MISE_RUSTUP_HOME="$MISE_DATA_DIR/rustup"
export MISE_CARGO_HOME="$MISE_DATA_DIR/cargo"

assert_contains "mise x rust@1.82.0 -- rustc --version" "rustc 1.82.0"
2 changes: 1 addition & 1 deletion registry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ rome.backends = ["asdf:kichiemon/asdf-rome"]
rstash.backends = ["asdf:carlduevel/asdf-rstash"]
ruby.backends = ["core:ruby"]
ruff.backends = ["ubi:astral-sh/ruff", "asdf:simhem/asdf-ruff"]
rust.backends = ["asdf:code-lever/asdf-rust"]
rust.backends = ["core:rust", "asdf:code-lever/asdf-rust"]
rust-analyzer.backends = ["aqua:rust-lang/rust-analyzer", "asdf:Xyven1/asdf-rust-analyzer"]
rustic.backends = ["ubi:rustic-rs/rustic"]
rye.backends = ["aqua:astral-sh/rye", "asdf:Azuki-bar/asdf-rye"]
Expand Down
13 changes: 13 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,19 @@
}
}
},
"rust": {
"additionalProperties": false,
"properties": {
"cargo_home": {
"description": "Path to the cargo home directory. Defaults to ~/.cargo or %USERPROFILE%\\.cargo",
"type": "string"
},
"rustup_home": {
"description": "Path to the rustup home directory. Defaults to ~/.rustup or %USERPROFILE%\\.rustup",
"type": "string"
}
}
},
"shorthands_file": {
"description": "Path to a file containing custom tool shorthands.",
"type": "string"
Expand Down
12 changes: 12 additions & 0 deletions settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,18 @@ type = "Bool"
optional = true
description = "Set to true to enable verbose output during ruby installation."

[rust.cargo_home]
env = "MISE_CARGO_HOME"
type = "Path"
optional = true
description = "Path to the cargo home directory. Defaults to ~/.cargo or %USERPROFILE%\\.cargo"

[rust.rustup_home]
env = "MISE_RUSTUP_HOME"
type = "Path"
optional = true
description = "Path to the rustup home directory. Defaults to ~/.rustup or %USERPROFILE%\\.rustup"

[shorthands_file]
env = "MISE_SHORTHANDS_FILE"
type = "Path"
Expand Down
8 changes: 4 additions & 4 deletions src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ pub fn make_symlink(target: &Path, link: &Path) -> Result<(PathBuf, PathBuf)> {

#[cfg(windows)]
//#[deprecated]
pub fn make_symlink(_target: &Path, _link: &Path) -> Result<(PathBuf, PathBuf)> {
unimplemented!("make_symlink is not implemented on Windows")
pub fn make_symlink(target: &Path, link: &Path) -> Result<(PathBuf, PathBuf)> {
junction::create(target, link)
.wrap_err_with(|| format!("failed to ln -sf {} {}", target.display(), link.display()))?;
Ok((target.to_path_buf(), link.to_path_buf()))
}

#[cfg(windows)]
Expand Down Expand Up @@ -403,8 +405,6 @@ pub fn make_executable<P: AsRef<Path>>(path: P) -> Result<()> {

#[cfg(windows)]
pub fn make_executable<P: AsRef<Path>>(path: P) -> Result<()> {
trace!("chmod +x {}", display_path(&path));
warn!("make executable is not available on Windows, use windows_executable_extensions settings instead");
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions src/plugins/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::plugins::core::go::GoPlugin;
use crate::plugins::core::java::JavaPlugin;
use crate::plugins::core::node::NodePlugin;
use crate::plugins::core::ruby::RubyPlugin;
use crate::plugins::core::rust::RustPlugin;
#[cfg(unix)]
use crate::plugins::core::zig::ZigPlugin;
use crate::timeout::run_with_timeout;
Expand All @@ -33,6 +34,7 @@ mod node;
mod python;
#[cfg_attr(windows, path = "ruby_windows.rs")]
mod ruby;
mod rust;
#[cfg(unix)]
mod zig;

Expand All @@ -47,6 +49,7 @@ pub static CORE_PLUGINS: Lazy<BackendMap> = Lazy::new(|| {
Arc::new(NodePlugin::new()),
Arc::new(PythonPlugin::new()),
Arc::new(RubyPlugin::new()),
Arc::new(RustPlugin::new()),
Arc::new(ZigPlugin::new()),
];
#[cfg(windows)]
Expand All @@ -59,6 +62,7 @@ pub static CORE_PLUGINS: Lazy<BackendMap> = Lazy::new(|| {
Arc::new(NodePlugin::new()),
Arc::new(PythonPlugin::new()),
Arc::new(RubyPlugin::new()),
Arc::new(RustPlugin::new()),
// Arc::new(ZigPlugin::new()),
];
plugins
Expand Down
Loading

0 comments on commit de3a209

Please sign in to comment.