# Compile Swift to Wasm WASI

Thanks to the great work of [Swift WASM](https://swiftwasm.org/) we can now compile Swift to WebAssembly WASI.

Wasienv makes very easy to get started with Swift and WebAssembly.

```
wasienv install-swift
```

{% hint style="warning" %}
You will need the latest version of version of Wasienv installed.

If you don't have wasienv installed in your system, or want to upgrade it please [follow the instructions here](/wasmer-docs/glibc-reqs/ecosystem/wasienv/getting-started.md)
{% endhint %}

Once that's done, just create an example Swift file:

{% tabs %}
{% tab title="example.swift" %}

```swift
if CommandLine.arguments.count < 2 {
    print("Hello, WASI!");
} else {
    print("Hello, \(CommandLine.arguments[1])");
}
```

{% endtab %}

{% tab title="fizzbuzz.swift" %}

```swift
for i in 1...100
{
    if i % 3 == 0 && i % 5 == 0 {
        print("FizzBuzz")
    } else if i % 3 == 0 {
        print("Fizz")
    } else if i % 5 == 0 {
        print("Buzz")
    } else {
        print(i)
    }
}
```

{% endtab %}
{% endtabs %}

Now let's Compile it!

```
wasiswiftc example.swift -o example.wasm
```

Once the program finishes, you will have a new `example.wasm` file ready to be executed with your favorite WebAssembly runtime!

```bash
$ wasmer example.wasm
Hello, WASI!
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jubianchi.gitbook.io/wasmer-docs/glibc-reqs/ecosystem/wasienv/compile-swift-to-wasm-wasi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
