Skip to content
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
16 changes: 14 additions & 2 deletions base/sysinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export BINDIR,
iswindows,
isjsvm,
isexecutable,
which
which,
detectwsl

import ..Base: show

Expand Down Expand Up @@ -411,7 +412,18 @@ including e.g. a WebAssembly JavaScript embedding in a web browser.
"""
isjsvm(os::Symbol) = (os === :Emscripten)

for f in (:isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
"""
Sys.detectwsl([os])

Runtime Predicate for testing if Julia is running inside WSL.
Copy link
Member

Choose a reason for hiding this comment

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

How about this? (The 1.11 would have to be changed if this were to be backported to 1.10)

Suggested change
Runtime Predicate for testing if Julia is running inside WSL.
Runtime predicate for testing if Julia is running inside
Windows Subsystem for Linux (WSL).
!!! note
Unlike `Sys.iswindows`, `Sys.islinux` etc., this is a runtime tests, and thus
cannot meaningfully be used in `@static if ` constructs.
!!! compat "Julia 1.11"
This function requires at least Julia 1.11.

"""
function detectwsl(os::Symbol)
islinux(os) &&
isfile("/proc/sys/kernel/osrelease") &&
contains(read("/proc/sys/kernel/osrelease", String), r"Microsoft|WSL"i)
end

for f in (:detectwsl, :isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
@eval $f() = $(getfield(@__MODULE__, f)(KERNEL))
end

Expand Down
5 changes: 5 additions & 0 deletions test/osutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
else
@test Sys.windows_version() >= v"1.0.0-"
end

@test !Sys.detectwsl(:Windows)
if !Sys.islinux()
@test !Sys.detectwsl()
end
end

@testset "@static" begin
Expand Down