diff --git a/docs/contribute/plugin/intro.md b/docs/contribute/plugin/intro.md index 1c9c1a12..8fa85862 100644 --- a/docs/contribute/plugin/intro.md +++ b/docs/contribute/plugin/intro.md @@ -94,4 +94,4 @@ Due to the `OpenVINO` dependency, we only release the WASI-NN plug-in for the `O [wasmedge_process_interface]: https://crates.io/crates/wasmedge_process_interface [wasmedge_tensorflow_interface]: https://crates.io/crates/wasmedge_tensorflow_interface [wasi-crypto]: https://crates.io/crates/wasi-crypto -[wasi-nn]: https://crates.io/crates/wasi-nn +[wasi-nn]: https://crates.io/crates/wasi-nn \ No newline at end of file diff --git a/docs/start/wasmedge/extensions/plugins.md b/docs/start/wasmedge/extensions/plugins.md index 8e471394..bc10697f 100644 --- a/docs/start/wasmedge/extensions/plugins.md +++ b/docs/start/wasmedge/extensions/plugins.md @@ -35,4 +35,4 @@ The latest version supporting the extensions is `0.12.1`. This chapter will be d | Extension | Description | Platform Support | Language support | | --- | --- | --- | --- | | [Image processing](https://github.com/second-state/WasmEdge-image) | A native library to manipulate images for AI inference tasks. Migrated into the plug-in after WasmEdge `0.13.0`. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `android aarch64`, `ubuntu 20.04 x86_64`, and `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | -| [TensorFlow and Tensorflow-Lite](https://github.com/second-state/WasmEdge-tensorflow) | A native library to inferring TensorFlow and TensorFlow-Lite models. Migrated into the plug-in after WasmEdge `0.13.0`. | `manylinux2014 x86_64`, `manylinux2014 aarch64` (TensorFlow-Lite only), `android aarch64` (TensorFlow-Lite only), `ubuntu 20.04 x86_64`, and `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | +| [TensorFlow and Tensorflow-Lite](https://github.com/second-state/WasmEdge-tensorflow) | A native library to inferring TensorFlow and TensorFlow-Lite models. Migrated into the plug-in after WasmEdge `0.13.0`. | `manylinux2014 x86_64`, `manylinux2014 aarch64` (TensorFlow-Lite only), `android aarch64` (TensorFlow-Lite only), `ubuntu 20.04 x86_64`, and `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | \ No newline at end of file diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/contribute/plugin/intro.md b/i18n/zh/docusaurus-plugin-content-docs/current/contribute/plugin/intro.md index 1c9c1a12..8fa85862 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/contribute/plugin/intro.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/contribute/plugin/intro.md @@ -94,4 +94,4 @@ Due to the `OpenVINO` dependency, we only release the WASI-NN plug-in for the `O [wasmedge_process_interface]: https://crates.io/crates/wasmedge_process_interface [wasmedge_tensorflow_interface]: https://crates.io/crates/wasmedge_tensorflow_interface [wasi-crypto]: https://crates.io/crates/wasi-crypto -[wasi-nn]: https://crates.io/crates/wasi-nn +[wasi-nn]: https://crates.io/crates/wasi-nn \ No newline at end of file diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/_category_.json index 2d5cc861..61ec721d 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/_category_.json @@ -1,8 +1,8 @@ { - "label": "Running with WasmEdge", + "label": "运行 WasmEdge", "position": 5, "link": { "type": "generated-index", - "description": "In this chapter, we will discuss WasmEdge CLIs and how to leverage Docker + WASM to run build, share, and run your WASM apps." + "description": "在这一章节中,我们将讨论 WasmEdge CLIs(命令行界面)以及如何利用 Docker 和 WASM 来构建、分享和运行你的 WASM 应用程序。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/aot.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/aot.md index 0d8ce4b4..c59904b3 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/aot.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/aot.md @@ -2,11 +2,11 @@ sidebar_position: 3 --- -# The AoT Compiler +# AoT 编译器 -After [installation](../install.md#install), users can execute the `wasmedge compile` command. +安装完成后(请参阅[安装指南](../install.md#install)),用户可以执行 `wasmedge compile` 命令。 -The usage of the `wasmedge compile` command will be: +`wasmedge compile` 命令的用法如下: ```bash $ wasmedge compile -h @@ -16,61 +16,60 @@ USAGE ... ``` -The `wasmedge compile` command can compile WebAssembly into native machine code (i.e., the AOT compiler). For the pure WebAssembly, the `wasmedge` tool will execute the WASM in interpreter mode. After compiling with the `wasmedge compile` AOT compiler, the `wasmedge` tool can execute the WASM in AOT mode, which is much faster. - -## Options - -The options of the `wasmedge compile` command are as follows. - -1. `-h|--help`: Show the help messages. Will ignore the other arguments below. -2. _(Optional)_ `--dump`: Dump the LLVM IR to `wasm.ll` and `wasm-opt.ll`. -3. _(Optional)_ `--interruptible`: Generate the binary which supports interruptible execution. - - By default, the AOT-compiled WASM not supports [interruptions in asynchronous executions](../../embed/c/reference/0.12.x#async). -4. _(Optional)_ Statistics information: - - By default, the AOT-compiled WASM not supports all statistics even if the options are turned on when running the `wasmedge` tool. - - Use `--enable-time-measuring` to generate code for enabling time-measuring statistics in execution. - - Use `--enable-gas-measuring` to generate code for enabling the statistics of gas measuring in execution. - - Use `--enable-instruction-count` to generate code for enabling the statistics of counting WebAssembly instructions. - - Or use `--enable-all-statistics` to generate code for enabling all of the statistics. -5. _(Optional)_ `--generic-binary`: Generate the generic binary of the current host CPU architecture. -6. _(Optional)_ WebAssembly proposals: - - Use `--disable-import-export-mut-globals` to disable the [Import/Export of Mutable Globals](https://github.com/WebAssembly/mutable-global) proposal (Default `ON`). - - Use `--disable-non-trap-float-to-int` to disable the [Non-Trapping Float-to-Int Conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) proposal (Default `ON`). - - Use `--disable-sign-extension-operators` to disable the [Sign-Extension Operators](https://github.com/WebAssembly/sign-extension-ops) proposal (Default `ON`). - - Use `--disable-multi-value` to disable the [Multi-value](https://github.com/WebAssembly/multi-value) proposal (Default `ON`). - - Use `--disable-bulk-memory` to disable the [Bulk Memory Operations](https://github.com/WebAssembly/bulk-memory-operations) proposal (Default `ON`). - - Use `--disable-reference-types` to disable the [Reference Types](https://github.com/WebAssembly/reference-types) proposal (Default `ON`). - - Use `--disable-simd` to disable the [Fixed-width SIMD](https://github.com/webassembly/simd) proposal (Default `ON`). - - Use `--enable-multi-memory` to enable the [Multiple Memories](https://github.com/WebAssembly/multi-memory) proposal (Default `OFF`). - - Use `--enable-tail-call` to enable the [Tail call](https://github.com/WebAssembly/tail-call) proposal (Default `OFF`). - - Use `--enable-extended-const` to enable the [Extended Constant Expressions](https://github.com/WebAssembly/extended-const) proposal (Default `OFF`). - - Use `--enable-threads` to enable the [Threads](https://github.com/webassembly/threads) proposal (Default `OFF`). - - Use `--enable-all` to enable ALL proposals above. -7. _(Optional)_ `--optimize`: Select the LLVM optimization level. - - Use `--optimize LEVEL` to set the optimization level. The `LEVEL` should be one of `0`, `1`, `2`, `3`, `s`, or `z`. - - The default value will be `2`, which means `O2`. -8. Input WASM file (`/path/to/wasm/file`). -9. Output path (`/path/to/output/file`). - - By default, the `wasmedge compile` command will output the [universal WASM format](#output-format-universal-wasm). - - If the specific file extension (`.so` on Linux, `.dylib` on MacOS, and `.dll` on Windows) is assigned in the output path, the `wasmedge compile` command will output the [shared library format](#output-format-shared-library). - -## Example - -We created the hand-written [fibonacci.wat](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/fibonacci.wat) and used the [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) tool to convert it into the `fibonacci.wasm` WebAssembly program. Take it, for example. It exported a `fib()` function, which takes a single `i32` integer as the input parameter. - -You can run: +`wasmedge compile` 命令可将 WebAssembly 编译为本机机器码(即,AOT 编译器)。对于纯 WebAssembly,`wasmedge` 工具将以解释器模式执行 WASM。通过 `wasmedge compile` AOT 编译器编译后,`wasmedge` 工具可以以 AOT 模式执行 WASM,速度要快得多。 + +## 选项 + +`wasmedge compile` 命令的选项如下。 + +1. `-h|--help`:显示帮助信息。将忽略下面的其他参数。 +2. (可选)`--dump`:将 LLVM IR 转储到 `wasm.ll` 和 `wasm-opt.ll`。 +3. (可选)`--interruptible`:生成支持可中断执行的二进制文件。 + - 默认情况下,AOT 编译的 WASM 不支持[异步执行中的中断](../../embed/c/reference/0.12.x#async)。 +4. (可选)统计信息: + - 默认情况下,即使在运行 `wasmedge` 工具时打开选项,AOT 编译的 WASM 也不支持所有统计信息。 + - 使用 `--enable-time-measuring` 生成用于启用执行时间测量统计的代码。 + - 使用 `--enable-gas-measuring` 生成用于启用执行中的 gas 测量统计的代码。 + - 使用 `--enable-instruction-count` 生成用于启用 WebAssembly 指令计数统计的代码。 +5. (可选)`--generic-binary`:生成通用二进制文件。 +6. (可选)WebAssembly 提案: + - 使用 `--disable-import-export-mut-globals` 禁用[可变全局变量的导入/导出](https://github.com/WebAssembly/mutable-global) 提案(默认为 `ON`)。 + - 使用 `--disable-non-trap-float-to-int` 禁用[非陷阱浮点到整数转换](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) 提案(默认为 `ON`)。 + - 使用 `--disable-sign-extension-operators` 禁用[符号扩展运算符](https://github.com/WebAssembly/sign-extension-ops) 提案(默认为 `ON`)。 + - 使用 `--disable-multi-value` 禁用[多值](https://github.com/WebAssembly/multi-value) 提案(默认为 `ON`)。 + - 使用 `--disable-bulk-memory` 禁用[批量内存操作](https://github.com/WebAssembly/bulk-memory-operations) 提案(默认为 `ON`)。 + - 使用 `--disable-reference-types` 禁用[引用类型](https://github.com/WebAssembly/reference-types) 提案(默认为 `ON`)。 + - 使用 `--disable-simd` 禁用[固定宽度 SIMD](https://github.com/webassembly/simd) 提案(默认为 `ON`)。 + - 使用 `--enable-multi-memory` 启用[多内存](https://github.com/WebAssembly/multi-memory) 提案(默认为 `OFF`)。 + - 使用 `--enable-tail-call` 启用[尾调用](https://github.com/WebAssembly/tail-call) 提案(默认为 `OFF`)。 + - 使用 `--enable-extended-const` 启用[扩展常量表达式](https://github.com/WebAssembly/extended-const) 提案(默认为 `OFF`)。 + - 使用 `--enable-threads` 启用[线程](https://github.com/webassembly/threads) 提案(默认为 `OFF`)。 + - 使用 `--enable-all` 启用上述所有提案。 +7. (可选)`--optimize`:选择 LLVM 优化级别。 + - 使用 `--optimize LEVEL` 来设置优化级别。`LEVEL` 应为 `0`、`1`、`2`、`3`、`s` 或 `z` 中的一个。 + - 默认值为 `2`,即 `O2`。 +8. 输入的 WASM 文件(`/path/to/wasm/file`)。 +9. 输出路径(`/path/to/output/file`)。 + - 默认情况下,`wasmedge compile` 命令将输出[通用的 WASM 格式](#output-format-universal-wasm)。 + - 如果在输出路径中指定了特定的文件扩展名(在 Linux 上为 `.so`,在 MacOS 上为 `.dylib`,在 Windows 上为 `.dll`),`wasmedge compile` 命令将输出[共享库格式](#output-format-shared-library)。 + +## 示例 + +我们创建了纯手工编写的 [fibonacci.wat](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/fibonacci.wat) 并使用 [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) 工具将其转换为 `fibonacci.wasm` WebAssembly 程序。以此为例,将它导出为一个接收单个 `i32` 整数作为输入参数的 `fib()` 函数。 + +你可以执行: ```bash wasmedge compile fibonacci.wasm fibonacci_aot.wasm ``` -or: +或者: ```bash -wasmedge compile fibonacci.wasm fibonacci_aot.so # On Linux. +wasmedge compile fibonacci.wasm fibonacci_aot.so # 在 Linux 上 ``` -The output will be: +输出将会是: ```bash [2022-09-09 14:22:10.540] [info] compile start @@ -81,13 +80,13 @@ The output will be: [2022-09-09 14:22:10.600] [info] compile done ``` -Then you can execute the output file with `wasmedge` and measure the execution time: +然后,你可以使用 `wasmedge` 执行输出文件并测量执行时间: ```bash time wasmedge --reactor fibonacci_aot.wasm fib 30 ``` -The output will be: +输出将会是: ```bash 1346269 @@ -97,13 +96,13 @@ user 0m0.012s sys 0m0.014s ``` -Then you can compare it with the interpreter mode: +接着,你可以与解释器模式进行比较: ```bash time wasmedge --reactor fibonacci.wasm fib 30 ``` -The output shows that the AOT-compiled WASM is much faster than the interpreter mode: +输出显示,AOT 编译的 WASM 比解释器模式快得多: ```bash 1346269 @@ -113,15 +112,15 @@ user 0m0.427s sys 0m0.012s ``` -## Output Format: Universal WASM +## 输出格式:通用 WASM -By default, the `wasmedge compile` AOT compiler tool could wrap the AOT-compiled native binary into a custom section in the origin WASM file. We call this the universal WASM binary format. +默认情况下,`wasmedge compile` AOT 编译器工具可以将 AOT 编译的本机二进制文件包装为原始 WASM 文件中的自定义部分。我们称其为通用 WASM 二进制格式。 -This AOT-compiled WASM file is compatible with any WebAssembly runtime. However, when this WASM file is executed by the WasmEdge runtime, WasmEdge will extract the native binary from the custom section and execute it in AOT mode. +这个 AOT 编译的 WASM 文件与所有的 WebAssembly runtime 兼容。但是,当 WasmEdge runtime 执行此 WASM 文件时,WasmEdge 将从自定义部分提取本机二进制并以 AOT 模式执行它。 :::note -On MacOS platforms, the universal WASM format will `bus error` in execution. By default, the `wasmedge compile` tool optimizes the WASM in the `O2` level. We are trying to fix this issue. For working around, please use the shared library output format instead. +在 MacOS 平台上,通用 WASM 格式在执行时会产生 `bus error`。默认情况下,`wasmedge compile` 工具会以 `O2` 级别优化 WASM。我们正在尝试解决此问题。请使用共享库输出格式以暂时解决此问题。 ::: ```bash @@ -129,11 +128,11 @@ wasmedge compile app.wasm app_aot.wasm wasmedge app_aot.wasm ``` -## Output Format: Shared Library +## 输出格式:共享库 -Users can assign the shared library extension for the output files (`.so` on Linux, `.dylib` on MacOS, and `.dll` on Windows) to generate the shared library output format output. +用户可以为输出文件指定共享库扩展名(在 Linux 上为 `.so`,在 MacOS 上为 `.dylib`,在 Windows 上为 `.dll`),以生成共享库格式的输出。 -This AOT-compiled WASM file is only for WasmEdge use and cannot be used by other WebAssembly runtimes. +这个 AOT 编译的 WASM 文件仅供 WasmEdge 使用,其他 WebAssembly runtime 无法使用。 ```bash wasmedge compile app.wasm app_aot.so diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/cli.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/cli.md index 36f389f9..d0c6def2 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/cli.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/cli.md @@ -2,20 +2,20 @@ sidebar_position: 1 --- -# The `wasmedge` CLI +# `wasmedge` 命令行工具 -After installing WasmEdge, you can use the `wasmedge` CLI to execute WASM files. We will cover how to run WASM files with WasmEdge on your machine and Docker images. +在安装了 WasmEdge 后,你可以使用 `wasmedge` 来执行 WASM 文件。我们将介绍如何在你的机器和 Docker 镜像上使用 WasmEdge 运行 WASM 文件。 -The `wasmedge` binary is a command line interface (CLI) program that runs WebAssembly programs. +`wasmedge` 二进制文件是一个命令行界面(CLI)程序,用于运行 WebAssembly 程序。 -- If the WebAssembly program contains a `main()` function, `wasmedge` would execute it as a standalone program in the command mode. -- If the WebAssembly program contains one or more exported public functions, `wasmedge` could invoke individual functions in the reactor mode. +- 如果 WebAssembly 程序包含 `main()` 函数,`wasmedge` 将把它作为独立程序以命令模式执行。 +- 如果 WebAssembly 程序包含一个或多个导出的公共函数,`wasmedge` 可以在反应器模式中调用单个函数。 -By default, the `wasmedge` will execute WebAssembly programs in interpreter mode and execute the AOT-compiled `.so`, `.dylib`, `.dll`, or `.wasm` (universal output format) in AOT mode. If you want to accelerate the WASM execution, we recommend to [compile the WebAssembly with the AOT compiler](aot.md) first. +默认情况下,`wasmedge` 将以解释器模式执行 WebAssembly 程序,并在 AOT 模式下执行 AOT 编译的 `.so`、`.dylib`、`.dll` 或 `.wasm`(通用输出格式)。如果要加速 WASM 执行,我们建议首先使用 [AOT 编译器对 WebAssembly 进行编译](aot.md)。 :::note -The original `wasmedgec` tool is changed to `wasmedge compile`. The [`wasmedge compile` CLI tool](aot.md) is the ahead-of-time compiler to compile the WebAssembly file into native code. +原始的 `wasmedgec` 工具已更改为 `wasmedge compile`。[`wasmedge compile` CLI 工具](aot.md) 是用于将 WebAssembly 文件编译为本机代码的预先编译器。 ::: ```bash @@ -23,7 +23,7 @@ $ wasmedge -v wasmedge version {{ wasmedge_version }} ``` -Users can run the `wasmedge -h` to realize the command line options quickly or [refer to the detailed `wasmedge` CLI options here](#options). The usage of the `wasmedge` tool will be: +用户可以运行 `wasmedge -h` 快速了解命令行选项,或者[在这里查看详细的 `wasmedge` CLI 选项](#选项)。`wasmedge` 工具的用法将是: ```bash $ wasmedge -h @@ -33,95 +33,95 @@ USAGE ... ``` -The `wasmedge` CLI tool will execute the wasm file in ahead-of-time(AOT) mode or interpreter mode. If the file has been compiled with `wasmedge compile`, then WasmEdge will execute it in AOT mode, otherwise, WasmEdge will execute it in interpreter mode. - -## Options - -The options of the `wasmedge` CLI tool are as follows: - -1. `-v|--version`: Show the version information. Will ignore other arguments below. -2. `-h|--help`: Show the help messages. Will ignore other arguments below. -3. _(Optional)_ `--reactor`: Enable the reactor mode. - - In the reactor mode, `wasmedge` runs a specified function exported by the WebAssembly program. - - WasmEdge will execute the function whose name should be given in `ARG[0]`. - - If an exported function names `_initialize`, the function will be executed with the empty parameter at first. -4. _(Optional)_ `--dir`: Bind directories into WASI virtual filesystem. - - Use `--dir guest_path:host_path` to bind the host path into the guest path in WASI virtual system. -5. _(Optional)_ `--env`: Assign the environment variables in WASI. - - Use `--env ENV_NAME=VALUE` to assign the environment variable. -6. _(Optional)_ Statistics information: - - Use `--enable-time-measuring` to show the execution time. - - Use `--enable-gas-measuring` to show the amount of used gas. - - Use `--enable-instruction-count` to display the number of executed instructions. - - Or use `--enable-all-statistics` to enable all of the statistics options. -7. _(Optional)_ Resource limitations: - - Use `--time-limit MILLISECOND_TIME` to limit the execution time. Default value is `0` which specifies no limitation. - - Use `--gas-limit GAS_LIMIT` to limit the execution cost. - - Use `--memory-page-limit PAGE_COUNT` to set the limitation of pages(as size of 64 KiB) in every memory instance. -8. _(Optional)_ WebAssembly proposals: - - Use `--disable-import-export-mut-globals` to disable the [Import/Export of Mutable Globals](https://github.com/WebAssembly/mutable-global) proposal (Default `ON`). - - Use `--disable-non-trap-float-to-int` to disable the [Non-Trapping Float-to-Int Conversions](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) proposal (Default `ON`). - - Use `--disable-sign-extension-operators` to disable the [Sign-Extension Operators](https://github.com/WebAssembly/sign-extension-ops) proposal (Default `ON`). - - Use `--disable-multi-value` to disable the [Multi-value](https://github.com/WebAssembly/multi-value) proposal (Default `ON`). - - Use `--disable-bulk-memory` to disable the [Bulk Memory Operations](https://github.com/WebAssembly/bulk-memory-operations) proposal (Default `ON`). - - Use `--disable-reference-types` to disable the [Reference Types](https://github.com/WebAssembly/reference-types) proposal (Default `ON`). - - Use `--disable-simd` to disable the [Fixed-width SIMD](https://github.com/webassembly/simd) proposal (Default `ON`). - - Use `--enable-multi-memory` to enable the [Multiple Memories](https://github.com/WebAssembly/multi-memory) proposal (Default `OFF`). - - Use `--enable-tail-call` to enable the [Tail call](https://github.com/WebAssembly/tail-call) proposal (Default `OFF`). - - Use `--enable-extended-const` to enable the [Extended Constant Expressions](https://github.com/WebAssembly/extended-const) proposal (Default `OFF`). - - Use `--enable-threads` to enable the [Threads](https://github.com/webassembly/threads) proposal (Default `OFF`). - - Use `--enable-all` to enable ALL proposals above. -9. WASM file (`/path/to/wasm/file`). -10. _(Optional)_ `ARG` command line arguments array. - - In reactor mode, the first argument will be the function name, and the arguments after `ARG[0]` will be parameters of wasm function `ARG[0]`. - - In command mode, the arguments will be the command line arguments of the WASI `_start` function. They are also known as command line arguments(`argv`) for a standalone C/C++ program. - -## TensorFlow Tools +`wasmedge` CLI 工具将以预先编译(AOT)模式或解释器模式执行 WASM 文件。如果文件已使用 `wasmedge compile` 编译,则 WasmEdge 将以 AOT 模式执行它,否则将以解释器模式执行。 + +## 选项 + +`wasmedge` 命令行工具的选项如下: + +1. `-v|--version`:显示版本信息。将忽略下面的其他参数。 +2. `-h|--help`:显示帮助信息。将忽略下面的其他参数。 +3. (可选)`--reactor`:启用反应器模式。 + - 在反应器模式下,`wasmedge` 运行 WebAssembly 程序中导出的特定函数。 + - WasmEdge 将执行函数,函数名应作为 `ARG[0]` 给出。 + - 如果一个导出函数名为 `_initialize`,该函数将首先以空参数执行。 +4. (可选)`--dir`:将目录绑定到 WASI 虚拟文件系统。 + - 使用 `--dir guest_path:host_path` 将主机路径绑定到 WASI 虚拟系统中的客户端路径。 +5. (可选)`--env`:在 WASI 中分配环境变量。 + - 使用 `--env ENV_NAME=VALUE` 分配环境变量。 +6. (可选)统计信息: + - 使用 `--enable-time-measuring` 显示执行时间。 + - 使用 `--enable-gas-measuring` 显示消耗的 gas 量。 + - 使用 `--enable-instruction-count` 显示执行的指令数量。 + - 或者使用 `--enable-all-statistics` 启用所有统计选项。 +7. (可选)资源限制: + - 使用 `--time-limit MILLISECOND_TIME` 限制执行时间。默认值为 `0`,表示无限制。 + - 使用 `--gas-limit GAS_LIMIT` 限制执行成本。 + - 使用 `--memory-page-limit PAGE_COUNT` 设置每个内存实例中页面(64 KiB 大小)的限制。 +8. (可选)WebAssembly 提案: + - 使用 `--disable-import-export-mut-globals` 禁用[可变全局变量的导入/导出](https://github.com/WebAssembly/mutable-global) 提案(默认为 `ON`)。 + - 使用 `--disable-non-trap-float-to-int` 禁用[非陷阱浮点到整数转换](https://github.com/WebAssembly/nontrapping-float-to-int-conversions) 提案(默认为 `ON`)。 + - 使用 `--disable-sign-extension-operators` 禁用[符号扩展运算符](https://github.com/WebAssembly/sign-extension-ops) 提案(默认为 `ON`)。 + - 使用 `--disable-multi-value` 禁用[多值](https://github.com/WebAssembly/multi-value) 提案(默认为 `ON`)。 + - 使用 `--disable-bulk-memory` 禁用[批量内存操作](https://github.com/WebAssembly/bulk-memory-operations) 提案(默认为 `ON`)。 + - 使用 `--disable-reference-types` 禁用[引用类型](https://github.com/WebAssembly/reference-types) 提案(默认为 `ON`)。 + - 使用 `--disable-simd` 禁用[固定宽度 SIMD](https://github.com/webassembly/simd) 提案(默认为 `ON`)。 + - 使用 `--enable-multi-memory` 启用[多内存](https://github.com/WebAssembly/multi-memory) 提案(默认为 `OFF`)。 + - 使用 `--enable-tail-call` 启用[尾调用](https://github.com/WebAssembly/tail-call) 提案(默认为 `OFF`)。 + - 使用 `--enable-extended-const` 启用[扩展常量表达式](https://github.com/WebAssembly/extended-const) 提案(默认为 `OFF`)。 + - 使用 `--enable-threads` 启用[线程](https://github.com/webassembly/threads) 提案(默认为 `OFF`)。 + - 使用 `--enable-all` 启用以上所有提案。 +9. WASM 文件(`/path/to/wasm/file`)。 +10. (可选)`ARG` 命令行参数数组。 + - 在反应器模式下,第一个参数将是函数名,`ARG[0]` 之后的参数将是 WASM 函数 `ARG[0]` 的参数。 + - 在命令模式下,参数将是 WASI `_start` 函数的命令行参数。它们也被称为独立的 C/C++ 程序的命令行参数(`argv`)。 + +## TensorFlow 工具 :::note -The `WasmEdge-tensorflow-tools` has been deprecated after the 0.12.1 version and replaced by the plug-ins after the 0.13.0 version. +在 0.12.1 版本之后,`WasmEdge-tensorflow-tools` 已被弃用,并在 0.13.0 版本之后由插件替代。 ::: -If users install WasmEdge from the install script with the option `-e tf,image`, the WasmEdge CLI tools with TensorFlow and TensorFlow-Lite extensions will also be installed. +如果用户使用安装脚本并选择 `-e tf,image` 选项安装 WasmEdge,那么 WasmEdge CLI 工具将会安装 TensorFlow 和 TensorFlow-Lite 扩展。 -- `wasmedge-tensorflow` CLI tool - - The `wasmedge` tool with TensorFlow, TensorFlow-Lite, and `wasmedge-image` extensions. - - Only on `x86_64` and `aarch64` Linux platforms and `x86_64` MacOS. -- `wasmedge-tensorflow-lite` CLI tool - - The `wasmedge` tool with TensorFlow-Lite, and `wasmedge-image` extensions. - - Only on `x86_64` and `aarch64` Linux platforms, Android, and `x86_64` MacOS. +- `wasmedge-tensorflow` CLI 工具 + - 包含 TensorFlow、TensorFlow-Lite 和 `wasmedge-image` 扩展的 `wasmedge` 工具。 + - 仅支持 `x86_64` 和 `aarch64` Linux 平台以及 `x86_64` MacOS。 +- `wasmedge-tensorflow-lite` CLI 工具 + - 包含 TensorFlow-Lite 和 `wasmedge-image` 扩展的 `wasmedge` 工具。 + - 仅支持 `x86_64` 和 `aarch64` Linux 平台、Android 和 `x86_64` MacOS。 -## Examples +## 示例 -### Build and run a standalone WebAssembly app +### 构建和运行独立的 WebAssembly 应用 -The Hello World example is a standalone Rust application that can be executed by the [WasmEdge CLI](../build-and-run/cli). Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/hello). +Hello World 示例是一个独立的 Rust 应用程序,可以通过 [WasmEdge 命令行工具](../build-and-run/cli)执行。它的源代码和构建说明可以在[此处](https://github.com/second-state/rust-examples/tree/main/hello)找到。 -You will need to have the [Rust compiler installed](https://github.com/second-state/rust-examples/blob/main/README.md#prerequisites), and then use the following command to build the WASM bytecode file from the Rust source code. +你需要安装 [Rust 编译器](https://github.com/second-state/rust-examples/blob/main/README.md#prerequisites),然后使用以下命令从 Rust 源代码构建 WASM 字节码文件。 ```bash cargo build --target wasm32-wasi --release ``` -You can then use the `wasmedge` command to run the program. +你可以使用 `wasmedge` 指令运行这个程序: ```bash $ wasmedge target/wasm32-wasi/release/hello.wasm Hello WasmEdge! ``` -#### Execute with `statistics` enabled +#### 开启 `statistics` 并执行 -The CLI supports `--enable-all-statistics` flags for the statistics and gas metering. +命令行支持 `--enable-all-statistics` 参数,用于启用所有统计选项。 -You can run: +你可以运行: ```bash wasmedge --enable-all-statistics hello.wasm ``` -The output will be: +输出为: ```bash Hello WasmEdge! @@ -135,17 +135,17 @@ Hello WasmEdge! [2021-12-09 16:03:33.261] [info] ======================= End ====================== ``` -#### Execute with `gas-limit` enabled +#### 开启 `gas-limit` 并执行 -The CLI supports `--gas-limit` flags for controlling the execution costs. +命令行支持 `--gas-limit`参数,用于控制执行成本。 -For giving sufficient gas as the example, you can run: +下面是提供足够的 Gas 的示例: ```bash wasmedge --enable-all-statistics --gas-limit 20425 hello.wasm ``` -The output will be: +输出为: ```bash Hello WasmEdge! @@ -159,13 +159,13 @@ Hello WasmEdge! [2021-12-09 16:03:33.261] [info] ======================= End ====================== ``` -For giving insufficient gas as the example, you can run: +下面是提供不足的 Gas 的示例: ```bash wasmedge --enable-all-statistics --gas-limit 20 hello.wasm ``` -The output will be: +输出为: ```bash Hello WasmEdge! @@ -183,50 +183,51 @@ Hello WasmEdge! [2021-12-23 15:19:06.690] [info] Gas costs: 20 ``` -### Call a WebAssembly function compiled from Rust +### 调用从 Rust 编译的 WebAssembly 函数 -The [add](https://github.com/second-state/wasm-learning/tree/master/cli/add) program is written in Rust and contains an exported `add()` function. You can compile it into WebAssembly and use `wasmedge` to call the `add()` function. In this example, you will see how it is done from the CLI. It is often used when you embed WasmEdge into another host application, and need to call a WASM function from the host. +[add](https://github.com/second-state/wasm-learning/tree/master/cli/add) 程序是用 Rust 编写的,包含一个导出的 `add()` 函数。你可以将其编译为 WebAssembly,并使用 `wasmedge` 调用 `add()` 函数。在这个示例中,你将看到如何从 CLI 进行此操作。通常在将 WasmEdge 嵌入到另一个主机应用程序中时,需要从主机调用 WASM 函数。 -You will need to have the [Rust compiler](https://github.com/second-state/rust-examples/blob/main/README.md#prerequisites) installed, and then use the following command to build the WASM bytecode file from the Rust source code. +你需要安装 [Rust 编译器](https://github.com/second-state/rust-examples/blob/main/README.md#prerequisites),然后使用以下命令从 Rust 源代码构建 WASM 字节码文件。 ```bash cargo build --target wasm32-wasi --release ``` -You can execute `wasmedge` in reactor mode to invoke the `add()` function with two `i32` integer input parameters. +你可以在反应器模式下执行 `wasmedge`,以调用具有两个 `i32` 整数输入参数的 `add()` 函数。 ```bash wasmedge --reactor add.wasm add 2 2 ``` -The output will be: +输出为: ```bash 4 ``` -### Call a WebAssembly function written in WAT -We created the hand-written [fibonacci.wat](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/fibonacci.wat) and used the [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) tool to convert it into the `fibonacci.wasm` WebAssembly program. It exported a `fib()` function which takes a single `i32` integer as the input parameter. We can execute `wasmedge` in reactor mode to invoke the exported function. +### 调用用 WAT 编写的 WebAssembly 函数 -You can run: +我们创建了纯手工编写的 [fibonacci.wat](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/fibonacci.wat) 文件,并使用 [wat2wasm](https://webassembly.github.io/wabt/demo/wat2wasm/) 工具将其转换为名为 `fibonacci.wasm` 的 WebAssembly 程序。它导出了一个 `fib()` 函数,该函数以单个 `i32` 整数作为输入参数。我们可以在反应器模式下执行 `wasmedge` 来调用导出的函数。 + +你可以运行: ```bash wasmedge --reactor fibonacci.wasm fib 10 ``` -The output will be: +输出为: ```bash 89 ``` -### JavaScript examples +### JavaScript 示例 -Using WasmEdge as a high-performance, secure, extensible, easy-to-deploy, and [Kubernetes-compliant](https://github.com/second-state/wasmedge-containers-examples) JavaScript runtime is possible. There is no need to build a JavaScript app. You need to download the WasmEdge JavaScript runtime for Node.js. +使用 WasmEdge 作为高性能、安全、可扩展、易于部署的、符合 [Kubernetes](https://github.com/second-state/wasmedge-containers-examples) 标准的 JavaScript 运行时是可能的。无需构建 JavaScript 应用程序。你需要下载适用于 Node.js 的 WasmEdge JavaScript 运行时。 -- [Download the wasmedge_quickjs.wasm file here](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm) -- [Download the modules.zip file here](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip) and then unzip it into the current folder as `./modules/` +- [在此处下载 wasmedge_quickjs.wasm 文件](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm) +- [在此处下载 modules.zip 文件](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip),然后解压到当前文件夹中并确保名称为 `./modules/`。 ```bash wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm @@ -234,26 +235,26 @@ wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-a unzip modules.zip ``` -Take a simple Javascript file for example. Save the following code as `hello.js`: +以一个简单的 JavaScript 文件为例。将以下代码保存为 `hello.js`: ```javascript args = args.slice(1); print('Hello', ...args); ``` -You can run: +你可以使用下面的命令运行: ```bash wasmedge --dir .:. wasmedge_quickjs.wasm hello.js 1 2 3 ``` -The output will be: +输出为: ```bash Hello 1 2 3 ``` -The [qjs_tf.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/js/qjs_tf.wasm) is a JavaScript interpreter with [WasmEdge Tensorflow extension](https://www.secondstate.io/articles/wasi-tensorflow/) compiled into WebAssembly. To run [qjs_tf.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/js/qjs_tf.wasm), you must use the `wasmedge-tensorflow-lite` CLI tool, which is a build of WasmEdge with Tensorflow-Lite extension built-in. You can download a full [Tensorflow-based JavaScript example](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) to classify images. +[qjs_tf.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/js/qjs_tf.wasm) 是一个被贬意为 WebAssembly 的包含 [WasmEdge Tensorflow 扩展](https://www.secondstate.io/articles/wasi-tensorflow/) 的 JavaScript 解释器。要运行 [qjs_tf.wasm](https://github.com/WasmEdge/WasmEdge/raw/master/examples/wasm/js/qjs_tf.wasm),你必须使用 `wasmedge-tensorflow-lite` CLI 工具,这是一个内置了 Tensorflow-Lite 扩展的 WasmEdge 构建版本。你可以下载一个完整的[基于 Tensorflow 的 JavaScript 示例](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) 进行图像分类。 ```bash # Download the Tensorflow example @@ -267,27 +268,27 @@ label: Hot dog confidence: 0.8941176470588236 ``` -## Docker images for the CLI tools +## CLI 工具的 Docker 镜像 -The Docker images in this section are mostly used for development purposes. They allow you to use WasmEdge tools in containerized Linux environments. If you want to containerize WASM apps, check out [this](../getting-started/quick_start_docker.md) section. +本节中的 Docker 镜像主要用于开发目的。它允许你在容器化的 Linux 环境中使用 WasmEdge 工具。如果你想要容器化 WASM 应用程序,请查看[此处](../getting-started/quick_start_docker.md)的内容。 -The `wasmedge/slim:{version}` Docker images provide a slim WasmEdge images built with [DockerSlim](https://dockersl.im) every releases. +`wasmedge/slim:{version}` Docker 镜像提供了使用 [DockerSlim](https://dockersl.im) 构建的精简 WasmEdge 镜像,每次发布都会更新。 -- Image `wasmedge/slim-runtime:{version}` includes only WasmEdge runtime with `wasmedge` command. -- Image `wasmedge/slim:{version}` includes the following command line utilities: +- 镜像 `wasmedge/slim-runtime:{version}` 仅包含具有 `wasmedge` 命令的 WasmEdge runtime。 +- 镜像 `wasmedge/slim:{version}` 包含以下命令行实用程序: - `wasmedge` - `wasmedge compile` -- Image `wasmedge/slim-tf:{version}` includes the following command line utilities (DEPRECATED after 0.13.0): +- 镜像 `wasmedge/slim-tf:{version}` 包含以下命令行实用程序 (在 0.13.0 版本之后不再推荐使用): - `wasmedge` - `wasmedge compile` - `wasmedge-tensorflow-lite` - `wasmedge-tensorflow` - `show-tflite-tensor` -- The working directory of the release docker image is `/app`. +- 发布 Docker 镜像的工作目录是 `/app`。 -### Dockerslim Examples +### Dockerslim 示例 -After pulling the docker image successfully, you could use `wasmedge compile` and `wasmedge` to aot compile the wasm file and run the wasm app. +成功拉取 Docker 镜像后,你可以使用 `wasmedge compile` 和 `wasmedge` 进行 AOT 编译 WASM 文件和运行 WASM 应用程序。 ```bash $ docker pull wasmedge/slim:{{ wasmedge_version }} @@ -306,11 +307,11 @@ hello world ``` -Use `wasmedge-tensorflow-lite` ([link](https://github.com/WasmEdge/WasmEdge/tree/master/examples/js)): +使用 `wasmedge-tensorflow-lite` ([link](https://github.com/WasmEdge/WasmEdge/tree/master/examples/js)): :::note -The `WasmEdge-tensorflow-tools` has been deprecated after the 0.12.1 version. We'll update to use the WasmEdge plug-in in the future. +`WasmEdge-tensorflow-tools` 已在 0.12.1 版本之后被弃用。我们将在未来更新使用 WasmEdge 插件。 ::: ```bash diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/docker_wasm.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/docker_wasm.md index 3d322870..0f6a4337 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/docker_wasm.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/docker_wasm.md @@ -4,35 +4,35 @@ sidebar_position: 4 # Docker + WASM -The Docker Desktop distributes with the WasmEdge Runtime embedded. That allows developers to build, share and run very lightweight containers (i.e., a `scratch` empty container with only the `.wasm` file without any Linux OS libraries or files) through Docker tools. Those "WASM containers" are fully OCI-compliant and hence can be managed by Docker Hub. They are cross-platform and can run on any OS / CPU Docker supports (the OS and CPU platform is `wasi/wasm`). But most importantly, they are 1/10 of the size of a comparable Linux container and start up in 1/10 of the time, as the WASM containers do not need to bundle and start Linux libraries and services. +Docker Desktop 分发了内置的 WasmEdge 运行时。这使开发人员可以通过 Docker 工具构建、分享和运行非常轻量的容器(即,只包含 `.wasm` 文件的 `scratch` 空容器,没有任何 Linux 操作系统库或文件)。这些“WASM 容器”完全符合 OCI 标准,因此可以由 Docker Hub 进行管理。它们是跨平台的,可以在 Docker 支持的任何操作系统/CPU 上运行(操作系统和 CPU 平台为 `wasi/wasm`)。但更重要的是,相较于 Linux 容器,它们的体积是其十分之一,因为 WASM 容器不需要捆绑和启动 Linux 库和服务,所以启动时间也是十分之一。 -Together with Docker's capability to containerize developer and deployment environments, you can create and deploy complex applications without installing any dependencies. For example, you could setup a complete Rust and WasmEdge development environment without installing either tool on your local dev machine. You can also deploy a complex WasmEdge app that needs to connect to a MySQL database without having to install MySQL locally. +结合 Docker 能够将开发环境和部署环境容器化的能力,你可以创建和部署复杂的应用程序,而无需安装任何依赖。例如,你可以在本地开发机器上设置完整的 Rust 和 WasmEdge 开发环境,而无需安装任何工具。你还可以部署一个复杂的 WasmEdge 应用,该应用需要连接到 MySQL 数据库,而无需在本地安装 MySQL。 -In this guide, we will cover how to: +在本指南中,我们将介绍如何: -- [Create and run a Rust program](#create-and-run-a-rust-program) -- [Create and run a node.js server](#create-and-run-a-nodejs-server) -- [Create and deploy a database driven microservice in Rust](#create-and-deploy-a-database-driven-microservice-in-rust) +- [创建并运行 Rust 程序](#创建并运行-Rust-程序) +- [创建并运行 Node.js 服务器](#创建并运行-Node.js-服务器) +- [在 Rust 中创建并部署数据库驱动的微服务](#在-Rust-中创建并部署数据库驱动的微服务) -## Prerequisite +## 环境要求 -Install [Docker Desktop](https://www.docker.com/products/docker-desktop/) and turn on the containerd image store feature in your Docker Desktop settings. +安装 [Docker Desktop](https://www.docker.com/products/docker-desktop/) 并在 Docker Desktop 设置中打开 containerd 镜像存储功能。 ![Docker config](docker_config.png) -## Create and run a Rust program +## 创建并运行 Rust 程序 -With Docker + WASM, you can use the entire Rust toolchain in a Docker container to build the WASM bytecode application, and then publish and run the WASM application. The [example Rust source code and build instructions are available here](https://github.com/second-state/rust-examples/tree/main/hello). +使用 Docker + WASM,你可以在 Docker 容器中使用完整的 Rust 工具链构建 WASM 字节码应用程序,并发布和运行 WASM 应用程序。[这里提供了示例 Rust 源代码和构建说明](https://github.com/second-state/rust-examples/tree/main/hello)。 -### Build the rust example +### 构建 Rust 示例 -In the project directory, run the following command to build the Rust source code into WASM and then package the WASM file into an empty container image. Notice that you do not need to install the Rust compiler toolchain here. +在项目目录中,运行以下命令,将 Rust 源代码构建为 WASM,并将 WASM 文件打包到一个空容器镜像中。请注意,你无需在此安装 Rust 编译器工具链。 ```bash docker buildx build --platform wasi/wasm -t secondstate/rust-example-hello . ``` -The [Dockerfile](https://github.com/second-state/rust-examples/blob/main/hello/Dockerfile) shows how it is done. The Dockerfile has three parts. The first part sets up a Docker container for the Rust build environment. +[Dockerfile](https://github.com/second-state/rust-examples/blob/main/hello/Dockerfile) 中显示了构建方式。Dockerfile 由三部分组成。第一部分设置了用于 Rust 构建环境的 Docker 容器。 ```dockerfile FROM --platform=$BUILDPLATFORM rust:1.64 AS buildbase @@ -47,7 +47,7 @@ RUN < :::note -For more Docker compose examples, including Linux containers + WASM containers mixed deployments, check out the [awesome-compose](https://github.com/docker/awesome-compose) repo. +要了解更多 Docker compose 示例,包括 Linux 容器 + WASM 容器混合部署,请查看 [awesome-compose](https://github.com/docker/awesome-compose) 仓库。 ::: -### Build the microservice example +### 构建微服务示例 -In the project directory, run the following command to build all three containers: `client`, `server` and `db`. +在项目目录中,运行以下命令以构建所有三个容器:`client`、`server` 和 `db`。 ```bash docker compose up ``` -There is a [docker-compose.yml](https://github.com/second-state/microservice-rust-mysql/blob/main/docker-compose.yml) file. It defines the 3 containers needed in this application. +在 [docker-compose.yml](https://github.com/second-state/microservice-rust-mysql/blob/main/docker-compose.yml) 文件中定义了本应用中所需的 3 个容器。 ```yaml services: @@ -220,62 +220,64 @@ services: MYSQL_ROOT_PASSWORD: whalehello ``` -- The `client` container is an Nginx web server - - Linux container with mapped HTTP port and volume for the static HTML/JS files -- The `server` container is a Rust container for the business logic - - The WASM container is built from [Rust source code](https://github.com/second-state/microservice-rust-mysql/blob/main/src/main.rs) using this [Dockerfile](https://github.com/second-state/microservice-rust-mysql/blob/main/Dockerfile) - - WASM container with mapped web service port and an environment variable for the database connection string -- The `db` container is a MySQL database - - Linux container with a pre-set database password +- `client` 容器是一个 Nginx Web 服务器 + - 一个 Linux 容器,映射了 HTTP 端口和用于放置静态 HTML/JS 文件的 Volume +- `server` 容器是一个用于业务逻辑的 Rust 容器 + - 一个 WASM 容器,通过使用此 [Dockerfile](https://github.com/second-state/microservice-rust-mysql/blob/main/Dockerfile) 构建的构建该 [Rust 源码](https://github.com/second-state/microservice-rust-mysql/blob/main/src/main.rs)生成 + - WASM 容器映射了 Web 服务端口,并设定了用于连接数据库连的环境变量 +- `db` 容器是一个 MySQL 数据库 + - 一个 Linux 容器,预设了数据库密码 -### Deploy the microservice example +### 部署微服务示例 -Start and run all three containers in the correct order with one command. +使用 `up` 指令依次启动和运行所有三个容器。 ```bash docker compose up ``` -Go back to Docker Desktop Dash board, you will see there're three containers running. +返回 Docker Desktop 管理后台,你将看到三个容器正在运行。 ![Docker](docker.jpeg) -### CRUD tests +### CRUD 测试 -Open another terminal, and you can use the `curl` command to interact with the web service. +打开另一个终端,你可以使用 `curl` 命令与 Web 服务交互。 -When the microservice receives a `GET` request to the `/init` endpoint, it would initialize the database with the `orders` table. +当微服务接收到 `/init` 终点的 `GET` 请求时,它将用 `orders` 表初始化数据库。 ```bash curl http://localhost:8080/init ``` -When the microservice receives a `POST` request to the `/create_order` endpoint, it would extract the JSON data from the `POST` body and insert an `Order` record into the database table. For multiple records, use the `/create_orders` endpoint and `POST` a JSON array of `Order` objects. +当微服务接收到 `/create_order` 的 `POST` 请求时,它将从 `POST` 主体中提取 JSON 数据,并将 `Order` 记录插入到数据库表中。对于多个记录,请访问 `/create_orders` 接口,并以 POST 一个 JSON 数组格式的 `Order` 对象。 ```bash curl http://localhost:8080/create_orders -X POST -d @orders.json ``` -When the microservice receives a `GET` request to the `/orders` endpoint, it would get all rows from the `orders` table and return the result set in a JSON array in the HTTP response. +当微服务接收到 `/orders` 的 `GET` 请求时,它将从 `orders` 表中获取所有行,并在 HTTP 响应中以 JSON 数组的形式返回结果集。 ```bash curl http://localhost:8080/orders ``` -When the microservice receives a `POST` request to the `/update_order` endpoint, it would extract the JSON data from the `POST` body and update the `Order` record in the database table that matches the `order_id` in the input data. +当微服务接收到 `/update_order` 的 `POST` 请求时,它将从 `POST` 主体中提取 JSON 数据,并更新数据库表中与输入数据中的 `order_id` 匹配的 `Order` 记录。 ```bash curl http://localhost:8080/update_order -X POST -d @update_order.json ``` -When the microservice receives a `GET` request to the `/delete_order` endpoint, it would delete the row in the `orders` table that matches the `id` `GET` parameter. +当微服务接收到 `/delete_order` 终点的 `GET` 请求时,它将删除与 `id` `GET` 参数匹配的 `orders` 表中的行。 ```bash curl http://localhost:8080/delete_order?id=2 ``` -That's it. Feel free to fork this project and use it as a template for your own lightweight microservices! +以上。 -### Further reading for the microservice example +你可以基于此项目创造自己轻量级微服务的模板! -To learn how Docker + WASM works under the hood, visit the [containerd](../../develop/deploy/cri-runtime/containerd.md) chapter for more details. +### 微服务示例的进一步阅读 + +要了解 Docker + WASM 在内部是如何工作的,请访问 [containerd](../../develop/deploy/cri-runtime/containerd.md) 章节了解更多详情。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/run.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/run.md index 84f972d4..a68bf762 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/run.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/build-and-run/run.md @@ -2,11 +2,11 @@ sidebar_position: 2 --- -# `wasmedge run` CLI +# `wasmedge run` -After [installation](../install.md#install), users can execute the `wasmedge run` command. +安装完成后(参见[安装](../install.md#install)),用户可以执行 `wasmedge run` 命令。 -`wasmedge run` is an alias of `wasmedge` without `-v|--version` option. The usage of the `wasmedge run` tool will be: +`wasmedge run` 是不带 `-v|--version` 选项的 `wasmedge` 的别名。`wasmedge run` 工具的用法如下: ```bash $ wasmedge run -h @@ -14,17 +14,17 @@ USAGE wasmedge run [OPTIONS] [--] WASM_OR_SO [ARG ...] ``` -## Options +## 选项 -`wasmedge run` is an alias of `wasmedge` without `-v|--version` option. +`wasmedge run` 是不带 `-v|--version` 选项的 `wasmedge` 的别名。 -In the other words, if users want to execute the following command. +换句话说,如果用户希望执行以下命令。 ```bash wasmedge --reactor fibonacci.wasm fib 10 ``` -It is also accepted to add subcommand `run` and will have no difference on execution process and result. +也可以使用子命令 `run`,在执行过程和结果上不会有任何区别。 ```bash wasmedge run --reactor fibonacci.wasm fib 10 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/_category_.json index 977d2d89..1e99c8be 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/_category_.json @@ -1,8 +1,8 @@ { - "label": "Getting Started with WasmEdge", + "label": "开始使用 WasmEdge", "position": 3, "link": { "type": "generated-index", - "description": "In this chapter, we will show you how to get WasmEdge up and running quickly." + "description": "在本章中,我们将向你展示如何快速启动和运行 WasmEdge。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start.md index fa729869..8779ca99 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start.md @@ -2,53 +2,53 @@ sidebar_position: 1 --- -# Quick start on Linux +# Linux 下的快速入门 -In this guide, we will walk you through how to quickly install and run the WasmEdge Runtime on a generic Linux distribution (such as Ubuntu, Debian, Raspberry OS or WSL on Windows). Comprehensive and OS-specific installation instructions can be found [here](../install.md#install). +在本指南中,我们将介绍如何快速地在常规 Linux 发行版(例如 Ubuntu、Debian、Raspberry OS 或 Windows 上的 WSL)上安装和运行 WasmEdge 运行时。你可以在[此处](../install.md#install)找到更全面和其他特定操作系统的安装说明。 :::note -If you have Docker Desktop 4.15 and above, you can skip this and [get started here](quick_start_docker.md). For Fedora Linux / Red Hat Linux / OpenShift / Podman users, [get started here](quick_start_redhat.md). +如果你使用 Docker Desktop 4.15 及以上版本,则可以跳过这一部分,可以[在此开始](quick_start_docker.md)。对于 Fedora Linux / Red Hat Linux / OpenShift / Podman 用户,可以[在此开始](quick_start_redhat.md)。 ::: -We will cover the following examples: +我们将涵盖以下示例: -- [How to run a standalone WASM app](#how-to-run-a-standalone-wasm-app) -- [How to run an HTTP server](#how-to-run-an-http-server) -- [How to run a JavaScript server (node.js)](#how-to-run-a-javascript-based-server) +- [如何运行一个独立的 WASM 应用](#how-to-run-a-standalone-wasm-app) +- [如何运行一个 HTTP 服务器](#how-to-run-an-http-server) +- [如何运行一个 JavaScript 服务器 (node.js)](#how-to-run-a-javascript-based-server) -## One-liner Installation of WasmEdge +## 使用一行指令安装 WasmEdge -The easiest way to install WasmEdge is to run the following command. You should have root or at least `sudo` privilege. Your system should have `git` and `curl` installed as prerequisites. +安装 WasmEdge 的最简单方式是运行以下命令。你应该具有 root 或至少 `sudo` 权限。在运行此命令之前,你的系统应该已经安装了 `git` 和 `curl`。 ```bash curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | sudo bash -s -- -p /usr/local ``` -If you do not have root or `sudo` rights, use the following line to install WasmEdge in your `$HOME/.wasmedge` directory: +如果你没有 root 或 `sudo` 权限,则可以使用以下命令在 `$HOME/.wasmedge` 目录中安装 WasmEdge: ```bash curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash ``` -## How to run a standalone WASM app +## 如何运行一个独立的 WASM 应用 -The Hello world example is a standalone Rust application that can be executed by the [WasmEdge CLI](../build-and-run/cli.md). Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/hello). +Hello World 示例是一个独立的 Rust 应用程序,可由[WasmEdge CLI](../build-and-run/cli.md)执行。其源代码和构建说明可在[此处](https://github.com/second-state/rust-examples/tree/main/hello)找到。 -Download the hello.wasm file [here](https://github.com/second-state/rust-examples/releases/latest/download/hello.wasm), or run the following command: +在[此处](https://github.com/second-state/rust-examples/releases/latest/download/hello.wasm)下载 hello.wasm 文件,或运行以下命令: ```bash wget https://github.com/second-state/rust-examples/releases/latest/download/hello.wasm ``` -Use the `wasmedge` command to run the program. +使用 `wasmedge` 命令来运行程序。 ```bash $ wasmedge hello.wasm Hello WasmEdge! ``` -Use the AoT compiler `wasmedgec` to get much better performance. +使用 AoT 编译器 `wasmedgec` 可获得更好的性能。 ```bash $ wasmedgec hello.wasm hello_aot.wasm @@ -56,34 +56,34 @@ $ wasmedge hello_aot.wasm Hello WasmEdge! ``` -To learn more about how to create WASM apps in Rust +了解更多如何在 Rust 中创建 WASM 应用 -- [Basic Rust examples for WasmEdge](https://github.com/second-state/rust-examples) -- [Rust developer guides](/category/develop-wasm-apps-in-rust) - - WASI-NN with [PyTorch](../../develop/rust/wasinn/pytorch.md), [OpenVINO](../../develop/rust/wasinn/openvino.md), or [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) backends - - [HTTP and HTTPS client](../../develop/rust/http_service/client.md) - - [MySQL database client](../../develop/rust/database/my_sql_driver.md) - - Redis client - - Kafka client +- [WasmEdge 的基本 Rust 示例](https://github.com/second-state/rust-examples) +- [Rust 开发指南](/category/develop-wasm-apps-in-rust) + - 使用 [PyTorch](../../develop/rust/wasinn/pytorch.md), [OpenVINO](../../develop/rust/wasinn/openvino.md) 或 [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) 后端的 WASI-NN + - [HTTP 和 HTTPS 客户端](../../develop/rust/http_service/client.md) + - [MySQL 数据库客户端](../../develop/rust/database/my_sql_driver.md) + - Redis 客户端 + - Kafka 客户端 -## How to run an HTTP server +## 如何运行一个 HTTP 服务器 -This example is a standalone HTTP server written in Rust. It demonstrates that Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/server). +此示例是一个使用 Rust 编写的独立 HTTP 服务器。它展示了将 Rust + WasmEdge 作为微服务的轻量级技术栈。其源代码和构建说明可在[此处](https://github.com/second-state/rust-examples/tree/main/server)找到。 -Download the server.wasm file [here](https://github.com/second-state/rust-examples/releases/latest/download/server.wasm), or run the following command: +在[此处](https://github.com/second-state/rust-examples/releases/latest/download/server.wasm)下载 server.wasm 文件,或运行以下命令: ```bash wget https://github.com/second-state/rust-examples/releases/latest/download/server.wasm ``` -Use the `wasmedge` command to run the program. +使用 `wasmedge` 命令来运行该程序。 ```bash $ wasmedge server.wasm Listening on http://0.0.0.0:8080 ``` -From another terminal window, do the following. +从另一个终端窗口执行以下步骤。 ```bash $ curl http://localhost:8080/ @@ -93,65 +93,65 @@ $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to create WASM services in Rust +了解如何在 Rust 中创建 WASM 服务 -- [Rust developer guides](/category/develop-wasm-apps-in-rust) -- [HTTP application examples](https://github.com/WasmEdge/wasmedge_hyper_demo) -- [Database application examples](https://github.com/WasmEdge/wasmedge-db-examples) -- Lightweight microservices in Rust and WasmEdge +- [Rust 开发指南](/category/develop-wasm-apps-in-rust) +- [HTTP 应用程序示例](https://github.com/WasmEdge/wasmedge_hyper_demo) +- [数据库应用程序示例](https://github.com/WasmEdge/wasmedge-db-examples) +- Rust 和 WasmEdge 中的轻量级微服务 - [WasmEdge + Nginx + MySQL](https://github.com/second-state/microservice-rust-mysql) - [WasmEdge + Kafka + MySQL](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) - [Dapr + WasmEdge](https://github.com/second-state/dapr-wasm) -## How to run a JavaScript-based server +## 如何运行基于 JavaScript 的服务器 -This example is a standalone HTTP server written in JavaScript using the node.js API. It demonstrates WasmEdge as a lightweight runtime for node.js applications. Its source code is available [here](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server). +该示例是基于 Node.js API 并使用 JavaScript 编写的独立 HTTP 服务器。它展示了如何将 WasmEdge 作为 Node.js 应用程序的轻量级运行时。其源代码可在[此处](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server)找到。 -- Download the wasmedge_quickjs.wasm file [here](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm), or run the following command: +- 在[此处](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm)下载 wasmedge_quickjs.wasm 文件,或运行以下命令: ```bash wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/wasmedge_quickjs.wasm ``` -- Download the modules.zip file [here](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip), or run the following command: +- 在[此处](https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip)下载 modules.zip 文件,或运行以下命令: ```bash wget https://github.com/second-state/wasmedge-quickjs/releases/download/v0.5.0-alpha/modules.zip ``` -Unzip the modules.zip file into the current folder as `./modules/`. +将 modules.zip 文件解压到当前文件夹,保存为 `./modules/`。 ```bash unzip modules.zip ``` -- Download the server.js file [here](https://raw.githubusercontent.com/second-state/wasmedge-quickjs/main/example_js/docker_wasm/server/server.js). +- 在[此处](https://raw.githubusercontent.com/second-state/wasmedge-quickjs/main/example_js/docker_wasm/server/server.js)下载 server.js 文件。 ```bash wget https://raw.githubusercontent.com/second-state/wasmedge-quickjs/main/example_js/docker_wasm/server/server.js ``` -Use the `wasmedge` command to run the program. +使用 `wasmedge` 命令来运行该程序。 ```bash $ wasmedge --dir .:. wasmedge_quickjs.wasm server.js -listen 8080 ... +Listening on 8080 ... ``` -From another terminal window, do the following. +从另一个终端窗口执行以下步骤。 ```bash $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to run JavaScript apps in WasmEdge. +了解如何在 WasmEdge 中运行 JavaScript 应用程序。 -- [The WasmEdge QuickJS runtime](https://github.com/second-state/wasmedge-quickjs) -- [AI inference application examples](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) -- [Web service client examples with fetch()](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) +- [WasmEdge QuickJS runtime](https://github.com/second-state/wasmedge-quickjs) +- [AI 推理应用示例](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) +- [使用 fetch() 的 Web 服务客户端示例](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) -## Next steps +## 下一步 -- Check out all available [WasmEdge CLI options](../build-and-run/cli.md) to explore WasmEdge's features. -- Write WASM apps in your favorite languages, like [Rust](/category/develop-wasm-apps-in-rust), [C/C++](/category/develop-wasm-apps-in-cc), [JavaScript](/category/develop-wasm-apps-in-javascript), [Go](/category/develop-wasm-apps-in-go), and many other languages. +- 查看所有可用的[WasmEdge CLI选项](../build-and-run/cli.md)以探索 WasmEdge 的功能。 +- 用你喜欢的语言编写 WASM 应用,如 [Rust](/category/develop-wasm-apps-in-rust)、[C/C++](/category/develop-wasm-apps-in-cc)、[JavaScript](/category/develop-wasm-apps-in-javascript)、[Go](/category/develop-wasm-apps-in-go) 等其他语言。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_docker.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_docker.md index 615bbb09..62a75e72 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_docker.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_docker.md @@ -2,62 +2,62 @@ sidebar_position: 2 --- -# Quick start with Docker +# 使用 Docker 的快速入门 -In this guide, we will walk you through how to quickly run WasmEdge apps in Docker Desktop. There is no additional dependencies as the entire development and runtime environments are managed by Docker Desktop. +在本指南中,我们将介绍如何在 Docker Desktop 中快速运行 WasmEdge 应用。由于整个开发和运行环境都由 Docker Desktop 管理,因此没有额外的依赖。 :::note -If you are not using Docker Desktop, [get started here](quick_start.md). +如果你没有使用 Docker Desktop,请[从这里开始](quick_start.md)。 ::: -We will cover the following examples. +我们将介绍以下示例。 -- [Run a standalone WASM app](#run-a-standalone-wasm-app) -- [Run an HTTP server](#run-an-http-server) -- [Run a JavaScript server (node.js)](#run-a-javascript-based-server) +- [运行一个独立的 WASM 应用](#run-a-standalone-wasm-app) +- [运行一个 HTTP 服务器](#run-an-http-server) +- [运行一个基于 JavaScript 的服务器 (node.js)](#run-a-javascript-based-server) -In this quick start guide, we cover how to run WASM container apps using Docker commands. If you are interested in how to build, publish, and compose WASM container apps from source code, check out the [Docker + wasm chapter](../build-and-run/docker_wasm.md). +在此快速入门指南中,我们将介绍如何使用 Docker 命令运行 WASM 容器应用。如果你对如何从源代码构建、发布和组合 WASM 容器应用感兴趣,请查看[Docker + wasm 章节](../build-and-run/docker_wasm.md)。 -## Prerequisite +## 环境 -You must have Docker Desktop 4.15+ installed. Make sure you have turned on the containerd image store feature in your Docker Desktop. +你必须安装 Docker Desktop 4.15+。确保在 Docker Desktop 中启用了 containerd 镜像存储功能。 ![Docker config](docker_config.png) -## Run a standalone WASM app +## 运行独立的 WASM 应用 -The Hello world example is a standalone Rust application. Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/hello). +Hello World 示例是一个独立的 Rust 应用程序。其源代码和构建说明在[此处](https://github.com/second-state/rust-examples/tree/main/hello)。 -Use Docker to run the containerized WASM app. The WASM container image is stored in Docker Hub, and its image size is only 500KB. This image can run on any OS and CPU platform Docker supports. +使用 Docker 来运行容器化的 WASM 应用。WASM 容器镜像存储在 Docker Hub 中,镜像大小仅为 500KB。该镜像可在 Docker 支持的任何 OS 和 CPU 平台上运行。 ```bash $ docker run --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-hello:latest Hello WasmEdge! ``` -To learn more about how to create WASM apps in Rust +了解如何在 Rust 中创建 WASM 应用 -- [Basic Rust examples for WasmEdge](https://github.com/second-state/rust-examples) -- [Rust developer guides](/category/develop-wasm-apps-in-rust) - - WASI-NN with [PyTorch](../../develop/rust/wasinn/pytorch.md), [OpenVINO](../../develop/rust/wasinn/openvino.md), or [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) backends - - [HTTP and HTTPS client](../../develop/rust/http_service/client.md) - - [MySQL database client](../../develop/rust/database/my_sql_driver.md) - - Redis client - - Kafka client +- [WasmEdge 的基本 Rust 示例](https://github.com/second-state/rust-examples) +- [Rust 开发者指南](/category/develop-wasm-apps-in-rust) + - 使用 [PyTorch](../../develop/rust/wasinn/pytorch.md)、[OpenVINO](../../develop/rust/wasinn/openvino.md) 或 [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) 后端的 WASI-NN + - [HTTP 和 HTTPS 客户端](../../develop/rust/http_service/client.md) + - [MySQL 数据库客户端](../../develop/rust/database/my_sql_driver.md) + - Redis 客户端 + - Kafka 客户端 -## Run an HTTP server +## 运行 HTTP 服务器 -This example is a standalone HTTP server written in Rust. It demonstrates that Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/server). +这个示例是一个用 Rust 编写的独立的 HTTP 服务器。它演示了 Rust + WasmEdge 作为轻量级微服务堆栈。其源代码和构建说明在[此处](https://github.com/second-state/rust-examples/tree/main/server)。 -Use Docker to pull the container image (around 800KB) from Docker Hub and then run it in a WasmEdge container. The container starts as a server. Note how we map the container's port 8080 to the local host's port 8080 so that the server becomes accessible from outside of the WASM container. +使用 Docker 从 Docker Hub 拉取容器镜像(大约 800KB),然后在 WasmEdge 容器中运行它。该容器作为服务器启动。请注意,我们将容器的端口 8080 映射到本地主机的端口 8080,以便从 WASM 容器外部访问服务器。 ```bash $ docker run -dp 8080:8080 --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/rust-example-server:latest Listening on http://0.0.0.0:8080 ``` -From another terminal window, do the following. +在另一个终端窗口中执行以下操作。 ```bash $ curl http://localhost:8080/ @@ -67,43 +67,43 @@ $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to create WASM services in Rust +了解如何在 Rust 中创建 WASM 服务 -- [Rust developer guides](/category/develop-wasm-apps-in-rust) -- [HTTP application examples](https://github.com/WasmEdge/wasmedge_hyper_demo) -- [Database application examples](https://github.com/WasmEdge/wasmedge-db-examples) -- Lightweight microservices in Rust and WasmEdge +- [Rust 开发者指南](/category/develop-wasm-apps-in-rust) +- [HTTP 应用程序示例](https://github.com/WasmEdge/wasmedge_hyper_demo) +- [数据库应用程序示例](https://github.com/WasmEdge/wasmedge-db-examples) +- Rust 和 WasmEdge 中的轻量级微服务 - [WasmEdge + Nginx + MySQL](https://github.com/second-state/microservice-rust-mysql) - [WasmEdge + Kafka + MySQL](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) - [Dapr + WasmEdge](https://github.com/second-state/dapr-wasm) -## Run a JavaScript-based server +## 运行基于 JavaScript 的服务器 -This example is a standalone HTTP server written in JavaScript using the node.js API. It demonstrates WasmEdge as a lightweight runtime for zero-dependency and portable node.js applications. Its source code is available [here](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server). +这个示例是使用 Node.js API 编写的独立 HTTP 服务器。它演示了将 WasmEdge 作为零依赖和可移植的 Node.js 应用的轻量级运行时。其源代码在[此处](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server)。 ```bash $ docker run -dp 8080:8080 --rm --runtime=io.containerd.wasmedge.v1 --platform=wasi/wasm secondstate/node-example-server:latest ... ... ``` -From another terminal window, do the following. +在另一个终端窗口中执行以下操作。 ```bash $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to run JavaScript apps in WasmEdge. +了解如何在 WasmEdge 中运行 JavaScript 应用。 -- [The WasmEdge QuickJS runtime](https://github.com/second-state/wasmedge-quickjs) -- [AI inference application examples](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) -- [Web service client examples with fetch()](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) +- [WasmEdge QuickJS runtime](https://github.com/second-state/wasmedge-quickjs) +- [AI 推理应用示例](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) +- [使用 fetch() 的 Web 服务客户端示例](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) -## Next steps +## 下一步 -- [Learn more about building and managing WASM containers in Docker](../build-and-run/docker_wasm.md) -- [Basic Rust examples for WasmEdge](https://github.com/second-state/rust-examples) -- Use Docker Compose to build and Rust-based microservices - - [WasmEdge / MySQL / Nginx](https://github.com/docker/awesome-compose/tree/master/wasmedge-mysql-nginx) - Sample Wasm-based web application with a static HTML frontend, using a MySQL (MariaDB) database. The frontend connects to a WASM microservice written in Rust, that runs using the WasmEdge runtime. - - [WasmEdge / Kafka / MySQL](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) - Sample Wasm-based microservice that subscribes to a Kafka (Redpanda) queue topic, and transforms and saves any incoming message into a MySQL (MariaDB) database. -- Write WASM apps in your favorite languages, like [Rust](/category/develop-wasm-apps-in-rust), [C/C++](/category/develop-wasm-apps-in-cc), [JavaScript](/category/develop-wasm-apps-in-javascript), [Go](/category/develop-wasm-apps-in-go), and many other languages. +- [了解有关在 Docker 中构建和管理 WASM 容器](../build-and-run/docker_wasm.md) +- [WasmEdge 的基本 Rust 示例](https://github.com/second-state/rust-examples) +- 使用 Docker Compose 构建和 Rust 的微服务 + - [WasmEdge / MySQL / Nginx](https://github.com/docker/awesome-compose/tree/master/wasmedge-mysql-nginx) - 示例使用静态 HTML 前端的 Wasm-based Web 应用,使用 MySQL(MariaDB)数据库。前端连接到使用 WasmEdge runtime 运行的用 Rust 编写的 WASM 微服务。 + - [WasmEdge / Kafka / MySQL](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) - 示例 Wasm-based 微服务订阅 Kafka(Redpanda)队列主题,并将任何传入的消息转换并保存到 MySQL(MariaDB)数据库中。 +- 用你喜欢的语言编写 WASM 应用,比如 [Rust](/category/develop-wasm-apps-in-rust)、[C/C++](/category/develop-wasm-apps-in-cc)、[JavaScript](/category/develop-wasm-apps-in-javascript)、[Go](/category/develop-wasm-apps-in-go) 和许多其他语言。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_redhat.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_redhat.md index 3badd85e..e92d1ed5 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_redhat.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/getting-started/quick_start_redhat.md @@ -2,62 +2,62 @@ sidebar_position: 3 --- -# Quick start with Red Hat +# 在 Red Hat 下的快速入门 -In this guide, we will walk you through how to quickly run WasmEdge apps in Fedora / CentOS / Red Hat Linux / OpenShift systems. There is no additional dependencies as the entire development and runtime environments are managed by OpenSift / Podman. +在本指南中,我们将指导你如何在 Fedora / CentOS / Red Hat Linux / OpenShift 系统中快速运行 WasmEdge 应用程序。整个开发和运行环境由 OpenSift / Podman 管理,因此不需要额外的依赖。 :::note -If you are not using OpenShift / Podman, [get started here](quick_start.md). +如果你不使用 OpenShift / Podman,请[从这里开始](quick_start.md)。 ::: -We will cover the following examples. +我们将涵盖以下示例。 -- [Run a standalone WASM app](#run-a-standalone-wasm-app) -- [Run an HTTP server](#run-an-http-server) -- [Run a JavaScript server (node.js)](#run-a-javascript-based-server) +- [运行独立的 WASM 应用](#运行独立的-wasm-应用) +- [运行 HTTP 服务器](#运行一个 HTTP 服务器) +- [运行基于 JavaScript 的服务器 (node.js)](#运行一个基于 JavaScript 的服务器) -## Install +## 安装 -You can use an one-liner `dnf` command to install WasmEdge, [crun](https://github.com/containers/crun) and [Podman](https://www.redhat.com/en/topics/containers/what-is-podman) on your Fedora / CentOS / Red Hat Linux system. The WasmEdge Runtime is available as an [officially maintained upstream package](https://packages.fedoraproject.org/pkgs/wasmedge/wasmedge/index.html) for Fedora 37 and Red Hat REPL 8 and 9. +你可以使用一行 `dnf` 命令在 Fedora / CentOS / Red Hat Linux 系统上安装 WasmEdge,[crun](https://github.com/containers/crun) 和 [Podman](https://www.redhat.com/en/topics/containers/what-is-podman)。WasmEdge 运行时是 Fedora 37 和 Red Hat REPL 8、9 的[官方维护上游包](https://packages.fedoraproject.org/pkgs/wasmedge/wasmedge/index.html)。 ```bash dnf install wasmedge crun-wasm podman ``` -## Run a standalone WASM app +## 运行独立的 WASM 应用程序 -The Hello world example is a standalone Rust application. Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/hello). +Hello world 示例是一个独立的 Rust 应用程序。其源代码和构建说明可在[此处](https://github.com/second-state/rust-examples/tree/main/hello)找到。 -Use Podman to run the containerized WASM app. The WASM container image is stored in Docker Hub, and its image size is only 500KB. This image can run on any OS and CPU platform Red Hat supports. +使用 Podman 运行容器化的 WASM 应用。WASM 容器镜像存储在 Docker Hub 中,其镜像大小仅为 500KB。该镜像可在 Red Hat 支持的任何 OS 和 CPU 平台上运行。 ```bash $ podman --runtime /usr/bin/crun-wasm run --platform=wasi/wasm -t --rm docker.io/secondstate/rust-example-hello:latest Hello WasmEdge! ``` -To learn more about how to create WASM apps in Rust +了解如何在 Rust 中创建 WASM 应用的更多信息 -- [Basic Rust examples for WasmEdge](https://github.com/second-state/rust-examples) -- [Rust developer guides](/category/develop-wasm-apps-in-rust) - - WASI-NN with [PyTorch](../../develop/rust/wasinn/pytorch.md), [OpenVINO](../../develop/rust/wasinn/openvino.md), or [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) backends - - [HTTP and HTTPS client](../../develop/rust/http_service/client.md) - - [MySQL database client](../../develop/rust/database/my_sql_driver.md) - - Redis client - - Kafka client +- [WasmEdge 的基本 Rust 示例](https://github.com/second-state/rust-examples) +- [Rust 开发人员指南](/category/develop-wasm-apps-in-rust) + - 使用 [PyTorch](../../develop/rust/wasinn/pytorch.md)、[OpenVINO](../../develop/rust/wasinn/openvino.md) 或 [Tensorflow Lite](../../develop/rust/wasinn/tensorflow_lite.md) 后端的 WASI-NN + - [HTTP 和 HTTPS 客户端](../../develop/rust/http_service/client.md) + - [MySQL 数据库客户端](../../develop/rust/database/my_sql_driver.md) + - Redis 客户端 + - Kafka 客户端 -## Run an HTTP server +## 运行 HTTP 服务器 -This example is a standalone HTTP server written in Rust. It demonstrates Rust + WasmEdge as a lightweight stack for microservices. Its source code and build instructions are available [here](https://github.com/second-state/rust-examples/tree/main/server). +该示例是一个独立的用 Rust 编写的 HTTP 服务器。它演示了 Rust + WasmEdge 作为微服务的轻量级技术栈。其源代码和构建说明可在[此处](https://github.com/second-state/rust-examples/tree/main/server)找到。 -Use Podman to pull the container image (around 800KB) from Docker Hub and then run it in a WasmEdge container. The container starts as a server. Note how we map the container's port 8080 to the local host's port 8080 so that the server becomes accessible from outside of the WASM container. +使用 Podman 从 Docker Hub 拉取容器镜像(大约 800KB),然后在 WasmEdge 容器中运行它。容器作为服务器启动。请注意,我们将容器的端口 8080 映射到本地主机的端口 8080,以使服务器从 WASM 容器外部访问。 ```bash $ podman --runtime /usr/bin/crun-wasm run -dp 8080:8080 --platform=wasi/wasm -t --rm docker.io/secondstate/rust-example-server:latest Listening on http://0.0.0.0:8080 ``` -From another terminal window, do the following. +从另一个终端窗口执行以下命令。 ```bash $ curl http://localhost:8080/ @@ -67,39 +67,39 @@ $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to create WASM services in Rust +了解如何在 Rust 中创建 WASM 服务的更多信息 -- [Rust developer guides](/category/develop-wasm-apps-in-rust) -- [HTTP application examples](https://github.com/WasmEdge/wasmedge_hyper_demo) -- [Database application examples](https://github.com/WasmEdge/wasmedge-db-examples) -- Lightweight microservices in Rust and WasmEdge +- [Rust 开发者指南](/category/develop-wasm-apps-in-rust) +- [HTTP 应用示例](https://github.com/WasmEdge/wasmedge_hyper_demo) +- [数据库应用示例](https://github.com/WasmEdge/wasmedge-db-examples) +- Rust 和 WasmEdge 中的轻量级微服务 - [WasmEdge + Nginx + MySQL](https://github.com/second-state/microservice-rust-mysql) - [WasmEdge + Kafka + MySQL](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) - [Dapr + WasmEdge](https://github.com/second-state/dapr-wasm) -## Run a JavaScript-based server +## 运行基于 JavaScript 的服务器 -This example is a standalone HTTP server written in JavaScript using the node.js API. It demonstrates WasmEdge as a lightweight runtime for zero-dependency and portable node.js applications. Its source code is available [here](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server). +此示例是使用 Node.js API 编写的独立 HTTP 服务器,演示了 WasmEdge 作为零依赖和可移动的 Node.js 应用的轻量级运行时。其源代码可在[此处](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/docker_wasm/server)找到。 ```bash $ podman --runtime /usr/bin/crun-wasm run -dp 8080:8080 --platform=wasi/wasm -t --rm docker.io/secondstate/node-example-server:latest ... ... ``` -From another terminal window, do the following. +从另一个终端窗口执行以下命令。 ```bash $ curl http://localhost:8080/echo -X POST -d "Hello WasmEdge" Hello WasmEdge ``` -To learn more about how to run JavaScript apps in WasmEdge. +了解如何在 WasmEdge 中运行 JavaScript 应用的更多信息。 -- [The WasmEdge QuickJS runtime](https://github.com/second-state/wasmedge-quickjs) -- [AI inference application examples](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) -- [Web service client examples with fetch()](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) +- [WasmEdge QuickJS 运行时](https://github.com/second-state/wasmedge-quickjs) +- [AI 推理应用示例](https://github.com/second-state/wasmedge-quickjs/tree/main/example_js/tensorflow_lite_demo) +- [使用 fetch() 的 Web 服务客户端示例](https://github.com/second-state/wasmedge-quickjs/blob/main/example_js/wasi_http_fetch.js) -## Next steps +## 下一步 -- [Basic Rust examples for WasmEdge](https://github.com/second-state/rust-examples) -- Write WASM apps in your favorite languages, like [Rust](/category/develop-wasm-apps-in-rust), [C/C++](/category/develop-wasm-apps-in-cc), [JavaScript](/category/develop-wasm-apps-in-javascript), [Go](/category/develop-wasm-apps-in-go), and many other languages. +- [WasmEdge 的基本 Rust 示例](https://github.com/second-state/rust-examples) +- 用你喜欢的语言编写 WASM 应用,如 [Rust](/category/develop-wasm-apps-in-rust)、[C/C++](/category/develop-wasm-apps-in-cc)、[JavaScript](/category/develop-wasm-apps-in-javascript)、[Go](/category/develop-wasm-apps-in-go) 以及其他许多语言。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/install.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/install.md index 9b34f496..77da0395 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/install.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/install.md @@ -121,7 +121,7 @@ dnf install wasmedge ## 安装 WasmEdge 插件和依赖项 -WasmEdge 使用插件来扩展其功能。如果您想使用更多 WasmEdge 的功能,可以按下面的说明安装 WasmEdge 以及其插件和扩展: +WasmEdge 使用插件来扩展其功能。如果你想使用更多 WasmEdge 的功能,可以按下面的说明安装 WasmEdge 以及其插件和扩展: ### TLS 插件 @@ -362,7 +362,7 @@ ln -s libtensorflow_framework.2.dylib ~/.wasmedge/lib/libtensorflow_framework.dy ### TensorFlow-Lite 依赖 -如果未使用安装程序安装 `WasmEdge-TensorflowLite` 插件,您可以使用以下命令下载共享库: +如果未使用安装程序安装 `WasmEdge-TensorflowLite` 插件,你可以使用以下命令下载共享库: ```bash VERSION=TF-2.12.0-CC diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/overview.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/overview.md index f6e5435c..05f731a7 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/overview.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/overview.md @@ -11,14 +11,22 @@ WasmEdge 运行时为其包含的 WebAssembly 字节码程序提供了良好定 本章将介绍如何安装并开始使用 WasmEdge。 -将涵盖以下内容: +涵盖以下内容: - [安装和卸载 WasmEdge](install.md) - [入门指南](/category/getting-started-with-wasmEdge) - 介绍 [WasmEdge 运行时](/category/what-is-wasmedge) - [运行 WasmEdge](/category/running-with-wasmedge) -对于使用 WasmEdge 进行高级编程,请参考 [开发 WASM 应用程序](../develop/overview.md),[在应用中嵌入 WasmEdge](../embed/overview.md),或向 WasmEdge [进行贡献](../contribute/overview.md) 的指南。 +对于使用 WasmEdge 进行高级编程,请参考[开发 WASM 应用程序](../develop/overview.md),[在应用中嵌入 WasmEdge](../embed/overview.md),或向 WasmEdge [进行贡献](../contribute/overview.md) 的指南。 + +如果你有任何问题或有任何反馈,请通过以下方式联系我们: + +- [Discord 聊天](https://discord.gg/U4B5sFTkFc) +- [创建 GitHub 问题以获取技术支持](https://github.com/WasmEdge/WasmEdge/issues) +- [提交 GitHub 讨论](https://github.com/WasmEdge/WasmEdge/discussions) +- [在 Twitter 关注 @realwasmedge](https://twitter.com/realwasmedge) +对于使用 WasmEdge 进行高级编程,请参考[开发 WASM 应用程序](../develop/overview.md),[在应用中嵌入 WasmEdge](../embed/overview.md),或向 WasmEdge [进行贡献](../contribute/overview.md) 的指南。 如果你有任何问题或有任何反馈,请通过以下方式联系我们: diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/_category_.json index 6fd88542..3eb25b86 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/_category_.json @@ -1,8 +1,8 @@ { - "label": "WasmEdge Use-cases", + "label": "WasmEdge 使用案例", "position": 5, "link": { "type": "generated-index", - "description": "In this chapter, we will discuss use-cases of WasmEdge" + "description": "在本章中,我们将讨论 WasmEdge 的使用案例。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/_category_.json index 075ab1a1..99e4e782 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/_category_.json @@ -1,8 +1,8 @@ { - "label": "Serverless Platforms", + "label": "Serverless 平台", "position": 9, "link": { "type": "generated-index", - "description": "Run WebAssembly as an alternative lightweight runtime side-by-side with Docker and microVMs in cloud native infrastructure" + "description": "在云原生基础设施中,使用 WebAssembly 作为一种轻量级的备选运行时,与 Docker 和微型虚拟机(microVMs)并行运行。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/aws.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/aws.md index c23c5610..572a9f79 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/aws.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/aws.md @@ -2,31 +2,31 @@ sidebar_position: 1 --- -# WebAssembly Serverless Functions in AWS Lambda +# 在 AWS Lambda 中使用 WebAssembly Serverless Functions -In this article, we will show you two serverless functions in Rust and WasmEdge deployed on AWS Lambda. One is the image processing function, the other one is the TensorFlow inference function. +在本文中,我们将展示在 AWS Lambda 上部署的两个使用 Rust 和 WasmEdge 编写的无服务器函数。一个是图像处理函数,另一个是 TensorFlow 推理函数。 -> For the insight on why WasmEdge on AWS Lambda, please refer to the article [WebAssembly Serverless Functions in AWS Lambda](https://www.secondstate.io/articles/webassembly-serverless-functions-in-aws-lambda/) +> 想了解为什么要在 AWS Lambda 上使用 WasmEdge,请参阅文章 [WebAssembly Serverless Functions in AWS Lambda](https://www.secondstate.io/articles/webassembly-serverless-functions-in-aws-lambda/)。 -## Prerequisites +## 环境 -Since our demo WebAssembly functions are written in Rust, you will need a [Rust compiler](https://www.rust-lang.org/tools/install). Make sure that you install the `wasm32-wasi` compiler target as follows, in order to generate WebAssembly bytecode. +由于我们的演示 WebAssembly 函数是用 Rust 编写的,你需要安装 [Rust 编译器](https://www.rust-lang.org/tools/install)。确保你按照以下方式安装 `wasm32-wasi` 编译目标,以生成 WebAssembly 字节码。 ```bash rustup target add wasm32-wasi ``` -The demo application front end is written in [Next.js](https://nextjs.org/), and deployed on AWS Lambda. We will assume that you already have the basic knowledge of how to work with Next.js and Lambda. +演示应用的前端是用 [Next.js](https://nextjs.org/) 编写的,并部署在 AWS Lambda 上。我们假设你已经对如何使用 Next.js 和 Lambda 有基本的了解。 -## Example 1: Image processing +## 示例1:图像处理 -Our first demo application allows users to upload an image and then invoke a serverless function to turn it into black and white. A [live demo](https://second-state.github.io/aws-lambda-wasm-runtime/) deployed through GitHub Pages is available. +我们的第一个演示应用允许用户上传图像,然后调用一个无服务器函数将其转换为黑白图像。通过 GitHub Pages 部署了一个[实时演示](https://second-state.github.io/aws-lambda-wasm-runtime/)。 -Fork the [demo application’s GitHub repo](https://github.com/second-state/aws-lambda-wasm-runtime) to get started. To deploy the application on AWS Lambda, follow the guide in the repository [README](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md). +首先 Fork [demo 应用的 GitHub 存储库](https://github.com/second-state/aws-lambda-wasm-runtime)。要在 AWS Lambda 上部署应用程序,请按照存储库 [README](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md)中的指南进行操作。 -### Create the function +### 创建函数 -This repo is a standard Next.js application. The backend serverless function is in the `api/functions/image_grayscale` folder. The `src/main.rs` file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the black-white image to the `STDOUT`. +此存储库是一个标准的 Next.js 应用程序。后端无服务器函数位于 `api/functions/image_grayscale` 文件夹中。`src/main.rs` 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将黑白图像输出到 `STDOUT`。 ```rust use hex; @@ -54,24 +54,24 @@ fn main() { } ``` -You can use Rust’s `cargo` tool to build the Rust program into WebAssembly bytecode or native code. +你可以使用 Rust 的 `cargo` 工具将 Rust 程序构建成 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-grayscale/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建出结果复制到 `api` 文件夹。 ```bash cp target/wasm32-wasi/release/grayscale.wasm ../../ ``` -> When we build the docker image, `api/pre.sh` is executed. `pre.sh` installs the WasmEdge runtime, and then compiles each WebAssembly bytecode program into a native `so` library for faster execution. +> 在构建 Docker 镜像时,将执行 `api/pre.sh`。`pre.sh` 安装 WasmEdge 运行时,然后将每个 WebAssembly 字节码程序编译成本地 `so` 库,以实现更快的执行。 -### Create the service script to load the function +### 创建服务脚本以加载函数 -The [`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/hello.js) script loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice that [`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/hello.js) runs the compiled `grayscale.so` file generated by [`api/pre.sh`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/pre.sh) for better performance. +[`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/hello.js) 脚本加载 WasmEdge 运行时,在 WasmEdge 中启动编译后的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,为了实现更好的性能,[`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/hello.js) 运行的由 [`api/pre.sh`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/main/api/pre.sh) 生成的编译后的 `grayscale.so` 文件。 ```javascript const { spawn } = require('child_process'); @@ -99,7 +99,7 @@ function _runWasm(reqBody) { } ``` -The `exports.handler` part of `hello.js` exports an async function handler, used to handle different events every time the serverless function is called. In this example, we simply process the image by calling the function above and return the result, but more complicated event-handling behavior may be defined based on your need. We also need to return some `Access-Control-Allow` headers to avoid [Cross-Origin Resource Sharing (CORS)](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) errors when calling the serverless function from a browser. You can read more about CORS errors [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors) if you encounter them when replicating our example. +`hello.js` 中的 `exports.handler` 部分导出了一个异步函数处理程序,用于处理每次调用无服务器函数时的不同事件。在本例中,我们简单地通过调用上述函数处理图像并返回结果,但可以根据你的需求定义更复杂的事件处理行为。此外,我们还需要返回一些 `Access-Control-Allow` 标头以避免在从浏览器调用无服务器函数时出现 [跨源资源共享(CORS)](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS) 错误。如果你在复制我们的示例时遇到 CORS 错误,可以在[这里](https://developer.mozilla.org/zh-CN/docs/Web/HTTP/CORS/Errors)了解更多关于 CORS 错误的信息。 ```javascript exports.handler = async function (event, context) { @@ -123,11 +123,11 @@ exports.handler = async function (event, context) { }; ``` -### Build the Docker image for Lambda deployment +### 构建用于 Lambda 部署的 Docker 镜像 -Now we have the WebAssembly bytecode function and the script to load and connect to the web request. In order to deploy them as a function service on AWS Lambda, you still need to package the whole thing into a Docker image. +现在我们拥有了 WebAssembly 字节码函数以及加载和连接到网络请求的脚本。为了将它们部署为 AWS Lambda 上的函数服务,你仍然需要将整个内容打包成一个 Docker 镜像。 -We are not going to cover in detail about how to build the Docker image and deploy on AWS Lambda, as there are detailed steps in the [Deploy section of the repository README](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md#deploy). However, we will highlight some lines in the [`Dockerfile`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/Dockerfile) for you to avoid some pitfalls. +我们不会详细介绍如何构建 Docker 镜像并在 AWS Lambda 上部署,因为在[存储库 README 的部署部分](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md#deploy)中有详细的步骤。然而,我们将为你突出显示 [`Dockerfile`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/Dockerfile) 中的一些行,以避免一些问题。 ```dockerfile FROM public.ecr.aws/lambda/nodejs:14 @@ -149,41 +149,41 @@ COPY *.js ./ CMD [ "hello.handler" ] ``` -First, we are building the image from [AWS Lambda's Node.js base image](https://hub.docker.com/r/amazon/aws-lambda-nodejs). The advantage of using AWS Lambda's base image is that it includes the [Lambda Runtime Interface Client (RIC)](https://github.com/aws/aws-lambda-nodejs-runtime-interface-client), which we need to implement in our Docker image as it is required by AWS Lambda. The Amazon Linux uses `yum` as the package manager. +首先,我们是从 [AWS Lambda 的 Node.js 基础镜像](https://hub.docker.com/r/amazon/aws-lambda-nodejs)构建镜像。使用 AWS Lambda 基础镜像的优势在于它包含了[Lambda Runtime Interface Client (RIC)](https://github.com/aws/aws-lambda-nodejs-runtime-interface-client),这是 Lambda 运行环境中所需的依赖。Amazon Linux 使用 `yum` 作为包管理器。 -> These base images contain the Amazon Linux Base operating system, the runtime for a given language, dependencies and the Lambda Runtime Interface Client (RIC), which implements the Lambda [Runtime API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html). The Lambda Runtime Interface Client allows your runtime to receive requests from and send requests to the Lambda service. +> 这些基础镜像包含了 Amazon Linux Base 操作系统、特定语言的运行时、依赖项和 Lambda Runtime Interface Client (RIC),该客户端实现了 Lambda [运行时 API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html)。Lambda Runtime Interface Client 允许你的运行时接收来自 Lambda 服务的请求并发送请求。 -Second, we need to put our function and all its dependencies in the `/var/task` directory. Files in other folders will not be executed by AWS Lambda. +其次,我们需要将我们的函数及其所有依赖项放在 `/var/task` 目录中。其他文件夹中的文件将不会被AWS Lambda执行。 -Third, we need to define the default command when we start our container. `CMD [ "hello.handler" ]` means that we will call the `handler` function in `hello.js` whenever our serverless function is called. Recall that we have defined and exported the handler function in the previous steps through `exports.handler = ...` in `hello.js`. +第三,我们需要定义启动容器时的默认命令。`CMD [ "hello.handler" ]` 表示在调用无服务器函数时,我们将调用 `hello.js` 中的 `handler` 函数。请回想我们在之前的步骤中通过 `exports.handler = ...` 在 `hello.js` 中定义并导出了处理程序函数。 -### Optional: test the Docker image locally +### 可选:本地测试 Docker 镜像 -Docker images built from AWS Lambda's base images can be tested locally following [this guide](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html). Local testing requires [AWS Lambda Runtime Interface Emulator (RIE)](https://github.com/aws/aws-lambda-runtime-interface-emulator), which is already installed in all of AWS Lambda's base images. To test your image, first, start the Docker container by running: +从 AWS Lambda 的基础镜像构建的 Docker 镜像可以按照[此指南](https://docs.aws.amazon.com/lambda/latest/dg/images-test.html)在本地进行测试。本地测试需要 [AWS Lambda Runtime Interface Emulator (RIE)](https://github.com/aws/aws-lambda-runtime-interface-emulator),它已经安装在所有 AWS Lambda 的基础镜像中。要测试你的镜像,首先运行以下命令启动 Docker 容器: ```bash docker run -p 9000:8080 myfunction:latest ``` -This command sets a function endpoint on your local machine at `http://localhost:9000/2015-03-31/functions/function/invocations`. +此命令在本地机器上设置一个函数接口,地址为 `http://localhost:9000/2015-03-31/functions/function/invocations`。 -Then, from a separate terminal window, run: +然后,从另一个终端窗口运行: ```bash curl -XPOST "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' ``` -And you should get your expected output in the terminal. +你应该在终端中获得你期望的输出。 -If you don't want to use a base image from AWS Lambda, you can also use your own base image and install RIC and/or RIE while building your Docker image. Just follow **Create an image from an alternative base image** section from [this guide](https://docs.aws.amazon.com/lambda/latest/dg/images-create.html). +如果你不想使用 AWS Lambda 的基础镜像,你也可以使用自己的基础镜像,并在构建 Docker 镜像时安装 RIC 和/或 RIE。只需按照[此指南](https://docs.aws.amazon.com/lambda/latest/dg/images-create.html)中的 **Create an image from an alternative base image** 部分进行操作。 -That's it! After building your Docker image, you can deploy it to AWS Lambda following steps outlined in the repository [README](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md#deploy). Now your serverless function is ready to rock! +准备就绪!在构建完 Docker 镜像后,可以参考存储库 [README](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/README.md#deploy)中简述的步骤将其部署到 AWS Lambda。然后你的无服务器函数就可以开始工作了! -## Example 2: AI inference +## 示例 2:AI 推理 -The [second demo](https://github.com/second-state/aws-lambda-wasm-runtime/tree/tensorflow) application allows users to upload an image and then invoke a serverless function to classify the main subject on the image. +[第二个演示](https://github.com/second-state/aws-lambda-wasm-runtime/tree/tensorflow) 应用允许用户上传图像,然后调用一个无服务器函数对图像的主要对象进行分类。 -It is in [the same GitHub repo](https://github.com/second-state/aws-lambda-wasm-runtime/tree/tensorflow) as the previous example but in the `tensorflow` branch. The backend serverless function for image classification is in the `api/functions/image-classification` folder in the `tensorflow` branch. The `src/main.rs` file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the text output to the `STDOUT`. It utilizes the WasmEdge Tensorflow API to run the AI inference. +它位于与之前示例相同的 [GitHub 存储库](https://github.com/second-state/aws-lambda-wasm-runtime/tree/tensorflow),但在 `tensorflow` 分支中。用于图像分类的后端无服务器函数位于 `tensorflow` 分支中的 `api/functions/image-classification` 文件夹中。`src/main.rs` 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将文本输出到 `STDOUT`。它利用了 WasmEdge Tensorflow API 来运行AI推理。 ```rust pub fn main() { @@ -221,22 +221,22 @@ pub fn main() { } ``` -You can use the `cargo` tool to build the Rust program into WebAssembly bytecode or native code. +你可以使用 `cargo` 工具将 Rust 程序构建成 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-classification/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建产物复制到 `api` 文件夹。 ```bash cp target/wasm32-wasi/release/classify.wasm ../../ ``` -Again, the `api/pre.sh` script installs WasmEdge runtime and its Tensorflow dependencies in this application. It also compiles the `classify.wasm` bytecode program to the `classify.so` native shared library at the time of deployment. +同样,`api/pre.sh` 脚本在此应用程序中安装了 WasmEdge 运行时及其 TensorFlow 依赖项。它还在部署时将 `classify.wasm` 字节码程序编译为 `classify.so` 本机共享库。 -The [`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/hello.js) script loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice [`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/hello.js) runs the compiled `classify.so` file generated by [`api/pre.sh`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/pre.sh) for better performance. The handler function is similar to our previous example, and is omitted here. +[`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/hello.js) 脚本加载 WasmEdge 运行时,在 WasmEdge 中启动编译后的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,[`api/hello.js`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/hello.js) 运行由 [`api/pre.sh`](https://github.com/second-state/aws-lambda-wasm-runtime/blob/tensorflow/api/pre.sh) 生成的编译后的 `classify.so` 文件,以获得更好的性能。处理函数类似于我们之前的示例,在此省略。 ```javascript const { spawn } = require('child_process'); @@ -267,6 +267,6 @@ function _runWasm(reqBody) { exports.handler = ... // _runWasm(reqBody) is called in the handler ``` -You can build your Docker image and deploy the function in the same way as outlined in the previous example. Now you have created a web app for subject classification! +你可以按照之前的示例中概述的方式构建你的 Docker 镜像并部署函数。现在你已经创建了一个用于主题分类的 Web 应用! -Next, it's your turn to use the [aws-lambda-wasm-runtime repo](https://github.com/second-state/aws-lambda-wasm-runtime/tree/main) as a template to develop Rust serverless function on AWS Lambda. Looking forward to your great work. +接下来,轮到你使用 [aws-lambda-wasm-runtime 存储库](https://github.com/second-state/aws-lambda-wasm-runtime/tree/main) 作为模板,在 AWS Lambda 上开发 Rust 无服务器函数了。期待着你的出色工作。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/netlify.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/netlify.md index 0f4b82db..fccf79de 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/netlify.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/netlify.md @@ -1,30 +1,30 @@ --- sidebar_position: 2 --- +# 在 Netlify 上的 WebAssembly 无服务器函数 -# WebAssembly Serverless Functions in Netlify +在本文中,我们将展示在 Netlify 上部署的两个使用 Rust 和 WasmEdge 的无服务器函数。一个是图像处理功能,另一个是 TensorFlow 推理功能。 -In this article we will show you two serverless functions in Rust and WasmEdge deployed on Netlify. One is the image processing function, the other one is the TensorFlow inference function. +> 欲了解更多有关为何在 Netlify 上使用 WasmEdge,请参阅文章 [WebAssembly Serverless Functions in Netlify](https://www.secondstate.io/articles/netlify-wasmedge-webassembly-rust-serverless/)。 -> For more insights on why WasmEdge on Netlify, please refer to the article [WebAssembly Serverless Functions in Netlify](https://www.secondstate.io/articles/netlify-wasmedge-webassembly-rust-serverless/). +## 环境 -## Prerequisite - -Since our demo WebAssembly functions are written in Rust, you will need a [Rust compiler](https://www.rust-lang.org/tools/install). Make sure that you install the `wasm32-wasi` compiler target as follows, in order to generate WebAssembly bytecode. +由于我们的演示 WebAssembly 函数是用 Rust 编写的,你将需要一个 [Rust 编译器](https://www.rust-lang.org/tools/install)。确保按照以下步骤安装 `wasm32-wasi` 编译目标,以便生成 WebAssembly 字节码。 ```bash rustup target add wasm32-wasi ``` -The demo application front end is written in [Next.js](https://nextjs.org/), and deployed on Netlify. We will assume that you already have the basic knowledge of how to work with Next.js and Netlify. +演示应用的前端是用 [Next.js](https://nextjs.org/) 编写的,并部署在 Netlify 上。我们假设你已经具备使用 Next.js 和 Netlify 的基本知识。 + +## 示例 1:图像处理 -## Example 1: Image processing +我们的第一个演示应用允许用户上传图像,然后调用无服务器函数将其转换为黑白。部署在 Netlify 上的 [实时演示](https://60fe22f9ff623f0007656040--reverent-hodgkin-dc1f51.netlify.app/) 可供使用。 -Our first demo application allows users to upload an image and then invoke a serverless function to turn it into black and white. A [live demo](https://60fe22f9ff623f0007656040--reverent-hodgkin-dc1f51.netlify.app/) deployed on Netlify is available. +首先请 fork [演示应用的 GitHub 存储库](https://github.com/second-state/netlify-wasm-runtime)。要在 Netlify 上部署该应用,只需[将你的 GitHub 存储库添加到 Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/)。 -Fork the [demo application’s GitHub repo](https://github.com/second-state/netlify-wasm-runtime) to get started. To deploy the application on Netlify, just [add your github repo to Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/). +该存储库是一个标准的 Netlify 平台 Next.js 应用程序。后端无服务器函数位于 [`api/functions/image_grayscale`](https://github.com/second-state/netlify-wasm-runtime/tree/main/api/functions/image-grayscale) 文件夹中。[`src/main.rs`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/functions/image-grayscale/src/main.rs) 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将黑白图像输出到 `STDOUT`。 -This repo is a standard Next.js application for the Netlify platform. The backend serverless function is in the [`api/functions/image_grayscale`](https://github.com/second-state/netlify-wasm-runtime/tree/main/api/functions/image-grayscale) folder. The [`src/main.rs`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/functions/image-grayscale/src/main.rs) file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the black-white image to the `STDOUT`. ```rust use hex; @@ -52,22 +52,22 @@ fn main() { } ``` -You can use Rust’s `cargo` tool to build the Rust program into WebAssembly bytecode or native code. +你可以使用 Rust 的 `cargo` 工具将 Rust 程序构建成 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-grayscale/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建产物复制到 `api` 文件夹。 ```bash cp target/wasm32-wasi/release/grayscale.wasm ../../ ``` -> The Netlify function runs [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/pre.sh) upon setting up the serverless environment. It installs the WasmEdge runtime, and then compiles each WebAssembly bytecode program into a native `so` library for faster execution. +> 在设置无服务器环境时,Netlify 函数会运行 [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/pre.sh)。该脚本安装 WasmEdge 运行时,然后将每个 WebAssembly 字节码程序编译为本机 `so` 库,以实现更快的执行。 -The [`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/hello.js) script loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice [`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/hello.js) runs the compiled `grayscale.so` file generated by [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/pre.sh) for better performance. +[`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/hello.js) 脚本加载 WasmEdge 运行时,启动 WasmEdge 中编译的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,为了获得更好的性能,[`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/hello.js) 运行的是由 [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/main/api/pre.sh) 生成的编译后的 `grayscale.so` 文件。 ```javascript const fs = require('fs'); @@ -96,13 +96,13 @@ module.exports = (req, res) => { }; ``` -That's it. [Deploy the repo to Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/) and you now have a Netlify Jamstack app with a high-performance Rust and WebAssembly based serverless backend. +准备就绪。现在[将存储库部署到 Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/),你就拥有了一个基于 Rust 和 WebAssembly 的高性能无服务器后端的 Netlify Jamstack 应用。 -## Example 2: AI inference +## 示例 2:AI 推理 -The [second demo](https://60ff7e2d10fe590008db70a9--reverent-hodgkin-dc1f51.netlify.app/) application allows users to upload an image and then invoke a serverless function to classify the main subject on the image. +[第二个演示](https://60ff7e2d10fe590008db70a9--reverent-hodgkin-dc1f51.netlify.app/) 应用允许用户上传图像,然后调用一个无服务器函数对图像中的主要主题进行分类。 -It is in [the same GitHub repo](https://github.com/second-state/netlify-wasm-runtime/tree/tensorflow) as the previous example but in the `tensorflow` branch. The backend serverless function for image classification is in the [`api/functions/image-classification`](https://github.com/second-state/netlify-wasm-runtime/tree/tensorflow/api/functions/image-classification) folder in the `tensorflow` branch. The [`src/main.rs`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/functions/image-classification/src/main.rs) file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the text output to the `STDOUT`. It utilizes the WasmEdge Tensorflow API to run the AI inference. +它位于[与上一个示例相同的 GitHub 存储库](https://github.com/second-state/netlify-wasm-runtime/tree/tensorflow)中,但在 `tensorflow` 分支中。用于图像分类的后端无服务器函数位于 `tensorflow` 分支的 [`api/functions/image-classification`](https://github.com/second-state/netlify-wasm-runtime/tree/tensorflow/api/functions/image-classification) 文件夹中。[`src/main.rs`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/functions/image-classification/src/main.rs) 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将文本输出输出到 `STDOUT`。它利用 WasmEdge Tensorflow API 运行 AI 推理。 ```rust pub fn main() { @@ -140,22 +140,22 @@ pub fn main() { } ``` -You can use the `cargo` tool to build the Rust program into WebAssembly bytecode or native code. +你可以使用 `cargo` 工具将 Rust 程序构建为 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-classification/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建产物复制到 `api` 文件夹中。 ```bash cp target/wasm32-wasi/release/classify.wasm ../../ ``` -Again, the [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/pre.sh) script installs WasmEdge runtime and its Tensorflow dependencies in this application. It also compiles the `classify.wasm` bytecode program to the `classify.so` native shared library at the time of deployment. +同样,[`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/pre.sh) 脚本在该应用程序中安装 WasmEdge 运行时及其 Tensorflow 依赖项。它还在部署时将 `classify.wasm` 字节码程序编译为 `classify.so` 本机共享库。 -The [`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/hello.js) script loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice [`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/hello.js) runs the compiled `classify.so` file generated by [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/pre.sh) for better performance. +[`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/hello.js) 脚本加载 WasmEdge 运行时,启动在 WasmEdge 中编译的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,[`api/hello.js`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/hello.js) 运行由 [`api/pre.sh`](https://github.com/second-state/netlify-wasm-runtime/blob/tensorflow/api/pre.sh) 生成的编译后的 `classify.so` 文件,以获得更好的性能。 ```javascript const fs = require('fs'); @@ -184,6 +184,6 @@ module.exports = (req, res) => { }; ``` -You can now [deploy your forked repo to Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/) and have a web app for subject classification. +现在,你可以[将你 Fork 的存储库部署到 Netlify](https://www.netlify.com/blog/2016/09/29/a-step-by-step-guide-deploying-on-netlify/),获得一个用于主题分类的 Web 应用程序。 -Next, it's your turn to develop Rust serverless functions in Netlify using the [netlify-wasm-runtime repo](https://github.com/second-state/netlify-wasm-runtime) as a template. Looking forward to your great work. +接下来,轮到你使用 [netlify-wasm-runtime 存储库](https://github.com/second-state/netlify-wasm-runtime) 作为模板在 Netlify 中开发 Rust 无服务器函数了。期待着你出色的工作。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/tencent.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/tencent.md index 9937f714..a2b97f5c 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/tencent.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/tencent.md @@ -1,11 +1,11 @@ --- sidebar_position: 4 --- +# 腾讯云上的 WebAssembly 无服务器函数 -# WebAssembly serverless functions on Tencent Cloud +由于腾讯云的主要用户来自中国,所以本教程是[用中文撰写的](https://my.oschina.net/u/4532842/blog/5172639)。 -As the main users of Tencent Cloud are from China, so the tutorial is [written in Chinese](https://my.oschina.net/u/4532842/blog/5172639). +我们还提供了一个代码模板,用于在腾讯云上部署无服务器的 WebAssembly 函数,请查看 [tencent-scf-wasm-runtime 存储库](https://github.com/second-state/tencent-scf-wasm-runtime)。 -We also provide a code template for deploying serverless WebAssembly functions on Tencent Cloud, please check out [the tencent-scf-wasm-runtime repo](https://github.com/second-state/tencent-scf-wasm-runtime). +Fork 这个存储库并开始编写你自己的 Rust 函数。 -Fork the repo and start writing your own rust functions. diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/vercel.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/vercel.md index 3ef87bd5..6ef540b4 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/vercel.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/serverless/vercel.md @@ -2,29 +2,29 @@ sidebar_position: 5 --- -# Rust and WebAssembly Serverless functions in Vercel +# 运行在 Vercel 上的 Rust 和 WebAssembly 无服务器函数 -In this article, we will show you two serverless functions in Rust and WasmEdge deployed on Vercel. One is the image processing function, the other one is the TensorFlow inference function. +在本文中,我们将展示在 Vercel 上部署的两个使用 Rust 和 WasmEdge 编写的无服务器函数。一个是图像处理函数,另一个是 TensorFlow 推理函数。 -> For more insights on why WasmEdge on Vercel, please refer to the article [Rust and WebAssembly Serverless Functions in Vercel](https://www.secondstate.io/articles/vercel-wasmedge-webassembly-rust/). +> 欲了解更多关于为何在 Vercel 上使用 WasmEdge,请参阅文章 [Rust and WebAssembly Serverless Functions in Vercel](https://www.secondstate.io/articles/vercel-wasmedge-webassembly-rust/)。 -## Prerequisite +## 环境 -Since our demo WebAssembly functions are written in Rust, you will need a [Rust compiler](https://www.rust-lang.org/tools/install). Make sure that you install the `wasm32-wasi` compiler target as follows, in order to generate WebAssembly bytecode. +由于我们的演示 WebAssembly 函数是用 Rust 编写的,你将需要 [Rust 编译器](https://www.rust-lang.org/tools/install)。确保你按照以下方式安装 `wasm32-wasi` 编译目标,以生成 WebAssembly 字节码。 ```bash rustup target add wasm32-wasi ``` -The demo application front end is written in [Next.js](https://nextjs.org/), and deployed on Vercel. We will assume that you already have the basic knowledge of how to work with Vercel. +演示应用的前端是用 [Next.js](https://nextjs.org/) 编写的,并部署在 Vercel 上。我们假设你对如何使用 Vercel 已经有基本的了解。 -## Example 1: Image processing +## 示例1:图像处理 -Our first demo application allows users to upload an image and then invoke a serverless function to turn it into black and white. A [live demo](https://vercel-wasm-runtime.vercel.app/) deployed on Vercel is available. +我们的第一个演示应用允许用户上传图像,然后调用一个无服务器函数将其转换为黑白图像。在 Vercel 上部署的[实时演示](https://vercel-wasm-runtime.vercel.app/)可以直接使用。 -Fork the [demo application’s GitHub repo](https://github.com/second-state/vercel-wasm-runtime) to get started. To deploy the application on Vercel, just [import the Github repo](https://vercel.com/docs/git#deploying-a-git-repository) from [Vercel for Github](https://vercel.com/docs/git/vercel-for-github) web page. +首先 Fork [演示应用的 GitHub 存储库](https://github.com/second-state/vercel-wasm-runtime)。要在 Vercel 上部署应用程序,只需从 [Vercel for Github](https://vercel.com/docs/git/vercel-for-github) 网页中[导入 Github 存储库](https://vercel.com/docs/git#deploying-a-git-repository)。 -This repo is a standard Next.js application for the Vercel platform. The backend serverless function is in the [`api/functions/image_grayscale`](https://github.com/second-state/vercel-wasm-runtime/tree/main/api/functions/image-grayscale) folder. The [`src/main.rs`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/functions/image-grayscale/src/main.rs) file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the black-white image to the `STDOUT`. +该存储库是一个标准的适用于 Vercel 平台的 Next.js 应用程序。后端无服务器函数位于 [`api/functions/image_grayscale`](https://github.com/second-state/vercel-wasm-runtime/tree/main/api/functions/image-grayscale) 文件夹中。[`src/main.rs`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/functions/image-grayscale/src/main.rs) 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将黑白图像输出到 `STDOUT`。 ```rust use hex; @@ -52,22 +52,25 @@ fn main() { } ``` -You can use Rust’s `cargo` tool to build the Rust program into WebAssembly bytecode or native code. + +你可以使用 Rust 的 `cargo` 工具将 Rust 程序构建成 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-grayscale/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建产物复制到 `api` 文件夹。 ```bash cp target/wasm32-wasi/release/grayscale.wasm ../../ ``` -> Vercel runs [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/pre.sh) upon setting up the serverless environment. It installs the WasmEdge runtime, and then compiles each WebAssembly bytecode program into a native `so` library for faster execution. +> 在构建 Docker 镜像时,将执行 `api/pre.sh`。`pre.sh` 安装 WasmEdge 运行时,然后将每个 WebAssembly 字节码程序编译成本地 `so` 库,以实现更快的执行。 + +### 创建服务脚本以加载函数 -The [`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/hello.js) file conforms Vercel serverless specification. It loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice [`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/hello.js) runs the compiled `grayscale.so` file generated by [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/pre.sh) for better performance. +[`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/hello.js) 脚本加载 WasmEdge 运行时,在 WasmEdge 中启动编译后的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,为了实现更好的性能,[`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/hello.js) 运行的是由 [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/main/api/pre.sh) 生成的编译后的 `grayscale.so` 文件。 ```javascript const fs = require('fs'); @@ -96,15 +99,15 @@ module.exports = (req, res) => { }; ``` -That's it. [Deploy the repo to Vercel](https://vercel.com/docs/git#deploying-a-git-repository) and you now have a Vercel Jamstack app with a high-performance Rust and WebAssembly based serverless backend. +准备就绪。现在[将存储库部署到 Vercel](https://vercel.com/docs/git#deploying-a-git-repository)上,你就拥有了一个使用高性能 Rust 和 WebAssembly 构建的无服务器后端的 Vercel Jamstack 应用程序。 -## Example 2: AI inference +## 示例 2:AI 推理 -The [second demo](https://vercel-wasm-runtime.vercel.app/) application allows users to upload an image and then invoke a serverless function to classify the main subject on the image. +[第二个演示](https://vercel-wasm-runtime.vercel.app/) 应用允许用户上传图像,然后调用一个无服务器函数对图像的主要对象进行分类。 -It is in [the same GitHub repo](https://github.com/second-state/vercel-wasm-runtime) as the previous example but in the `tensorflow` branch. Note: when you [import this GitHub repo](https://vercel.com/docs/git#deploying-a-git-repository) on the Vercel website, it will create a [preview URL](https://vercel.com/docs/platform/deployments#preview) for each branch. The `tensorflow` branch would have its own deployment URL. +这个示例位于[与之前示例相同的 GitHub 存储库](https://github.com/second-state/vercel-wasm-runtime),但在 `tensorflow` 分支中。注意:当你[在 Vercel 网站上导入此 GitHub 存储库](https://vercel.com/docs/git#deploying-a-git-repository)时,它会为每个分支创建一个[预览 URL](https://vercel.com/docs/platform/deployments#preview)。`tensorflow` 分支将有其自己的部署URL。 -The backend serverless function for image classification is in the [`api/functions/image-classification`](https://github.com/second-state/vercel-wasm-runtime/tree/tensorflow/api/functions/image-classification) folder in the `tensorflow` branch. The [`src/main.rs`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/functions/image-classification/src/main.rs) file contains the Rust program’s source code. The Rust program reads image data from the `STDIN`, and then outputs the text output to the `STDOUT`. It utilizes the WasmEdge Tensorflow API to run the AI inference. +用于图像分类的后端无服务器函数位于 `tensorflow` 分支中的 [`api/functions/image-classification`](https://github.com/second-state/vercel-wasm-runtime/tree/tensorflow/api/functions/image-classification) 文件夹中。[`src/main.rs`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/functions/image-classification/src/main.rs) 文件包含了 Rust 程序的源代码。Rust 程序从 `STDIN` 读取图像数据,然后将文本输出到 `STDOUT`。它利用了 WasmEdge Tensorflow API 来进行AI 推理。 ```rust pub fn main() { @@ -142,22 +145,22 @@ pub fn main() { } ``` -You can use the `cargo` tool to build the Rust program into WebAssembly bytecode or native code. +你可以使用 `cargo` 工具将 Rust 程序构建成 WebAssembly 字节码或本机代码。 ```bash cd api/functions/image-classification/ cargo build --release --target wasm32-wasi ``` -Copy the build artifacts to the `api` folder. +将构建产物复制到 `api` 文件夹。 ```bash cp target/wasm32-wasi/release/classify.wasm ../../ ``` -Again, the [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/pre.sh) script installs WasmEdge runtime and its Tensorflow dependencies in this application. It also compiles the `classify.wasm` bytecode program to the `classify.so` native shared library at the time of deployment. +同样,`api/pre.sh` 脚本在此应用程序中安装了 WasmEdge 运行时及其 TensorFlow 依赖项。它还在部署时将 `classify.wasm` 字节码程序编译为 `classify.so` 本机共享库。 -The [`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/hello.js) file conforms Vercel serverless specification. It loads the WasmEdge runtime, starts the compiled WebAssembly program in WasmEdge, and passes the uploaded image data via `STDIN`. Notice [`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/hello.js) runs the compiled `classify.so` file generated by [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/pre.sh) for better performance. +[`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/hello.js) 文件符合 Vercel 无服务器规范。它加载 WasmEdge 运行时,在 WasmEdge 中启动已编译的 WebAssembly 程序,并通过 `STDIN` 传递上传的图像数据。请注意,[`api/hello.js`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/hello.js) 运行由 [`api/pre.sh`](https://github.com/second-state/vercel-wasm-runtime/blob/tensorflow/api/pre.sh) 生成的已编译 `classify.so` 文件,以获得更佳的性能。 ```javascript const fs = require('fs'); @@ -186,6 +189,6 @@ module.exports = (req, res) => { }; ``` -You can now [deploy your forked repo to Vercel](https://vercel.com/docs/git#deploying-a-git-repository) and have a web app for subject classification. +现在,你可以[将你 Fork 的存储库部署到 Vercel](https://vercel.com/docs/git#deploying-a-git-repository),获得一个用于主题分类的 Web 应用。 -Next, it's your turn to use [the vercel-wasm-runtime repo](https://github.com/second-state/vercel-wasm-runtime) as a template to develop your own Rust serverless functions in Vercel. Looking forward to your great work. +接下来,轮到你使用 [vercel-wasm-runtime 存储库](https://github.com/second-state/vercel-wasm-runtime) 作为模板,在 Vercel 中开发你自己的 Rust 无服务器函数了。期待着你出色的工作。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/use-cases.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/use-cases.md index 69284963..aa886582 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/use-cases.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/use-cases.md @@ -2,22 +2,22 @@ sidebar_position: 1 --- -# Use Cases +# 使用案例 -Featuring AOT compiler optimization, WasmEdge is one of the fastest WebAssembly runtimes on the market today. Therefore WasmEdge is widely used in edge computing, automotive, Jamstack, serverless, SaaS, service mesh, and even blockchain applications. +由于 WasmEdge 具备 AOT(Ahead of Time)编译器优化,是当今市场上最快的 WebAssembly 运行时之一。因此,在边缘计算、汽车行业、Jamstack、无服务器架构、SaaS、服务网格,甚至区块链应用中广泛使用。 -- Modern web apps feature rich UIs that are rendered in the browser and/or on the edge cloud. WasmEdge works with popular web UI frameworks, such as React, Vue, Yew, and Percy, to support isomorphic [server-side rendering (SSR)](../../embed/use-case/ssr-modern-ui.md) functions on edge servers. It could also support server-side rendering of Unity3D animations and AI-generated interactive videos for web applications on the edge cloud. +- 现代 Web 应用程序具有丰富的用户界面,这些界面在浏览器和/或边缘云上渲染。WasmEdge 与流行的 Web UI 框架(如 React、Vue、Yew 和 Percy)合作,支持边缘服务器上的同构 [服务器端渲染(SSR)](../../embed/use-case/ssr-modern-ui.md) 功能。它还可以支持在边缘云上为 Unity3D 动画和 AI 生成的交互式视频进行服务器端渲染,用于 Web 应用程序。 -- WasmEdge provides a lightweight, secure and high-performance runtime for microservices. It is fully compatible with application service frameworks such as Dapr, and service orchestrators like Kubernetes. WasmEdge microservices can run on edge servers, and have access to distributed cache, to support both stateless and stateful business logic functions for modern web apps. Also related: Serverless function-as-a-service in public clouds. +- WasmEdge 为微服务提供了一个轻量级、安全且高性能的运行时。它与 Dapr 等应用服务框架以及 Kubernetes 等服务编排器完全兼容。WasmEdge 微服务可以在边缘服务器上运行,并且可以访问分布式缓存,以支持现代 Web 应用程序的无状态和有状态业务逻辑功能。另外相关的有:公共云中的无服务器函数即服务。 -- [Serverless SaaS (Software-as-a-Service)](/category/serverless-platforms) functions enables users to extend and customize their SaaS experience without operating their own API callback servers. The serverless functions can be embedded into the SaaS or reside on edge servers next to the SaaS servers. Developers simply upload functions to respond to SaaS events or to connect SaaS APIs. +- [无服务器 SaaS(软件即服务)](/category/serverless-platforms) 函数使用户可以在不运营自己的 API 回调服务器的情况下扩展和自定义其 SaaS 体验。无服务器函数可以嵌入到 SaaS 中,或者驻留在与 SaaS 服务器相邻的边缘服务器上。开发人员可以简单地上传函数来响应 SaaS 事件或连接 SaaS API。 -- [Smart device apps](./wasm-smart-devices.md) could embed WasmEdge as a middleware runtime to render interactive content on the UI, connect to native device drivers, and access specialized hardware features (i.e, the GPU for AI inference). The benefits of the WasmEdge runtime over native-compiled machine code include security, safety, portability, manageability, and developer productivity. WasmEdge runs on Android, OpenHarmony, and seL4 RTOS devices. +- [智能设备应用](./wasm-smart-devices.md) 可以将 WasmEdge 嵌入为中间件运行时,用于在 UI 上呈现交互式内容、连接原生设备驱动程序,并访问专门的硬件功能(例如,用于 AI 推断的 GPU)。与本地编译的机器码相比,WasmEdge 运行时的优势包括安全性、安全性、可移植性、可管理性和开发者生产力。WasmEdge 可在 Android、OpenHarmony 和 seL4 RTOS 设备上运行。 -- WasmEdge could support high performance DSLs (Domain Specific Languages) or act as a cloud-native JavaScript runtime by embedding a JS execution engine or interpreter. +- WasmEdge 可以支持高性能的领域特定语言(DSL),或者作为一个云原生的 JavaScript 运行时,通过嵌入 JS 执行引擎或解释器。 -- Developers can leverage container tools such as [Kubernetes](../../develop/deploy/kubernetes/kubernetes-containerd-crun.md), Docker and CRI-O to deploy, manage, and run lightweight WebAssembly applications. +- 开发人员可以利用诸如 [Kubernetes](../../develop/deploy/kubernetes/kubernetes-containerd-crun.md)、Docker 和 CRI-O 等容器工具来部署、管理和运行轻量级的 WebAssembly 应用程序。 -- WasmEdge applications can be plugged into existing application frameworks or platforms. +- WasmEdge 应用程序可以插入到现有的应用程序框架或平台中。 -If you have any great ideas on WasmEdge, don't hesitate to open a GitHub issue to discuss together. +如果你对 WasmEdge 有任何好的想法,请毫不犹豫地开启一个 GitHub 问题,我们一起讨论。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/wasm-smart-devices.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/wasm-smart-devices.md index 17cd9ad7..c6e822e6 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/wasm-smart-devices.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/usage/wasm-smart-devices.md @@ -2,13 +2,13 @@ sidebar_position: 4 --- -# WasmEdge On Smart Devices +# WasmEdge 在智能设备上 -Smart device apps could embed WasmEdge as a middleware runtime to render interactive content on the UI, connect to native device drivers, and access specialized hardware features (i.e., the GPU for AI inference). The benefits of the WasmEdge runtime over native-compiled machine code include security, safety, portability, manageability, OTA upgradability, and developer productivity. WasmEdge runs on the following device OSes. +智能设备应用可以将 WasmEdge 嵌入为中间件运行时,以在用户界面上呈现交互式内容,连接原生设备驱动程序,并访问专门的硬件功能(例如,用于 AI 推断的 GPU)。WasmEdge 运行时相对于本地编译的机器码的优势包括安全性、安全性、可移植性、可管理性、OTA 升级能力和开发者生产力。WasmEdge 可在以下设备操作系统上运行。 - [Android](/category/build-and-run-wasmedge-on-android) - [OpenHarmony](../../contribute/source/os/openharmony.md) - [Raspberry Pi](../../contribute/source/os/raspberrypi.md) - [The seL4 RTOS](../../contribute/source/os/sel4.md) -With WasmEdge on both the device and the edge server, we can support [isomorphic Server-Side Rendering (SSR)](../../develop/rust/ssr.md) and [microservices](../../start/build-and-run/docker_wasm.md#deploy-the-microservice-example) for rich-client mobile applications that are both portable and upgradeable. +通过在设备和边缘服务器上使用 WasmEdge,我们可以为丰富的客户端移动应用程序提供支持,实现[同构的服务器端渲染(SSR)](../../develop/rust/ssr.md)和[微服务](../../start/build-and-run/docker_wasm.md#deploy-the-microservice-example),使其具备可移植性和可升级性。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/_category_.json index 0e257dc0..39840806 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/_category_.json @@ -1,8 +1,8 @@ { - "label": "What is WasmEdge", + "label": "WasmEdge 是什么", "position": 4, "link": { "type": "generated-index", - "description": "WasmEdge is a WebAssembly runtime optimized for cloud-native and edge-native applications. It is a safe, fast, lightweight, and portable alternative to Linux containers in the cloud. It is also an ideal runtime for serverless functions, user-defined functions, embedded functions in application platforms and data pipelines." + "description": "WasmEdge 是为云原生和边缘原生应用优化的 WebAssembly 运行时。它是云环境中安全、快速、轻量且可移植的替代方案,适合于 Linux 容器。它也是无服务器函数、用户自定义函数、应用平台和数据流水线中的嵌入式函数的理想运行时。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/comparison.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/comparison.md index 20fc78cb..893a696a 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/comparison.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/comparison.md @@ -2,15 +2,15 @@ sidebar_position: 5 --- -# Comparison +# 对比 -## What's the relationship between WebAssembly and Docker? +## WebAssembly 与 Docker 之间的关系是什么? -Check out our infographic [WebAssembly vs. Docker](https://wasmedge.org/wasm_docker/). WebAssembly runs side by side with Docker in cloud native and edge native applications. +请查看我们的信息图表 [WebAssembly vs. Docker](https://wasmedge.org/wasm_docker/)。在云原生和边缘原生应用中,WebAssembly 与 Docker 并驾齐驱。 -## What's the difference for Native clients (NaCl), Application runtimes, and WebAssembly? +## Native clients(NaCl)、应用程序运行时和 WebAssembly 之间有何区别? -We created a handy table for the comparison. +我们创建了一个便捷的表格进行对比。 | | NaCl | Application runtimes (eg Node & Python) | Docker-like container | WebAssembly | | --- | --- | --- | --- | --- | @@ -24,6 +24,6 @@ We created a handy table for the comparison. | Ease of use | OK | Great | Great | OK | | Manageability | Poor | Poor | Great | Great | -## What's the difference between WebAssembly and eBPF? +## WebAssembly 与 eBPF 有何区别? -`eBPF` is the bytecode format for a Linux kernel space VM that is suitable for network or security related tasks. WebAssembly is the bytecode format for a user space VM that is suited for business applications. [See details here](https://medium.com/codex/ebpf-and-webassembly-whose-vm-reigns-supreme-c2861ce08f89). +`eBPF` 是适用于网络或安全相关任务的 Linux 内核空间虚拟机的字节码格式。而 WebAssembly 是适用于业务应用的用户空间虚拟机的字节码格式。[点击此处查看详细信息](https://medium.com/codex/ebpf-and-webassembly-whose-vm-reigns-supreme-c2861ce08f89)。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/component_model.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/component_model.md index f8948c21..e0f4dc88 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/component_model.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/component_model.md @@ -2,10 +2,10 @@ sidebar_position: 4 --- -# Component Model +# 组件模型 -The component model for WASM would dramatically improve WASM module’s reusability and composability. It will allow better access from one WASM module to other modules and systems, including the operating system APIs (e.g., networking). +WASM 的组件模型将大幅改善 WASM 模块的可重用性和可组合性。它将允许一个 WASM 模块更好地访问其他模块和系统,包括操作系统的 API(例如网络功能)。 -WasmEdge is already committed to supporting and implementing [the component model proposal](https://github.com/WebAssembly/component-model). See the related issue [here](https://github.com/WasmEdge/WasmEdge/issues/1892). +WasmEdge 已经致力于支持和实现 [组件模型提案](https://github.com/WebAssembly/component-model)。请在[此处](https://github.com/WasmEdge/WasmEdge/issues/1892)查看相关问题。 -After the support for the component model is done, WasmEdge could be integrated by Spin and Spiderlightning. +在支持组件模型之后,WasmEdge 将能够被 Spin 和 Spiderlightning 集成。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/_category_.json b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/_category_.json index 32aaf833..4ff1ada9 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/_category_.json +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/_category_.json @@ -1,8 +1,8 @@ { - "label": "WasmEdge Extensions", + "label": "WasmEdge 拓展", "position": 3, "link": { "type": "generated-index", - "description": "WasmEdge supports all standard WebAssembly and WASI specifications. In addition, it supports features and APIs that are crucial for the cloud-native use cases. WasmEdge is a superset of standard Wasm. Through its extension SDK, developers can easily add features they need to the WasmEdge Runtime as plugins." + "description": "WasmEdge 支持所有标准的 WebAssembly 和 WASI 规范。此外,它支持对云原生用例至关重要的特性和 API。WasmEdge 是标准 WebAssembly 的超集。通过其扩展 SDK,开发人员可以轻松地将所需的功能作为插件添加到 WasmEdge 运行时中。" } } diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/plugins.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/plugins.md index 8e471394..98a27b18 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/plugins.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/plugins.md @@ -2,37 +2,37 @@ sidebar_position: 2 --- -# WasmEdge Plug-ins +# WasmEdge 插件 -For those workloads which are too heavy to compile into WebAssembly, it would be more appropriate to build them into native host functions. To satisfy the portability of WebAssembly runtime, WasmEdge introduced the plug-in mechanism to make the host functions loadable and portable. +对于那些过于重而难以编译成 WebAssembly的工作负载,将它们构建成本机主机函数是更好的选择。为了满足 WebAssembly 运行时的可移植性,WasmEdge 引入了插件机制,使主机函数可以加载和传输。 -The plug-in mechanism for WasmEdge is an easy way to extend the host modules from loadable shared libraries. With the plug-ins, users can load and instantiate the host functions from the shared libraries released by WasmEdge official or even by other developers. +WasmEdge 的插件机制是一种扩展主机模块的简便方法,用户可以通过插件从由 WasmEdge 官方发布或其他开发人员发布的共享库中加载和实例化主机函数。 -## Official Released Plug-ins +## 官方插件 -The following lists are the WasmEdge official released plug-ins. Users can install them easily by the installer. +下面列出了 WasmEdge 官方发布的插件。用户可以通过安装程序轻松安装它们。 -| Plug-in | Description | Platform Support | Language support | -|----------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------| -| [WasmEdge-Process](../../../contribute/source/plugin/process.md) | Allows WebAssembly programs to execute native commands in the host operating system. It supports passing arguments, environment variables, `STDIN`/`STDOUT` pipes, and security policies for host access. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, and `ubuntu 20.04 x86_64` (since `0.10.0`) | [Rust](https://crates.io/crates/wasmedge_process_interface) | -| [WASI-Crypto](https://github.com/WebAssembly/wasi-crypto) | APIs that a runtime can expose to WebAssembly modules in order to perform cryptographic operations and key management. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, and `ubuntu 20.04 x86_64` (since `0.10.1`) | [Rust](https://crates.io/crates/wasi-crypto) | -| [WASI-NN](https://github.com/WebAssembly/wasi-nn) [(OpenVINO backend)](../../../develop/rust/wasinn/openvino.md) | AI inference using OpenVINO models. | `ubuntu 20.04 x86_64` (since `0.10.1`) | [Rust](https://crates.io/crates/wasi-nn), JavaScript | -| [WASI-NN](https://github.com/WebAssembly/wasi-nn) [(Pytorch backend)](../../../develop/rust/wasinn/pytorch.md) | AI inference using Pytorch models. | `manylinux2014 x86_64` and `ubuntu 20.04 x86_64` (since `0.11.1`) | [Rust](https://crates.io/crates/wasi-nn), JavaScript | -| [WASI-NN](https://github.com/WebAssembly/wasi-nn) [(TensorFlow-Lite backend)](../../../develop/rust/wasinn/tensorflow_lite.md) | AI inference using TensorFlow-Lite models. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, and `ubuntu 20.04 x86_64` (since `0.11.2`) | [Rust](https://crates.io/crates/wasi-nn), JavaScript | -| [WasmEdge-Image](../../../contribute/source/plugin/image.md) | A native library to manipulate images for AI inference tasks. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.3.0) | -| [WasmEdge-Tensorflow](../../../contribute/source/plugin/tensorflow.md) | A native library for inferring TensorFlow models. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.3.0) | -| [WasmEdge-TensorflowLite](../../../contribute/source/plugin/tensorflowlite.md) | A native library for inferring TensorFlow-Lite models. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) | -| WasmEdge-OpenCV | Very popular utility functions to process images and videos for AI input/output. | Unreleased | Rust | -| WasmEdge-eBPF | A native library for inferring eBPF applications | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | Rust | -| WasmEdge-rusttls | A native library for inferring Rust and TLS Library | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | [Rust](https://crates.io/crates/wasmedge_rustls_api) +| 插件 | 描述 | 平台支持 | 语言支持 | +| --- | --- | --- | --- | +| [WasmEdge-Process](../../../contribute/source/plugin/process.md) | 允许 WebAssembly 程序在主机操作系统中执行本机命令。它支持传递参数、环境变量、`STDIN`/`STDOUT` 管道以及主机访问的安全策略。 | `manylinux2014 x86_64`,`manylinux2014 aarch64` 和 `ubuntu 20.04 x86_64`(自`0.10.0`) | [Rust](https://crates.io/crates/wasmedge_process_interface) | +| [WASI-Crypto](https://github.com/WebAssembly/wasi-crypto) | 用于运行时向 WebAssembly 模块公开的 API,以执行加密操作和密钥管理。 | `manylinux2014 x86_64`,`manylinux2014 aarch64` 和 `ubuntu 20.04 x86_64`(自`0.10.1`) | [Rust](https://crates.io/crates/wasi-crypto) | +| [WASI-NN](https://github.com/WebAssembly/wasi-nn)[(OpenVINO 后端)](../../../develop/rust/wasinn/openvino.md) | 使用 OpenVINO 模型进行 AI 推理。 | `ubuntu 20.04 x86_64`(自`0.10.1`) | [Rust](https://crates.io/crates/wasi-nn),JavaScript | +| [WASI-NN](https://github.com/WebAssembly/wasi-nn)[(Pytorch 后端)](../../../develop/rust/wasinn/pytorch.md) | 使用 Pytorch 模型进行 AI 推理。 | `manylinux2014 x86_64` 和 `ubuntu 20.04 x86_64`(自`0.11.1`) | [Rust](https://crates.io/crates/wasi-nn),JavaScript | +| [WASI-NN](https://github.com/WebAssembly/wasi-nn)[(TensorFlow-Lite 后端)](../../../develop/rust/wasinn/tensorflow_lite.md) | 使用 TensorFlow-Lite 模型进行 AI 推理。 | `manylinux2014 x86_64`,`manylinux2014 aarch64` 和 `ubuntu 20.04 x86_64`(自`0.11.2`) | [Rust](https://crates.io/crates/wasi-nn),JavaScript | +| [WasmEdge-Image](../../../contribute/source/plugin/image.md) | 用于 AI 推理任务中处理图像的本机库。 | `manylinux2014 x86_64`,`manylinux2014 aarch64`,`ubuntu 20.04 x86_64`,`darwin x86_64` 和 `darwin arm64`(自`0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface)(0.3.0) | +| [WasmEdge-Tensorflow](../../../contribute/source/plugin/tensorflow.md) | 用于推理 TensorFlow 模型的本机库。 | `manylinux2014 x86_64`,`manylinux2014 aarch64`,`ubuntu 20.04 x86_64`,`darwin x86_64` 和 `darwin arm64`(自`0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface)(0.3.0) | +| [WasmEdge-TensorflowLite](../../../contribute/source/plugin/tensorflowlite.md) | 用于推理 TensorFlow-Lite 模型的本机库。 | `manylinux2014 x86_64`,`manylinux2014 aarch64`,`ubuntu 20.04 x86_64`,`darwin x86_64` 和 `darwin arm64`(自`0.13.0`) | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) | +| WasmEdge-OpenCV | 一个非常流行的常用于处理图像和视频以供 AI 输入/输出函数库。 | 未发布 | Rust | +| WasmEdge-eBPF | 一个用于进行 eBPF 应用推理的原生库 | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | Rust | +| WasmEdge-rusttls | 一个用于进行 Rust 和 TLS 推理的原生库 | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `ubuntu 20.04 x86_64`, `darwin x86_64`, and `darwin arm64` (since `0.13.0`) | [Rust](https://crates.io/crates/wasmedge_rustls_api) | -## Old WasmEdge Extensions +## (过去的)WasmEdge 拓展 -Besides the plug-ins, WasmEdge provides the extensions before the `0.13.0` versions. Noticed that the extensions are replaced by the corresponding plug-ins after the `0.13.0` version. +除了插件,WasmEdge 在 `0.13.0` 版本之前还提供了扩展功能。请注意,在 `0.13.0` 版本之后,这些扩展已经被相应的插件所取代。 -The latest version supporting the extensions is `0.12.1`. This chapter will be deprecated when the `0.12.x` versions are no longer supported by the WasmEdge installer. +支持这些扩展的最新版本是 `0.12.1`。当 WasmEdge 安装程序不再支持安装 `0.12.x` 版本时,本段将被废弃。 -| Extension | Description | Platform Support | Language support | +| 扩展 | 描述 | 平台支持 | 语言支持 | | --- | --- | --- | --- | -| [Image processing](https://github.com/second-state/WasmEdge-image) | A native library to manipulate images for AI inference tasks. Migrated into the plug-in after WasmEdge `0.13.0`. | `manylinux2014 x86_64`, `manylinux2014 aarch64`, `android aarch64`, `ubuntu 20.04 x86_64`, and `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | -| [TensorFlow and Tensorflow-Lite](https://github.com/second-state/WasmEdge-tensorflow) | A native library to inferring TensorFlow and TensorFlow-Lite models. Migrated into the plug-in after WasmEdge `0.13.0`. | `manylinux2014 x86_64`, `manylinux2014 aarch64` (TensorFlow-Lite only), `android aarch64` (TensorFlow-Lite only), `ubuntu 20.04 x86_64`, and `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | +| [图像处理](https://github.com/second-state/WasmEdge-image) | 用于处理人工智能推推理任务中的图像的本地库。在 WasmEdge `0.13.0` 版本后迁移到插件中。 | `manylinux2014 x86_64`,`manylinux2014 aarch64`,`android aarch64`,`ubuntu 20.04 x86_64` 和 `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | +| [TensorFlow 和 Tensorflow-Lite](https://github.com/second-state/WasmEdge-tensorflow) | 用于 TensorFlow 和 TensorFlow-Lite 模型推理的本地库。在 WasmEdge `0.13.0` 版本后迁移到插件中。 | `manylinux2014 x86_64`,`manylinux2014 aarch64`(仅限TensorFlow-Lite),`android aarch64`(仅限TensorFlow-Lite),`ubuntu 20.04 x86_64` 和 `darwin x86_64` | [Rust](https://crates.io/crates/wasmedge_tensorflow_interface) (0.2.2) | diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/proposals.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/proposals.md index 0c33f0db..9a1f1ebe 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/proposals.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/proposals.md @@ -2,32 +2,32 @@ sidebar_position: 1 --- -# WebAssembly Proposals +# WebAssembly 提案 -## Standard WebAssembly Features +## 标准的 WebAssembly 功能 -WasmEdge supports the following [WebAssembly proposals](https://github.com/WebAssembly/proposals). These proposals are likely to become official WebAssembly specifications in the future. +WasmEdge 支持以下 [WebAssembly 提案](https://github.com/WebAssembly/proposals)。这些提案可能成为未来的官方 WebAssembly 规范。 -| Proposal | WasmEdge CLI flag | WasmEdge C API enumeration | Default turning on | Interpreter mode | AOT mode | +| 提案 | WasmEdge CLI 标志 | WasmEdge C API 枚举 | 默认开启 | 解释器模式 | AOT 模式 | | --- | --- | --- | --- | --- | --- | -| [Import/Export of Mutable Globals][] | `--disable-import-export-mut-globals` | `WasmEdge_Proposal_ImportExportMutGlobals` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Non-trapping float-to-int conversions][] | `--disable-non-trap-float-to-int` | `WasmEdge_Proposal_NonTrapFloatToIntConversions` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Sign-extension operators][] | `--disable-sign-extension-operators` | `WasmEdge_Proposal_SignExtensionOperators` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Multi-value][] | `--disable-multi-value` | `WasmEdge_Proposal_MultiValue` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Reference Types][] | `--disable-reference-types` | `WasmEdge_Proposal_ReferenceTypes` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Bulk memory operations][] | `--disable-bulk-memory` | `WasmEdge_Proposal_BulkMemoryOperations` | ✓ (since `0.8.2`) | ✓ | ✓ | -| [Fixed-width SIMD][] | `--disable-simd` | `WasmEdge_Proposal_SIMD` | ✓ (since `0.9.0`) | ✓ (since `0.8.2`) | ✓ (since `0.8.2`) | -| [Tail call][] | `--enable-tail-call` | `WasmEdge_Proposal_TailCall` | | ✓ (since `0.10.0`) | ✓ (since `0.10.0`) | -| [Multiple memories][] | `--enable-multi-memory` | `WasmEdge_Proposal_MultiMemories` | | ✓ (since `0.9.1`) | ✓ (since `0.9.1`) | -| [Extended Constant Expressions][] | `--enable-extended-const` | `WasmEdge_Proposal_ExtendedConst` | | ✓ (since `0.10.0`) | ✓ (since `0.10.0`) | -| [Threads][] | `--enable-threads` | `WasmEdge_Proposal_Threads` | | ✓ (since `0.10.1`) | ✓ (since `0.10.1`) | +| [可变全局变量的导入/导出][] | `--disable-import-export-mut-globals` | `WasmEdge_Proposal_ImportExportMutGlobals` | ✓(自`0.8.2`) | ✓ | ✓ | +| [非陷阱浮点数到整数转换][] | `--disable-non-trap-float-to-int` | `WasmEdge_Proposal_NonTrapFloatToIntConversions` | ✓(自`0.8.2`) | ✓ | ✓ | +| [符号扩展操作][] | `--disable-sign-extension-operators` | `WasmEdge_Proposal_SignExtensionOperators` | ✓(自`0.8.2`) | ✓ | ✓ | +| [多值返回][] | `--disable-multi-value` | `WasmEdge_Proposal_MultiValue` | ✓(自`0.8.2`) | ✓ | ✓ | +| [引用类型][] | `--disable-reference-types` | `WasmEdge_Proposal_ReferenceTypes` | ✓(自`0.8.2`) | ✓ | ✓ | +| [批量内存操作][] | `--disable-bulk-memory` | `WasmEdge_Proposal_BulkMemoryOperations` | ✓(自`0.8.2`) | ✓ | ✓ | +| [固定宽度 SIMD][] | `--disable-simd` | `WasmEdge_Proposal_SIMD` | ✓(自`0.9.0`) | ✓(自`0.8.2`) | ✓(自`0.8.2`) | +| [尾调用][] | `--enable-tail-call` | `WasmEdge_Proposal_TailCall` | | ✓(自`0.10.0`) | ✓(自`0.10.0`) | +| [多内存][] | `--enable-multi-memory` | `WasmEdge_Proposal_MultiMemories` | | ✓(自`0.9.1`) | ✓(自`0.9.1`) | +| [扩展常量表达式][] | `--enable-extended-const` | `WasmEdge_Proposal_ExtendedConst` | | ✓(自`0.10.0`) | ✓(自`0.10.0`) | +| [线程][] | `--enable-threads` | `WasmEdge_Proposal_Threads` | | ✓(自`0.10.1`) | ✓(自`0.10.1`) | -The following proposals are under development and may be supported in the future: +以下提案正在开发中,可能在将来得到支持: -- [Component Model][] -- [Exception handling][] -- [Garbage collection][] -- [WebAssembly C and C++ API][] +- [组件模型][] +- [异常处理][] +- [垃圾回收][] +- [WebAssembly C 和 C++ API][] [Import/Export of Mutable Globals]: https://github.com/WebAssembly/mutable-global [Non-trapping float-to-int conversions]: https://github.com/WebAssembly/nontrapping-float-to-int-conversions @@ -45,22 +45,22 @@ The following proposals are under development and may be supported in the future [Garbage collection]: https://github.com/WebAssembly/gc [WebAssembly C and C++ API]: https://github.com/WebAssembly/wasm-c-api -## WASI proposals +## WASI 提案 -WasmEdge implements the following [WASI proposals](https://github.com/WebAssembly/WASI/blob/main/Proposals.md): +WasmEdge 实现了以下 [WASI 提案](https://github.com/WebAssembly/WASI/blob/main/Proposals.md): -| Proposal | Platforms | +| 提案 | 平台支持 | | --- | --- | -| [Sockets][] | `x86_64 Linux`, `aarch64 Linux` (since `0.10.0`) | -| [Crypto][] | `x86_64 Linux`, `aarch64 Linux` (since `0.10.1`) | -| [Machine Learning (wasi-nn)][] | `x86_64 Linux`, OpenVINO (since `0.10.1`), PyTorch (since `0.11.1`), and TensorFlow-Lite (since `0.11.2`) backends | -| [proxy-wasm][] | `x86_64 Linux (Interpreter only)` (since `0.8.2`) | +| [Sockets][] | `x86_64 Linux`, `aarch64 Linux` (自 `0.10.0` 起) | +| [Crypto][] | `x86_64 Linux`, `aarch64 Linux` (自 `0.10.1` 起) | +| [机器学习(wasi-nn)][] | `x86_64 Linux`, OpenVINO (自 `0.10.1` 起), PyTorch (自 `0.11.1` 起), 以及 TensorFlow-Lite (自 `0.11.2` 起) 后端 | +| [proxy-wasm][] | `x86_64 Linux(仅解释器)` (自 `0.8.2` 起) | -The following proposals is under development and may be supported in the future: +以下提案正在开发中,将来可能会得到支持: -- TensorFlow backend of WASI-NN +- WASI-NN 的 TensorFlow 后端 [Sockets]: https://github.com/WebAssembly/wasi-sockets [Crypto]: https://github.com/WebAssembly/wasi-crypto -[Machine Learning (wasi-nn)]: https://github.com/WebAssembly/wasi-nn +[机器学习(wasi-nn)]: https://github.com/WebAssembly/wasi-nn [proxy-wasm]: https://github.com/proxy-wasm/spec diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/unique_extensions.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/unique_extensions.md index 5ae5f8f3..accf5dda 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/unique_extensions.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/extensions/unique_extensions.md @@ -2,33 +2,33 @@ sidebar_position: 3 --- -# Other Extensions +# 其他扩展 -A challenge for running WASM apps on the server side is the lack of support for Linux APIs and common application libraries. WasmEdge fixes this by adding support for many platform APIs for WASM apps. Developers can often simply compile their Linux apps to WASM and expect it run in WasmEdge. WasmEdge provides an easy extension mechanism for the community to add these APIs. For example, +在服务器端运行 WASM 应用的挑战之一是缺乏对 Linux API 和常用应用程序库的支持。WasmEdge 通过为 WASM 应用程序添加许多平台 API 的支持来解决这个问题。开发人员通常可以简单地将他们的 Linux 应用编译成 WASM,并期望在 WasmEdge 中运行。WasmEdge 为社区提供了一种简单的扩展机制来添加这些 API。例如, -Through its support for networking socket and related APIs, WasmEdge can run Rust applications that +通过其对网络套接字和相关 API 的支持,WasmEdge 可以运行 Rust 应用程序,实现以下功能: -- [provide HTTP services](https://github.com/WasmEdge/wasmedge_hyper_demo) -- [access external web services](https://github.com/WasmEdge/wasmedge_reqwest_demo) -- [connect to databases](https://github.com/WasmEdge/wasmedge-db-examples) -- [connect to messging queues](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) -- [support database driven microservices](https://github.com/second-state/microservice-rust-mysql) -- [support microservices with Dapr sidecars](https://github.com/second-state/dapr-wasm) +- [提供HTTP服务](https://github.com/WasmEdge/wasmedge_hyper_demo) +- [访问外部网络服务](https://github.com/WasmEdge/wasmedge_reqwest_demo) +- [连接到数据库](https://github.com/WasmEdge/wasmedge-db-examples) +- [连接到消息队列](https://github.com/docker/awesome-compose/tree/master/wasmedge-kafka-mysql) +- [支持基于数据库的微服务](https://github.com/second-state/microservice-rust-mysql) +- [支持具有Dapr边车的微服务](https://github.com/second-state/dapr-wasm) -Furthermore, the networking socket APIs also allow us to support the node.js API, including both the `server` and `fetch()`, in WasmEdge's JavaScript runtime. +此外,网络套接字 API 还允许我们在 WasmEdge 的 JavaScript 运行时中支持 Node.js API,包括 `server` 和 `fetch()`。 -Through its support for WASI-NN APIs, WasmEdge can support Rust and JavaScript applications for AI inference. Models from popular AI frameworks such as Tensorflow, PyTorch and OpenVINO [are all supported](https://github.com/second-state/WasmEdge-WASINN-examples). +通过其对 WASI-NN API 的支持,WasmEdge 可以支持用于 AI 推理的 Rust 和 JavaScript 应用程序。来自流行 AI 框架(如 Tensorflow、PyTorch 和 OpenVINO)的模型[都已经得到了支持](https://github.com/second-state/WasmEdge-WASINN-examples)。 -## Available extensions +## 可用扩展 -The extensions can be easily installed by the WasmEdge installer. They can also be included in WASM container images for Docker, Podman, and Kubernetes applications. +这些扩展可以通过 WasmEdge 安装程序轻松安装。它们也可以包含在用于 Docker、Podman 和 Kubernetes 应用程序的 WASM 容器映像中。 -| Name | Description | Platform Support | Language support | Note | +| 名称 | 描述 | 平台支持 | 语言支持 | 备注 | | --- | --- | --- | --- | --- | -| Networking sockets | Supports async (non-blocking) POSIX networking sockets | Linux | Rust, JavaScript, C | Supports popular libraries such as tokio (Rust) and node (JavaScript) | -| DNS | Supports DNS domain names in networking sockets | Linux | Rust, JavaScript, C | Supports popular libraries such as tokio (Rust) and node (JavaScript) | -| Domain sockets | Supports high-performance data exchange between processes | Linux | Rust, JavaScript, C | | -| TLS | Supports TLS and HTTPS connections from the networking sockets | Linux | Rust, JavaScript, C | | -| KV Storage | Allows WebAssembly programs to read and write a key value store | Linux | Rust | | -| [Ethereum](https://github.com/second-state/wasmedge-evmc) | supports Ethereum smart contracts compiled to WebAssembly. | Linux | none | It is a leading implementation for Ethereum flavored WebAssembly (Ewasm). | -| [Substrate](https://github.com/second-state/substrate-ssvm-node) | The [Pallet](https://github.com/second-state/pallet-ssvm) allows WasmEdge to act as an Ethereum smart contract execution engine on any Substrate based blockchains. | Linux | none | | +| 网络套接字 | 支持异步(非阻塞)的 POSIX 网络套接字 | Linux | Rust、JavaScript、C | 支持诸如 tokio(Rust)和 node(JavaScript)等流行库 | +| DNS | 支持网络套接字中的 DNS 域名 | Linux | Rust、JavaScript、C | 支持诸如 tokio(Rust)和 node(JavaScript)等流行库 | +| 域套接字 | 支持进程之间的高性能数据交换 | Linux | Rust、JavaScript、C | | +| TLS | 支持从网络套接字进行 TLS 和 HTTPS 连接 | Linux | Rust、JavaScript、C | | +| KV 存储 | 允许 WebAssembly 程序读写键值存储 | Linux | Rust | | +| [以太坊](https://github.com/second-state/wasmedge-evmc) | 支持编译为 WebAssembly 的以太坊智能合约。 | Linux | 无 | 它是以太坊风格的 WebAssembly(Ewasm)的主要实现。 | +| [Substrate](https://github.com/second-state/substrate-ssvm-node) | [Pallet](https://github.com/second-state/pallet-ssvm) 允许 WasmEdge 在任何基于 Substrate 的区块链上作为以太坊智能合约执行引擎。 | Linux | 无 | | diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/features.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/features.md index 4d02007a..704c6b82 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/features.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/features.md @@ -2,79 +2,79 @@ sidebar_position: 1 --- -# WasmEdge Features +# WasmEdge 功能 -WasmEdge ([a sandbox project under CNCF](https://www.cncf.io/projects/wasmedge/)) is a safe, fast, lightweight, portable, and extensible WebAssembly runtime. +WasmEdge([CNCF 旗下的沙盒项目](https://www.cncf.io/projects/wasmedge/))是一个安全、快速、轻量、可移植且可扩展的 WebAssembly 运行时。 -## High Performance +## 高性能 -Taking advantage of [the LLVM-based AoT compiler](../build-and-run/aot), WasmEdge is the fastest WebAssembly runtime on the market. +利用[基于 LLVM 的 AoT 编译器](../build-and-run/aot),WasmEdge 是市场上速度最快的 WebAssembly 运行时。 -- [A Lightweight Design for High-performance Serverless Computing](https://arxiv.org/abs/2010.07115), published on IEEE Software, Jan 2021. [https://arxiv.org/abs/2010.07115](https://arxiv.org/abs/2010.07115) -- [Performance Analysis for Arm vs. x86 CPUs in the Cloud](https://www.infoq.com/articles/arm-vs-x86-cloud-performance/), published on infoQ.com, Jan 2021. [https://www.infoq.com/articles/arm-vs-x86-cloud-performance/](https://www.infoq.com/articles/arm-vs-x86-cloud-performance/) -- [WasmEdge is the fastest WebAssembly Runtime in Suborbital Reactr test suite](https://blog.suborbital.dev/suborbital-wasmedge), Dec 2021 +- [高性能轻量设计用于无服务器计算](https://arxiv.org/abs/2010.07115),发表于 2021 年 1 月 IEEE 软件。[https://arxiv.org/abs/2010.07115](https://arxiv.org/abs/2010.07115) +- [云端性能分析:Arm 与 x86 CPU 的比较](https://www.infoq.com/articles/arm-vs-x86-cloud-performance/),发表于 2021 年 1 月的 infoQ.com。[https://www.infoq.com/articles/arm-vs-x86-cloud-performance/](https://www.infoq.com/articles/arm-vs-x86-cloud-performance/) +- [WasmEdge 在 Suborbital Reactr 测试套件中是最快的 WebAssembly 运行时](https://blog.suborbital.dev/suborbital-wasmedge),2021 年 12 月 -## Cloud-native Extensions +## 云原生扩展 -Besides WASI and the standard WebAssembly proposal, WasmEdge has some cloud-native extensions. +除了 WASI 和标准的 WebAssembly 提案,WasmEdge 还有一些云原生扩展。 -- Non-blocking network sockets and web services with Rust, C, and JavaScript SDK -- MySQL-based database driver -- Key value store -- Gas meter for resource limitation -- WasmEdge-bindgen for complex para passing -- AI inference with TensorFlow, TensorFlow Lite, Pytorch, and OpenVINO +- 使用 Rust、C 和 JavaScript SDK 实现的非阻塞网络套接字和 Web 服务 +- 基于 MySQL 的数据库驱动程序 +- 键值存储 +- 用于资源限制的 Gas 计量器 +- 用于复杂参数传递的 WasmEdge-bindgen +- 使用 TensorFlow、TensorFlow Lite、PyTorch 和 OpenVINO 进行 AI 推理 -## JavaScript Support +## JavaScript 支持 -Through the [WasmEdge-Quickjs](https://github.com/second-state/wasmedge-quickjs) project, WasmEdge could run a JavaScript program, lowering the bar for developing a WASM app. +通过 [WasmEdge-Quickjs](https://github.com/second-state/wasmedge-quickjs) 项目,WasmEdge 可以运行 JavaScript 程序,降低开发 WASM 应用的门槛。 -- ES6 module and std API support -- NPM module support -- Native JS API in Rust -- Node.js API Support -- Async networking +- ES6 模块和 std API 支持 +- NPM 模块支持 +- Rust 中的原生 JS API +- Node.js API 支持 +- 异步网络 - Fetch API - React SSR -## Cloud Native orchestration +## 云原生编排 -WasmEdge could be seamlessly integrated with the existing cloud-native infra. +WasmEdge 可以与现有的云原生基础设施无缝集成。 -To integrate WasmEdge with your existing cloud-native infrastructure, there are several options available for managing WASM applications as "containers" under Kubernetes. These options enables you to run Linux containers and WASM containers side by side within a Kubernetes cluster. +要将 WasmEdge 与你现有的云原生基础架构集成,有几种管理 WASM 应用程序作为 Kubernetes 下的“容器”的选项。这些选项使你能够在 Kubernetes 集群中同时运行 Linux 容器和 WASM 容器。 -**Option #1:** is to [use an OCI runtime crun](../../develop/deploy/oci-runtime/crun.md) (the C version of runc — mainly supported by Red Hat). crun decides whether an OCI image is WASM or Linux based on image annotations. If the image is annotated as wasm32, crun will bypass the Linux container setup and just use WasmEdge to run the image. By using crun, you can get the entire Kubernetes stack - including CRI-O, containerd, Podman, kind, micro k8s, and k8s - to work with WASM images. +**选项 #1:**[使用 OCI 运行时 crun](../../develop/deploy/oci-runtime/crun.md)(runc 的 C 版本,主要由 Red Hat 支持)。crun 根据镜像注释决定 OCI 镜像是 WASM 还是基于 Linux 的。如果镜像被注释为 wasm32,则 crun 将绕过 Linux 容器设置,直接使用 WasmEdge 运行镜像。通过使用 crun,你可以让整个 Kubernetes 栈(包括 CRI-O、containerd、Podman、kind、micro k8s 和 k8s)与 WASM 镜像一起工作。 -Option #2 is to [use a containerd-shim to start WASM "containers" via runwasi](../../develop/deploy/cri-runtime/containerd.md). Basically, containerd could look at the image's target platform. It uses runwasi if the image is wasm32 and runc if it is x86 / arm. This is the approach used by Docker + Wasm. +选项 #2:[使用 containerd-shim 通过 runwasi 启动 WASM“容器”](../../develop/deploy/cri-runtime/containerd.md)。基本上,containerd 可以查看镜像的目标平台。如果镜像是 wasm32,则使用 runwasi;如果是 x86 / arm,则使用 runc。这是 Docker + Wasm 使用的方法。 -## Cross Platform +## 跨平台 -WASM is Portable. The compiled wasm file could run on different hardware and platforms without any changes. +WASM 具有可移植性。编译后的 wasm 文件可以在不同的硬件和平台上运行,而无需任何更改。 -WasmEdge supports a wide range of operating systems and hardware platforms. It allows WebAssembly applications to be truly portable across platforms. It runs on Linux-like systems and microkernels such as the `seL4` real-time system. +WasmEdge 支持多种操作系统和硬件平台。它允许 WebAssembly 应用程序在各个平台上实现真正的可移植性。它可以在类似 Linux 的系统和微内核(例如实时系统 `seL4`)上运行。 -WasmEdge now supports: +WasmEdge 目前支持: -- [Linux (x86_64 and aarch64)](../../contribute/source/os/linux.md) -- [MacOS (x86_64 and M1)](../../contribute/source/os/macos.md) +- [Linux(x86_64 和 aarch64)](../../contribute/source/os/linux.md) +- [MacOS(x86_64 和 M1)](../../contribute/source/os/macos.md) - [Windows 10](../../contribute/source/os/windows.md) - [Android](/category/build-and-run-wasmedge-on-android) - [seL4 RTOS](../../contribute/source/os/sel4.md) - [OpenWrt](../../contribute/source/os/openwrt.md) - [OpenHarmony](../../contribute/source/os/openharmony.md) - [Raspberry Pi](../../contribute/source/os/raspberrypi.md) -- [RISC-V (WIP)](../../contribute/source/os/riscv64.md) +- [RISC-V(WIP)](../../contribute/source/os/riscv64.md) -## Easy extensible +## 易于扩展 -It is easy to build customized WasmEdge runtime with native host functions in C, Go, and Rust. +使用 C、Go 和 Rust 中的原生宿主函数很容易构建自定义的 WasmEdge 运行时。 -Or you could build your own plug-ins for WasmEdge in, +或者,你可以为 WasmEdge 构建自己的插件, - [Rust](../../contribute/plugin/develop_plugin_rustsdk) - [C](../../contribute/plugin/develop_plugin_c) - [C++](../../contribute/plugin/develop_plugin_cpp) -## Easy to Embed into a Host Application +## 易于嵌入到主机应用程序中 -Embedded runtime is the classical use case for WasmEdge. You could embed WasmEdge functions in C, Go, Rust, Node.js, Java (WIP), and Python (WIP) host applications. +嵌入式运行时是 WasmEdge 的经典用例。你可以将 WasmEdge 函数嵌入到 C、Go、Rust、Node.js、Java(WIP) 和 Python(WIP) 主机应用程序中。 diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/integrations.md b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/integrations.md index 2a0bedef..3c70a349 100644 --- a/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/integrations.md +++ b/i18n/zh/docusaurus-plugin-content-docs/current/start/wasmedge/integrations.md @@ -2,36 +2,36 @@ sidebar_position: 2 --- -# WasmEdge Integrations +# WasmEdge 集成 -WasmEdge is a "serverless" runtime for cloud-native and edge computing applications. It allows developers safely embed third-party or "native" functions into a host application or a distributed computing framework. +WasmEdge 是云原生和边缘计算应用的“无服务器”运行时。它允许开发人员安全地将第三方或“本地”函数嵌入主机应用程序或分布式计算框架中。 -## Embed WasmEdge Into A Host Application +## 将 WasmEdge 嵌入到主机应用程序中 -A major use case of WasmEdge is to start a VM instance from a host application. Depending on your host application's programming language, you can use WasmEdge SDKs to start and invoke WasmEdge functions. +WasmEdge 的一个主要用例是从主机应用程序启动虚拟机实例。根据你的主机应用程序编程语言,你可以使用 WasmEdge SDK 来启动和调用 WasmEdge 函数。 -- Embed WasmEdge functions into a `C`-based application using the [WasmEdge C API](/category/c-sdk-for-embedding-wasmedge). Checkout the [quick start guide](../../embed/c/intro.md). -- Embed WasmEdge functions into a `Go` application using the [WasmEdge Go API](/category/go-sdk-for-embedding-wasmedge). Here is a [tutorial](https://www.secondstate.io/articles/extend-golang-app-with-webassembly-rust/) and are some [examples](https://github.com/second-state/WasmEdge-go-examples)! -- Embed WasmEdge functions into a `Rust` application using the [WasmEdge Rust crate](https://crates.io/crates/wasmedge-sdk). -- Embed WasmEdge functions into a `Node.js` application using the `NAPI`. Here is a [tutorial](https://www.secondstate.io/articles/getting-started-with-rust-function/). -- Embed WasmEdge functions into any application by spawning a new process. See examples for [Vercel Serverless Functions](https://www.secondstate.io/articles/vercel-wasmedge-webassembly-rust/) and [AWS Lambda](https://www.cncf.io/blog/2021/08/25/webassembly-serverless-functions-in-aws-lambda/). +- 使用 [WasmEdge C API](/category/c-sdk-for-embedding-wasmedge) 将 WasmEdge 函数嵌入到基于 `C` 的应用程序中。查看[快速入门指南](../../embed/c/intro.md)。 +- 使用 [WasmEdge Go API](/category/go-sdk-for-embedding-wasmedge) 将 WasmEdge 函数嵌入到 `Go` 应用程序中。这里有一个[教程](https://www.secondstate.io/articles/extend-golang-app-with-webassembly-rust/) 和一些[示例](https://github.com/second-state/WasmEdge-go-examples)! +- 使用 [WasmEdge Rust crate](https://crates.io/crates/wasmedge-sdk) 将 WasmEdge 函数嵌入到 `Rust` 应用程序中。 +- 使用 `NAPI` 将 WasmEdge 函数嵌入到 `Node.js` 应用程序中。这里有一个[教程](https://www.secondstate.io/articles/getting-started-with-rust-function/)。 +- 通过生成一个新进程将 WasmEdge 函数嵌入到任何应用程序。查看 [Vercel 无服务器函数](https://www.secondstate.io/articles/vercel-wasmedge-webassembly-rust/) 和 [AWS Lambda](https://www.cncf.io/blog/2021/08/25/webassembly-serverless-functions-in-aws-lambda/) 的示例。 -However, the WebAssembly spec only supports very limited data types as input parameters and return values for the WebAssembly bytecode functions. To pass complex data types, such as a string of an array, as call arguments into WebAssembly compiled from Rust, you should use the `bindgen` solution provided by the [`wasmedge-bindgen`](https://crates.io/crates/wasmedge-bindgen). We currently support the `wasmedge-bindgen` in the [Rust](../../develop/rust/bindgen.md) and in [Go](../../embed/go/bindgen.md). +不过,WebAssembly 规范仅支持用于 WebAssembly 字节码函数的非常有限的输入参数和返回值的数据类型。要传递复杂数据类型(例如字符串或数组)作为来自 Rust 编译的 WebAssembly 的调用参数,你应该使用[`wasmedge-bindgen`](https://crates.io/crates/wasmedge-bindgen)提供的 `bindgen` 解决方案。我们目前在 [Rust](../../develop/rust/bindgen.md) 和 [Go](../../embed/go/bindgen.md) 中支持`wasmedge-bindgen`。 -## Use WasmEdge As A Docker-Like Container +## 使用 WasmEdge 作为类似 Docker 的容器 -WasmEdge provides an OCI-compliant interface. You can use container tools like CRI-O, Docker Hub, and Kubernetes to orchestrate and manage WasmEdge runtimes. +WasmEdge 提供符合 OCI 规范的接口。你可以使用诸如 CRI-O、Docker Hub 和 Kubernetes 之类的容器工具来编排和管理 WasmEdge 运行时。 -- [Manage WasmEdge with CRI-O and Docker Hub](https://www.secondstate.io/articles/manage-webassembly-apps-in-wasmedge-using-docker-tools/). +- [使用 CRI-O 和 Docker Hub 管理 WasmEdge](https://www.secondstate.io/articles/manage-webassembly-apps-in-wasmedge-using-docker-tools/)。 -## Call Native Host Functions From WasmEdge +## 从 WasmEdge 调用原生宿主函数 -A key feature of WasmEdge is its extensibility. WasmEdge APIs allow developers to register "host functions" from the host programming languages into a WasmEdge instance and invoke these functions from the WebAssembly program. +WasmEdge 的一个关键特性是其可扩展性。WasmEdge API 允许开发人员将来自主机编程语言的“主机函数”注册到 WasmEdge 实例中,并从 WebAssembly 程序中调用这些函数。 -- The WasmEdge C API supports the [C host functions](../../embed/c/host_function.md). -- The WasmEdge Go API supports the [Go host functions](https://github.com/second-state/WasmEdge-go-examples/tree/master/go_HostFunc#wasmedge-go-host-function-example). -- The WasmEdge Rust API supports the [Rust host functions](https://github.com/second-state/wasmedge-rustsdk-examples/blob/main/README.md#host-functions). +- WasmEdge C API 支持 [C 主机函数](../../embed/c/host_function.md)。 +- WasmEdge Go API 支持 [Go 主机函数](https://github.com/second-state/WasmEdge-go-examples/tree/master/go_HostFunc#wasmedge-go-host-function-example)。 +- WasmEdge Rust API 支持 [Rust 主机函数](https://github.com/second-state/wasmedge-rustsdk-examples/blob/main/README.md#host-functions)。 -[Here is an example](https://www.secondstate.io/articles/call-native-functions-from-javascript/) of a JavaScript program in WasmEdge calling a C-based host function in the underlying OS. +[这是一个示例](https://www.secondstate.io/articles/call-native-functions-from-javascript/),演示了 WasmEdge 中的 JavaScript 程序调用底层操作系统中基于 C 的主机函数。 -The host functions break the WASM sandbox to access the underly OS or hardware. But the sandbox breaking is done with explicit permission from the system’s operator. +主机函数打破了 WASM 沙箱,以便访问底层操作系统或硬件。但这种沙箱破坏是经过系统操作者明确许可的。