-
Notifications
You must be signed in to change notification settings - Fork 121
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
[FR] A way to use pwsh.exe
(PowershellCore) on Windows by default instead of cmd.exe
#677
Comments
you can use that runner today by pointing to that exe. you can't change defaults but that might break other makefiles you are importing (like the core makefiles) |
I can use that runner only if I use this config: [tasks.windows_start]
script_runner = "pwsh"
script_extension = "ps1" # If I remove this line it doesn't work!
script = "echo hello"
[tasks.start]
windows_alias = "windows_start" |
yes exactly! [tasks.powershell]
private = true # do not call it directly
script_runner = "pwsh"
script_extension = "ps1"
[tasks.print_hello]
extend = "powershell"
script = "echo hello"
[tasks.something-else]
extend = "powershell"
script = "echo whatever...." however, if you want multi platform, you can add the .windows like this: [tasks.print_hello]
script = "echo hello from non windows"
[tasks.print_hello.windows]
extend = "powershell"
script = "echo hello from windows" also if you want to have some automatic handling without doing extend, you can write a custom cargo-make plugin: |
Thanks. It may work, but I feel it could be done better. Each time the script starts it must create a temporary A way to directly call |
you can use the command and args if possible. meaning put in command pwsh and in args the script (if powershell supports that...) |
I'll try now. Anyway, I'm having this error trying with this code: [tasks.powershell]
private = true
script_runner = "pwsh"
script_extension = "ps1"
[tasks.print_hello]
script = "echo hello from non windows"
[tasks.print_hello.windows]
extend = "powershell"
script = "echo hello from windows"
[config]
skip_core_tasks = true
skip_git_env_info = true
skip_rust_env_info = true
skip_crate_env_info = true
default_to_workspace = false makers print_hello
[cargo-make] INFO - makers 0.35.15
[cargo-make] INFO - Build File: Makefile.toml
[cargo-make] INFO - Task: print_hello
[cargo-make] INFO - Profile: development
[cargo-make] ERROR - Task print_hello is private
[cargo-make] WARN - Build Failed. Why? |
So I can confirm this works on Windows: pwsh.exe -C "echo hello from windows" Is there a way to use this? I tried with: [tasks.print_hello.windows]
extend = "pwsh"
args = ["echo hello from windows"]
[tasks.pwsh]
command = "pwsh.exe -C" but I get an error:
|
Ok the problem was I was using The error now is this:
with: [tasks.print_hello]
args = ["echo hello from non windows"]
[tasks.print_hello.windows]
extend = "pwsh"
args = ["echo hello from windows"]
[tasks.pwsh]
command = "pwsh.exe -C" Why? |
[tasks.print_hello.windows]
command = "pwsh.exe"
args = ["-C", "echo hello from windows"] |
@frederikhors please check my answer and feel free to reopen if not solved |
If I use this I need to repeat It would be AWESOME, really, to have in [config]
windows_shell = ["pwsh.exe", "-NoLogo", "-Command"] Like Justfile does. I cannot re-open this if you close it. Please, please, please create this config for us. We tried A LOT of libraries like this and Makers is THE BEST of all. If you add this it will be the NON PLUS ULTRA. PLEASE. 🙏 |
let me think of some solution here... |
Since you are thinking, it would also be very useful to have a way to pass a list of commands as if it were a script but by running each command by itself, without using the syntax of args. Example: [tasks.backup]
args = '''
echo Starting backup
command 1
command 2
command 3
echo Done backup
''' |
that feels like a script instead [tasks.backup]
script_runner = "pwsh"
script_extension = "ps1"
script = '''
echo Starting backup
command 1
command 2
command 3
echo Done backup
''' |
@frederikhors so I improved the cargo-make plugin system to enable users to create tasks on the fly and run them. so i created a powershell plugin: naturally that plugin code is not inside cargo-make so you do have to put it in your makefile (as the example i linked to shows). in order to test it, please use the dev 0.35.16 branch and tell me if it works well for you. |
by the way, with plugins, you can expand mine to support a list of commands as you wanted. but you will have to implement that. |
@frederikhors this is now released so you can use the official cargo-make version with this plugin code |
Thank you very much. Unfortunately now with plugins it has become really complex, even just to understand. I cannot present this solution to the team. Thank you very much also for your speed. I had something much simpler in mind, like justfile does. Thanks again. |
than maybe i didn't explain it well, since it simplifies your work. i'm not sure if its 1 project or multiple or a workspace, but it supports all very easily.
extends = "plugins.toml"
[env]
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true see https://github.com/sagiegurari/cargo-make#usage-workspace-extend explanation about that. than when you define tasks in the crate makefile just do [tasks.task1]
plugin = "powershell"
args = ["echo whatever..."] Lets say you have multiple projects of standalone crates.... [config]
load_script = "git clone git@mygitserver:user/project.git /home/myuser/common" see more at: https://github.com/sagiegurari/cargo-make#usage-load-scripts lets say you have only one standalone repo and thats it. |
Ok. Thanks again. But for a moment imagine if everything you are telling me can be solved without plugins and without all this with a simple line: [config]
windows_shell = ["pwsh.exe", "-NoLogo", "-Command"]
[tasks.hello]
cmd = "echo hello from NON windows"
[tasks.hello.windows]
cmd = "echo hello from windows" Great, right? |
and how would some tasks use powershell and some use something else? i'm not sure i get it? |
With the example I wrote above I want Makers to execute all commands in pwsh.exe when it comes to Windows. I don't want to use cmd.exe at all. |
but its not cmd. i'm not sure i get it.
what would tell it to use powershell capability in pwsh task and ignore it and call cargo in the cargo build task? |
@frederikhors maybe just is using cmd to call commands. thats similar to what cargo-make does with scripts. |
Ok. Let's recape. I know the difference between script and single command with args. In this post I was asking for a feature to call many commands in one task only without using script. But it's another question. Forget it. What I need is a way to use Makers on Windows/Linux with the same Makefile.toml file committed in my git project. What I need too is to NOT use cmd.exe on Windows only because you choose it but to specify another shell, like Justfile does (read the comment above). Is there a way to choose my shell for my commands using a config like Justfile? I do not like the plugin way you did: it's too complex for such a "simple" thing. |
ok, but I don't use cmd.exe for commands at all, only for scripts :) i gave the plugin solution as it is the way for users to expand on what cargo-make doesn't give out of the box by putting a reusable piece of code that they can 'call/use' in tasks. |
I'm using Windows and the new Powershell Core (
pwsh.exe
and notpowershell.exe
).It would be amazing to be able to use
pwsh.exe
instead ofcmd.exe
by default:The text was updated successfully, but these errors were encountered: