www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - Spasm 0.1.3 released - with bindings to web apis

reply Sebastiaan Koppe <mail skoppe.eu> writes:
Spasm is a betterC library for web development that uses LDC to 
compile to WebAssembly, and I just released a major update.

It now has bindings to most web api's, like the dom, fetch, 
audio, webgl, etc.

So you can do things like this:

---
import spasm.bindings;
import spasm.dom;
import spasm.types;

extern (C) export void _start()
{
   auto elem = document.createElement("div").as!HTMLElement;
   elem.style.backgroundColor = "green";
   elem.innerHTML = "BLA BLA!";
   elem.addEventListener("mouseover",(event){
       console.log("onmouseover");
       console.log(event);
       console.log(event.as!MouseEvent.clientX);
     });

   auto root = document.querySelector("body").front;
   root.appendChild(elem);
}
---

And have it Just Work.

See the repo for more info: https://github.com/skoppe/spasm

It is still a WIP but I am getting there.
Jan 26
next sibling parent reply WebFreak001 <d.forum webfreak.org> writes:
On Saturday, 26 January 2019 at 10:24:05 UTC, Sebastiaan Koppe 
wrote:
 Spasm is a betterC library for web development that uses LDC to 
 compile to WebAssembly, and I just released a major update.

 It now has bindings to most web api's, like the dom, fetch, 
 audio, webgl, etc.

 So you can do things like this:

 ---
 import spasm.bindings;
 import spasm.dom;
 import spasm.types;

 extern (C) export void _start()
 {
   auto elem = document.createElement("div").as!HTMLElement;
   elem.style.backgroundColor = "green";
   elem.innerHTML = "BLA BLA!";
   elem.addEventListener("mouseover",(event){
       console.log("onmouseover");
       console.log(event);
       console.log(event.as!MouseEvent.clientX);
     });

   auto root = document.querySelector("body").front;
   root.appendChild(elem);
 }
 ---

 And have it Just Work.

 See the repo for more info: https://github.com/skoppe/spasm

 It is still a WIP but I am getting there.
amazing! I would really like to try it but it seem the precompiled LDC version doesn't support the wasm output and I have no idea what that wercker stuff is you mentioned or how to use the container you sent with compiling on my local filesystem and not inside a sandbox :/ Still looks great having this, especially now with all these APIs. I would really like to try making WebGL run with this in the future Great work, keep it up!
Jan 26
parent reply Sebastiaan Koppe <mail skoppe.eu> writes:
On Saturday, 26 January 2019 at 15:34:15 UTC, WebFreak001 wrote:
 amazing! I would really like to try it but it seem the 
 precompiled LDC version doesn't support the wasm output and I 
 have no idea what that wercker stuff is you mentioned or how to 
 use the container you sent with compiling on my local 
 filesystem and not inside a sandbox :/
Make sure you have installed docker on your machine (are you running windows?), go inside your workspace directory and run `docker run --rm -ti -v $PWD:/app --workdir /app dlang2/ldc-ubuntu:1.13.0 /bin/bash` This will start a docker container with ldc 1.13.0 installed on ubuntu. It will also mount the current directory under `/app`. Inside the container you can just run dub, etc. And on your host you can just edit the files.
 Still looks great having this, especially now with all these 
 APIs. I would really like to try making WebGL run with this in 
 the future
Have you seen the underrun example?
Jan 27
parent reply WebFreak001 <d.forum webfreak.org> writes:
On Sunday, 27 January 2019 at 09:22:19 UTC, Sebastiaan Koppe 
wrote:
 On Saturday, 26 January 2019 at 15:34:15 UTC, WebFreak001 wrote:
 amazing! I would really like to try it but it seem the 
 precompiled LDC version doesn't support the wasm output and I 
 have no idea what that wercker stuff is you mentioned or how 
 to use the container you sent with compiling on my local 
 filesystem and not inside a sandbox :/
Make sure you have installed docker on your machine (are you running windows?), go inside your workspace directory and run `docker run --rm -ti -v $PWD:/app --workdir /app dlang2/ldc-ubuntu:1.13.0 /bin/bash` This will start a docker container with ldc 1.13.0 installed on ubuntu. It will also mount the current directory under `/app`. Inside the container you can just run dub, etc. And on your host you can just edit the files.
 Still looks great having this, especially now with all these 
 APIs. I would really like to try making WebGL run with this in 
 the future
Have you seen the underrun example?
the underrun example looks really cool! I'm on linux but I don't use docker, that command you sent is something I would have honestly never found out myself, it's just too cryptic. I will try out making something with spasm soon!
Jan 29
parent reply Sebastiaan Koppe <mail skoppe.eu> writes:
On Wednesday, 30 January 2019 at 00:22:15 UTC, WebFreak001 wrote:
 the underrun example looks really cool! I'm on linux but I 
 don't use docker
