
Libc++ 9.0.0 adds explicit support for WASI - iwillrunoutofsp
https://releases.llvm.org/9.0.0/projects/libcxx/docs/ReleaseNotes.html
======
mikece
Is WASI (WebAssembly System Interface) a way to run WebAssembly outside of the
browser on (theoretically) any device or is this a way to do systems
programming in WebAssembly?

~~~
phickey
Its an evolving standard set of system interfaces. Right now it supports
sandboxed access to the filesystem via a POSIX-like api, as well as other
basic interfaces like argv, environment variables, random numbers, and timers.

[https://wasi.dev](https://wasi.dev)

------
MuffinFlavored
Say you have `shared_library.so` which exposes methods/APS `foo()` and `bar()`

How would you load them/link against them + call them in Webassembly land?

~~~
pjmlp
By using dynamic loading capabilities of WebAssembly runtimes.

Watch Lin Clark's closing keynote at RustConf 2019.

[https://www.youtube.com/watch?v=VlIydW5Fojw](https://www.youtube.com/watch?v=VlIydW5Fojw)

~~~
MuffinFlavored
Doesn't it kind of stink that there are so many WebAssembly runtimes?
Fragmentation, different ways of doing things, etc.

~~~
krapp
No, this is what freedom and innovation looks like.

Javascript has become mostly a lost cause as far as open source development
goes, as it's basically owned and controlled by NPM Inc and corporate
interests now, but WebAssembly at least still has the possibility of remaining
open.

At the very least, we should go through a period of experimentation by the
community to settle on the best possible solutions (or sets of solution) and
let things mature a bit, first. Now is not the time to bless a single runtime,
package manager, etc.

~~~
pjmlp
WebAssembly is developed by the same corporations that own JavaScript.

~~~
krapp
They don't own the runtime and package manager, though.

Although Wasmer does come with a package manager (WAPM) that uses a
proprietary registry like NPM, at least the developers have said they're
committed to decentralized hosting[0]. Maybe someone can come up with a
completely distributed package management alternative, which I would prefer,
but at least Webassembly isn't yet at the degree of centralization that
Javascript is.

[0][https://news.ycombinator.com/item?id=19732794](https://news.ycombinator.com/item?id=19732794)

~~~
pjmlp
Which are utterly meaningless with the specification developed by said
corporations.

And really, the only thing going for WebAssembly is being the PNaCL that those
corporations were willing to agree on.

~~~
krapp
It's not the best possible scenario but "utterly meaningless" is hyperbole.

Certainly it's better not to have every aspect of a language be centralized.
It's already near impossible to distribute Javascript, or even software in
many languages, without going through NPM. WebAssembly, thankfully, isn't
there yet.

~~~
pjmlp
It surely is meaningless, because whatever your favourite WebAssembly
implementation is capable of, ultimately it only matters if it is spec
compliant.

A spec, which is under control of those organisations.

~~~
iwillrunoutofsp
What organisations should control a standard if not those that develop
implementations?

~~~
pjmlp
The point is that WebAssembly isn't something independent of JavaScript
masters control as the OP is portraying.

------
bla3
I'm not very familiar with WASI. For this to be useful for in-browser wasm
apps, would browser wasm runtimes have to implement WASI too? If so, are any
browsers looking at doing this?

I do know that there are WASI runtimes for non-browser wasm applications.

~~~
matthewbauer
I don't think this exists yet, but it is definitely possible to write a WASI
runtime in pure JavaScript. A precursor to WASI, jfbastien's musl fork, had
one:

[https://github.com/jfbastien/musl/blob/wasm-
prototype-1/arch...](https://github.com/jfbastien/musl/blob/wasm-
prototype-1/arch/wasm32/wasm.js)

------
matthewbauer
Exceptions still don't work! That ends up making lots of C++ code not
compilable.

~~~
azakai
That's not a limitation of WASI - WASI is just the system APIs.

Exceptions don't work natively in wasm yet, that's true. But they do work in
wasm+JS (using JS exceptions for unwinding, in Emscripten).

~~~
matthewbauer
Yeah, Emscripten does support exceptions, but I don't think Emscripten creates
WASI yet? It would be useful to separate out the exception handling from
Emscripten to a runtime library so that other projects could use it, without
relying on the entire Emscripten toolchain.

I suspect we'll get exception handling at some point, but for now so much
stuff just does not work without it. The whole idea of WASI is that it is not
JavaScript-specific, so needing some JavaScript code just to get this basic
feature is kind of surprising.

~~~
azakai
Emscripten does use some WASI APIs already, both normally and especially in
standalone mode [1].

But yeah, for now WASI and wasm don't provide enough to do things like C++
exceptions, longjmp, etc., so Emscripten supports them using non-WASI APIs.

Native exception handling for wasm is being worked on. If we don't want to
wait for that, we could do exceptions using Asyncify [2]. But since we have
the JS+wasm option for now, and native support coming, that's maybe not worth
it.

[1] [https://github.com/emscripten-
core/emscripten/wiki/WebAssemb...](https://github.com/emscripten-
core/emscripten/wiki/WebAssembly-Standalone)

[2]
[https://www.youtube.com/watch?v=qQOP6jqZqf8](https://www.youtube.com/watch?v=qQOP6jqZqf8)

------
dmitrygr
WebAssembly people continue to reinvent java, it seems

~~~
pjmlp
Not only Java

UNCOL -
[https://en.wikipedia.org/wiki/UNCOL](https://en.wikipedia.org/wiki/UNCOL)

IBM i ILE -
[https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/...](https://www.ibm.com/support/knowledgecenter/en/ssw_ibm_i_73/ilec/ilecmain.htm)

IBM z/OS Language Environment -
[https://www.ibm.com/support/knowledgecenter/zosbasics/com.ib...](https://www.ibm.com/support/knowledgecenter/zosbasics/com.ibm.zos.zappldev/zappldev_88.htm)

Xerox Mesa -
[http://www.softwarepreservation.org/projects/lang/mesa](http://www.softwarepreservation.org/projects/lang/mesa)

Xerox Interlisp-D -
[http://www.softwarepreservation.org/projects/LISP/interlisp_...](http://www.softwarepreservation.org/projects/LISP/interlisp_family/#Interlisp-
D_)

UCSD P-Code -
[https://en.wikipedia.org/wiki/P-code_machine](https://en.wikipedia.org/wiki/P-code_machine)

Modula-2 M-Code -
[https://www.cfbsoftware.com/modula2/](https://www.cfbsoftware.com/modula2/)

CLR - [https://www.ecma-
international.org/publications/standards/Ec...](https://www.ecma-
international.org/publications/standards/Ecma-335.htm)

PNaCL naturally - [https://developer.chrome.com/native-
client/reference/pnacl-b...](https://developer.chrome.com/native-
client/reference/pnacl-bitcode-abi)

And many many others that I didn't bother to refer to, just WebAssembly is
cooler somehow.

~~~
msla
And with all of that, it's utterly disqualifying for a systems language to
have garbage collection.

The fact it's been done means it's impossible to do. Well-known fact.

~~~
pjmlp
Xerox PARC, TI, MIT, ETHZ, Microsoft, Apple and Google beg to differ.

In fact, Swift, Go, Java and .NET Native seem to be doing relatively well
across their systems level projects, regardless on what naysayers think.

Swift as C and Objective-C replacement on Apple platforms.

Go as the implementation of gVisor used on ChromeOS Crostini security layer
and Compute Cloud, Android GPGPU debugger, Fuchsia's TCP/IP stack.

Java, alongside C++ for writing Project Trebel and Android Things drivers.
Letting aside all those real time Java projects that run it bare metal, using
the likes of PTC, Aicas and Gemalto compilers.

.NET Native across Windows IoT Core and Azure Edge modules.

But lets keep hating GC systems based languages instead.

~~~
msla
Either I suck at conveying sarcasm or you suck at picking up on it.

------
svnpenn
I still dont understand the point of this. Why are people trying to turn
JavaScript into a systems programming language? It isnt, has never been, and
never will be that.

If you wish to use a systems programming language, use a systems programming
language. Plenty of old ones (Java, C, C++) and plenty of new ones (Go, D,
Nim, Rust, Zig) are available. Its like people took a square piece of rock and
said:

A: hey, lets chip off some corners so that this can roll!

B: but now its an octagon...

A: well if you put it on a hill it can tumble down!

All the while several styles of modern wheels sit behind them.

~~~
josephg
Uh, I think you have the metaphor the wrong way around. The goal of wasm /
wasi isn’t to allow javascript to be a systems language. It’s to allow systems
languages to be used in javascript, or allow them to interoperate with one
another or run on different operating systems, or run on different hardware
platforms.

In javascript we’ve been stuck using octagon wheels but there’s all these new
modern wheels sitting around that we haven’t been able to use because browsers
could only run javascript. But now we have a way to fit the modern wheels on
our javascript car.

~~~
snagglegaggle
But I gave you octagon wheels because I don't want you using real wheels.

~~~
josephg
You don’t want web developers to have access to the tools we need to make
websites cpu and and memory efficient?

I for one am sick of web apps being so slow and bloated. The day react’s code
runs in wasm with native wsdl calls is the day websites the world over will
suddenly get a lot faster. What is the problem with that?

~~~
fredsanford
And also the day every browser will turn into IE 5.x

