I tried to get started with WebAssembly

Suddenly, I decided to try WebAssembly and tried it.

What is WebAssembly?

WebAssembly runs your code in a browser at high speed. The language that works on the front side of the Web was javascript. Since javascript is a dynamically typed language and is an interpreter type, it is intuitive and easy to write, but it is slow because it is executed while type inference. That's where WebAssembly comes in, which compiles a statically typed language into intermediate code and then converts it into a binary format. I understand that it is a technology that realizes faster execution speed by reducing the file size and shortening the parsing process by using this binary format. (Understanding after studying for about 30 minutes)

I haven't read it yet, but it looks good to deepen my understanding of the article WebAssembly below. https://qiita.com/ShuntaShirai/items/3ac92412720789576f22

getting started

The execution OS was Ubuntu 18.04.4. Ubuntu 16.04 seems to be the best. I tried to move it according to the following site. https://webassembly.org/getting-started/developers-guide/

First of all,

git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest

It is a procedure to install emsdk, clone from Github and install. later

source ./emsdk_env.sh --build=Release

Ready to execute the command through the path. From here, the main is to create a Web API in C language. Create a new hello directory and create hello.c with the following contents directly under it.

#include <stdio.h>
int main(int argc, char ** argv) {
  printf("Hello, world!\n");
}

If hello.c is created,

emcc hello.c -o hello.html

And compile hello.c. After compiling, the directory

ll
total 256
drwxr-xr-x 2 kerneltyu kerneltyu 4096 May 10 02:37 ./
drwxr-xr-x 3 kerneltyu kerneltyu 4096 May 10 02:35 ../
-rw-r--r--1 kerneltyu kerneltyu 84 May 10 02:37 hello.c
-rw-r--r--1 kerneltyu kerneltyu 102675 May 10 02:37 hello.html
-rw-r--r--1 kerneltyu kerneltyu 115460 May 10 02:37 hello.js
-rw-r--r--1 kerneltyu kerneltyu 21716 May 10 02:37 hello.wasm

You can create a file like this. There is a javascript file, html and wasm in binary format.

emrun --no_browser --port 8080 .

When you start up with and access localhost: 8080

wa-demo.png

A screen like this will be displayed. That's all for getting started with WebAssembly!

Question

There was something I didn't understand, so I'll keep it as a record.

  1. In this example, I don't think there was a part to use javascript. (Although a fair amount of code was written in the generated html and js) I don't really understand the advantages. Maybe I need to experiment with something that uses more js.
  2. What do you do when debugging in a browser? I wonder if it will be while spitting out logs. It doesn't seem to be as rich as js in a debug environment.
  3. I didn't understand how to associate html and wasm.

Impressions

It was good to realize that the era of developing web applications in C language is approaching. I feel that the background is that Web applications are getting richer and the demand for execution at the edge is increasing. I personally wanted to deepen the use at the edge. Suddenly I started writing, but I became even more interested. Let's study a little more.

reference

Serverless future created by WebAssembly and Rust WebAssembly

Recommended Posts

I tried to get started with WebAssembly
I tried to get started with Spring Data JPA
I tried to get started with Swagger using Spring Boot
Rails beginners tried to get started with RSpec
I started MySQL 5.7 with docker-compose and tried to connect
I tried to interact with Java
[Note] How to get started with Rspec
I tried to implement ModanShogi with Kinx
Get started with Gradle
I tried to verify AdoptOpenJDK 11 (11.0.2) with Docker image
I tried to make Basic authentication with Java
I tried to manage struts configuration with Coggle
I tried to manage login information with JMX
I also tried WebAssembly with Nim and C
How to get started with Eclipse Micro Profile
I tried to break a block with java (1)
I tried Getting Started with Gradle on Heroku
I tried what I wanted to try with Stream softly.
I tried to implement file upload with Spring MVC
I tried DI with Ruby
I tried to read and output CSV with Outsystems
I tried to implement TCP / IP + BIO with JAVA
[Java 11] I tried to execute Java without compiling with javac
Get started with Spring boot
I tried to get the distance from the address string to the nearest station with ruby
Get started with DynamoDB with docker
I tried to draw animation with Blazor + canvas API
Get started with "Introduction to Practical Rust Programming" (Day 3)
I tried to implement Stalin sort with Java Collector
I tried UPSERT with PostgreSQL.
I tried BIND with Docker
I tried to verify yum-cron
How to get started with creating a Rails app
I want to get along with Map [Java beginner]
roman numerals (I tried to simplify it with hash)
I tried to make an introduction to PHP + MySQL with Docker
I tried to create a java8 development environment with Chocolatey
I tried to modernize a Java EE application with OpenShift.
I tried to increase the processing speed with spiritual engineering
[Rails] I tried to create a mini app with FullCalendar
How to get started with Gatsby (TypeScript) x Netlify x Docker
I tried to link chat with Minecraft server with Discord API
[Rails] I tried to implement batch processing with Rake task
I tried to automate LibreOffice Calc with Ruby + PyCall.rb (Ubuntu 18.04)
Now is the time to get started with the Stream API
I tried to create a padrino development environment with Docker
How to get started with JDBC using PostgresSQL on MacOS
I tried upgrading from CentOS 6.5 to CentOS 7 with the upgrade tool
I tried to be able to pass multiple objects with Ractor
Let's get started with parallel programming
I tried to chew C # (indexer)
I tried morphological analysis with MeCab
I tried to summarize iOS 14 support
I tried UDP communication with Java
I tried to explain the method
I tried GraphQL with Spring Boot
I tried to summarize Java learning (1)
How to get along with Rails
I tried to understand nil guard
I tried Flyway with Spring Boot
I tried using WebAssembly Stadio (2018/4/17 version)