Background:
I am doing a project where I need to open Host system browser. The WSL is causing some problems if I detect it as Linux so I need to detect if Host is WSL to fix it.
While I can do someting like this: https://github.com/microsoft/WSL/issues/4071 It would be convenient if we could have a Sys.iswsl() in Julia.
I would like to work on it myself but I couldn't understand Sys module .
Note that this would be different from all other Sys.is*
since this would have to be a runtime detection. Whether having it or not, giving it such similar a name would be misleading.
(It's more similar to detection of linux distribution)
@yuyichao why this would be a runtime detection? How does exactly OS is detected in Julia please help me understand.
why this would be a runtime detection
Because you are not running a different binary from the linux one.
How does exactly OS is detected in Julia please help me understand.
This has nothing to do with why it needs to be done at runtime. It has to be done at runtime simply because this is a runtime property. It is not known at compile time and it can't be stored in the code as a constant.
There's nothing special about OS detection in julia. In fact there is none. All what Sys.is*
do is returning a constant.
We can check the version/release of Linux during compile time which will tell us if its wsl ? see https://github.com/microsoft/WSL/issues/4071#issuecomment-496737093
No that's the wrong thing to do, that cannot tell you if you are running at runtime.
Again, it isn't about how to do the detection, it's about when to do the detection. The detection must be done after you download the binary from https://julialang.org/downloads/ when you start julia. It cannot be done when generating the binary you download.
In another word, you don't care about whether your julia is compiled on WSL (it's not). You care about if it is running on WSL. And that's different from every other Sys.is*
. It's not a property of the OS/target (i.e. ABI) it's a property of the distribution.
Okay thanks for clearing my confusion. I compile my Julia on wsl so I forgot that people download binaries 馃槃
I do think we need a WSL feature detection macro, since we will also need to start shipping WSL-specific CUDA binaries. We may want to rethink how Sys.
works in general. E.g. there's also the FreeBSD linux emulation layer.
I don't think any change to how Sys works is necessary. Adding this as runtime detection won't break anything. However, I do think there's currently an expectation that these are not runtime detection so I think a different name should be used for ones that are done at runtime to break that expectation.
@yuyichao what should be its name? It will help since I want to work on it
Maybe something with the word "detect" in it to indicate that active runtime detection is required for this.
How about Sys.detectwsl
?
Then in the future more runtime detection methods could be added for things like containers as Sys.detectcontainer
, etc.
Most helpful comment
Okay thanks for clearing my confusion. I compile my Julia on wsl so I forgot that people download binaries 馃槃