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
Support cmd.exe on windows #326
Comments
The use case that I'm most interested in here is being able to set up a single justfile that works across windows/mac/linux. My (initial, unsubstantiated) thought is that, for most commands, I'll want them to work on both Now, we could have these split out into different justfiles (distinguished by extension, like you suggested) - but it would make a lot more sense to me if they were actually packed into a single file, with a concise syntax to specify different "implementations" of the same command, for different shells. Here's an example syntax (not a serious suggestion, just for discussion purposes):
This syntax can naturally be extended to specify that a single implementation happens to work across both shells:
This feature does have some overlap with the ability to specify an interpreter through a shebang-style line, but the key difference I'm proposing is that a single "command" (from the user's perspective) can have multiple different implementations for different platforms. What I'm getting at, is that I'd like to be able to suggest a single workflow/command to run for both windows and mac users, while also making it obvious which commands are not (yet) translated for my platform. So, for example,
Of course, there are a lot of other ways to solve the same "one workflow for all platforms" problem. This is just one thought. 😄 |
I actually think the syntax you propose is pretty reasonable, since it kind of looks like rust attributes, and it looks natural in I'm wondering how |
We have to solve the same problem of "which version to run", regardless of whether the commands are in one file or across several... no? In your original proposal, a user could (I think?) have both a As to actually making the choice, that's a good question, it's not immediately obvious what it should do. As a dummy proposal, we could start out by always preferring |
I would personally suggest a different approach:
test: test-{{os()}} This allows Windows users to use a decent shell, allow existing just recipes to work, adds functionality that is otherwise useful and allows users to write recipes that work cross-platform. Just my opinion, would love to see something created around this! |
@joshuawarner32 Yeah, totally, the problem of which version to run exists for both versions, just curious to hear your thoughts. I think preferring I'm wary of changing behavior based on autodetecting what shells are available, since it might vary unexpectedly based on installing or uninstalling different packages, or depend on whether @justdan96 Thanks for mentioning Powershell! I had totally forgot that it was an option. Is powershell harder to learn than cmd.exe? If it's just a strictly better shell than |
CMD is lighter weight than PowerShell and supported farther back in Windows versions. PowerShell requires .NET be installed (for the most part) which isn't the default if you go back a few versions of Windows. Many older Windows users may be very familiar with CMD and BATCHfile creation. Most newer Windows shell scripters are going to use PowerShell though. It's at least as powerful as BASH with newer versions being backed by .NET. Though also far more verbose. So supporting both options has many advantages. If we're tagging the shell option then the mechanism to support one is the same or at least very similar for both, no? |
Powershell was included with the OS as far back as XP SP3, so you don't have to worry about support any more. Moreover it is a proper shell which even supports some Unix-like aliases such as ls and pwd. Appreciate the point about auto detection, and backwards compatibility is always a concern. Maybe special comments could switch behaviour? A switch for selecting shells might work. Are there any thoughts about introducing interpolation in recipe names, as I suggested? I thought that could allow switching by OS without introducing new syntax. |
As an aside I have partially got this working for us by creating a small passthru program called sh.exe that translates -cu to -command and then calls Powershell - works for us! |
@runimp: Thanks for the info! Is PowerShell slower to start up than cmd.exe? Supporting both shells is definitely a good idea, however there almost always winds up being incompatibilities between shells, so I'd rather start with one and add support for others as necessary, instead of trying to support everything right out of the gate. @justdan96 I think that adding some kind of syntax to set the default shell for the entire justfile is reasonable. The actual syntax is up for bikeshedding. |
Also, @justdan96, that's a pretty sweet workaround. |
What about adopting something like rust's cfg attributes wholesale? The syntax is familiar to Rust users and the attribute would be ignored as comments by older versions. You'd end up with something like #[cfg(shell="sh")
list:
ls -R .
#[cfg(shell="pwsh")]
list:
Get-ChildItem -Recurse . The semantics would be to ignore rules that aren't configured for the current shell (perhaps with a different error message for commands that are defined, but not defined for your current shell). I'm also 👍 for PowerShell. I even use it on Ubuntu sometimes (heresy, I know). |
Take another +1 for poweshell. @justdan96 can you give me more details about your passthru program? EDIT: I got the passthru program working. My issue was that I didn't realize it had to be an executable; I tried to use poweshell and batch scripts. I ended up writing it in Rust. |
@neganp Although old versions would ignore the comments, the non sh recipes would likely be broken, an duplicate recipe names would be an error, unfortunately. |
Ah, of course! Good point. |
I think that it would be a good idea to land a conservative version of this feature and try to punt on as many tricky details as possible. My thoughts on what that might look like:
# annotations may be on the same line:
[sh] foo:
ls /
# or on a previous line:
[powershell]
bar:
dir C:\\
There are lots of things we might want to add later, but those can wait, since they can be added in a backwards compatible fashion. In particular:
Adding this will look roughly like:
I don't have immediate plans to tackle this, so if someone is up for it let me know! I'm super happy to provide guidance and advice. |
I'd like to work on this some, but the next substantial chunk of time I can carve out is in mid August. I'll try to chip away at it until then unless someone else wants to take the lead. I can also split some of the points above into a Project if that would be helpful. |
@neganp Sweet! Cool, putting some of the above points into a Project sounds useful. We could also start a feature branch, into which you could land partial/intermediate PRs. And definitely ping me with questions, both about the |
That all sounds great. Unfortunately I don't know Rust but if you need any help with testing or documentation please let me know! |
I was thinking, if This would remove the cygwin/sh dependency on windows, and justfiles would naturally be cross-platform. This might be somewhat annoying, and we might have to bundle a cygwin-built However, it still wouldn't allow recipes written with cmd.exe/powershell syntax. |
I tested and using Busybox for Windows (https://github.com/rmyorston/busybox-w32) seems to work okay if you set the line endings to Unix. |
@justdan96 Thank you for the pointer! I tried out the windows build of busybox, and it seems like it might be a viable option for making Just and justfiles portable between windows and linux. Here is how it could work: Windows builds of Hopefully, most justfiles would just work on Windows and Linux. Busybox doesn't support all unix commands and options, but it supports quite a few, and definitely all the commonly used ones. What do you think? Any drawbacks that I'm not considering? Note that this would be orthogonal to the shell setting detailed in #361. If I ever get around to implementing that, users could still use it to opt into a different shell on all platforms. (@joshuawarner32, I think we talked a little about this at the recent Rust meetup, so thanks for pushing me to think about this!) |
I just released v0.5.0, which includes the ability to set the shell used for recipes and backticks on a justfile-wide basis. This gives This doesn't address the desire to write cross-platform justfiles, so I opened #531 to track that separately. I also included a summary of the discussion and design from this thread. I hope the new |
Currently, just uses
sh
to execute all recipes on windows. This requires users to have installed sh, usually from cygwin or git-bash.I would like to make this dependency optional. It should be possible for a user to create a justfile that uses
cmd.exe
to execute recipes.I'm not sure the best way to indicate that a justfile uses
cmd.exe
for recipe execution, but my thought it to have just search for a file calledjustfile.com
, and if it finds it usecmd.exe
to execute all recipes within. It may be desirable to allow individual recipes to usecmd.exe
, or to give some kind of syntax within a justfile, aside from the name, for usingcmd.exe
so all that is up in the air.I don't know enough about windows to be able to do this, so I'm looking for help! If you're a windows dev and would like to implement this, do reach out!
The text was updated successfully, but these errors were encountered: