Skip to content

Commit

Permalink
Merge pull request #1327 from fermyon/tpmccallum-patch-17
Browse files Browse the repository at this point in the history
Update from version 14 to version 20
  • Loading branch information
Timothy McCallum authored Jun 26, 2024
2 parents c1044d4 + 90b39d5 commit 6641b2b
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions content/wasm-languages/c-lang.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ Since it supports the WASI specification, C can be used on the Fermyon Platform
The first step is to install the WASI SDK. If you use this broadly, it may be a good idea to install it in a common location. For our example, though, we will create a project and install the SDK inside of that project.

You can download the latest version from the [WASI releases page](https://github.com/WebAssembly/wasi-sdk/releases).
At the time of this writing, the latest version is `14.0`. Here's a command line example for a Mac:
At the time of this writing, the latest version is `20.0`:

```console
$ curl -O -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-14/wasi-sdk-14.0-macos.tar.gz
$ tar xf wasi-sdk-14.0-macos.tar.gz
$ curl -O -sSL https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-linux.tar.gz
$ tar -xzf wasi-sdk-20.0-linux.tar.gz
```

Now we can write a simple C program using WASI. Here is the text ouf `hello.c`:
Now we can write a simple C program using WASI. Here is the text of our `hello.c` file:

```c
#include <stdio.h>
Expand All @@ -94,10 +94,10 @@ int main() {
To compile this, we will use the `clang` that comes with the WASI SDK.

```console
./wasi-sdk-14.0/bin/clang --sysroot wasi-sdk-14.0/share/wasi-sysroot/ hello.c -o hello.wasm
$ ./wasi-sdk-20.0/bin/clang --sysroot wasi-sdk-20.0/share/wasi-sysroot/ hello.c -o hello.wasm
```

>> Newer versions of Clang may only need the command `clang --target=wasm32-wasi --sysroot=wasi-sdk-14.0/share/wasi-sysroot/ hello.c -o hello.wasm`
>> Newer versions of Clang may only need the command `clang --target=wasm32-wasi --sysroot=wasi-sdk-20.0/share/wasi-sysroot/ hello.c -o hello.wasm`
The above should produce a file named `hello.wasm`. We can execute that with Wasmtime:

Expand Down Expand Up @@ -167,4 +167,4 @@ Here are some great resources:
- Mozilla has a tutorial on [Compiling C/C++ to Wasm with Emscripten](https://developer.mozilla.org/en-US/docs/WebAssembly/C_to_wasm)
- The [yo-wasm](https://github.com/deislabs/yo-wasm) tool can help you get started faster. (Yes, we built `yo-wasm`.)
- Here's an example of a [Wagi fileserver written in C](https://github.com/deislabs/wagi-fileserver-c)
- If you want to work directly with the [Wasi libc](https://github.com/WebAssembly/wasi-libc), you can do that, too.
- If you want to work directly with the [Wasi libc](https://github.com/WebAssembly/wasi-libc), you can do that, too.

0 comments on commit 6641b2b

Please sign in to comment.