daviwil / emscripten-guix

An example of building a C application with Emscripten on Guix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using Emscripten on Guix

Emscripten is a compiler toolchain that enables you to build native C/C++ applications (and more) to run in the browser via WebAssembly.

Since the emsdk includes a bunch of pre-compiled binaries, we need to use guix shell with the new --enable-fhs parameter to run it locally without having to build it from scratch.

Here’s how you can do that!

You can also see a demo of the program this repo builds.

Installing Emscripten in Guix Shell

This part is only necessary if you want to run Emscripten in Guix Shell. First of all, make sure you’ve run guix pull to ensure you have the latest Guix! Then, clone this repository and execute the following command in the repo folder:

guix shell --container --emulate-fhs --network -m manifest.scm -- ./install.sh

The manifest.scm file will give you a picture of the required dependencies for running Emscripten’s SDK distribution in Guix.

Installing Emscripten Manually

The Emscripten documentation explains this better than I can, but to get started quickly, make sure you have Python 3 installed and then follow these steps.

IMPORTANT: If you’re doing this manually in guix shell you will first need to set the SSL_CERT_FILE environment variable so that the emsdk script can download files correctly:

export SSL_CERT_FILE="$(python3 -m certifi)"

Now, run the following commands in your shell:

# Clone the emsdk to ./emsdk and install it
git clone https://github.com/emscripten-core/emsdk.git
cd emsdk
./emsdk install latest
./emsdk activate latest
. ./emsdk_env.sh

# Go back to your repository root
cd ..

Emscripten SDK should now be installed in the ./emsdk subfolder.

Building the Code

Check out the contents of build.sh to see how to use emcc to build the application and host it locally for testing.

Run it inside the container environment to give it a try:

guix shell --container --emulate-fhs --network -m manifest.scm -- ./install.sh

About

An example of building a C application with Emscripten on Guix

License:The Unlicense


Languages

Language:C 49.4%Language:Shell 43.7%Language:Scheme 7.0%