Skip to content
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

feat: add isWSL function to detect if Task is being ran on WSL #1731

Open
ssbarnea opened this issue Jul 25, 2024 · 5 comments
Open

feat: add isWSL function to detect if Task is being ran on WSL #1731

ssbarnea opened this issue Jul 25, 2024 · 5 comments
Labels
os: windows Issues that affect users on Windows.

Comments

@ssbarnea
Copy link
Contributor

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: -
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Jul 25, 2024
@andreynering andreynering added type: feature A new feature or functionality. os: windows Issues that affect users on Windows. and removed state: needs triage Waiting to be triaged by a maintainer. labels Jul 26, 2024
@andreynering andreynering changed the title Platforms renders as linux instead of windows when run under wsl feat: add isWSL function to detect if Task is being ran on WSL Jul 26, 2024
@andreynering
Copy link
Member

andreynering commented Jul 26, 2024

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.

@andreynering
Copy link
Member

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.

@vmaerten
Copy link
Member

I like the idea @andreynering

@alexhampu
Copy link

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.

@trulede
Copy link

trulede commented Sep 29, 2024

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).

@pd93 pd93 removed the type: feature A new feature or functionality. label Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
os: windows Issues that affect users on Windows.
Projects
None yet
Development

No branches or pull requests

8 participants
@ssbarnea @andreynering @vmaerten @pd93 @alexhampu @trulede @task-bot and others