task
task copied to clipboard
feat: add `isWSL` function to detect if Task is being ran on WSL
It seems that the platform is evaluated as "linux" instead of "windows" or at least something as "wsl" when you run taskfile on windows under wsl.
I am not totally surprised by this but it is still incorrect as it does not allow us to properly identify windows platform when we executed commands under wsl (we are forced to do that due to the build chain).
- Task version: 3.37.2
- Operating system: Windows with WSL
- Experiments enabled: -
Hey @ssbarnea,
Can we reliably detect that a Linux binary is ran under WSL? If so, we can consider adding another template function.
I wouldn't change the {{OS}} function because, tecnically, it is running on Linux because WSL is Linux, and I'm certain people rely on the current behavior. If we changed it to return windows it would break people's Taskfiles.
We can get some inspiration from https://github.com/scivision/detect-windows-subsystem-for-linux
There's potential to publish this on a standalone Go package on its own repository, so other people can benefit from it.
I like the idea @andreynering
This is something that will come really useful to support Windows devices as well as Linux and Mac, without fully rewriting a lot of task commands to use Powershell.
If you run running Task in/under the WSL then the OS is linux.
@ssbarnea why exactly do you need to know your Windows platform? Especially when you are running commands in Linux. If you are building software then, without question, you will need some kind of cross compiler. This is a normal thing and there are ways to deal with that (typically using environment variables).
In terms of detecting WSL ... I would suggest one of these ENVARS:
HOSTTYPE=x86_64 WSL2_GUI_APPS_ENABLED=1 WSLENV= WSL_DISTRO_NAME=Ubuntu-20.04 WSL_INTEROP=/run/WSL/791_interop
which will (probably**) be available to you when Task is running in WSL.
** Here I mean WSL Version 2 (version 1 is well in the past).