Wait, you are on linux. Why doesn't your ldc have wasm target? How did you install it?
 I will try out making something with spasm soon!
Cool.
Jan 30
parent reply WebFreak001 <d.forum webfreak.org> writes:
On Wednesday, 30 January 2019 at 08:26:22 UTC, Sebastiaan Koppe 
wrote:
 On Wednesday, 30 January 2019 at 00:22:15 UTC, WebFreak001 
 wrote:
 the underrun example looks really cool! I'm on linux but I 
 don't use docker
Wait, you are on linux. Why doesn't your ldc have wasm target? How did you install it?
 I will try out making something with spasm soon!
Cool.
I install LDC from the arch repositories, which should just be the prebuilt binaries from the ldc repo I think
Jan 30
parent reply kinke <noone nowhere.com> writes:
On Wednesday, 30 January 2019 at 11:03:13 UTC, WebFreak001 wrote:
 I install LDC from the arch repositories, which should just be 
 the prebuilt binaries from the ldc repo I think
Nope, they aren't. I guess your problem is that you cannot *link* wasm; that will only work with v1.14 for distro packages (without integrated LLD).
Jan 30
parent reply Thomas Brix Larsen <brix brix-verden.dk> writes:
On Wednesday, 30 January 2019 at 11:49:17 UTC, kinke wrote:
 On Wednesday, 30 January 2019 at 11:03:13 UTC, WebFreak001 
 wrote:
 I install LDC from the arch repositories, which should just be 
 the prebuilt binaries from the ldc repo I think
Nope, they aren't. I guess your problem is that you cannot *link* wasm; that will only work with v1.14 for distro packages (without integrated LLD).
The targets wasm32 and wasm64 are missing in the Arch package.
Jan 31
parent kinke <noone nowhere.com> writes:
On Thursday, 31 January 2019 at 09:21:45 UTC, Thomas Brix Larsen 
wrote:
 The targets wasm32 and wasm64 are missing in the Arch package.
Ah, too bad. wasm is still considered an experimental LLVM target (at least for LLVM 7), so LLVM needs to be built in a special way (LLVM_EXPERIMENTAL_TARGETS_TO_BUILD CMake variable) to enable it.
Jan 31
prev sibling parent reply Mike Franklin <slavo5150 yahoo.com> writes:
On Saturday, 26 January 2019 at 10:24:05 UTC, Sebastiaan Koppe 
wrote:
 Spasm is a betterC library for web development that uses LDC to 
 compile to WebAssembly, and I just released a major update.

 It now has bindings to most web api's, like the dom, fetch, 
 audio, webgl, etc.
[...]
 See the repo for more info: https://github.com/skoppe/spasm

 It is still a WIP but I am getting there.
This is really cool; nice work! Over the past 6 months I've been working a lot with .Net's WASM implementation, code-named Blazor. I estimate I can build GUI applications at 20% the development cost, while also getting portability, and a more rich features set (alpha transparency, flow layout, SVG, video, GL, etc...). Bundled with Electron, it makes for a convenient cross-platform application GUI framework. It's actually changed everything I do for desktop and ARM Cortex-A embedded GUI work (still need something for Cortex-M, though), and I don't think I'll be going back. The upcoming .Net Core 3.0 will include something called Razor Components, previously called Server-Side Blazor. It uses Microsoft's SignalR (think web sockets) to create signals on the server, slots on the client, and to push UI render changes to the client. Are you aware of SignalR, and do you see something similar eventually being added to Spasm? Also, what are the limitations that prevent the D runtime (just druntime, not Phobos) from being ported to WASM? Again, nice work! Mike
Jan 26
parent Sebastiaan Koppe <mail skoppe.eu> writes:
On Saturday, 26 January 2019 at 23:40:01 UTC, Mike Franklin wrote:
 This is really cool; nice work!
Thanks.
 Are you aware of SignalR, and do you see something similar 
 eventually being added to Spasm?
I don't use .NET myself, but I once reverse engineered a signalR client for some data feed I wanted to listen to, so I am a little familiar with it. But why not use gRPC over websockets, or real-time graphQL? Spasm has bindings to the browsers websocket and I don't think its hard to connect that to a D client implementation of gRPC or graphQL.
 Also, what are the limitations that prevent the D runtime (just 
 druntime, not Phobos) from being ported to WASM?
The real blocker was the GC. In wasm the address space starts at 0, so almost everything looks like a pointer :) But now that we have a precise GC, that should be solved. Maybe some issues with threaded since Webassembly is currently single-threaded (although multithreading is on the roadmap.) So yeah, there aren't many blockers. I did actually try it a couple of months ago, and got pretty far. But I wanted to keep things lean and mean and decided to constrain it to betterC. I am first going to see how well I can implement some material-ui components. That is going to be the litmus test for the SPA framework part of spasm.
 Again, nice work!
Thanks. A lot of praise goes to the LDC team and the fact they build it on top of LLVM.
Jan 27