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 1 commit
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_string_lossy(); | ||
|
|
||
| let args: Vec<String> = env::args().skip(1).collect(); | ||
|
|
||
| let status = Command::new("mise") | ||
| .arg("x") | ||
| .arg("--") | ||
| .arg(tool.as_ref()) | ||
| .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 |
|---|---|---|
|
|
@@ -35,6 +35,17 @@ Describe 'shim_mode' { | |
| (Get-Item -Path (Join-Path -Path $shimPath -ChildPath go.cmd)).LinkType | Should -Be $null | ||
| } | ||
|
|
||
| It 'run on exe' { | ||
| changeShimMode "exe" | ||
|
|
||
| mise x go@1.23.3 -- where go | ||
| mise x go@1.23.3 -- go version | Should -BeLike "go version go1.23.3 windows/*" | ||
|
||
|
|
||
| $goShim = Get-Item -Path (Join-Path -Path $shimPath -ChildPath go.exe) | ||
| $goShim.LinkType | Should -Be $null | ||
| $goShim.Length | Should -BeGreaterThan 0 | ||
| } | ||
|
|
||
| It 'run on hardlink' { | ||
| mise settings windows_shim_mode "hardlink" | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -105,8 +105,14 @@ 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 { | ||||||||||||||||||
| let shim_mode = if cfg!(windows) { | ||||||||||||||||||
| Settings::get().windows_shim_mode.clone() | ||||||||||||||||||
| } else { | ||||||||||||||||||
| String::new() | ||||||||||||||||||
| }; | ||||||||||||||||||
| let is_windows_hardlink_or_exe = | ||||||||||||||||||
| cfg!(windows) && (shim_mode == "hardlink" || shim_mode == "exe"); | ||||||||||||||||||
| if force || is_windows_hardlink_or_exe { | ||||||||||||||||||
|
cursor[bot] marked this conversation as resolved.
Resolved
|
||||||||||||||||||
| file::remove_all(*dirs::SHIMS)?; | ||||||||||||||||||
| } | ||||||||||||||||||
| file::create_dir_all(*dirs::SHIMS)?; | ||||||||||||||||||
|
|
@@ -143,9 +149,56 @@ pub async fn reshim(config: &Arc<Config>, ts: &Toolset, force: bool) -> Result<( | |||||||||||||||||
| Ok(()) | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| #[cfg(windows)] | ||||||||||||||||||
| fn find_mise_shim_bin(mise_bin: &Path) -> Result<PathBuf> { | ||||||||||||||||||
| // Look next to the mise binary first | ||||||||||||||||||
| if let Some(parent) = mise_bin.parent() { | ||||||||||||||||||
| let candidate = parent.join("mise-shim.exe"); | ||||||||||||||||||
| if candidate.exists() { | ||||||||||||||||||
|
||||||||||||||||||
| if candidate.exists() { | |
| if candidate.is_file() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The which crate, which file::which seems to wrap, automatically handles executable extensions like .exe on Windows. Therefore, calling file::which("mise-shim.exe") in the or_else is redundant. You can simplify this to a single call to file::which("mise-shim").
| if let Some(found) = file::which("mise-shim").or_else(|| file::which("mise-shim.exe")) { | |
| if let Some(found) = file::which("mise-shim") { |
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copy operation writes to symlink_path.with_extension("exe"), but the error message reports the destination as display_path(symlink_path), which can be misleading (especially when symlink_path is extensionless). Use the same computed destination path in both the actual copy and the error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation for the "exe" shim mode is inefficient. It's called for each desired shim file (<tool>.exe and <tool>), but in both cases, it attempts to create both files. This results in redundant file operations. The function should only create the single file specified by its symlink_path argument, depending on whether it's the .exe or the extensionless script.
"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)
)
})
}
}
Copilot
AI
Feb 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In "exe" mode, add_shim already creates both <tool>.exe and the extensionless bash script. Returning both paths from get_desired_shims() likely causes add_shim to be invoked twice per tool, duplicating file I/O (two copies + two writes) and repeated find_mise_shim_bin() lookups. Consider returning only the .exe path for "exe" mode (and letting add_shim create the extensionless script as it already does), or alternatively adjust add_shim to create only the file corresponding to symlink_path.
| 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()] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
env::args()forces UTF-8Stringarguments and can be lossy/non-representable on some platforms;Commandis designed to work with OS-native strings. Preferenv::args_os().skip(1)and pass those directly to.args(...)(and consider keepingtoolas anOsString/OsStras well) to avoid any encoding edge cases.