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

is_wsl returns false negative when using WSL2 #9208

Closed
mon opened this issue Sep 2, 2021 · 4 comments
Closed

is_wsl returns false negative when using WSL2 #9208

mon opened this issue Sep 2, 2021 · 4 comments

Comments

@mon
Copy link
Contributor

mon commented Sep 2, 2021

Describe the bug
#8445 is hitting me again, where Windows EXEs attempt to be wrapped using mono. This is caused by is_wsl using the check:
'microsoft' in platform.version().lower()

Which fails on WSL2, as platform.version() in my case is #1 SMP Wed Oct 28 23:40:43 UTC 2020.

To Reproduce

project('test', 'c')

run_target('example',
    command : [find_program('/mnt/c/WINDOWS/system32/help.exe')]
)

Expected behavior
help.exe's default output is printed as meson runs the command, but instead it fails to find mono (which I do not have installed)

system parameters
Meson: 0.59.1
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal

@xclaesse
Copy link
Member

xclaesse commented Sep 2, 2021

Any suggestion how we can detect wsl2 then?

@mon
Copy link
Contributor Author

mon commented Sep 2, 2021

Good question, it seems we're in luck!

I just checked, on another machine, running platform.uname():

WSL 1:
uname_result(system='Linux', node='smol', release='4.4.0-19041-Microsoft', version='#1151-Microsoft Thu Jul 22 21:05:00 PST 2021', machine='x86_64', processor='x86_64')

WSL 2:
uname_result(system='Linux', node='smol', release='4.19.104-microsoft-standard', version='#1 SMP Wed Feb 19 06:37:35 UTC 2020', machine='x86_64', processor='x86_64')

So it seems that 'microsoft' in platform.release().lower() will work for both WSL 1 and WSL2, and hopefully into the future. Should I make a PR, or would you be faster?

@xclaesse
Copy link
Member

xclaesse commented Sep 2, 2021

They even changed to remove the capital letter, to be sure they break as many script as possible, well done.

Here they suggest reading /proc/version: microsoft/WSL#4071, they even have a meson.build example :D

So it seems that 'microsoft' in platform.release().lower() will work for both WSL 1 and WSL2, and hopefully into the future. Should I make a PR, or would you be faster?

Yes, I think that should be fine until they change it again... I haven't found a formal documented way of doing it, so we can only hope. PR welcome :)

@eli-schwartz
Copy link
Member

Fixed by linked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants