diff --git a/examples/wasi-hello-world/wasi-hello-world.rust.en-us.md b/examples/wasi-hello-world/wasi-hello-world.rust.en-us.md index b1fe1bf..2e342fd 100644 --- a/examples/wasi-hello-world/wasi-hello-world.rust.en-us.md +++ b/examples/wasi-hello-world/wasi-hello-world.rust.en-us.md @@ -36,7 +36,7 @@ fn main() { // This code requires the Wasi host to provide a `/helloworld` directory on the guest. // If the `/helloworld` directory is not available, the unwrap() will cause this program to panic. // For example, in Wasmtime, if you want to map the current directory to `/helloworld`, - // invoke the runtime with the flag/argument: `--mapdir /helloworld::.` + // invoke the runtime with the flag/argument: `--dir /helloworld::.` // This will map the `/helloworld` directory on the guest, to the current directory (`.`) on the host let mut file = fs::File::create("/helloworld/helloworld.txt").unwrap(); @@ -58,16 +58,16 @@ Our wasm file should be compiled to `target/wasm32-wasi/debug/wasi_hello_world.w 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. -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: +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: ```bash -wasmtime --mapdir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm +wasmtime --dir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm ``` So, **to run our compiled WASI program, we will run**: ```bash -wasmtime --mapdir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm +wasmtime --dir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm ``` 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!". diff --git a/examples/wasi-hello-world/wasi-hello-world.rust.pt-br.md b/examples/wasi-hello-world/wasi-hello-world.rust.pt-br.md index 5afff8c..b3a7393 100644 --- a/examples/wasi-hello-world/wasi-hello-world.rust.pt-br.md +++ b/examples/wasi-hello-world/wasi-hello-world.rust.pt-br.md @@ -36,7 +36,7 @@ fn main() { // This code requires the Wasi host to provide a `/helloworld` directory on the guest. // If the `/helloworld` directory is not available, the unwrap() will cause this program to panic. // For example, in Wasmtime, if you want to map the current directory to `/helloworld`, - // invoke the runtime with the flag/argument: `--mapdir /helloworld::.` + // invoke the runtime with the flag/argument: `--dir /helloworld::.` // This will map the `/helloworld` directory on the guest, to the current directory (`.`) on the host let mut file = fs::File::create("/helloworld/helloworld.txt").unwrap(); @@ -58,16 +58,16 @@ O nosso arquivo wasm deveria ser compilado a `target/wasm32-wasi/debug/wasi_hell 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. -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: +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: ```bash -wasmtime --mapdir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm +wasmtime --dir GUEST_DIRECTORY::HOST_DIRECTORY my-wasi-program.wasm ``` E assim, **para rodar o nosso programa WASI compilado, executamos**: ```bash -wasmtime --mapdir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm +wasmtime --dir /helloworld::. target/wasm32-wasi/debug/wasi_hello_world.wasm ``` 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!". diff --git a/examples/wasi-introduction/wasi-introduction.all.en-us.md b/examples/wasi-introduction/wasi-introduction.all.en-us.md index 76c8789..bc320fd 100644 --- a/examples/wasi-introduction/wasi-introduction.all.en-us.md +++ b/examples/wasi-introduction/wasi-introduction.all.en-us.md @@ -33,7 +33,7 @@ I also think it'd be worth getting some key terms out of the way. This will make - 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)). - 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! -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. +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. 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! diff --git a/examples/wasi-introduction/wasi-introduction.all.pt-br.md b/examples/wasi-introduction/wasi-introduction.all.pt-br.md index 550af80..0b8f023 100644 --- a/examples/wasi-introduction/wasi-introduction.all.pt-br.md +++ b/examples/wasi-introduction/wasi-introduction.all.pt-br.md @@ -33,7 +33,7 @@ Eu também acho que valeria a pena já aprender alguns termos chaves. Eles vão - 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)). - 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! -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. +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. 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!