Skip to content

Commit b105474

Browse files
committed
wasmtime 14.0.0 merged --mapdir into --dir
1 parent fce82ed commit b105474

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

examples/wasi-hello-world/wasi-hello-world.rust.en-us.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
// This code requires the Wasi host to provide a `/helloworld` directory on the guest.
3737
// If the `/helloworld` directory is not available, the unwrap() will cause this program to panic.
3838
// For example, in Wasmtime, if you want to map the current directory to `/helloworld`,
39-
// invoke the runtime with the flag/argument: `--mapdir /helloworld::.`
39+
// invoke the runtime with the flag/argument: `--dir /helloworld::.`
4040
// This will map the `/helloworld` directory on the guest, to the current directory (`.`) on the host
4141
let mut file = fs::File::create("/helloworld/helloworld.txt").unwrap();
4242

@@ -58,16 +58,16 @@ Our wasm file should be compiled to `target/wasm32-wasi/debug/wasi_hello_world.w
5858

5959
To do this, we can use the Wasmtime CLI, which we mentioned should be installed at the beginning of this tutorial. However, there is one thing to note that was mentioned in the code comments. **We need to give our program explicit access to create files on our host, because our program creates a new file**. As mentioned in the [WASI Introduction](/example-redirect?exampleName=wasi-introduction), our guest will not have this capability unless we give them the capability.
6060

61-
To grant the capability to write in a directory using the Wasmtime CLI, we need to use the `--mapdir` flag. `--mapdir` will allow us to map the `/helloworld` directory on the guest's virtual filesystem, to the current directory (`.`) on the host fileystem. For example:
61+
To grant the capability to write in a directory using the Wasmtime CLI, we need to use the `--dir` flag. `--dir` will allow us to map the `/helloworld` directory on the guest's virtual filesystem, to the current directory (`.`) on the host fileystem. For example:
6262

6363
```bash
64-
wasmtime --mapdir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm
64+
wasmtime --dir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm
6565
```
6666

6767
So, **to run our compiled WASI program, we will run**:
6868

6969
```bash
70-
wasmtime --mapdir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm
70+
wasmtime --dir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm
7171
```
7272

7373
You should then see "Hello World!" logged in your terminal. You should also notice that a `helloworld.txt` file was created in your current directory, with the contents of "Hello World!".

examples/wasi-hello-world/wasi-hello-world.rust.pt-br.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn main() {
3636
// This code requires the Wasi host to provide a `/helloworld` directory on the guest.
3737
// If the `/helloworld` directory is not available, the unwrap() will cause this program to panic.
3838
// For example, in Wasmtime, if you want to map the current directory to `/helloworld`,
39-
// invoke the runtime with the flag/argument: `--mapdir /helloworld::.`
39+
// invoke the runtime with the flag/argument: `--dir /helloworld::.`
4040
// This will map the `/helloworld` directory on the guest, to the current directory (`.`) on the host
4141
let mut file = fs::File::create("/helloworld/helloworld.txt").unwrap();
4242

@@ -58,16 +58,16 @@ O nosso arquivo wasm deveria ser compilado a `target/wasm32-wasi/debug/wasi_hell
5858

5959
Para isso, podemos usar a linha de comando do Wasmtime, que lhe pedimos para instalar no início deste tutorial. No entanto, há uma coisa a notar que foi mencionada nos comentários do programa. **Precisamos explicitamente dar ao nosso programa acesso à criação de arquivos no nosso host, pois o nosso programa cria um novo arquivo**. Como mencionado na [Introdução à WASI](/example-redirect?exampleName=wasi-introduction), o nosso guest não tem essa capacidade a menos que nós lhe demos tal capacidade.
6060

61-
Para autorizar o uso da capacidade de escrever em um diretório usando a linha de comando do Wasmtime, precisamos passar o parâmetro `--mapdir`. `--mapdir` nos permite mapear o diretório `/helloworld` no sistema de arquivos virtual do guest, ao diretório atual (`.`) no sistema de arquivos do host. Por exemplo:
61+
Para autorizar o uso da capacidade de escrever em um diretório usando a linha de comando do Wasmtime, precisamos passar o parâmetro `--dir`. `--dir` nos permite mapear o diretório `/helloworld` no sistema de arquivos virtual do guest, ao diretório atual (`.`) no sistema de arquivos do host. Por exemplo:
6262

6363
```bash
64-
wasmtime --mapdir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm
64+
wasmtime --dir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm
6565
```
6666

6767
E assim, **para rodar o nosso programa WASI compilado, executamos**:
6868

6969
```bash
70-
wasmtime --mapdir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm
70+
wasmtime --dir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm
7171
```
7272

