Skip to content

Commit f217e0d

Browse files
committed
detectwsl
1 parent 07385ab commit f217e0d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

base/sysinfo.jl

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export BINDIR,
3131
iswindows,
3232
isjsvm,
3333
isexecutable,
34-
which
34+
which,
35+
detectwsl
3536

3637
import ..Base: show
3738

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

414-
for f in (:isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
415+
"""
416+
Sys.detectwsl([os])
417+
418+
Runtime Predicate for testing if Julia is running inside WSL.
419+
"""
420+
function detectwsl(os::Symbol)
421+
islinux(os) &&
422+
isfile("/proc/sys/kernel/osrelease") &&
423+
contains(read("/proc/sys/kernel/osrelease", String), r"Microsoft|WSL"i)
424+
end
425+
426+
for f in (:detectwsl, :isunix, :islinux, :isbsd, :isapple, :iswindows, :isfreebsd, :isopenbsd, :isnetbsd, :isdragonfly, :isjsvm)
415427
@eval $f() = $(getfield(@__MODULE__, f)(KERNEL))
416428
end
417429

test/osutils.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
else
2929
@test Sys.windows_version() >= v"1.0.0-"
3030
end
31+
32+
@test !Sys.detectwsl(:Windows)
33+
if !Sys.islinux()
34+
@test !Sys.detectwsl()
35+
end
3136
end
3237

3338
@testset "@static" begin

0 commit comments

Comments
 (0)