Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Practical WebAssembly

You're reading from   Practical WebAssembly Explore the fundamentals of WebAssembly programming using Rust

Arrow left icon
Product type Paperback
Published in May 2022
Publisher Packt
ISBN-13 9781838828004
Length 232 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Sendil Kumar Nellaiyapen Sendil Kumar Nellaiyapen
Author Profile Icon Sendil Kumar Nellaiyapen
Sendil Kumar Nellaiyapen
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Section 1: Introduction to WebAssembly
2. Chapter 1: Understanding LLVM FREE CHAPTER 3. Chapter 2: Understanding Emscripten 4. Chapter 3: Exploring WebAssembly Modules 5. Section 2: WebAssembly Tools
6. Chapter 4: Understanding WebAssembly Binary Toolkit 7. Chapter 5: Understanding Sections in WebAssembly Modules 8. Chapter 6: Installing and Using Binaryen 9. Section 3: Rust and WebAssembly
10. Chapter 7: Integrating Rust with WebAssembly 11. Chapter 8: Bundling WebAssembly Using wasm-pack 12. Chapter 9: Crossing the Boundary between Rust and WebAssembly 13. Chapter 10: Optimizing Rust and WebAssembly 14. Other Books You May Enjoy

Running Hello World with Emscripten in the browser

In this section, we will see how to convert C/C++ code into the WebAssembly binary via Emscripten and run it in the browser.

Note

If the terminal says that the emcc command is not found, it is highly likely that you have missed setting up the environment variables. To set up the environment variables, run the following command from inside the emsdk folder: source ./emsdk_env.sh

Let's use the same code example used in the Generating asm.js using Emscripten section . Now, instead of just running emcc, let's pass the -o option and instruct emcc to generate the .html file:

$ emcc hello_web.c -o helloweb.html

Once completed, the following files are generated:

  • helloweb.js
  • helloweb.wasm
  • helloweb.html

Similar to the Node example, the generated JavaScript file is huge. We will learn how to optimize the file size later in this chapter.

Note

The -o option ensures all the files generated...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime