Repository navigation
feat(shim): add native .exe shim mode for Windows #8045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
bf92ca0
4fb076a
b38087c
bf5bba8
654e9bf
e2012cd
d4ff85e
d96ca2d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| [package] | ||
| name = "mise-shim" | ||
| version = "2026.2.5" | ||
| edition = "2024" | ||
| license = "MIT" | ||
| description = "Native executable shim for mise" | ||
| homepage = "https://github.com/jdx/mise" | ||
| repository = "https://github.com/jdx/mise" | ||
|
|
||
| [[bin]] | ||
| name = "mise-shim" | ||
| path = "src/main.rs" | ||
|
|
||
| [dependencies] | ||
| # zero external dependencies — only std |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2026 Jeff Dickey | ||
| Copyright (c) 2026 Jan Killian | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| of this software and associated documentation files (the "Software"), to deal | ||
| in the Software without restriction, including without limitation the rights | ||
| to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| copies of the Software, and to permit persons to whom the Software is | ||
| furnished to do so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| // Based on https://github.com/iki/mise-shim by Jan Killian (MIT License) | ||
|
|
||
| use std::env; | ||
| use std::process::{Command, exit}; | ||
|
|
||
| fn main() { | ||
| let exe = env::current_exe().unwrap_or_else(|e| { | ||
| eprintln!("mise-shim: failed to determine executable path: {e}"); | ||
| exit(1); | ||
| }); | ||
| let tool = exe | ||
| .file_stem() | ||
| .unwrap_or_else(|| { | ||
| eprintln!("mise-shim: failed to determine tool name from executable path"); | ||
| exit(1); | ||
| }) | ||
| .to_os_string(); | ||
|
|
||
| let args = env::args_os().skip(1); | ||
|
|
||
| let status = Command::new("mise") | ||
| .arg("x") | ||
| .arg("--") | ||
| .arg(&tool) | ||
| .args(args) | ||
| .status(); | ||
|
|
||
| match status { | ||
| Ok(s) => exit(s.code().unwrap_or(1)), | ||
| Err(e) => { | ||
| eprintln!("mise-shim: failed to execute mise: {e}"); | ||
| eprintln!("Ensure `mise` is installed and available on your PATH."); | ||
| eprintln!("See https://mise.jdx.dev for installation instructions."); | ||
| exit(1); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -105,8 +105,13 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<( | |||||||||||||||||
| let mise_bin = file::which("mise").unwrap_or(env::MISE_BIN.clone()); | ||||||||||||||||||
| let mise_bin = mise_bin.absolutize()?; // relative paths don't work as shims | ||||||||||||||||||
|
|
||||||||||||||||||
| let is_windows_hardlink = cfg!(windows) && Settings::get().windows_shim_mode.eq("hardlink"); | ||||||||||||||||||
| if force || is_windows_hardlink { | ||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| let shim_mode = effective_shim_mode(&mise_bin); | ||||||||||||||||||
| #[cfg(not(windows))] | ||||||||||||||||||
| let shim_mode = String::new(); | ||||||||||||||||||
| let is_windows_hardlink_or_exe = | ||||||||||||||||||
| cfg!(windows) && (shim_mode == "hardlink" || shim_mode == "exe"); | ||||||||||||||||||
| if force || is_windows_hardlink_or_exe { | ||||||||||||||||||
| file::remove_all(*dirs::SHIMS)?; | ||||||||||||||||||
| } | ||||||||||||||||||
| file::create_dir_all(*dirs::SHIMS)?; | ||||||||||||||||||
|
|
@@ -143,9 +148,72 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<( | |||||||||||||||||
| Ok(()) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| fn find_mise_shim_bin(mise_bin: &Path) -> Option<PathBuf> { | ||||||||||||||||||
| // Look next to the mise binary first | ||||||||||||||||||
| if let Some(parent) = mise_bin.parent() { | ||||||||||||||||||
| let candidate = parent.join("mise-shim.exe"); | ||||||||||||||||||
| if candidate.is_file() { | ||||||||||||||||||
| return Some(candidate); | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| // Fall back to searching PATH | ||||||||||||||||||
| file::which("mise-shim.exe") | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| /// Resolve the effective Windows shim mode, falling back to "file" if "exe" is | ||||||||||||||||||
| /// requested but mise-shim.exe is not available. | ||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| fn effective_shim_mode(mise_bin: &Path) -> String { | ||||||||||||||||||
| let mode = Settings::get().windows_shim_mode.clone(); | ||||||||||||||||||
| if mode == "exe" && find_mise_shim_bin(mise_bin).is_none() { | ||||||||||||||||||
| warn!( | ||||||||||||||||||
| "mise-shim.exe not found next to {} or on PATH, falling back to \"file\" shim mode", | ||||||||||||||||||
| display_path(mise_bin) | ||||||||||||||||||
| ); | ||||||||||||||||||
| return "file".to_string(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
| mode | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| fn add_shim(mise_bin: &Path, symlink_path: &Path, shim: &str) -> Result<()> { | ||||||||||||||||||
| match Settings::get().windows_shim_mode.as_ref() { | ||||||||||||||||||
| match effective_shim_mode(mise_bin).as_ref() { | ||||||||||||||||||
| "exe" => { | ||||||||||||||||||
| if symlink_path.extension().and_then(|s| s.to_str()) == Some("exe") { | ||||||||||||||||||
| let mise_shim_bin = | ||||||||||||||||||
| find_mise_shim_bin(mise_bin).ok_or_else(|| eyre!("mise-shim.exe not found"))?; | ||||||||||||||||||
| // Copy mise-shim.exe as <tool>.exe | ||||||||||||||||||
| fs::copy(&mise_shim_bin, symlink_path).wrap_err_with(|| { | ||||||||||||||||||
| eyre!( | ||||||||||||||||||
| "Failed to copy {} to {}", | ||||||||||||||||||
| display_path(&mise_shim_bin), | ||||||||||||||||||
| display_path(symlink_path) | ||||||||||||||||||
| ) | ||||||||||||||||||
| })?; | ||||||||||||||||||
| Ok(()) | ||||||||||||||||||
| } else { | ||||||||||||||||||
| let shim_name = symlink_path | ||||||||||||||||||
| .file_name() | ||||||||||||||||||
| .unwrap_or_default() | ||||||||||||||||||
| .to_string_lossy(); | ||||||||||||||||||
| // Create extensionless bash script for Git Bash/Cygwin | ||||||||||||||||||
| file::write( | ||||||||||||||||||
| symlink_path, | ||||||||||||||||||
| formatdoc! {r#" | ||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||
|
|
||||||||||||||||||
| exec mise x -- {shim_name} "$@" | ||||||||||||||||||
| "#}, | ||||||||||||||||||
| ) | ||||||||||||||||||
| .wrap_err_with(|| { | ||||||||||||||||||
| eyre!( | ||||||||||||||||||
| "Failed to create shim script for {}", | ||||||||||||||||||
| display_path(symlink_path) | ||||||||||||||||||
| ) | ||||||||||||||||||
| }) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+195
to
+229
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation for the "exe" => {
if symlink_path.extension().and_then(|s| s.to_str()) == Some("exe") {
let mise_shim_bin = find_mise_shim_bin(mise_bin)?;
// Copy mise-shim.exe as <tool>.exe
fs::copy(&mise_shim_bin, symlink_path).wrap_err_with(|| {
eyre!(
"Failed to copy {} to {}",
display_path(&mise_shim_bin),
display_path(symlink_path)
)
})
} else {
let shim_name = symlink_path.file_name().unwrap().to_string_lossy();
// Also create extensionless bash script for Git Bash/Cygwin
file::write(
symlink_path,
formatdoc! {r#"
#!/bin/bash
exec mise x -- {shim_name} "$@"
"#},
)
.wrap_err_with(|| {
eyre!(
"Failed to create shim script for {}",
display_path(symlink_path)
)
})
}
} |
||||||||||||||||||
| "file" => { | ||||||||||||||||||
| let shim = shim.trim_end_matches(".cmd"); | ||||||||||||||||||
| // write a shim file without extension for use in Git Bash/Cygwin | ||||||||||||||||||
|
|
@@ -223,7 +291,7 @@ pub async fn get_shim_diffs( | |||||||||||||||||
| let mise_bin = mise_bin.as_ref(); | ||||||||||||||||||
| let (actual_shims, desired_shims) = tokio::join!( | ||||||||||||||||||
| get_actual_shims(mise_bin), | ||||||||||||||||||
| get_desired_shims(config, toolset) | ||||||||||||||||||
| get_desired_shims(config, mise_bin, toolset) | ||||||||||||||||||
| ); | ||||||||||||||||||
| let (actual_shims, desired_shims) = (actual_shims?, desired_shims?); | ||||||||||||||||||
| let out: (BTreeSet<String>, BTreeSet<String>) = ( | ||||||||||||||||||
|
|
@@ -287,7 +355,12 @@ fn list_shims() -> Result<HashSet<String>> { | |||||||||||||||||
| .collect()) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| async fn get_desired_shims(config: &Arc<Config>, toolset: &Toolset) -> Result<HashSet<String>> { | ||||||||||||||||||
| async fn get_desired_shims( | ||||||||||||||||||
| config: &Arc<Config>, | ||||||||||||||||||
| mise_bin: &Path, | ||||||||||||||||||
| toolset: &Toolset, | ||||||||||||||||||
| ) -> Result<HashSet<String>> { | ||||||||||||||||||
| let _mise_bin = mise_bin; // used on Windows only | ||||||||||||||||||
| let mut shims = HashSet::new(); | ||||||||||||||||||
| for (t, tv) in toolset.list_installed_versions(config).await? { | ||||||||||||||||||
| let bins = list_tool_bins(config, t.clone(), &tv) | ||||||||||||||||||
|
|
@@ -297,12 +370,22 @@ async fn get_desired_shims(config: &Arc<Config>, toolset: &Toolset) -> Result<Ha | |||||||||||||||||
| Vec::new() | ||||||||||||||||||
| }); | ||||||||||||||||||
| if cfg!(windows) { | ||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| let shim_mode = effective_shim_mode(_mise_bin); | ||||||||||||||||||
| #[cfg(not(windows))] | ||||||||||||||||||
| let shim_mode = String::new(); | ||||||||||||||||||
| shims.extend(bins.into_iter().flat_map(|b| { | ||||||||||||||||||
| let p = PathBuf::from(&b); | ||||||||||||||||||
| match Settings::get().windows_shim_mode.as_ref() { | ||||||||||||||||||
| match shim_mode.as_ref() { | ||||||||||||||||||
| "hardlink" | "symlink" => { | ||||||||||||||||||
| vec![p.with_extension("exe").to_string_lossy().to_string()] | ||||||||||||||||||
| } | ||||||||||||||||||
| "exe" => { | ||||||||||||||||||
| vec![ | ||||||||||||||||||
| p.with_extension("exe").to_string_lossy().to_string(), | ||||||||||||||||||
| p.with_extension("").to_string_lossy().to_string(), | ||||||||||||||||||
| ] | ||||||||||||||||||
|
Comment on lines
+402
to
+405
|
||||||||||||||||||
| vec![ | |
| p.with_extension("exe").to_string_lossy().to_string(), | |
| p.with_extension("").to_string_lossy().to_string(), | |
| ] | |
| // In "exe" mode, add_shim already creates both <tool>.exe and the | |
| // extensionless shim script. We only need to track the .exe path here | |
| // to avoid invoking add_shim twice for the same tool. | |
| vec![p.with_extension("exe").to_string_lossy().to_string()] |
Uh oh!
There was an error while loading. Please reload this page.