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

Introduce Sys.isWSL() #56671

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/path.jl
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ function uripath end
else
function uripath(path::String)
localpath = join(eachsplit(abspath(path), path_separator_re, keepempty=false), '/')
host = if ispath("/proc/sys/fs/binfmt_misc/WSLInterop") # WSL sigil
host = if Sys.isWSL()
distro = get(ENV, "WSL_DISTRO_NAME", "") # See <https://patrickwu.space/wslconf/>
"wsl\$/$distro" # See <https://github.com/microsoft/terminal/pull/14993> and <https://learn.microsoft.com/en-us/windows/wsl/filesystems>
else
Expand Down
14 changes: 13 additions & 1 deletion base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ A symbol representing the architecture of the build configuration.
"""
const ARCH = ccall(:jl_get_ARCH, Any, ())::Symbol


"""
Sys.KERNEL::Symbol

Expand Down Expand Up @@ -513,6 +512,19 @@ See documentation in [Handling Operating System Variation](@ref).
"""
iswindows(os::Symbol) = (os === :Windows || os === :NT)

"""
Sys.isWSL([os])

Predicate for testing if the OS is the Windows subsystem for Linux (version 2 or the original),
running under a derivative of Microsoft Windows NT.
See documentation in [Handling Operating System Variation](@ref).

!!! compat "Julia 1.12"
This function requires at least Julia 1.12.
"""
# https://superuser.com/questions/1749781/how-can-i-check-if-the-environment-is-wsl-from-a-shell-script
isWSL(os::Symbol) = ispath("/proc/sys/fs/binfmt_misc/WSLInterop") # WSL sigil
Comment on lines +523 to +526
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting a comment there might break the docstring lookup

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, why camelcase which isn't used anywhere in Julia?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, you aren't using the input argument, besides not defining the method you try to use elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes like this seems better:
#36354 (comment)

How about Sys.detectwsl?

I'll just abandon this/make a draft, since there's this other PR. If I don't see it move then I may work on it here later. There one implementation here outside of Julia:

https://github.com/tpapp/DefaultApplication.jl/pull/17/files


"""
Sys.isapple([os])

Expand Down