Practical WebAssembly by @sendilkumarn

I was lucky enough to get my hands on a copy of Practical WebAssembly by Sendil Kumar Nellaiyapen (Engineering Manager at Uber). I found the book very informative, sharing insights on the WebAssembly we use today, but also just-enough technical details behind the scenes to fully appreciate where we've come.

Running the examples on Windows, however, I found that the book lacked some clarity. Here's what I figured out.

To run the examples in Chapter 1, you'll need to download and install the LLVM compiler infrastructure (from GitHub), e.g. the 14.0.6 release for Windows. There's no need to build the toolchain from source. Once installed, you'll have access to clangemcc and other tools.

I found the output on Windows was different than the examples (presumably from a Mac). The sum.c example, looked like this after compilation by clang:

; ModuleID = 'sum.c'
source_filename = "sum.c"
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.32.31332"

; Function Attrs: mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn
define dso_local i32 @sum(i32 noundef %0, i32 noundef %1) local_unnamed_addr #0 {
%3 = add i32 %1, %0
ret i32 %3
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind readnone uwtable willreturn "frame-pointer"="none" "min-
legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-featur
es"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }

!llvm.module.flags = !{!0, !1, !2}
!llvm.ident = !{!3}

!0 = !{i32 1, !"wchar_size", i32 2}
!1 = !{i32 7, !"PIC Level", i32 2}
!2 = !{i32 7, !"uwtable", i32 1}
!3 = !{!"clang version 14.0.6"}


To run the examples in Chapter 2, the book lets you know that you need Python >= 3.7. To figure out if you do, run python --version from your Windows Terminal.

Sendil then goes to lengths to detail how the binding file that 
emcc
 produces interacts with the runtime environment (node, browser), the JavaScript environment and the Web Assembly runtime, which is all very interesting and very well described!

Chapter 2 also asks you to run the time command. There's no such command by default in Windows, but PowerShell instead offers the Measure-Command:

(Measure-Command { emcc .\optimization_check.c }).TotalSeconds


Next up: Exploring WebAssembly Modules! I can't wait 🤩
 
For more information about the author, see the link below:


Comments

Popular posts from this blog

Auto Mapper and Record Types - will they blend?

Unit testing your Azure functions - part 2: Queues and Blobs

Testing WCF services with user credentials and binary endpoints