Skip to content

Herman J. Radtke III

fastly/lucet in five minutes

Lucet is Fastly's native WebAssembly compiler and runtime. I am a big fan of Rust, Fastly and WASM. Especially WASM on the server via WASI. I jumped right in and tried to get my own lucet program running, but the setup is a rather long process. My plan was to introduce lucet to some colleagues at my local Rust meetup. I am a huge fan of Rust, but the compile times are an issue. Spending 30 minutes on setup was a non-starter. I was excited when I saw that Fastly published a Docker container:

However, this container was built for people developing on lucet. The container has all of the required dependencies, but still requires the same initial setup process. So, I decided to take advantage of Docker's multi-stage build process to create a container that has lucet already built. It comes in at the slim size of 107 MB, which should make it fast to download.

Here is how you can get lucet running a simple Hello World program in 5 minutes.

$ docker pull hjr3/lucet
$ cat hello.c
#include <stdio.h>

int main(void)
    puts("Hello world");
    return 0;
$ docker run --rm -it -v "$(pwd)":/usr/local/src hjr3/lucet wasm32-unknown-wasi-clang -Ofast -o hello.wasm hello.c
$ docker run --rm -it -v "$(pwd)":/usr/local/src hjr3/lucet lucetc-wasi -o hello.wasm
$ docker run --rm -it -v "$(pwd)":/usr/local/src hjr3/lucet lucet-wasi
Hello world

This docker container provides a version of clang capable of compiling to wasm via the wasm32-unknown-wasi-clang command. It is a not a requirement to compile your program to wasi using wasm32-unknown-wasi-clang in this docker container. The only requirement is that you compile the program to wasi before using lucetc-wasi. Also, take note that lucetc-wasi and lucet-wasi have very similar spellings, but are indeed two different programs.

If you are wondering why I did not demo converting a Rust program to WASI, we are blocked until wasm32-unknown-wasi is a valid target in rustup. As soon as that target is available, then I plan on creating another post showing how to get Rust + lucet working together. See WASI example using Rust and Lucet for a Rust example that runs on lucet.

Lucet is not 1.0 yet and I expect to be changing it a lot. As of this moment, the hjr3/lucet container is built against fastly/lucet commit e6b399b. As new changes come in, I will do my best to update the container. I may setup an automated process if this proves useful to people. I will tag each version against the fastly/lucet commit the container is built against.