7373
Você deve então ver "Hello World!" escrito na tela do seu terminal. E também deve notar que um novo arquivo `helloworld.txt` apareceu no seu diretório atual, com o conteúdo "Hello World!".

examples/wasi-introduction/wasi-introduction.all.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ I also think it'd be worth getting some key terms out of the way. This will make
3333
- The host is able to provide additional functionality to guest, by doing tasks on the guests' behalf. This functionality is offered by passing functions to the importObject ([Similar to how we do this for the browser in the "Importing Javascript Functions Into Webassembly"](/example-redirect?exampleName=importing-javascript-functions-into-webassembly)).
3434
- This brings us back to WASI, as WASI is a standardized set of APIs for hosts to do system level actions (such as filystem operations) for the guest WebAssembly module. Therefore, this allows developers to write WebAssembly modules that can access system resources!
3535

36-
The last thing worth mentioning is that WASI uses a [capability based security model](https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-capabilities.md). Meaning, the host must explicitly grant a capability to a guest module in order for the guest module to perform an action. For example in [Wasmtime](https://wasmtime.dev/), by default, the guest module cannot access any part of the host's filesystem. The user that invokes Wasmtime must pass in the `--mapdir` or `--dir` flag to grant modules the capability to access directories in the host filesystem.
36+
The last thing worth mentioning is that WASI uses a [capability based security model](https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-capabilities.md). Meaning, the host must explicitly grant a capability to a guest module in order for the guest module to perform an action. For example in [Wasmtime](https://wasmtime.dev/), by default, the guest module cannot access any part of the host's filesystem. The user that invokes Wasmtime must pass in the `--dir` flag to grant modules the capability to access directories in the host filesystem.
3737

3838
At the time of this writing, a lot of WASI is still in proposals and things. Other system resources, like networking, are not yet part of the WASI standard, though they will be one day. So, if you're hoping to `bind()` to a socket in your WebAssembly module, WASI hosts don't yet expose those capabilities. Only a few features of what WASI is hoping to acheive is fully implemented and standardized. One of those features is filesystem access!
3939

examples/wasi-introduction/wasi-introduction.all.pt-br.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Eu também acho que valeria a pena já aprender alguns termos chaves. Eles vão
3333
- O host é capaz de prover funcionalidades extras ao guest, ao executar tarefas no lugar do guest. Essa prestação se oferece passando funções ao importObject ([Similar a quando fizemos isso no browser usando `importObject` com o JavaScript no exemplo "Como Importar Funções do Javascript Em WebAssembly"](/example-redirect?exampleName=importing-javascript-functions-into-webassembly)).
3434
- E isto nos remete de volta à WASI, já que a WASI é o conjunto padrão de APIs para que os hosts façam as ações de sistema (tais como as ações de operações do sistema de arquivos) para o módulo guest de WebAssembly. Portanto, isso permite que os programadores escrevam módulos WebAssembly que podem acessar os recursos de sistema!
3535

36-
A última coisa que vale a pena mencionar é que a WASI usa um [modelo de segurança baseado em capacidade](https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-capabilities.md). Significa que o host deve oferecer explicitamente uma capacidade ao módulo guest para que ele possa realizar uma ação. Por exemplo, no [Wasmtime](https://wasmtime.dev/), por padrão, o módulo guest não pode acessar qualquer parte do sistema de arquivos do host. O usuário que invoca o Wasmtime deve passar os parâmetros `--mapdir` ou `--dir` para autorizar aos módulos a capacidade de acessar diretórios no sistema de arquivos do host.
36+
A última coisa que vale a pena mencionar é que a WASI usa um [modelo de segurança baseado em capacidade](https://github.com/bytecodealliance/wasmtime/blob/master/docs/WASI-capabilities.md). Significa que o host deve oferecer explicitamente uma capacidade ao módulo guest para que ele possa realizar uma ação. Por exemplo, no [Wasmtime](https://wasmtime.dev/), por padrão, o módulo guest não pode acessar qualquer parte do sistema de arquivos do host. O usuário que invoca o Wasmtime deve passar o parâmetro `--dir` para autorizar aos módulos a capacidade de acessar diretórios no sistema de arquivos do host.
3737

3838
No momento em que escrevemos esta introdução, grande parte da WASI ainda são propostas em discussão. Outros recursos de sistema, tais como rede, ainda não são parte do padrão WASI, mas um dia serão. Então, se você estiver esperando fazer o `bind()` de um socket no seu módulo WebAssembly, os hosts WASI ainda não expõem essa capacidade. Apenas algumas poucas funcionalidades das que a WASI espera atingir estão completamente implementadas e padronizadas. Uma dessas funcionalidades é o acesso ao sistema de arquivos!
3939

0 commit comments

Comments
 (0)