├── .bazelversion ├── CODEOWNERS ├── .gitignore ├── .actrc ├── .bazelrc ├── examples ├── grpc_auth_random │ ├── Cargo.toml │ ├── docker-compose.yaml │ ├── README.md │ ├── envoy.yaml │ └── src │ │ └── lib.rs ├── http_body │ ├── Cargo.toml │ ├── README.md │ ├── docker-compose.yaml │ ├── src │ │ └── lib.rs │ └── envoy.yaml ├── http_config │ ├── Cargo.toml │ ├── README.md │ ├── docker-compose.yaml │ ├── src │ │ └── lib.rs │ └── envoy.yaml ├── http_headers │ ├── Cargo.toml │ ├── docker-compose.yaml │ ├── README.md │ ├── src │ │ └── lib.rs │ └── envoy.yaml ├── envoy_filter_metadata │ ├── Cargo.toml │ ├── docker-compose.yaml │ ├── README.md │ ├── src │ │ └── lib.rs │ └── envoy.yaml ├── http_auth_random │ ├── Cargo.toml │ ├── docker-compose.yaml │ ├── README.md │ ├── src │ │ └── lib.rs │ └── envoy.yaml └── hello_world │ ├── Cargo.toml │ ├── README.md │ ├── docker-compose.yaml │ ├── envoy.yaml │ └── src │ └── lib.rs ├── bazel ├── BUILD ├── rules_rust.patch ├── dependencies_bazel.bzl ├── dependencies_compat.bzl ├── cargo │ ├── BUILD │ ├── remote │ │ ├── crates.bzl │ │ ├── alias_rules.bzl │ │ ├── BUILD.bazel │ │ ├── BUILD.log-0.4.27.bazel │ │ ├── BUILD.foldhash-0.2.0.bazel │ │ ├── BUILD.equivalent-1.0.2.bazel │ │ ├── BUILD.unicode-ident-1.0.19.bazel │ │ ├── BUILD.allocator-api2-0.2.21.bazel │ │ ├── BUILD.mockalloc-0.1.2.bazel │ │ ├── BUILD.mockalloc-macros-0.1.0.bazel │ │ ├── BUILD.hashbrown-0.16.0.bazel │ │ ├── BUILD.quote-1.0.41.bazel │ │ ├── BUILD.proc-macro2-1.0.101.bazel │ │ ├── BUILD.syn-1.0.109.bazel │ │ └── defs.bzl │ └── Cargo.Bazel.lock ├── dependencies_crates.bzl ├── extensions.bzl └── repositories.bzl ├── WORKSPACE.bzlmod ├── WORKSPACE ├── Cargo.toml ├── DEVELOPMENT.md ├── src ├── allocator.rs ├── lib.rs ├── logger.rs ├── types.rs └── traits.rs ├── CONTRIBUTING.md ├── README.md ├── BUILD ├── MODULE.bazel ├── CHANGELOG.md ├── LICENSE └── .github └── workflows └── rust.yml /.bazelversion: -------------------------------------------------------------------------------- 1 | 7.7.1 2 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @PiotrSikora 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /bazel-* 2 | target 3 | Cargo.lock 4 | -------------------------------------------------------------------------------- /.actrc: -------------------------------------------------------------------------------- 1 | -P ubuntu-24.04=catthehacker/ubuntu:act-24.04 2 | -------------------------------------------------------------------------------- /.bazelrc: -------------------------------------------------------------------------------- 1 | # Force Bazel to use --target=wasm32-wasip1 2 | build --platforms=@rules_rust//rust/platform:wasi 3 | -------------------------------------------------------------------------------- /examples/grpc_auth_random/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-grpc-auth-random" 4 | version = "0.0.1" 5 | description = "Proxy-Wasm plugin example: gRPC auth (random)" 6 | license = "Apache-2.0" 7 | edition = "2018" 8 | 9 | [lib] 10 | crate-type = ["cdylib"] 11 | 12 | [dependencies] 13 | log = "0.4" 14 | proxy-wasm = { path = "../../" } 15 | 16 | [profile.release] 17 | lto = true 18 | opt-level = 3 19 | codegen-units = 1 20 | panic = "abort" 21 | strip = "debuginfo" 22 | -------------------------------------------------------------------------------- /examples/http_body/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-http-body" 4 | version = "0.0.1" 5 | authors = ["Piotr Sikora "] 6 | description = "Proxy-Wasm plugin example: HTTP body" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | proxy-wasm = { path = "../../" } 15 | 16 | [profile.release] 17 | lto = true 18 | opt-level = 3 19 | codegen-units = 1 20 | panic = "abort" 21 | strip = "debuginfo" 22 | -------------------------------------------------------------------------------- /examples/http_config/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-http-config" 4 | version = "0.0.1" 5 | authors = ["Piotr Sikora "] 6 | description = "Proxy-Wasm plugin example: HTTP config" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | proxy-wasm = { path = "../../" } 15 | 16 | [profile.release] 17 | lto = true 18 | opt-level = 3 19 | codegen-units = 1 20 | panic = "abort" 21 | strip = "debuginfo" 22 | -------------------------------------------------------------------------------- /examples/http_headers/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-http-headers" 4 | version = "0.0.1" 5 | authors = ["Piotr Sikora "] 6 | description = "Proxy-Wasm plugin example: HTTP headers" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | log = "0.4" 15 | proxy-wasm = { path = "../../" } 16 | 17 | [profile.release] 18 | lto = true 19 | opt-level = 3 20 | codegen-units = 1 21 | panic = "abort" 22 | strip = "debuginfo" 23 | -------------------------------------------------------------------------------- /examples/envoy_filter_metadata/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-envoy-filter-metadata" 4 | version = "0.0.1" 5 | authors = ["Martijn Swaagma "] 6 | description = "Proxy-Wasm plugin example: Envoy filter metadata" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | proxy-wasm = { path = "../../" } 15 | 16 | [profile.release] 17 | lto = true 18 | opt-level = 3 19 | codegen-units = 1 20 | panic = "abort" 21 | strip = "debuginfo" 22 | -------------------------------------------------------------------------------- /examples/http_auth_random/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-http-auth-random" 4 | version = "0.0.1" 5 | authors = ["Piotr Sikora "] 6 | description = "Proxy-Wasm plugin example: HTTP auth (random)" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | log = "0.4" 15 | proxy-wasm = { path = "../../" } 16 | 17 | [profile.release] 18 | lto = true 19 | opt-level = 3 20 | codegen-units = 1 21 | panic = "abort" 22 | strip = "debuginfo" 23 | -------------------------------------------------------------------------------- /bazel/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /WORKSPACE.bzlmod: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | -------------------------------------------------------------------------------- /WORKSPACE: -------------------------------------------------------------------------------- 1 | workspace(name = "proxy_wasm_rust_sdk") 2 | 3 | load("@proxy_wasm_rust_sdk//bazel:repositories.bzl", "proxy_wasm_rust_sdk_repositories") 4 | 5 | proxy_wasm_rust_sdk_repositories() 6 | 7 | load("@proxy_wasm_rust_sdk//bazel:dependencies_bazel.bzl", "proxy_wasm_rust_sdk_dependencies_bazel") 8 | 9 | proxy_wasm_rust_sdk_dependencies_bazel() 10 | 11 | load("@proxy_wasm_rust_sdk//bazel:dependencies_compat.bzl", "proxy_wasm_rust_sdk_dependencies_compat") 12 | 13 | proxy_wasm_rust_sdk_dependencies_compat() 14 | 15 | load("@proxy_wasm_rust_sdk//bazel:dependencies_crates.bzl", "proxy_wasm_rust_sdk_dependencies_crates") 16 | 17 | proxy_wasm_rust_sdk_dependencies_crates() 18 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "proxy-wasm" 3 | version = "0.2.5-dev" 4 | authors = ["Piotr Sikora "] 5 | rust-version = "1.68" 6 | description = "WebAssembly for Proxies" 7 | readme = "README.md" 8 | license = "Apache-2.0" 9 | repository = "https://github.com/proxy-wasm/proxy-wasm-rust-sdk" 10 | edition = "2018" 11 | build = "build.rs" 12 | 13 | [dependencies] 14 | hashbrown = "0.16" 15 | log = "0.4" 16 | 17 | [dev-dependencies] 18 | mockalloc = "0.1.2" 19 | 20 | [profile.release] 21 | lto = true 22 | opt-level = 3 23 | codegen-units = 1 24 | panic = "abort" 25 | strip = "debuginfo" 26 | 27 | [profile.test] 28 | inherits = "release" 29 | debug = true 30 | 31 | [profile.bench] 32 | inherits = "release" 33 | debug = true 34 | -------------------------------------------------------------------------------- /bazel/rules_rust.patch: -------------------------------------------------------------------------------- 1 | # https://github.com/bazelbuild/rules_rust/pull/1315 2 | 3 | diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl 4 | index 20a09f94..53122967 100644 5 | --- a/rust/private/rustc.bzl 6 | +++ b/rust/private/rustc.bzl 7 | @@ -1612,7 +1612,7 @@ def rustc_compile_action( 8 | **crate_info_dict 9 | ) 10 | 11 | - if crate_info.type in ["staticlib", "cdylib"]: 12 | + if crate_info.type in ["staticlib", "cdylib"] and not out_binary: 13 | # These rules are not supposed to be depended on by other rust targets, and 14 | # as such they shouldn't provide a CrateInfo. However, one may still want to 15 | # write a rust_test for them, so we provide the CrateInfo wrapped in a provider 16 | -------------------------------------------------------------------------------- /examples/hello_world/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | publish = false 3 | name = "proxy-wasm-example-hello-world" 4 | version = "0.0.1" 5 | authors = ["Piotr Sikora "] 6 | description = "Proxy-Wasm plugin example: Hello World" 7 | license = "Apache-2.0" 8 | edition = "2018" 9 | 10 | [lib] 11 | crate-type = ["cdylib"] 12 | 13 | [dependencies] 14 | cfg-if = "1.0" 15 | chrono = { version = "0.4", default-features = false, features = ["clock", "std"] } 16 | log = "0.4" 17 | proxy-wasm = { path = "../../" } 18 | 19 | [target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dependencies] 20 | getrandom = "0.3" 21 | 22 | [profile.release] 23 | lto = true 24 | opt-level = 3 25 | codegen-units = 1 26 | panic = "abort" 27 | strip = "debuginfo" 28 | -------------------------------------------------------------------------------- /bazel/dependencies_bazel.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@bazel_features//:deps.bzl", "bazel_features_deps") 16 | 17 | def proxy_wasm_rust_sdk_dependencies_bazel(): 18 | bazel_features_deps() 19 | -------------------------------------------------------------------------------- /bazel/dependencies_compat.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_cc//cc:extensions.bzl", "compatibility_proxy_repo") 16 | 17 | def proxy_wasm_rust_sdk_dependencies_compat(): 18 | compatibility_proxy_repo() 19 | -------------------------------------------------------------------------------- /examples/http_config/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: HTTP config 2 | 3 | Proxy-Wasm plugin that injects HTTP response header with a value from Envoy config. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | Send HTTP request to `localhost:10000/hello`: 21 | 22 | ```sh 23 | $ curl -I localhost:10000/hello 24 | HTTP/1.1 200 OK 25 | content-length: 40 26 | content-type: text/plain 27 | custom-header: The secret to life is meaningless unless you discover it yourself 28 | date: Tue, 22 Nov 2022 04:09:05 GMT 29 | server: envoy 30 | ``` 31 | -------------------------------------------------------------------------------- /examples/http_body/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: HTTP body 2 | 3 | Proxy-Wasm plugin that redacts sensitive HTTP responses. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | #### Response without secrets. 21 | 22 | Send HTTP request to `localhost:10000/hello`: 23 | 24 | ```sh 25 | $ curl localhost:10000/hello 26 | Everyone may read this message. 27 | ``` 28 | 29 | #### Response with (redacted) secrets. 30 | 31 | Send HTTP request to `localhost:10000/secret`: 32 | 33 | ```sh 34 | $ curl localhost:10000/secret 35 | Original message body (50 bytes) redacted. 36 | ``` 37 | -------------------------------------------------------------------------------- /DEVELOPMENT.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | ## Testing 4 | 5 | GitHub Actions can be executed locally using the [`act`] tool. 6 | 7 | All tests can be executed using: 8 | 9 | act 10 | 11 | Individual tests can be executed using `-j` and `--matrix` parameters, e.g.: 12 | 13 | act -j bazel 14 | act -j stable 15 | act -j nightly 16 | act -j examples --matrix example:http_auth_random 17 | 18 | By default, all jobs are cached in `~/.cache/actcache`. This can be disabled 19 | using the `--no-cache-server` parameter. 20 | 21 | ## Updating Bazel dependencies 22 | 23 | When adding or updating Cargo dependencies, the existing Bazel `BUILD` files 24 | must be regenerated using the [`bazelisk`] tool: 25 | 26 | ```sh 27 | bazelisk run //bazel/cargo:crates_vendor -- --repin all 28 | ``` 29 | 30 | 31 | [`act`]: https://github.com/nektos/act 32 | [`bazelisk`]: https://github.com/bazelbuild/bazelisk 33 | -------------------------------------------------------------------------------- /examples/hello_world/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: Hello World 2 | 3 | Proxy-Wasm background service plugin that logs time and random numbers. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | Expected Envoy logs (new line generated every 5s): 21 | 22 | ```console 23 | [...] wasm log: Hello, World! 24 | [...] wasm log: It's 2022-11-22 03:39:17.849616 UTC, your lucky number is 41. 25 | [...] wasm log: It's 2022-11-22 03:39:22.846531 UTC, your lucky number is 28. 26 | [...] wasm log: It's 2022-11-22 03:39:27.847489 UTC, your lucky number is 102. 27 | [...] wasm log: It's 2022-11-22 03:39:32.848443 UTC, your lucky number is 250. 28 | ``` 29 | -------------------------------------------------------------------------------- /examples/hello_world/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | networks: 27 | envoymesh: {} 28 | -------------------------------------------------------------------------------- /examples/http_body/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | networks: 27 | envoymesh: {} 28 | -------------------------------------------------------------------------------- /examples/http_config/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | networks: 27 | envoymesh: {} 28 | -------------------------------------------------------------------------------- /examples/http_headers/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | networks: 27 | envoymesh: {} 28 | -------------------------------------------------------------------------------- /examples/envoy_filter_metadata/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | networks: 27 | envoymesh: {} 28 | -------------------------------------------------------------------------------- /bazel/cargo/BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_rust//crate_universe:defs.bzl", "crates_vendor") 16 | 17 | exports_files([ 18 | "Cargo.Bazel.lock", 19 | ]) 20 | 21 | crates_vendor( 22 | name = "crates_vendor", 23 | cargo_lockfile = "//bazel/cargo:Cargo.Bazel.lock", 24 | manifests = ["//:Cargo.toml"], 25 | mode = "remote", 26 | tags = ["manual"], 27 | vendor_path = "//bazel/cargo/remote", 28 | ) 29 | -------------------------------------------------------------------------------- /bazel/dependencies_crates.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@proxy_wasm_rust_sdk//bazel/cargo/remote:defs.bzl", "crate_repositories") 16 | load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") 17 | load("@rules_rust//rust:repositories.bzl", "rust_repositories") 18 | 19 | def proxy_wasm_rust_sdk_dependencies_crates(): 20 | rust_repositories(versions = ["1.90.0"]) 21 | crate_universe_dependencies() 22 | crate_repositories() 23 | -------------------------------------------------------------------------------- /examples/envoy_filter_metadata/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: Envoy metadata 2 | 3 | Proxy-Wasm plugin that demonstrates reading metadata set by other Envoy filters. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | Send a HTTP request to `localhost:10000` that will return the configured response. 21 | 22 | ```sh 23 | $ curl localhost:10000 24 | Welcome, set the `x-custom-metadata` header to change the response! 25 | ``` 26 | 27 | Send a HTTP request to `localhost:10000` with a `x-custom-metadata` header value to get 28 | the uppercased value in the response. 29 | 30 | The response will also contain a response header `uppercased-metadata: SOME-VALUE`. 31 | 32 | ```sh 33 | $ curl localhost:10000 -H "x-custom-metadata: some-value" 34 | Custom response with Envoy metadata: "SOME-VALUE" 35 | ``` 36 | -------------------------------------------------------------------------------- /examples/hello_world/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | bootstrap_extensions: 16 | - name: envoy.bootstrap.wasm 17 | typed_config: 18 | "@type": type.googleapis.com/envoy.extensions.wasm.v3.WasmService 19 | singleton: true 20 | config: 21 | name: "hello_world" 22 | vm_config: 23 | runtime: "envoy.wasm.runtime.v8" 24 | code: 25 | local: 26 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_hello_world.wasm" 27 | -------------------------------------------------------------------------------- /src/allocator.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use std::mem::MaybeUninit; 16 | 17 | #[cfg_attr( 18 | all(target_arch = "wasm32", target_os = "unknown"), 19 | export_name = "malloc" 20 | )] 21 | #[cfg_attr(not(all(target_arch = "wasm32", target_os = "unknown")), no_mangle)] 22 | pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 { 23 | let mut vec: Vec> = Vec::with_capacity(size); 24 | unsafe { 25 | vec.set_len(size); 26 | } 27 | let slice = vec.into_boxed_slice(); 28 | Box::into_raw(slice) as *mut u8 29 | } 30 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows [Google's Open Source Community 28 | Guidelines](https://opensource.google/conduct/). 29 | -------------------------------------------------------------------------------- /bazel/extensions.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@proxy_wasm_rust_sdk//bazel/cargo/remote:crates.bzl", "crate_repositories") 16 | 17 | def _crates_deps_impl(module_ctx): 18 | deps = [] 19 | for repo in crate_repositories(): 20 | if not repo.is_dev_dep: 21 | deps.append(repo.repo) 22 | 23 | return module_ctx.extension_metadata( 24 | root_module_direct_deps = deps, 25 | root_module_direct_dev_deps = [], 26 | ) 27 | 28 | crates_deps = module_extension( 29 | doc = "Dependencies for the Proxy-Wasm Rust SDK.", 30 | implementation = _crates_deps_impl, 31 | ) 32 | -------------------------------------------------------------------------------- /examples/grpc_auth_random/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | depends_on: 27 | - grpcbin 28 | grpcbin: 29 | image: kong/grpcbin 30 | hostname: grpcbin 31 | ports: 32 | - "9000:9000" 33 | networks: 34 | - envoymesh 35 | networks: 36 | envoymesh: {} 37 | -------------------------------------------------------------------------------- /examples/http_auth_random/docker-compose.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | services: 16 | envoy: 17 | image: envoyproxy/envoy:v1.34-latest 18 | hostname: envoy 19 | ports: 20 | - "10000:10000" 21 | volumes: 22 | - ./envoy.yaml:/etc/envoy/envoy.yaml 23 | - ./target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins 24 | networks: 25 | - envoymesh 26 | depends_on: 27 | - httpbin 28 | httpbin: 29 | image: mccutchen/go-httpbin 30 | hostname: httpbin 31 | ports: 32 | - "8080:8080" 33 | networks: 34 | - envoymesh 35 | networks: 36 | envoymesh: {} 37 | -------------------------------------------------------------------------------- /examples/grpc_auth_random/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: gRPC auth (random) 2 | 3 | Proxy-Wasm plugin that grants access based on a result of gRPC callout. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | #### Access granted. 21 | 22 | Send gRPC request to `localhost:10000` service `hello.HelloService`: 23 | 24 | ```sh 25 | $ grpcurl -d '{"greeting": "Rust"}' -plaintext localhost:10000 hello.HelloService/SayHello 26 | { 27 | "reply": "hello Rust" 28 | } 29 | ``` 30 | 31 | Expected Envoy logs: 32 | 33 | ```console 34 | [...] wasm log grpc_auth_random: Access granted. 35 | ``` 36 | 37 | #### Access forbidden. 38 | 39 | Send gRPC request to `localhost:10000` service `hello.HelloService`: 40 | 41 | ```sh 42 | $ grpcurl -d '{"greeting": "Rust"}' -plaintext localhost:10000 hello.HelloService/SayHello 43 | ERROR: 44 | Code: Aborted 45 | Message: Aborted by Proxy-Wasm! 46 | ``` 47 | 48 | Expected Envoy logs: 49 | 50 | ```console 51 | [...] wasm log grpc_auth_random: Access forbidden. 52 | ``` 53 | -------------------------------------------------------------------------------- /examples/http_auth_random/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: HTTP auth (random) 2 | 3 | Proxy-Wasm plugin that grants access based on a result of HTTP callout. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | #### Access granted. 21 | 22 | Send HTTP request to `localhost:10000/headers`: 23 | 24 | ```sh 25 | $ curl localhost:10000/headers 26 | { 27 | "headers": { 28 | "Accept": "*/*", 29 | "Host": "localhost", 30 | "User-Agent": "curl/7.81.0", 31 | "X-Amzn-Trace-Id": "Root=1-637c4767-6e31776a0b407a0219b5b570", 32 | "X-Envoy-Expected-Rq-Timeout-Ms": "15000" 33 | } 34 | } 35 | ``` 36 | 37 | Expected Envoy logs: 38 | 39 | ```console 40 | [...] wasm log http_auth_random: Access granted. 41 | ``` 42 | 43 | #### Access forbidden. 44 | 45 | Send HTTP request to `localhost:10000/headers`: 46 | 47 | ```sh 48 | $ curl localhost:10000/headers 49 | Access forbidden. 50 | ``` 51 | 52 | Expected Envoy logs: 53 | 54 | ```console 55 | [...] wasm log http_auth_random: Access forbidden. 56 | ``` 57 | -------------------------------------------------------------------------------- /bazel/cargo/remote/crates.bzl: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # This file is auto-generated by the cargo-bazel tool. 4 | # 5 | # DO NOT MODIFY: Local changes may be replaced in future executions. 6 | ############################################################################### 7 | """Rules for defining repositories for remote `crates_vendor` repositories""" 8 | 9 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 10 | 11 | # buildifier: disable=bzl-visibility 12 | load("@proxy_wasm_rust_sdk//bazel/cargo/remote:defs.bzl", _crate_repositories = "crate_repositories") 13 | 14 | # buildifier: disable=bzl-visibility 15 | load("@rules_rust//crate_universe/private:crates_vendor.bzl", "crates_vendor_remote_repository") 16 | 17 | def crate_repositories(): 18 | """Generates repositories for vendored crates. 19 | 20 | Returns: 21 | A list of repos visible to the module through the module extension. 22 | """ 23 | maybe( 24 | crates_vendor_remote_repository, 25 | name = "crates_vendor", 26 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.bazel"), 27 | defs_module = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:defs.bzl"), 28 | ) 29 | 30 | direct_deps = [struct(repo = "crates_vendor", is_dev_dep = False)] 31 | direct_deps.extend(_crate_repositories()) 32 | return direct_deps 33 | -------------------------------------------------------------------------------- /examples/http_headers/README.md: -------------------------------------------------------------------------------- 1 | ## Proxy-Wasm plugin example: HTTP headers 2 | 3 | Proxy-Wasm plugin that logs HTTP request/response headers. 4 | 5 | ### Building 6 | 7 | ```sh 8 | $ cargo build --target wasm32-wasip1 --release 9 | ``` 10 | 11 | ### Using in Envoy 12 | 13 | This example can be run with [`docker compose`](https://docs.docker.com/compose/install/) 14 | and has a matching Envoy configuration. 15 | 16 | ```sh 17 | $ docker compose up 18 | ``` 19 | 20 | Send HTTP request to `localhost:10000/hello`: 21 | 22 | ```sh 23 | $ curl localhost:10000/hello 24 | Hello, World! 25 | ``` 26 | 27 | Expected Envoy logs: 28 | 29 | ```console 30 | [...] wasm log http_headers: #2 -> :authority: localhost:10000 31 | [...] wasm log http_headers: #2 -> :path: /hello 32 | [...] wasm log http_headers: #2 -> :method: GET 33 | [...] wasm log http_headers: #2 -> :scheme: http 34 | [...] wasm log http_headers: #2 -> user-agent: curl/7.81.0 35 | [...] wasm log http_headers: #2 -> accept: */* 36 | [...] wasm log http_headers: #2 -> x-forwarded-proto: http 37 | [...] wasm log http_headers: #2 -> x-request-id: 3ed6eb3b-ddce-4fdc-8862-ddb8f168d406 38 | [...] wasm log http_headers: #2 <- :status: 200 39 | [...] wasm log http_headers: #2 <- hello: World 40 | [...] wasm log http_headers: #2 <- powered-by: proxy-wasm 41 | [...] wasm log http_headers: #2 <- content-length: 14 42 | [...] wasm log http_headers: #2 <- content-type: text/plain 43 | [...] wasm log http_headers: #2 completed. 44 | ``` 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WebAssembly for Proxies (Rust SDK) 2 | 3 | [![Build Status][build-badge]][build-link] 4 | [![Crate][crate-badge]][crate-link] 5 | [![Documentation][docs-badge]][docs-link] 6 | [![Apache 2.0 License][license-badge]][license-link] 7 | 8 | [build-badge]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/workflows/Rust/badge.svg?branch=main 9 | [build-link]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/actions?query=workflow%3ARust+branch%3Amain 10 | [crate-badge]: https://img.shields.io/crates/v/proxy-wasm.svg 11 | [crate-link]: https://crates.io/crates/proxy-wasm 12 | [docs-badge]: https://docs.rs/proxy-wasm/badge.svg 13 | [docs-link]: https://docs.rs/proxy-wasm 14 | [license-badge]: https://img.shields.io/github/license/proxy-wasm/proxy-wasm-rust-sdk 15 | [license-link]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/blob/main/LICENSE 16 | 17 | ## Examples 18 | 19 | - [Hello World](./examples/hello_world/) 20 | - [HTTP Auth (random)](./examples/http_auth_random/) 21 | - [HTTP Headers](./examples/http_headers/) 22 | - [HTTP Response body](./examples/http_body/) 23 | - [HTTP Configuration](./examples/http_config/) 24 | - [gRPC Auth (random)](./examples/grpc_auth_random/) 25 | - [Envoy filter metadata](./examples/envoy_filter_metadata/) 26 | 27 | ## Articles & blog posts from the community 28 | 29 | - [Extending Envoy with WASM and Rust](https://antweiss.com/blog/extending-envoy-with-wasm-and-rust/) 30 | - [Writing Envoy filters in Rust with WebAssembly](https://content.red-badger.com/resources/extending-istio-with-rust-and-webassembly) 31 | 32 | ## Contributing changes 33 | 34 | See [CONTRIBUTING.md](./CONTRIBUTING.md) and [DEVELOPMENT.md](./DEVELOPMENT.md) files. 35 | -------------------------------------------------------------------------------- /BUILD: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@rules_rust//cargo:defs.bzl", "cargo_build_script") 16 | load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library") 17 | 18 | exports_files([ 19 | "Cargo.toml", 20 | ]) 21 | 22 | cargo_build_script( 23 | name = "proxy_wasm_build_script", 24 | srcs = ["build.rs"], 25 | edition = "2018", 26 | tags = ["manual"], 27 | visibility = ["//visibility:private"], 28 | ) 29 | 30 | rust_library( 31 | name = "proxy_wasm", 32 | srcs = glob(["src/*.rs"]), 33 | edition = "2018", 34 | visibility = ["//visibility:public"], 35 | deps = [ 36 | ":proxy_wasm_build_script", 37 | "//bazel/cargo/remote:hashbrown", 38 | "//bazel/cargo/remote:log", 39 | ], 40 | ) 41 | 42 | rust_binary( 43 | name = "http_auth_random", 44 | srcs = ["examples/http_auth_random/src/lib.rs"], 45 | crate_type = "cdylib", 46 | edition = "2018", 47 | out_binary = True, 48 | rustc_flags = ["-Cstrip=debuginfo"], 49 | visibility = ["//visibility:private"], 50 | deps = [ 51 | ":proxy_wasm", 52 | "//bazel/cargo/remote:log", 53 | ], 54 | ) 55 | -------------------------------------------------------------------------------- /examples/hello_world/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use cfg_if::cfg_if; 16 | use chrono::{DateTime, Utc}; 17 | use log::info; 18 | use proxy_wasm::traits::*; 19 | use proxy_wasm::types::*; 20 | use std::time::Duration; 21 | 22 | proxy_wasm::main! {{ 23 | proxy_wasm::set_log_level(LogLevel::Trace); 24 | proxy_wasm::set_root_context(|_| -> Box { Box::new(HelloWorld) }); 25 | }} 26 | 27 | struct HelloWorld; 28 | 29 | impl Context for HelloWorld {} 30 | 31 | impl RootContext for HelloWorld { 32 | fn on_vm_start(&mut self, _: usize) -> bool { 33 | info!("Hello, World!"); 34 | self.set_tick_period(Duration::from_secs(5)); 35 | true 36 | } 37 | 38 | fn on_tick(&mut self) { 39 | cfg_if! { 40 | if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] { 41 | let now: DateTime = self.get_current_time().into(); 42 | info!("It's {}, there is no lucky number.", now); 43 | 44 | } else { 45 | let now: DateTime = Utc::now(); 46 | let mut buf = [0u8; 1]; 47 | getrandom::fill(&mut buf).unwrap(); 48 | info!("It's {}, your lucky number is {}.", now, buf[0]); 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /MODULE.bazel: -------------------------------------------------------------------------------- 1 | # Copyright 2025 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | module( 16 | name = "proxy_wasm_rust_sdk", 17 | version = "0.2.5-dev", 18 | ) 19 | 20 | # Regular dependencies (sorted alphabetically). 21 | bazel_dep(name = "bazel_features", version = "1.38.0") 22 | bazel_dep(name = "bazel_skylib", version = "1.8.2") 23 | bazel_dep(name = "rules_cc", version = "0.2.14") 24 | bazel_dep(name = "rules_rust", version = "0.67.0") 25 | single_version_override( 26 | module_name = "rules_rust", 27 | patch_strip = 1, 28 | patches = [ 29 | "//bazel:rules_rust.patch", 30 | ], 31 | version = "0.67.0", 32 | ) 33 | 34 | # Configure Rust toolchain. 35 | rust = use_extension("@rules_rust//rust:extensions.bzl", "rust") 36 | rust.toolchain( 37 | edition = "2018", 38 | versions = ["1.90.0"], 39 | ) 40 | use_repo(rust, "rust_toolchains") 41 | 42 | register_toolchains( 43 | "@rust_toolchains//:all", 44 | # Dummy C/C++ toolchains for Wasm targets. 45 | "@rules_rust//rust/private/dummy_cc_toolchain:dummy_cc_wasm32_toolchain", 46 | "@rules_rust//rust/private/dummy_cc_toolchain:dummy_cc_wasm64_toolchain", 47 | ) 48 | 49 | # Cargo dependencies. 50 | crates_deps = use_extension("//bazel:extensions.bzl", "crates_deps") 51 | use_repo( 52 | crates_deps, 53 | "crates_vendor", 54 | "crates_vendor__hashbrown-0.16.0", 55 | "crates_vendor__log-0.4.27", 56 | ) 57 | -------------------------------------------------------------------------------- /examples/envoy_filter_metadata/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use proxy_wasm::traits::*; 16 | use proxy_wasm::types::*; 17 | 18 | proxy_wasm::main! {{ 19 | proxy_wasm::set_log_level(LogLevel::Trace); 20 | proxy_wasm::set_http_context(|_, _| -> Box { Box::new(MetadataHttp {}) }); 21 | }} 22 | 23 | struct MetadataHttp {} 24 | 25 | impl Context for MetadataHttp {} 26 | 27 | impl HttpContext for MetadataHttp { 28 | fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { 29 | // Read data set by the lua filter 30 | match self.get_property(vec![ 31 | "metadata", 32 | "filter_metadata", 33 | "envoy.filters.http.lua", 34 | "uppercased-custom-metadata", 35 | ]) { 36 | Some(metadata) => match String::from_utf8(metadata) { 37 | Ok(data) => { 38 | self.send_http_response( 39 | 200, 40 | vec![("Powered-By", "proxy-wasm"), ("uppercased-metadata", &data)], 41 | Some(format!("Custom response with Envoy metadata: {data:?}\n").as_bytes()), 42 | ); 43 | Action::Pause 44 | } 45 | _ => Action::Continue, 46 | }, 47 | _ => Action::Continue, 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /bazel/cargo/remote/alias_rules.bzl: -------------------------------------------------------------------------------- 1 | """Alias that transitions its target to `compilation_mode=opt`. Use `transition_alias="opt"` to enable.""" 2 | 3 | load("@rules_cc//cc:defs.bzl", "CcInfo") 4 | load("@rules_rust//rust:rust_common.bzl", "COMMON_PROVIDERS") 5 | 6 | def _transition_alias_impl(ctx): 7 | # `ctx.attr.actual` is a list of 1 item due to the transition 8 | providers = [ctx.attr.actual[0][provider] for provider in COMMON_PROVIDERS] 9 | if CcInfo in ctx.attr.actual[0]: 10 | providers.append(ctx.attr.actual[0][CcInfo]) 11 | return providers 12 | 13 | def _change_compilation_mode(compilation_mode): 14 | def _change_compilation_mode_impl(_settings, _attr): 15 | return { 16 | "//command_line_option:compilation_mode": compilation_mode, 17 | } 18 | 19 | return transition( 20 | implementation = _change_compilation_mode_impl, 21 | inputs = [], 22 | outputs = [ 23 | "//command_line_option:compilation_mode", 24 | ], 25 | ) 26 | 27 | def _transition_alias_rule(compilation_mode): 28 | return rule( 29 | implementation = _transition_alias_impl, 30 | provides = COMMON_PROVIDERS, 31 | attrs = { 32 | "actual": attr.label( 33 | mandatory = True, 34 | doc = "`rust_library()` target to transition to `compilation_mode=opt`.", 35 | providers = COMMON_PROVIDERS, 36 | cfg = _change_compilation_mode(compilation_mode), 37 | ), 38 | "_allowlist_function_transition": attr.label( 39 | default = "@bazel_tools//tools/allowlists/function_transition_allowlist", 40 | ), 41 | }, 42 | doc = "Transitions a Rust library crate to the `compilation_mode=opt`.", 43 | ) 44 | 45 | transition_alias_dbg = _transition_alias_rule("dbg") 46 | transition_alias_fastbuild = _transition_alias_rule("fastbuild") 47 | transition_alias_opt = _transition_alias_rule("opt") 48 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | package(default_visibility = ["//visibility:public"]) 10 | 11 | exports_files( 12 | [ 13 | "cargo-bazel.json", 14 | "crates.bzl", 15 | "defs.bzl", 16 | ] + glob( 17 | include = ["*.bazel"], 18 | allow_empty = True, 19 | ), 20 | ) 21 | 22 | filegroup( 23 | name = "srcs", 24 | srcs = glob( 25 | include = [ 26 | "*.bazel", 27 | "*.bzl", 28 | ], 29 | allow_empty = True, 30 | ), 31 | ) 32 | 33 | # Workspace Member Dependencies 34 | alias( 35 | name = "hashbrown-0.16.0", 36 | actual = "@crates_vendor__hashbrown-0.16.0//:hashbrown", 37 | tags = ["manual"], 38 | ) 39 | 40 | alias( 41 | name = "hashbrown", 42 | actual = "@crates_vendor__hashbrown-0.16.0//:hashbrown", 43 | tags = ["manual"], 44 | ) 45 | 46 | alias( 47 | name = "log-0.4.27", 48 | actual = "@crates_vendor__log-0.4.27//:log", 49 | tags = ["manual"], 50 | ) 51 | 52 | alias( 53 | name = "log", 54 | actual = "@crates_vendor__log-0.4.27//:log", 55 | tags = ["manual"], 56 | ) 57 | 58 | alias( 59 | name = "mockalloc-0.1.2", 60 | actual = "@crates_vendor__mockalloc-0.1.2//:mockalloc", 61 | tags = ["manual"], 62 | ) 63 | 64 | alias( 65 | name = "mockalloc", 66 | actual = "@crates_vendor__mockalloc-0.1.2//:mockalloc", 67 | tags = ["manual"], 68 | ) 69 | 70 | alias( 71 | name = "proxy-wasm-0.2.5-dev", 72 | actual = "@crates_vendor__proxy-wasm-0.2.5-dev//:proxy_wasm", 73 | tags = ["manual"], 74 | ) 75 | 76 | alias( 77 | name = "proxy-wasm", 78 | actual = "@crates_vendor__proxy-wasm-0.2.5-dev//:proxy_wasm", 79 | tags = ["manual"], 80 | ) 81 | -------------------------------------------------------------------------------- /examples/http_config/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use proxy_wasm::traits::*; 16 | use proxy_wasm::types::*; 17 | 18 | proxy_wasm::main! {{ 19 | proxy_wasm::set_log_level(LogLevel::Trace); 20 | proxy_wasm::set_root_context(|_| -> Box { 21 | Box::new(HttpConfigHeaderRoot { 22 | header_content: String::new(), 23 | }) 24 | }); 25 | }} 26 | 27 | struct HttpConfigHeader { 28 | header_content: String, 29 | } 30 | 31 | impl Context for HttpConfigHeader {} 32 | 33 | impl HttpContext for HttpConfigHeader { 34 | fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { 35 | self.add_http_response_header("custom-header", self.header_content.as_str()); 36 | Action::Continue 37 | } 38 | } 39 | 40 | struct HttpConfigHeaderRoot { 41 | header_content: String, 42 | } 43 | 44 | impl Context for HttpConfigHeaderRoot {} 45 | 46 | impl RootContext for HttpConfigHeaderRoot { 47 | fn on_configure(&mut self, _: usize) -> bool { 48 | if let Some(config_bytes) = self.get_plugin_configuration() { 49 | self.header_content = String::from_utf8(config_bytes).unwrap() 50 | } 51 | true 52 | } 53 | 54 | fn create_http_context(&self, _: u32) -> Option> { 55 | Some(Box::new(HttpConfigHeader { 56 | header_content: self.header_content.clone(), 57 | })) 58 | } 59 | 60 | fn get_type(&self) -> Option { 61 | Some(ContextType::HttpContext) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /bazel/repositories.bzl: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 16 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 17 | 18 | def proxy_wasm_rust_sdk_repositories(): 19 | maybe( 20 | http_archive, 21 | name = "bazel_features", 22 | sha256 = "07271d0f6b12633777b69020c4cb1eb67b1939c0cf84bb3944dc85cc250c0c01", 23 | url = "https://github.com/bazel-contrib/bazel_features/releases/download/v1.38.0/bazel_features-v1.38.0.tar.gz", 24 | strip_prefix = "bazel_features-1.38.0", 25 | ) 26 | 27 | maybe( 28 | http_archive, 29 | name = "rules_cc", 30 | sha256 = "a2fdfde2ab9b2176bd6a33afca14458039023edb1dd2e73e6823810809df4027", 31 | url = "https://github.com/bazelbuild/rules_cc/releases/download/0.2.14/rules_cc-0.2.14.tar.gz", 32 | strip_prefix = "rules_cc-0.2.14", 33 | ) 34 | 35 | maybe( 36 | http_archive, 37 | name = "rules_rust", 38 | sha256 = "dc287e3eca80b29d5cc95e261cae273eedf1af4a00a96ae937e234534dadb24c", 39 | url = "https://github.com/bazelbuild/rules_rust/releases/download/0.67.0/rules_rust-0.67.0.tar.gz", 40 | patches = ["//bazel:rules_rust.patch"], 41 | patch_args = ["-p1"], 42 | ) 43 | 44 | maybe( 45 | http_archive, 46 | name = "bazel_skylib", 47 | sha256 = "6e78f0e57de26801f6f564fa7c4a48dc8b36873e416257a92bbb0937eeac8446", 48 | url = "https://github.com/bazelbuild/bazel-skylib/releases/download/1.8.2/bazel-skylib-1.8.2.tar.gz", 49 | ) 50 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #![cfg_attr(all(test, nightly), feature(test))] 16 | 17 | #[cfg(all(test, nightly))] 18 | extern crate test; 19 | 20 | pub mod hostcalls; 21 | pub mod traits; 22 | pub mod types; 23 | 24 | mod allocator; 25 | mod dispatcher; 26 | mod logger; 27 | 28 | // For crate-type="cdylib". 29 | #[cfg(not(wasi_exec_model_reactor))] 30 | #[macro_export] 31 | macro_rules! main { 32 | ($code:block) => { 33 | #[cfg(target_os = "wasi")] 34 | extern "C" { 35 | fn __wasm_call_ctors(); 36 | } 37 | 38 | #[no_mangle] 39 | pub extern "C" fn _initialize() { 40 | #[cfg(target_os = "wasi")] 41 | unsafe { 42 | __wasm_call_ctors(); 43 | } 44 | 45 | $code; 46 | } 47 | }; 48 | } 49 | 50 | // For crate-type="bin" with RUSTFLAGS="-Z wasi-exec-model=reactor". 51 | #[cfg(wasi_exec_model_reactor)] 52 | #[macro_export] 53 | macro_rules! main { 54 | ($code:block) => { 55 | pub fn main() -> Result<(), Box> { 56 | $code; 57 | Ok(()) 58 | } 59 | }; 60 | } 61 | 62 | pub fn set_log_level(level: types::LogLevel) { 63 | logger::set_log_level(level); 64 | } 65 | 66 | pub fn set_root_context(callback: types::NewRootContext) { 67 | dispatcher::set_root_context(callback); 68 | } 69 | 70 | pub fn set_stream_context(callback: types::NewStreamContext) { 71 | dispatcher::set_stream_context(callback); 72 | } 73 | 74 | pub fn set_http_context(callback: types::NewHttpContext) { 75 | dispatcher::set_http_context(callback); 76 | } 77 | 78 | #[no_mangle] 79 | pub extern "C" fn proxy_abi_version_0_2_1() {} 80 | -------------------------------------------------------------------------------- /examples/http_auth_random/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use log::info; 16 | use proxy_wasm::traits::*; 17 | use proxy_wasm::types::*; 18 | use std::time::Duration; 19 | 20 | proxy_wasm::main! {{ 21 | proxy_wasm::set_log_level(LogLevel::Trace); 22 | proxy_wasm::set_http_context(|_, _| -> Box { Box::new(HttpAuthRandom) }); 23 | }} 24 | 25 | struct HttpAuthRandom; 26 | 27 | impl HttpContext for HttpAuthRandom { 28 | fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { 29 | self.dispatch_http_call( 30 | "httpbin", 31 | vec![ 32 | (":method", "GET"), 33 | (":path", "/bytes/1"), 34 | (":authority", "httpbin.org"), 35 | ], 36 | None, 37 | vec![], 38 | Duration::from_secs(1), 39 | ) 40 | .unwrap(); 41 | Action::Pause 42 | } 43 | 44 | fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { 45 | self.set_http_response_header("Powered-By", Some("proxy-wasm")); 46 | Action::Continue 47 | } 48 | } 49 | 50 | impl Context for HttpAuthRandom { 51 | fn on_http_call_response(&mut self, _: u32, _: usize, body_size: usize, _: usize) { 52 | if let Some(body) = self.get_http_call_response_body(0, body_size) { 53 | #[allow(unknown_lints, clippy::manual_is_multiple_of)] 54 | if !body.is_empty() && body[0] % 2 == 0 { 55 | info!("Access granted."); 56 | self.resume_http_request(); 57 | return; 58 | } 59 | } 60 | info!("Access forbidden."); 61 | self.send_http_response( 62 | 403, 63 | vec![("Powered-By", "proxy-wasm")], 64 | Some(b"Access forbidden.\n"), 65 | ); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /examples/http_headers/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use log::info; 16 | use proxy_wasm::traits::*; 17 | use proxy_wasm::types::*; 18 | 19 | proxy_wasm::main! {{ 20 | proxy_wasm::set_log_level(LogLevel::Trace); 21 | proxy_wasm::set_root_context(|_| -> Box { Box::new(HttpHeadersRoot) }); 22 | }} 23 | 24 | struct HttpHeadersRoot; 25 | 26 | impl Context for HttpHeadersRoot {} 27 | 28 | impl RootContext for HttpHeadersRoot { 29 | fn get_type(&self) -> Option { 30 | Some(ContextType::HttpContext) 31 | } 32 | 33 | fn create_http_context(&self, context_id: u32) -> Option> { 34 | Some(Box::new(HttpHeaders { context_id })) 35 | } 36 | } 37 | 38 | struct HttpHeaders { 39 | context_id: u32, 40 | } 41 | 42 | impl Context for HttpHeaders {} 43 | 44 | impl HttpContext for HttpHeaders { 45 | fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { 46 | for (name, value) in &self.get_http_request_headers() { 47 | info!("#{} -> {}: {}", self.context_id, name, value); 48 | } 49 | 50 | match self.get_http_request_header(":path") { 51 | Some(path) if path == "/hello" => { 52 | self.send_http_response( 53 | 200, 54 | vec![("Hello", "World"), ("Powered-By", "proxy-wasm")], 55 | Some(b"Hello, World!\n"), 56 | ); 57 | Action::Pause 58 | } 59 | _ => Action::Continue, 60 | } 61 | } 62 | 63 | fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { 64 | for (name, value) in &self.get_http_response_headers() { 65 | info!("#{} <- {}: {}", self.context_id, name, value); 66 | } 67 | Action::Continue 68 | } 69 | 70 | fn on_log(&mut self) { 71 | info!("#{} completed.", self.context_id); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /examples/http_headers/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/" 37 | direct_response: 38 | status: 200 39 | body: 40 | inline_string: "Request /hello and be welcomed!\n" 41 | http_filters: 42 | - name: envoy.filters.http.wasm 43 | typed_config: 44 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 45 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 46 | value: 47 | config: 48 | name: "http_headers" 49 | vm_config: 50 | runtime: "envoy.wasm.runtime.v8" 51 | code: 52 | local: 53 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_http_headers.wasm" 54 | - name: envoy.filters.http.router 55 | typed_config: 56 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 57 | -------------------------------------------------------------------------------- /src/logger.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use crate::hostcalls; 16 | use crate::types::LogLevel; 17 | use std::panic; 18 | use std::sync::atomic::{AtomicBool, Ordering}; 19 | 20 | struct Logger; 21 | 22 | static LOGGER: Logger = Logger; 23 | static INITIALIZED: AtomicBool = AtomicBool::new(false); 24 | 25 | pub(crate) fn set_log_level(level: LogLevel) { 26 | if !INITIALIZED.load(Ordering::Relaxed) { 27 | log::set_logger(&LOGGER).unwrap(); 28 | panic::set_hook(Box::new(|panic_info| { 29 | hostcalls::log(LogLevel::Critical, &panic_info.to_string()).unwrap(); 30 | })); 31 | INITIALIZED.store(true, Ordering::Relaxed); 32 | } 33 | LOGGER.set_log_level(level); 34 | } 35 | 36 | impl Logger { 37 | pub fn set_log_level(&self, level: LogLevel) { 38 | let filter = match level { 39 | LogLevel::Trace => log::LevelFilter::Trace, 40 | LogLevel::Debug => log::LevelFilter::Debug, 41 | LogLevel::Info => log::LevelFilter::Info, 42 | LogLevel::Warn => log::LevelFilter::Warn, 43 | LogLevel::Error => log::LevelFilter::Error, 44 | LogLevel::Critical => log::LevelFilter::Off, 45 | }; 46 | log::set_max_level(filter); 47 | } 48 | } 49 | 50 | impl log::Log for Logger { 51 | fn enabled(&self, metadata: &log::Metadata) -> bool { 52 | metadata.level() <= log::max_level() 53 | } 54 | 55 | fn log(&self, record: &log::Record) { 56 | if !self.enabled(record.metadata()) { 57 | return; 58 | } 59 | let level = match record.level() { 60 | log::Level::Trace => LogLevel::Trace, 61 | log::Level::Debug => LogLevel::Debug, 62 | log::Level::Info => LogLevel::Info, 63 | log::Level::Warn => LogLevel::Warn, 64 | log::Level::Error => LogLevel::Error, 65 | }; 66 | let message = record.args().to_string(); 67 | hostcalls::log(level, &message).unwrap(); 68 | } 69 | 70 | fn flush(&self) {} 71 | } 72 | -------------------------------------------------------------------------------- /examples/http_body/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use proxy_wasm::traits::*; 16 | use proxy_wasm::types::*; 17 | 18 | proxy_wasm::main! {{ 19 | proxy_wasm::set_log_level(LogLevel::Trace); 20 | proxy_wasm::set_root_context(|_| -> Box { Box::new(HttpBodyRoot) }); 21 | }} 22 | 23 | struct HttpBodyRoot; 24 | 25 | impl Context for HttpBodyRoot {} 26 | 27 | impl RootContext for HttpBodyRoot { 28 | fn get_type(&self) -> Option { 29 | Some(ContextType::HttpContext) 30 | } 31 | 32 | fn create_http_context(&self, _: u32) -> Option> { 33 | Some(Box::new(HttpBody)) 34 | } 35 | } 36 | 37 | struct HttpBody; 38 | 39 | impl Context for HttpBody {} 40 | 41 | impl HttpContext for HttpBody { 42 | fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { 43 | // If there is a Content-Length header and we change the length of 44 | // the body later, then clients will break. So remove it. 45 | // We must do this here, because once we exit this function we 46 | // can no longer modify the response headers. 47 | self.set_http_response_header("content-length", None); 48 | Action::Continue 49 | } 50 | 51 | fn on_http_response_body(&mut self, body_size: usize, end_of_stream: bool) -> Action { 52 | if !end_of_stream { 53 | // Wait -- we'll be called again when the complete body is buffered 54 | // at the host side. 55 | return Action::Pause; 56 | } 57 | 58 | // Replace the message body if it contains the text "secret". 59 | // Since we returned "Pause" previuously, this will return the whole body. 60 | if let Some(body_bytes) = self.get_http_response_body(0, body_size) { 61 | let body_str = String::from_utf8(body_bytes).unwrap(); 62 | if body_str.contains("secret") { 63 | let new_body = format!("Original message body ({body_size} bytes) redacted.\n"); 64 | self.set_http_response_body(0, body_size, &new_body.into_bytes()); 65 | } 66 | } 67 | Action::Continue 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /examples/http_config/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/" 37 | direct_response: 38 | status: 200 39 | body: 40 | inline_string: "Inspect the HTTP header: custom-header.\n" 41 | http_filters: 42 | - name: envoy.filters.http.wasm 43 | typed_config: 44 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 45 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 46 | value: 47 | config: 48 | name: "http_config" 49 | configuration: 50 | "@type": "type.googleapis.com/google.protobuf.StringValue" 51 | value: The secret to life is meaningless unless you discover it yourself 52 | vm_config: 53 | runtime: "envoy.wasm.runtime.v8" 54 | code: 55 | local: 56 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_http_config.wasm" 57 | - name: envoy.filters.http.router 58 | typed_config: 59 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 60 | -------------------------------------------------------------------------------- /examples/http_body/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/secret" 37 | direct_response: 38 | status: 200 39 | body: 40 | inline_string: "This secret message should not be read by anyone.\n" 41 | - match: 42 | prefix: "/" 43 | direct_response: 44 | status: 200 45 | body: 46 | inline_string: "Everyone may read this message.\n" 47 | http_filters: 48 | - name: envoy.filters.http.wasm 49 | typed_config: 50 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 51 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 52 | value: 53 | config: 54 | name: "http_body" 55 | vm_config: 56 | runtime: "envoy.wasm.runtime.v8" 57 | code: 58 | local: 59 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_http_body.wasm" 60 | - name: envoy.filters.http.router 61 | typed_config: 62 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 63 | -------------------------------------------------------------------------------- /examples/http_auth_random/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/" 37 | route: 38 | cluster: httpbin 39 | http_filters: 40 | - name: envoy.filters.http.wasm 41 | typed_config: 42 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 43 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 44 | value: 45 | config: 46 | name: "http_auth_random" 47 | vm_config: 48 | runtime: "envoy.wasm.runtime.v8" 49 | code: 50 | local: 51 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_http_auth_random.wasm" 52 | - name: envoy.filters.http.router 53 | typed_config: 54 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 55 | clusters: 56 | - name: httpbin 57 | connect_timeout: 5s 58 | type: STRICT_DNS 59 | lb_policy: ROUND_ROBIN 60 | load_assignment: 61 | cluster_name: httpbin 62 | endpoints: 63 | - lb_endpoints: 64 | - endpoint: 65 | address: 66 | socket_address: 67 | address: httpbin 68 | port_value: 8080 69 | -------------------------------------------------------------------------------- /examples/grpc_auth_random/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/" 37 | route: 38 | cluster: grpcbin 39 | http_filters: 40 | - name: envoy.filters.http.wasm 41 | typed_config: 42 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 43 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 44 | value: 45 | config: 46 | name: "grpc_auth_random" 47 | vm_config: 48 | runtime: "envoy.wasm.runtime.v8" 49 | code: 50 | local: 51 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_grpc_auth_random.wasm" 52 | - name: envoy.filters.http.router 53 | typed_config: 54 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 55 | clusters: 56 | - name: grpcbin 57 | connect_timeout: 5s 58 | type: STRICT_DNS 59 | lb_policy: ROUND_ROBIN 60 | http2_protocol_options: {} 61 | load_assignment: 62 | cluster_name: grpcbin 63 | endpoints: 64 | - lb_endpoints: 65 | - endpoint: 66 | address: 67 | socket_address: 68 | address: grpcbin 69 | port_value: 9000 70 | -------------------------------------------------------------------------------- /bazel/cargo/Cargo.Bazel.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "allocator-api2" 7 | version = "0.2.21" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" 10 | 11 | [[package]] 12 | name = "equivalent" 13 | version = "1.0.2" 14 | source = "registry+https://github.com/rust-lang/crates.io-index" 15 | checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" 16 | 17 | [[package]] 18 | name = "foldhash" 19 | version = "0.2.0" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" 22 | 23 | [[package]] 24 | name = "hashbrown" 25 | version = "0.16.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" 28 | dependencies = [ 29 | "allocator-api2", 30 | "equivalent", 31 | "foldhash", 32 | ] 33 | 34 | [[package]] 35 | name = "log" 36 | version = "0.4.27" 37 | source = "registry+https://github.com/rust-lang/crates.io-index" 38 | checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94" 39 | 40 | [[package]] 41 | name = "mockalloc" 42 | version = "0.1.2" 43 | source = "registry+https://github.com/rust-lang/crates.io-index" 44 | checksum = "5a6c93486116b2ab028d2a2c5f5ff42020407d1c7048b77ca0b196a511a12a94" 45 | dependencies = [ 46 | "mockalloc-macros", 47 | ] 48 | 49 | [[package]] 50 | name = "mockalloc-macros" 51 | version = "0.1.0" 52 | source = "registry+https://github.com/rust-lang/crates.io-index" 53 | checksum = "23565dcdaedab64115f722c31d84e5bdb7125724097dcafce160a64806d6fb65" 54 | dependencies = [ 55 | "proc-macro2", 56 | "quote", 57 | "syn", 58 | ] 59 | 60 | [[package]] 61 | name = "proc-macro2" 62 | version = "1.0.101" 63 | source = "registry+https://github.com/rust-lang/crates.io-index" 64 | checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" 65 | dependencies = [ 66 | "unicode-ident", 67 | ] 68 | 69 | [[package]] 70 | name = "proxy-wasm" 71 | version = "0.2.5-dev" 72 | dependencies = [ 73 | "hashbrown", 74 | "log", 75 | "mockalloc", 76 | ] 77 | 78 | [[package]] 79 | name = "quote" 80 | version = "1.0.41" 81 | source = "registry+https://github.com/rust-lang/crates.io-index" 82 | checksum = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1" 83 | dependencies = [ 84 | "proc-macro2", 85 | ] 86 | 87 | [[package]] 88 | name = "syn" 89 | version = "1.0.109" 90 | source = "registry+https://github.com/rust-lang/crates.io-index" 91 | checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" 92 | dependencies = [ 93 | "proc-macro2", 94 | "quote", 95 | "unicode-ident", 96 | ] 97 | 98 | [[package]] 99 | name = "unicode-ident" 100 | version = "1.0.19" 101 | source = "registry+https://github.com/rust-lang/crates.io-index" 102 | checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" 103 | -------------------------------------------------------------------------------- /examples/grpc_auth_random/src/lib.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use log::info; 16 | use proxy_wasm::traits::*; 17 | use proxy_wasm::types::*; 18 | use std::time::Duration; 19 | 20 | proxy_wasm::main! {{ 21 | proxy_wasm::set_log_level(LogLevel::Trace); 22 | proxy_wasm::set_http_context(|_, _| -> Box { Box::new(GrpcAuthRandom) }); 23 | }} 24 | 25 | struct GrpcAuthRandom; 26 | 27 | impl HttpContext for GrpcAuthRandom { 28 | fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { 29 | match self.get_http_request_header("content-type") { 30 | Some(value) if value.starts_with("application/grpc") => {} 31 | _ => { 32 | // Reject non-gRPC clients. 33 | self.send_http_response( 34 | 503, 35 | vec![("Powered-By", "proxy-wasm")], 36 | Some(b"Service accessible only to gRPC clients.\n"), 37 | ); 38 | return Action::Pause; 39 | } 40 | } 41 | 42 | match self.get_http_request_header(":path") { 43 | Some(value) if value.starts_with("/grpc.reflection") => { 44 | // Always allow gRPC calls to the reflection API. 45 | Action::Continue 46 | } 47 | _ => { 48 | // Allow other gRPC calls based on the result of grpcbin.GRPCBin/RandomError. 49 | self.dispatch_grpc_call( 50 | "grpcbin", 51 | "grpcbin.GRPCBin", 52 | "RandomError", 53 | vec![], 54 | None, 55 | Duration::from_secs(1), 56 | ) 57 | .unwrap(); 58 | Action::Pause 59 | } 60 | } 61 | } 62 | 63 | fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { 64 | self.set_http_response_header("Powered-By", Some("proxy-wasm")); 65 | Action::Continue 66 | } 67 | } 68 | 69 | impl Context for GrpcAuthRandom { 70 | fn on_grpc_call_response(&mut self, _: u32, status_code: u32, _: usize) { 71 | #[allow(unknown_lints, clippy::manual_is_multiple_of)] 72 | if status_code % 2 == 0 { 73 | info!("Access granted."); 74 | self.resume_http_request(); 75 | } else { 76 | info!("Access forbidden."); 77 | self.send_grpc_response( 78 | GrpcStatusCode::Aborted, 79 | Some("Aborted by Proxy-Wasm!"), 80 | vec![("Powered-By", b"proxy-wasm")], 81 | ); 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /examples/envoy_filter_metadata/envoy.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | static_resources: 16 | listeners: 17 | address: 18 | socket_address: 19 | address: 0.0.0.0 20 | port_value: 10000 21 | filter_chains: 22 | - filters: 23 | - name: envoy.filters.network.http_connection_manager 24 | typed_config: 25 | "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager 26 | stat_prefix: ingress_http 27 | codec_type: AUTO 28 | route_config: 29 | name: local_routes 30 | virtual_hosts: 31 | - name: local_service 32 | domains: 33 | - "*" 34 | routes: 35 | - match: 36 | prefix: "/" 37 | direct_response: 38 | status: 200 39 | body: 40 | inline_string: "Welcome, set the `x-custom-metadata` header to change the response!\n" 41 | http_filters: 42 | # Set uppercase metadata in Lua filter 43 | - name: envoy.filters.http.lua 44 | typed_config: 45 | "@type": type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua 46 | default_source_code: 47 | inline_string: | 48 | function envoy_on_request(request_handle) 49 | local headers = request_handle:headers() 50 | local data = headers:get("x-custom-metadata") 51 | 52 | if data then 53 | request_handle:streamInfo():dynamicMetadata():set("envoy.filters.http.lua", "uppercased-custom-metadata", string.upper(data)) 54 | end 55 | 56 | request_handle:logInfo("Metadata set by lua filter") 57 | end 58 | # Read it from a WASM filter 59 | - name: envoy.filters.http.wasm 60 | typed_config: 61 | "@type": type.googleapis.com/udpa.type.v1.TypedStruct 62 | type_url: type.googleapis.com/envoy.extensions.filters.http.wasm.v3.Wasm 63 | value: 64 | config: 65 | name: "envoy_metadata_filter" 66 | vm_config: 67 | runtime: "envoy.wasm.runtime.v8" 68 | code: 69 | local: 70 | filename: "/etc/envoy/proxy-wasm-plugins/proxy_wasm_example_envoy_filter_metadata.wasm" 71 | - name: envoy.filters.http.router 72 | typed_config: 73 | "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router 74 | -------------------------------------------------------------------------------- /src/types.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use crate::traits::*; 16 | 17 | pub type NewRootContext = fn(context_id: u32) -> Box; 18 | pub type NewStreamContext = fn(context_id: u32, root_context_id: u32) -> Box; 19 | pub type NewHttpContext = fn(context_id: u32, root_context_id: u32) -> Box; 20 | 21 | #[repr(u32)] 22 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 23 | pub enum LogLevel { 24 | Trace = 0, 25 | Debug = 1, 26 | Info = 2, 27 | Warn = 3, 28 | Error = 4, 29 | Critical = 5, 30 | } 31 | 32 | #[repr(u32)] 33 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 34 | #[non_exhaustive] 35 | pub enum Action { 36 | Continue = 0, 37 | Pause = 1, 38 | } 39 | 40 | #[repr(u32)] 41 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 42 | #[non_exhaustive] 43 | pub enum Status { 44 | Ok = 0, 45 | NotFound = 1, 46 | BadArgument = 2, 47 | SerializationFailure = 3, 48 | ParseFailure = 4, 49 | Empty = 7, 50 | CasMismatch = 8, 51 | InternalFailure = 10, 52 | } 53 | 54 | #[repr(u32)] 55 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 56 | #[non_exhaustive] 57 | pub enum ContextType { 58 | HttpContext = 0, 59 | StreamContext = 1, 60 | } 61 | 62 | #[repr(u32)] 63 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 64 | #[non_exhaustive] 65 | pub enum StreamType { 66 | HttpRequest = 0, 67 | HttpResponse = 1, 68 | Downstream = 2, 69 | Upstream = 3, 70 | } 71 | 72 | #[repr(u32)] 73 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 74 | #[non_exhaustive] 75 | pub enum BufferType { 76 | HttpRequestBody = 0, 77 | HttpResponseBody = 1, 78 | DownstreamData = 2, 79 | UpstreamData = 3, 80 | HttpCallResponseBody = 4, 81 | GrpcReceiveBuffer = 5, 82 | VmConfiguration = 6, 83 | PluginConfiguration = 7, 84 | CallData = 8, 85 | } 86 | 87 | #[repr(u32)] 88 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 89 | #[non_exhaustive] 90 | pub enum MapType { 91 | HttpRequestHeaders = 0, 92 | HttpRequestTrailers = 1, 93 | HttpResponseHeaders = 2, 94 | HttpResponseTrailers = 3, 95 | GrpcReceiveInitialMetadata = 4, 96 | GrpcReceiveTrailingMetadata = 5, 97 | HttpCallResponseHeaders = 6, 98 | HttpCallResponseTrailers = 7, 99 | } 100 | 101 | #[repr(u32)] 102 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 103 | #[non_exhaustive] 104 | pub enum PeerType { 105 | Unknown = 0, 106 | Local = 1, 107 | Remote = 2, 108 | } 109 | 110 | #[repr(u32)] 111 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 112 | #[non_exhaustive] 113 | pub enum MetricType { 114 | Counter = 0, 115 | Gauge = 1, 116 | Histogram = 2, 117 | } 118 | 119 | #[repr(u32)] 120 | #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 121 | #[non_exhaustive] 122 | pub enum GrpcStatusCode { 123 | Ok = 0, 124 | Cancelled = 1, 125 | Unknown = 2, 126 | InvalidArgument = 3, 127 | DeadlineExceeded = 4, 128 | NotFound = 5, 129 | AlreadyExists = 6, 130 | PermissionDenied = 7, 131 | ResourceExhausted = 8, 132 | FailedPrecondition = 9, 133 | Aborted = 10, 134 | OutOfRange = 11, 135 | Unimplemented = 12, 136 | Internal = 13, 137 | Unavailable = 14, 138 | DataLoss = 15, 139 | Unauthenticated = 16, 140 | } 141 | 142 | pub type Bytes = Vec; 143 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.log-0.4.27.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "log", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2021", 39 | rustc_env_files = [ 40 | ":cargo_toml_env_vars", 41 | ], 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-bazel", 47 | "crate-name=log", 48 | "manual", 49 | "noclippy", 50 | "norustfmt", 51 | ], 52 | target_compatible_with = select({ 53 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 54 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 55 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 56 | "@rules_rust//rust/platform:aarch64-linux-android": [], 57 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 58 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 59 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 60 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 63 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 64 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 65 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 66 | "@rules_rust//rust/platform:i686-apple-darwin": [], 67 | "@rules_rust//rust/platform:i686-linux-android": [], 68 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 69 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 70 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 71 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 72 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 73 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 75 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 76 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 77 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 78 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 79 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 80 | "@rules_rust//rust/platform:wasm32-wasip1": [], 81 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 82 | "@rules_rust//rust/platform:wasm32-wasip2": [], 83 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 84 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 85 | "@rules_rust//rust/platform:x86_64-linux-android": [], 86 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 87 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 88 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 89 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 93 | "//conditions:default": ["@platforms//:incompatible"], 94 | }), 95 | version = "0.4.27", 96 | ) 97 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.foldhash-0.2.0.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "foldhash", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2021", 39 | rustc_env_files = [ 40 | ":cargo_toml_env_vars", 41 | ], 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-bazel", 47 | "crate-name=foldhash", 48 | "manual", 49 | "noclippy", 50 | "norustfmt", 51 | ], 52 | target_compatible_with = select({ 53 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 54 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 55 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 56 | "@rules_rust//rust/platform:aarch64-linux-android": [], 57 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 58 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 59 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 60 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 63 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 64 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 65 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 66 | "@rules_rust//rust/platform:i686-apple-darwin": [], 67 | "@rules_rust//rust/platform:i686-linux-android": [], 68 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 69 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 70 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 71 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 72 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 73 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 75 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 76 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 77 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 78 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 79 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 80 | "@rules_rust//rust/platform:wasm32-wasip1": [], 81 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 82 | "@rules_rust//rust/platform:wasm32-wasip2": [], 83 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 84 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 85 | "@rules_rust//rust/platform:x86_64-linux-android": [], 86 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 87 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 88 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 89 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 93 | "//conditions:default": ["@platforms//:incompatible"], 94 | }), 95 | version = "0.2.0", 96 | ) 97 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.equivalent-1.0.2.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "equivalent", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2015", 39 | rustc_env_files = [ 40 | ":cargo_toml_env_vars", 41 | ], 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-bazel", 47 | "crate-name=equivalent", 48 | "manual", 49 | "noclippy", 50 | "norustfmt", 51 | ], 52 | target_compatible_with = select({ 53 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 54 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 55 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 56 | "@rules_rust//rust/platform:aarch64-linux-android": [], 57 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 58 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 59 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 60 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 63 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 64 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 65 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 66 | "@rules_rust//rust/platform:i686-apple-darwin": [], 67 | "@rules_rust//rust/platform:i686-linux-android": [], 68 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 69 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 70 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 71 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 72 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 73 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 75 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 76 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 77 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 78 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 79 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 80 | "@rules_rust//rust/platform:wasm32-wasip1": [], 81 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 82 | "@rules_rust//rust/platform:wasm32-wasip2": [], 83 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 84 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 85 | "@rules_rust//rust/platform:x86_64-linux-android": [], 86 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 87 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 88 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 89 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 93 | "//conditions:default": ["@platforms//:incompatible"], 94 | }), 95 | version = "1.0.2", 96 | ) 97 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.unicode-ident-1.0.19.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "unicode_ident", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2018", 39 | rustc_env_files = [ 40 | ":cargo_toml_env_vars", 41 | ], 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-bazel", 47 | "crate-name=unicode-ident", 48 | "manual", 49 | "noclippy", 50 | "norustfmt", 51 | ], 52 | target_compatible_with = select({ 53 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 54 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 55 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 56 | "@rules_rust//rust/platform:aarch64-linux-android": [], 57 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 58 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 59 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 60 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 63 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 64 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 65 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 66 | "@rules_rust//rust/platform:i686-apple-darwin": [], 67 | "@rules_rust//rust/platform:i686-linux-android": [], 68 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 69 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 70 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 71 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 72 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 73 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 75 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 76 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 77 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 78 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 79 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 80 | "@rules_rust//rust/platform:wasm32-wasip1": [], 81 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 82 | "@rules_rust//rust/platform:wasm32-wasip2": [], 83 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 84 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 85 | "@rules_rust//rust/platform:x86_64-linux-android": [], 86 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 87 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 88 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 89 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 93 | "//conditions:default": ["@platforms//:incompatible"], 94 | }), 95 | version = "1.0.19", 96 | ) 97 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.allocator-api2-0.2.21.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "allocator_api2", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_features = [ 38 | "alloc", 39 | ], 40 | crate_root = "src/lib.rs", 41 | edition = "2018", 42 | rustc_env_files = [ 43 | ":cargo_toml_env_vars", 44 | ], 45 | rustc_flags = [ 46 | "--cap-lints=allow", 47 | ], 48 | tags = [ 49 | "cargo-bazel", 50 | "crate-name=allocator-api2", 51 | "manual", 52 | "noclippy", 53 | "norustfmt", 54 | ], 55 | target_compatible_with = select({ 56 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 57 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 58 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 59 | "@rules_rust//rust/platform:aarch64-linux-android": [], 60 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 63 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 64 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 65 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 66 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 67 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 68 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 69 | "@rules_rust//rust/platform:i686-apple-darwin": [], 70 | "@rules_rust//rust/platform:i686-linux-android": [], 71 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 72 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 73 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 75 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 76 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 77 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 78 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 79 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 80 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 81 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 82 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 83 | "@rules_rust//rust/platform:wasm32-wasip1": [], 84 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 85 | "@rules_rust//rust/platform:wasm32-wasip2": [], 86 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 87 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 88 | "@rules_rust//rust/platform:x86_64-linux-android": [], 89 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 93 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 94 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 95 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 96 | "//conditions:default": ["@platforms//:incompatible"], 97 | }), 98 | version = "0.2.21", 99 | ) 100 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.mockalloc-0.1.2.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "mockalloc", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2018", 39 | proc_macro_deps = [ 40 | "@crates_vendor__mockalloc-macros-0.1.0//:mockalloc_macros", 41 | ], 42 | rustc_env_files = [ 43 | ":cargo_toml_env_vars", 44 | ], 45 | rustc_flags = [ 46 | "--cap-lints=allow", 47 | ], 48 | tags = [ 49 | "cargo-bazel", 50 | "crate-name=mockalloc", 51 | "manual", 52 | "noclippy", 53 | "norustfmt", 54 | ], 55 | target_compatible_with = select({ 56 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 57 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 58 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 59 | "@rules_rust//rust/platform:aarch64-linux-android": [], 60 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 63 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 64 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 65 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 66 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 67 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 68 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 69 | "@rules_rust//rust/platform:i686-apple-darwin": [], 70 | "@rules_rust//rust/platform:i686-linux-android": [], 71 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 72 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 73 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 75 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 76 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 77 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 78 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 79 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 80 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 81 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 82 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 83 | "@rules_rust//rust/platform:wasm32-wasip1": [], 84 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 85 | "@rules_rust//rust/platform:wasm32-wasip2": [], 86 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 87 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 88 | "@rules_rust//rust/platform:x86_64-linux-android": [], 89 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 93 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 94 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 95 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 96 | "//conditions:default": ["@platforms//:incompatible"], 97 | }), 98 | version = "0.1.2", 99 | ) 100 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.mockalloc-macros-0.1.0.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_proc_macro") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_proc_macro( 20 | name = "mockalloc_macros", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_root = "src/lib.rs", 38 | edition = "2018", 39 | rustc_env_files = [ 40 | ":cargo_toml_env_vars", 41 | ], 42 | rustc_flags = [ 43 | "--cap-lints=allow", 44 | ], 45 | tags = [ 46 | "cargo-bazel", 47 | "crate-name=mockalloc-macros", 48 | "manual", 49 | "noclippy", 50 | "norustfmt", 51 | ], 52 | target_compatible_with = select({ 53 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 54 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 55 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 56 | "@rules_rust//rust/platform:aarch64-linux-android": [], 57 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 58 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 59 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 60 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 61 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 62 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 63 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 64 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 65 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 66 | "@rules_rust//rust/platform:i686-apple-darwin": [], 67 | "@rules_rust//rust/platform:i686-linux-android": [], 68 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 69 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 70 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 71 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 72 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 73 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 75 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 76 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 77 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 78 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 79 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 80 | "@rules_rust//rust/platform:wasm32-wasip1": [], 81 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 82 | "@rules_rust//rust/platform:wasm32-wasip2": [], 83 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 84 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 85 | "@rules_rust//rust/platform:x86_64-linux-android": [], 86 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 87 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 88 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 89 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 91 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 92 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 93 | "//conditions:default": ["@platforms//:incompatible"], 94 | }), 95 | version = "0.1.0", 96 | deps = [ 97 | "@crates_vendor__proc-macro2-1.0.101//:proc_macro2", 98 | "@crates_vendor__quote-1.0.41//:quote", 99 | "@crates_vendor__syn-1.0.109//:syn", 100 | ], 101 | ) 102 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.hashbrown-0.16.0.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load("@rules_rust//cargo:defs.bzl", "cargo_toml_env_vars") 10 | load("@rules_rust//rust:defs.bzl", "rust_library") 11 | 12 | package(default_visibility = ["//visibility:public"]) 13 | 14 | cargo_toml_env_vars( 15 | name = "cargo_toml_env_vars", 16 | src = "Cargo.toml", 17 | ) 18 | 19 | rust_library( 20 | name = "hashbrown", 21 | srcs = glob( 22 | include = ["**/*.rs"], 23 | allow_empty = True, 24 | ), 25 | compile_data = glob( 26 | include = ["**"], 27 | allow_empty = True, 28 | exclude = [ 29 | "**/* *", 30 | ".tmp_git_root/**/*", 31 | "BUILD", 32 | "BUILD.bazel", 33 | "WORKSPACE", 34 | "WORKSPACE.bazel", 35 | ], 36 | ), 37 | crate_features = [ 38 | "allocator-api2", 39 | "default", 40 | "default-hasher", 41 | "equivalent", 42 | "inline-more", 43 | "raw-entry", 44 | ], 45 | crate_root = "src/lib.rs", 46 | edition = "2021", 47 | rustc_env_files = [ 48 | ":cargo_toml_env_vars", 49 | ], 50 | rustc_flags = [ 51 | "--cap-lints=allow", 52 | ], 53 | tags = [ 54 | "cargo-bazel", 55 | "crate-name=hashbrown", 56 | "manual", 57 | "noclippy", 58 | "norustfmt", 59 | ], 60 | target_compatible_with = select({ 61 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 62 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 63 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 64 | "@rules_rust//rust/platform:aarch64-linux-android": [], 65 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 66 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 67 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 68 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 69 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 70 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 71 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 72 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 73 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 74 | "@rules_rust//rust/platform:i686-apple-darwin": [], 75 | "@rules_rust//rust/platform:i686-linux-android": [], 76 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 77 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 78 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 79 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 80 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 81 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 82 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 83 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 84 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 85 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 86 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 87 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 88 | "@rules_rust//rust/platform:wasm32-wasip1": [], 89 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 90 | "@rules_rust//rust/platform:wasm32-wasip2": [], 91 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 92 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 93 | "@rules_rust//rust/platform:x86_64-linux-android": [], 94 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 95 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 96 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 97 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 98 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 99 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 100 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 101 | "//conditions:default": ["@platforms//:incompatible"], 102 | }), 103 | version = "0.16.0", 104 | deps = [ 105 | "@crates_vendor__allocator-api2-0.2.21//:allocator_api2", 106 | "@crates_vendor__equivalent-1.0.2//:equivalent", 107 | "@crates_vendor__foldhash-0.2.0//:foldhash", 108 | ], 109 | ) 110 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). 6 | 7 | ## [0.2.4] - 2025-10-01 8 | 9 | ### Fixed 10 | 11 | - Fixed a memory leak in `get_map` and `get_map_bytes` hostcalls. 12 | This issue has been introduced in [0.2.3]. 13 | Thanks [@JaatadiaMulesoft](https://github.com/JaatadiaMulesoft)! 14 | 15 | ## [0.2.3] - 2025-06-04 16 | 17 | ### Changed 18 | 19 | - An empty value (`Some("")` or `Some([])`) is now returned when retrieving 20 | value of a HTTP header or trailer with an empty value. This is consistent 21 | with the representation when retrieving a full HTTP header or trailer map. 22 | Previously, a "no value" (`None`) was being returned, which made an empty 23 | value indistinguishable from a non-existent HTTP header or trailer. 24 | Thanks [@prembhaskal](https://github.com/prembhaskal)! 25 | 26 | ### Added 27 | 28 | - Added support for foreign function callbacks. 29 | Thanks [@casimiro](https://github.com/casimiro)! 30 | 31 | - Added convenience functions to remove headers and trailers. 32 | Thanks [@itsLucario](https://github.com/itsLucario)! 33 | 34 | - Added convenience function to remove shared data. 35 | 36 | ## [0.2.2] - 2024-07-21 37 | 38 | ### Fixed 39 | 40 | - Fixed support for nested gRPC callouts. 41 | Thanks [@andytesti](https://github.com/andytesti)! 42 | 43 | - Fixed panic on unknown `token_id` in `on_grpc_receive_initial_metadata` 44 | and `on_grpc_receive_trailing_metadata`. 45 | Thanks [@erikness-doordash](https://github.com/erikness-doordash)! 46 | 47 | - Fixed panic on unexpected failures in `get_property`. 48 | Thanks [@alexsnaps](https://github.com/alexsnaps)! 49 | 50 | - Fixed panic on unexpected failures in `call_foreign_function`. 51 | Reported by [@geNAZt](https://github.com/geNAZt). 52 | 53 | ### Added 54 | 55 | - Added support for sending error responses with gRPC status codes. 56 | Thanks [@juanmolle](https://github.com/juanmolle)! 57 | 58 | ## [0.2.1] - 2022-11-22 59 | 60 | ### Fixed 61 | 62 | - Fixed panic on unknown `token_id` in `on_grpc_close`. 63 | Thanks [@Protryon](https://github.com/Protryon)! 64 | 65 | ### Changed 66 | 67 | - Changed MSRV to v1.61.0. 68 | 69 | ### Removed 70 | 71 | - Removed `wee-alloc` feature, because that crate is no longer maintained 72 | and it leaks memory. 73 | 74 | ## [0.2.0] - 2022-04-08 75 | 76 | ### Fixed 77 | 78 | - Fixed performance degradation with `wasm32-wasi` target in Rust v1.56.0 79 | or newer by adding `proxy_wasm::main` macro that should be used instead 80 | of custom `_start`, `_initialize` and/or `main` exports. 81 | 82 | ### Changed 83 | 84 | - Updated ABI to Proxy-Wasm ABI v0.2.1. 85 | 86 | ### Added 87 | 88 | - Added support for calling foreign functions. 89 | Thanks [@Gsantomaggio](https://github.com/Gsantomaggio)! 90 | 91 | ## [0.1.4] - 2021-07-01 92 | 93 | ### Added 94 | 95 | - Added support for gRPC callouts. 96 | Thanks [@Shikugawa](https://github.com/Shikugawa)! 97 | 98 | ## [0.1.3] - 2020-12-04 99 | 100 | ### Fixed 101 | 102 | - Fixed support for nested HTTP callouts. 103 | Thanks [@SvetlinZarev](https://github.com/SvetlinZarev)! 104 | 105 | ### Changed 106 | 107 | - Changed `wee-alloc` to an optional feature. 108 | Thanks [@yuval-k](https://github.com/yuval-k)! 109 | 110 | ### Added 111 | 112 | - Added support for building for `wasm32-wasi` target. 113 | - Added support for metrics. 114 | - Added support for `RootContext` to create child contexts for streams. 115 | Thanks [@dgn](https://github.com/dgn)! 116 | - Added support for setting network buffers. 117 | 118 | ## [0.1.2] - 2020-08-05 119 | 120 | ### Changed 121 | 122 | - Updated `MapType` values to match updated Proxy-Wasm ABI v0.1.0. 123 | Thanks [@yskopets](https://github.com/yskopets)! 124 | 125 | ## [0.1.1] - 2020-08-05 126 | 127 | ### Added 128 | 129 | - Added support for building with Bazel. 130 | - Added support for setting HTTP bodies. 131 | Thanks [@gbrail](https://github.com/gbrail)! 132 | 133 | ## [0.1.0] - 2020-02-29 134 | 135 | ### Added 136 | 137 | - Initial release. 138 | 139 | 140 | [0.2.4]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.2.3...v0.2.4 141 | [0.2.3]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.2.2...v0.2.3 142 | [0.2.2]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.2.1...v0.2.2 143 | [0.2.1]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.2.0...v0.2.1 144 | [0.2.0]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.4...v0.2.0 145 | [0.1.4]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.3...v0.1.4 146 | [0.1.3]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.2...v0.1.3 147 | [0.1.2]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.1...v0.1.2 148 | [0.1.1]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.0...v0.1.1 149 | [0.1.0]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/releases/tag/v0.1.0 150 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.quote-1.0.41.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load( 10 | "@rules_rust//cargo:defs.bzl", 11 | "cargo_build_script", 12 | "cargo_toml_env_vars", 13 | ) 14 | load("@rules_rust//rust:defs.bzl", "rust_library") 15 | 16 | package(default_visibility = ["//visibility:public"]) 17 | 18 | cargo_toml_env_vars( 19 | name = "cargo_toml_env_vars", 20 | src = "Cargo.toml", 21 | ) 22 | 23 | rust_library( 24 | name = "quote", 25 | srcs = glob( 26 | include = ["**/*.rs"], 27 | allow_empty = True, 28 | ), 29 | compile_data = glob( 30 | include = ["**"], 31 | allow_empty = True, 32 | exclude = [ 33 | "**/* *", 34 | ".tmp_git_root/**/*", 35 | "BUILD", 36 | "BUILD.bazel", 37 | "WORKSPACE", 38 | "WORKSPACE.bazel", 39 | ], 40 | ), 41 | crate_features = [ 42 | "default", 43 | "proc-macro", 44 | ], 45 | crate_root = "src/lib.rs", 46 | edition = "2018", 47 | rustc_env_files = [ 48 | ":cargo_toml_env_vars", 49 | ], 50 | rustc_flags = [ 51 | "--cap-lints=allow", 52 | ], 53 | tags = [ 54 | "cargo-bazel", 55 | "crate-name=quote", 56 | "manual", 57 | "noclippy", 58 | "norustfmt", 59 | ], 60 | target_compatible_with = select({ 61 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 62 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 63 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 64 | "@rules_rust//rust/platform:aarch64-linux-android": [], 65 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 66 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 67 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 68 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 69 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 70 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 71 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 72 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 73 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 74 | "@rules_rust//rust/platform:i686-apple-darwin": [], 75 | "@rules_rust//rust/platform:i686-linux-android": [], 76 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 77 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 78 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 79 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 80 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 81 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 82 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 83 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 84 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 85 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 86 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 87 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 88 | "@rules_rust//rust/platform:wasm32-wasip1": [], 89 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 90 | "@rules_rust//rust/platform:wasm32-wasip2": [], 91 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 92 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 93 | "@rules_rust//rust/platform:x86_64-linux-android": [], 94 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 95 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 96 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 97 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 98 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 99 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 100 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 101 | "//conditions:default": ["@platforms//:incompatible"], 102 | }), 103 | version = "1.0.41", 104 | deps = [ 105 | "@crates_vendor__proc-macro2-1.0.101//:proc_macro2", 106 | "@crates_vendor__quote-1.0.41//:build_script_build", 107 | ], 108 | ) 109 | 110 | cargo_build_script( 111 | name = "_bs", 112 | srcs = glob( 113 | include = ["**/*.rs"], 114 | allow_empty = True, 115 | ), 116 | compile_data = glob( 117 | include = ["**"], 118 | allow_empty = True, 119 | exclude = [ 120 | "**/* *", 121 | "**/*.rs", 122 | ".tmp_git_root/**/*", 123 | "BUILD", 124 | "BUILD.bazel", 125 | "WORKSPACE", 126 | "WORKSPACE.bazel", 127 | ], 128 | ), 129 | crate_features = [ 130 | "default", 131 | "proc-macro", 132 | ], 133 | crate_name = "build_script_build", 134 | crate_root = "build.rs", 135 | data = glob( 136 | include = ["**"], 137 | allow_empty = True, 138 | exclude = [ 139 | "**/* *", 140 | ".tmp_git_root/**/*", 141 | "BUILD", 142 | "BUILD.bazel", 143 | "WORKSPACE", 144 | "WORKSPACE.bazel", 145 | ], 146 | ), 147 | edition = "2018", 148 | pkg_name = "quote", 149 | rustc_env_files = [ 150 | ":cargo_toml_env_vars", 151 | ], 152 | rustc_flags = [ 153 | "--cap-lints=allow", 154 | ], 155 | tags = [ 156 | "cargo-bazel", 157 | "crate-name=quote", 158 | "manual", 159 | "noclippy", 160 | "norustfmt", 161 | ], 162 | version = "1.0.41", 163 | visibility = ["//visibility:private"], 164 | ) 165 | 166 | alias( 167 | name = "build_script_build", 168 | actual = ":_bs", 169 | tags = ["manual"], 170 | ) 171 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.proc-macro2-1.0.101.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load( 10 | "@rules_rust//cargo:defs.bzl", 11 | "cargo_build_script", 12 | "cargo_toml_env_vars", 13 | ) 14 | load("@rules_rust//rust:defs.bzl", "rust_library") 15 | 16 | package(default_visibility = ["//visibility:public"]) 17 | 18 | cargo_toml_env_vars( 19 | name = "cargo_toml_env_vars", 20 | src = "Cargo.toml", 21 | ) 22 | 23 | rust_library( 24 | name = "proc_macro2", 25 | srcs = glob( 26 | include = ["**/*.rs"], 27 | allow_empty = True, 28 | ), 29 | compile_data = glob( 30 | include = ["**"], 31 | allow_empty = True, 32 | exclude = [ 33 | "**/* *", 34 | ".tmp_git_root/**/*", 35 | "BUILD", 36 | "BUILD.bazel", 37 | "WORKSPACE", 38 | "WORKSPACE.bazel", 39 | ], 40 | ), 41 | crate_features = [ 42 | "default", 43 | "proc-macro", 44 | ], 45 | crate_root = "src/lib.rs", 46 | edition = "2021", 47 | rustc_env_files = [ 48 | ":cargo_toml_env_vars", 49 | ], 50 | rustc_flags = [ 51 | "--cap-lints=allow", 52 | ], 53 | tags = [ 54 | "cargo-bazel", 55 | "crate-name=proc-macro2", 56 | "manual", 57 | "noclippy", 58 | "norustfmt", 59 | ], 60 | target_compatible_with = select({ 61 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 62 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 63 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 64 | "@rules_rust//rust/platform:aarch64-linux-android": [], 65 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 66 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 67 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 68 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 69 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 70 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 71 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 72 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 73 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 74 | "@rules_rust//rust/platform:i686-apple-darwin": [], 75 | "@rules_rust//rust/platform:i686-linux-android": [], 76 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 77 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 78 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 79 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 80 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 81 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 82 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 83 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 84 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 85 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 86 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 87 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 88 | "@rules_rust//rust/platform:wasm32-wasip1": [], 89 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 90 | "@rules_rust//rust/platform:wasm32-wasip2": [], 91 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 92 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 93 | "@rules_rust//rust/platform:x86_64-linux-android": [], 94 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 95 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 96 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 97 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 98 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 99 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 100 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 101 | "//conditions:default": ["@platforms//:incompatible"], 102 | }), 103 | version = "1.0.101", 104 | deps = [ 105 | "@crates_vendor__proc-macro2-1.0.101//:build_script_build", 106 | "@crates_vendor__unicode-ident-1.0.19//:unicode_ident", 107 | ], 108 | ) 109 | 110 | cargo_build_script( 111 | name = "_bs", 112 | srcs = glob( 113 | include = ["**/*.rs"], 114 | allow_empty = True, 115 | ), 116 | compile_data = glob( 117 | include = ["**"], 118 | allow_empty = True, 119 | exclude = [ 120 | "**/* *", 121 | "**/*.rs", 122 | ".tmp_git_root/**/*", 123 | "BUILD", 124 | "BUILD.bazel", 125 | "WORKSPACE", 126 | "WORKSPACE.bazel", 127 | ], 128 | ), 129 | crate_features = [ 130 | "default", 131 | "proc-macro", 132 | ], 133 | crate_name = "build_script_build", 134 | crate_root = "build.rs", 135 | data = glob( 136 | include = ["**"], 137 | allow_empty = True, 138 | exclude = [ 139 | "**/* *", 140 | ".tmp_git_root/**/*", 141 | "BUILD", 142 | "BUILD.bazel", 143 | "WORKSPACE", 144 | "WORKSPACE.bazel", 145 | ], 146 | ), 147 | edition = "2021", 148 | pkg_name = "proc-macro2", 149 | rustc_env_files = [ 150 | ":cargo_toml_env_vars", 151 | ], 152 | rustc_flags = [ 153 | "--cap-lints=allow", 154 | ], 155 | tags = [ 156 | "cargo-bazel", 157 | "crate-name=proc-macro2", 158 | "manual", 159 | "noclippy", 160 | "norustfmt", 161 | ], 162 | version = "1.0.101", 163 | visibility = ["//visibility:private"], 164 | ) 165 | 166 | alias( 167 | name = "build_script_build", 168 | actual = ":_bs", 169 | tags = ["manual"], 170 | ) 171 | -------------------------------------------------------------------------------- /bazel/cargo/remote/BUILD.syn-1.0.109.bazel: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | 9 | load( 10 | "@rules_rust//cargo:defs.bzl", 11 | "cargo_build_script", 12 | "cargo_toml_env_vars", 13 | ) 14 | load("@rules_rust//rust:defs.bzl", "rust_library") 15 | 16 | package(default_visibility = ["//visibility:public"]) 17 | 18 | cargo_toml_env_vars( 19 | name = "cargo_toml_env_vars", 20 | src = "Cargo.toml", 21 | ) 22 | 23 | rust_library( 24 | name = "syn", 25 | srcs = glob( 26 | include = ["**/*.rs"], 27 | allow_empty = True, 28 | ), 29 | compile_data = glob( 30 | include = ["**"], 31 | allow_empty = True, 32 | exclude = [ 33 | "**/* *", 34 | ".tmp_git_root/**/*", 35 | "BUILD", 36 | "BUILD.bazel", 37 | "WORKSPACE", 38 | "WORKSPACE.bazel", 39 | ], 40 | ), 41 | crate_features = [ 42 | "clone-impls", 43 | "default", 44 | "derive", 45 | "full", 46 | "parsing", 47 | "printing", 48 | "proc-macro", 49 | "quote", 50 | ], 51 | crate_root = "src/lib.rs", 52 | edition = "2018", 53 | rustc_env_files = [ 54 | ":cargo_toml_env_vars", 55 | ], 56 | rustc_flags = [ 57 | "--cap-lints=allow", 58 | ], 59 | tags = [ 60 | "cargo-bazel", 61 | "crate-name=syn", 62 | "manual", 63 | "noclippy", 64 | "norustfmt", 65 | ], 66 | target_compatible_with = select({ 67 | "@rules_rust//rust/platform:aarch64-apple-darwin": [], 68 | "@rules_rust//rust/platform:aarch64-apple-ios": [], 69 | "@rules_rust//rust/platform:aarch64-apple-ios-sim": [], 70 | "@rules_rust//rust/platform:aarch64-linux-android": [], 71 | "@rules_rust//rust/platform:aarch64-pc-windows-msvc": [], 72 | "@rules_rust//rust/platform:aarch64-unknown-fuchsia": [], 73 | "@rules_rust//rust/platform:aarch64-unknown-linux-gnu": [], 74 | "@rules_rust//rust/platform:aarch64-unknown-nixos-gnu": [], 75 | "@rules_rust//rust/platform:aarch64-unknown-nto-qnx710": [], 76 | "@rules_rust//rust/platform:aarch64-unknown-uefi": [], 77 | "@rules_rust//rust/platform:arm-unknown-linux-gnueabi": [], 78 | "@rules_rust//rust/platform:armv7-linux-androideabi": [], 79 | "@rules_rust//rust/platform:armv7-unknown-linux-gnueabi": [], 80 | "@rules_rust//rust/platform:i686-apple-darwin": [], 81 | "@rules_rust//rust/platform:i686-linux-android": [], 82 | "@rules_rust//rust/platform:i686-pc-windows-msvc": [], 83 | "@rules_rust//rust/platform:i686-unknown-freebsd": [], 84 | "@rules_rust//rust/platform:i686-unknown-linux-gnu": [], 85 | "@rules_rust//rust/platform:powerpc-unknown-linux-gnu": [], 86 | "@rules_rust//rust/platform:riscv32imc-unknown-none-elf": [], 87 | "@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu": [], 88 | "@rules_rust//rust/platform:riscv64gc-unknown-none-elf": [], 89 | "@rules_rust//rust/platform:s390x-unknown-linux-gnu": [], 90 | "@rules_rust//rust/platform:thumbv7em-none-eabi": [], 91 | "@rules_rust//rust/platform:thumbv8m.main-none-eabi": [], 92 | "@rules_rust//rust/platform:wasm32-unknown-emscripten": [], 93 | "@rules_rust//rust/platform:wasm32-unknown-unknown": [], 94 | "@rules_rust//rust/platform:wasm32-wasip1": [], 95 | "@rules_rust//rust/platform:wasm32-wasip1-threads": [], 96 | "@rules_rust//rust/platform:wasm32-wasip2": [], 97 | "@rules_rust//rust/platform:x86_64-apple-darwin": [], 98 | "@rules_rust//rust/platform:x86_64-apple-ios": [], 99 | "@rules_rust//rust/platform:x86_64-linux-android": [], 100 | "@rules_rust//rust/platform:x86_64-pc-windows-msvc": [], 101 | "@rules_rust//rust/platform:x86_64-unknown-freebsd": [], 102 | "@rules_rust//rust/platform:x86_64-unknown-fuchsia": [], 103 | "@rules_rust//rust/platform:x86_64-unknown-linux-gnu": [], 104 | "@rules_rust//rust/platform:x86_64-unknown-nixos-gnu": [], 105 | "@rules_rust//rust/platform:x86_64-unknown-none": [], 106 | "@rules_rust//rust/platform:x86_64-unknown-uefi": [], 107 | "//conditions:default": ["@platforms//:incompatible"], 108 | }), 109 | version = "1.0.109", 110 | deps = [ 111 | "@crates_vendor__proc-macro2-1.0.101//:proc_macro2", 112 | "@crates_vendor__quote-1.0.41//:quote", 113 | "@crates_vendor__syn-1.0.109//:build_script_build", 114 | "@crates_vendor__unicode-ident-1.0.19//:unicode_ident", 115 | ], 116 | ) 117 | 118 | cargo_build_script( 119 | name = "_bs", 120 | srcs = glob( 121 | include = ["**/*.rs"], 122 | allow_empty = True, 123 | ), 124 | compile_data = glob( 125 | include = ["**"], 126 | allow_empty = True, 127 | exclude = [ 128 | "**/* *", 129 | "**/*.rs", 130 | ".tmp_git_root/**/*", 131 | "BUILD", 132 | "BUILD.bazel", 133 | "WORKSPACE", 134 | "WORKSPACE.bazel", 135 | ], 136 | ), 137 | crate_features = [ 138 | "clone-impls", 139 | "default", 140 | "derive", 141 | "full", 142 | "parsing", 143 | "printing", 144 | "proc-macro", 145 | "quote", 146 | ], 147 | crate_name = "build_script_build", 148 | crate_root = "build.rs", 149 | data = glob( 150 | include = ["**"], 151 | allow_empty = True, 152 | exclude = [ 153 | "**/* *", 154 | ".tmp_git_root/**/*", 155 | "BUILD", 156 | "BUILD.bazel", 157 | "WORKSPACE", 158 | "WORKSPACE.bazel", 159 | ], 160 | ), 161 | edition = "2018", 162 | pkg_name = "syn", 163 | rustc_env_files = [ 164 | ":cargo_toml_env_vars", 165 | ], 166 | rustc_flags = [ 167 | "--cap-lints=allow", 168 | ], 169 | tags = [ 170 | "cargo-bazel", 171 | "crate-name=syn", 172 | "manual", 173 | "noclippy", 174 | "norustfmt", 175 | ], 176 | version = "1.0.109", 177 | visibility = ["//visibility:private"], 178 | ) 179 | 180 | alias( 181 | name = "build_script_build", 182 | actual = ":_bs", 183 | tags = ["manual"], 184 | ) 185 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | name: Rust 16 | 17 | on: 18 | 19 | pull_request: 20 | branches: 21 | - main 22 | 23 | push: 24 | branches: 25 | - main 26 | 27 | schedule: 28 | - cron: '0 0 * * *' 29 | 30 | jobs: 31 | 32 | licenses: 33 | runs-on: ubuntu-24.04 34 | 35 | steps: 36 | - uses: actions/checkout@v4 37 | - uses: actions/setup-go@v5 38 | with: 39 | go-version: '^1.16' 40 | 41 | - name: Cache 42 | if: ${{ env.ACT }} 43 | uses: actions/cache@v4 44 | with: 45 | path: | 46 | ~/go/pkg/mod 47 | key: licenses-${{ hashFiles('.github/workflows/rust.yml') }} 48 | 49 | - name: Install dependencies 50 | run: | 51 | go install github.com/google/addlicense@v1.1.1 52 | export PATH=$PATH:$(go env GOPATH)/bin 53 | 54 | - name: Check licenses 55 | run: | 56 | addlicense -check -ignore "bazel/cargo/remote/**" . 57 | 58 | bazel: 59 | runs-on: ubuntu-24.04 60 | 61 | steps: 62 | - uses: actions/checkout@v4 63 | - uses: actions/setup-go@v5 64 | with: 65 | go-version: '^1.16' 66 | 67 | - name: Cache 68 | uses: actions/cache@v4 69 | with: 70 | path: | 71 | ~/.cache/bazel 72 | ~/.cache/bazelisk 73 | ~/.cargo/.crates.toml 74 | ~/.cargo/.crates2.json 75 | ~/.cargo/advisory-db 76 | ~/.cargo/bin 77 | ~/.cargo/registry 78 | ~/go/pkg/mod 79 | key: bazel-${{ hashFiles('.github/workflows/rust.yml', 'BUILD', 'WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.Bazel.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }} 80 | 81 | - name: Install dependencies 82 | run: | 83 | go install github.com/bazelbuild/bazelisk@v1.25.0 84 | go install github.com/bazelbuild/buildtools/buildifier@v0.0.0-20241212155839-a9c248f4b684 85 | export PATH=$PATH:$(go env GOPATH)/bin 86 | 87 | - name: Build (wasm32-unknown-unknown) 88 | run: bazelisk --noworkspace_rc build --noenable_bzlmod --platforms=@rules_rust//rust/platform:wasm //... 89 | 90 | - name: Build (wasm32-unknown-unknown/bzlmod) 91 | run: bazelisk --noworkspace_rc build --enable_bzlmod --platforms=@rules_rust//rust/platform:wasm //... 92 | 93 | - name: Build (wasm32-wasip1) 94 | run: bazelisk --noworkspace_rc build --noenable_bzlmod --platforms=@rules_rust//rust/platform:wasi //... 95 | 96 | - name: Build (wasm32-wasip1/bzlmod) 97 | run: bazelisk --noworkspace_rc build --enable_bzlmod --platforms=@rules_rust//rust/platform:wasi //... 98 | 99 | - name: Format (buildifier) 100 | run: | 101 | buildifier -mode=check -r . 102 | 103 | - name: Format (rules_rust) 104 | run: | 105 | bazelisk --noworkspace_rc run --noenable_bzlmod //bazel/cargo:crates_vendor 106 | git diff --exit-code 107 | 108 | - name: Format (MODULE.bazel.lock) 109 | run: bazelisk mod deps --lockfile_mode=error 110 | 111 | msrv: 112 | runs-on: ubuntu-24.04 113 | 114 | env: 115 | RUSTFLAGS: -D warnings 116 | 117 | steps: 118 | - uses: actions/checkout@v4 119 | 120 | - name: Cache 121 | if: ${{ env.ACT }} 122 | uses: actions/cache@v4 123 | with: 124 | path: | 125 | ~/.cargo/.crates.toml 126 | ~/.cargo/.crates2.json 127 | ~/.cargo/advisory-db 128 | ~/.cargo/bin 129 | ~/.cargo/registry 130 | ~/.rustup 131 | **/target 132 | key: msrv-${{ hashFiles('Cargo.toml') }} 133 | 134 | - name: Install Rustup 135 | if: ${{ env.ACT }} 136 | run: | 137 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 138 | chmod +x ./rustup-init.sh 139 | ./rustup-init.sh -y --default-toolchain 1.68.0 140 | rm rustup-init.sh 141 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 142 | 143 | - name: Update Rust 144 | run: | 145 | rustup toolchain install 1.68.0 --component clippy --component rustfmt 146 | rustup default 1.68.0 147 | rustup target add wasm32-unknown-unknown 148 | rustup target add wasm32-wasi 149 | 150 | - name: Build (wasm32-unknown-unknown) 151 | run: cargo build --release --all-targets --target=wasm32-unknown-unknown 152 | 153 | - name: Clippy (wasm32-unknown-unknown) 154 | run: cargo clippy --release --all-targets --target=wasm32-unknown-unknown 155 | 156 | - name: Build (wasm32-wasi) 157 | run: cargo build --release --all-targets --target=wasm32-wasi 158 | 159 | - name: Clippy (wasm32-wasi) 160 | run: cargo clippy --release --all-targets --target=wasm32-wasi 161 | 162 | - name: Test 163 | run: cargo test 164 | 165 | - name: Format (rustfmt) 166 | run: cargo fmt -- --check 167 | 168 | - name: Format (manifest) 169 | run: cargo verify-project 170 | 171 | - name: Package (docs) 172 | run: cargo doc --no-deps --target=wasm32-unknown-unknown 173 | 174 | - name: Package (publish) 175 | run: cargo publish --dry-run --target=wasm32-unknown-unknown 176 | 177 | stable: 178 | runs-on: ubuntu-24.04 179 | 180 | env: 181 | RUSTFLAGS: -D warnings 182 | 183 | steps: 184 | - uses: actions/checkout@v4 185 | 186 | - name: Cache 187 | if: ${{ env.ACT }} 188 | uses: actions/cache@v4 189 | with: 190 | path: | 191 | ~/.cargo/.crates.toml 192 | ~/.cargo/.crates2.json 193 | ~/.cargo/advisory-db 194 | ~/.cargo/bin 195 | ~/.cargo/registry 196 | ~/.rustup 197 | **/target 198 | key: stable-${{ hashFiles('Cargo.toml') }} 199 | 200 | - name: Install Rustup 201 | if: ${{ env.ACT }} 202 | run: | 203 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 204 | chmod +x ./rustup-init.sh 205 | ./rustup-init.sh -y --default-toolchain stable 206 | rm rustup-init.sh 207 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 208 | 209 | - name: Update Rust 210 | run: | 211 | rustup toolchain install stable --component clippy --component rustfmt 212 | rustup target add wasm32-unknown-unknown 213 | rustup target add wasm32-wasip1 214 | 215 | - name: Build (wasm32-unknown-unknown) 216 | run: cargo build --release --all-targets --target=wasm32-unknown-unknown 217 | 218 | - name: Clippy (wasm32-unknown-unknown) 219 | run: cargo clippy --release --all-targets --target=wasm32-unknown-unknown 220 | 221 | - name: Build (wasm32-wasip1) 222 | run: cargo build --release --all-targets --target=wasm32-wasip1 223 | 224 | - name: Clippy (wasm32-wasip1) 225 | run: cargo clippy --release --all-targets --target=wasm32-wasip1 226 | 227 | - name: Test 228 | run: cargo test 229 | 230 | - name: Format (rustfmt) 231 | run: cargo fmt -- --check 232 | 233 | - name: Format (manifest) 234 | run: cargo verify-project 235 | 236 | - name: Package (docs) 237 | run: cargo doc --no-deps --target=wasm32-unknown-unknown 238 | 239 | - name: Package (publish) 240 | run: cargo publish --dry-run --target=wasm32-unknown-unknown 241 | 242 | nightly: 243 | runs-on: ubuntu-24.04 244 | 245 | env: 246 | RUSTFLAGS: -D warnings 247 | 248 | steps: 249 | - uses: actions/checkout@v4 250 | 251 | - name: Cache 252 | if: ${{ env.ACT }} 253 | uses: actions/cache@v4 254 | with: 255 | path: | 256 | ~/.cargo/.crates.toml 257 | ~/.cargo/.crates2.json 258 | ~/.cargo/advisory-db 259 | ~/.cargo/bin 260 | ~/.cargo/registry 261 | ~/.rustup 262 | **/target 263 | key: nightly-${{ hashFiles('Cargo.toml') }} 264 | 265 | - name: Install Rustup 266 | if: ${{ env.ACT }} 267 | run: | 268 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 269 | chmod +x ./rustup-init.sh 270 | ./rustup-init.sh -y --default-toolchain nightly 271 | rm rustup-init.sh 272 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 273 | 274 | - name: Update Rust 275 | run: | 276 | rustup toolchain install nightly --component clippy --component rustfmt 277 | rustup default nightly 278 | rustup target add wasm32-unknown-unknown 279 | rustup target add wasm32-wasip1 280 | 281 | - name: Build (wasm32-unknown-unknown) 282 | run: cargo build --release --all-targets --target=wasm32-unknown-unknown 283 | 284 | - name: Clippy (wasm32-unknown-unknown) 285 | run: cargo clippy --release --all-targets --target=wasm32-unknown-unknown 286 | 287 | - name: Build (wasm32-wasip1) 288 | run: cargo build --release --all-targets --target=wasm32-wasip1 289 | 290 | - name: Clippy (wasm32-wasip1) 291 | run: cargo clippy --release --all-targets --target=wasm32-wasip1 292 | 293 | - name: Test 294 | run: cargo test 295 | 296 | - name: Bench 297 | run: cargo bench 298 | 299 | - name: Format (rustfmt) 300 | run: cargo fmt -- --check 301 | 302 | - name: Format (manifest) 303 | run: cargo verify-project 304 | 305 | - name: Package (docs) 306 | run: cargo doc --no-deps --target=wasm32-unknown-unknown 307 | 308 | - name: Package (publish) 309 | run: cargo publish --dry-run --target=wasm32-unknown-unknown 310 | 311 | outdated: 312 | runs-on: ubuntu-24.04 313 | 314 | steps: 315 | - uses: actions/checkout@v4 316 | 317 | - name: Cache 318 | uses: actions/cache@v4 319 | with: 320 | path: | 321 | ~/.cargo/.crates.toml 322 | ~/.cargo/.crates2.json 323 | ~/.cargo/advisory-db 324 | ~/.cargo/bin 325 | ~/.cargo/registry 326 | ~/.rustup 327 | key: outdated-${{ hashFiles('.github/workflows/rust.yml', 'Cargo.toml') }} 328 | 329 | - name: Install Rustup 330 | if: ${{ env.ACT }} 331 | run: | 332 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 333 | chmod +x ./rustup-init.sh 334 | ./rustup-init.sh -y 335 | rm rustup-init.sh 336 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 337 | 338 | - name: Install dependencies 339 | run: | 340 | cargo install cargo-outdated --version 0.17.0 341 | 342 | - name: Run cargo outdated (main) 343 | run: | 344 | cargo outdated --root-deps-only --exit-code 1 345 | 346 | - name: Run cargo outdated (examples) 347 | run: | 348 | for example in $(find examples -name Cargo.toml); do \ 349 | cd $(dirname $GITHUB_WORKSPACE/$example); \ 350 | cargo outdated --root-deps-only --exit-code 1; \ 351 | done 352 | 353 | audit: 354 | runs-on: ubuntu-24.04 355 | 356 | steps: 357 | - uses: actions/checkout@v4 358 | 359 | - name: Cache 360 | uses: actions/cache@v4 361 | with: 362 | path: | 363 | ~/.cargo/.crates.toml 364 | ~/.cargo/.crates2.json 365 | ~/.cargo/advisory-db 366 | ~/.cargo/bin 367 | ~/.cargo/registry 368 | ~/.rustup 369 | key: audit-${{ hashFiles('.github/workflows/rust.yml', 'Cargo.toml') }} 370 | 371 | - name: Install Rustup 372 | if: ${{ env.ACT }} 373 | run: | 374 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 375 | chmod +x ./rustup-init.sh 376 | ./rustup-init.sh -y 377 | rm rustup-init.sh 378 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 379 | 380 | - name: Install dependencies 381 | run: | 382 | cargo install cargo-audit --version 0.22.0 383 | 384 | - name: Run cargo audit (main) 385 | run: | 386 | cp -p bazel/cargo/Cargo.Bazel.lock Cargo.lock 387 | cargo audit 388 | 389 | - name: Run cargo audit (examples) 390 | run: | 391 | for example in $(find examples -name Cargo.toml); do \ 392 | cd $(dirname $GITHUB_WORKSPACE/$example); \ 393 | cargo audit; \ 394 | done 395 | 396 | examples: 397 | runs-on: ubuntu-24.04 398 | 399 | strategy: 400 | matrix: 401 | example: 402 | - 'hello_world' 403 | - 'http_auth_random' 404 | - 'http_body' 405 | - 'http_config' 406 | - 'http_headers' 407 | - 'grpc_auth_random' 408 | - 'envoy_filter_metadata' 409 | 410 | defaults: 411 | run: 412 | working-directory: ./examples/${{ matrix.example }} 413 | 414 | env: 415 | RUSTFLAGS: -D warnings 416 | 417 | steps: 418 | - uses: actions/checkout@v4 419 | 420 | - name: Cache 421 | if: ${{ env.ACT }} 422 | uses: actions/cache@v4 423 | with: 424 | path: | 425 | ~/.cargo/.crates.toml 426 | ~/.cargo/.crates2.json 427 | ~/.cargo/advisory-db 428 | ~/.cargo/bin 429 | ~/.cargo/registry 430 | ~/.rustup 431 | **/target 432 | key: example-${{ matrix.example }}-${{ hashFiles('Cargo.toml') }} 433 | 434 | - name: Install Rustup 435 | if: ${{ env.ACT }} 436 | run: | 437 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 438 | chmod +x ./rustup-init.sh 439 | ./rustup-init.sh -y 440 | rm rustup-init.sh 441 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 442 | 443 | - name: Update Rust 444 | run: | 445 | rustup toolchain install stable --component clippy --component rustfmt 446 | rustup target add wasm32-wasip1 447 | 448 | - name: Build (wasm32-wasip1) 449 | run: cargo build --release --target=wasm32-wasip1 450 | 451 | - name: Clippy (wasm32-wasip1) 452 | run: cargo clippy --release --target=wasm32-wasip1 453 | 454 | - name: Format (rustfmt) 455 | run: cargo fmt -- --check 456 | 457 | - name: Format (manifest) 458 | run: cargo verify-project 459 | 460 | - name: Validate Envoy config 461 | run: | 462 | docker run --rm \ 463 | -v $(pwd)/envoy.yaml:/envoy.yaml \ 464 | -v $(pwd)/target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins \ 465 | envoyproxy/envoy:v1.34-latest \ 466 | --mode validate \ 467 | -c envoy.yaml 468 | 469 | reactors: 470 | runs-on: ubuntu-24.04 471 | 472 | strategy: 473 | matrix: 474 | example: 475 | - 'hello_world' 476 | - 'http_auth_random' 477 | - 'http_body' 478 | - 'http_config' 479 | - 'http_headers' 480 | - 'grpc_auth_random' 481 | - 'envoy_filter_metadata' 482 | 483 | defaults: 484 | run: 485 | working-directory: ./examples/${{ matrix.example }} 486 | 487 | env: 488 | RUSTFLAGS: -D warnings -Z wasi-exec-model=reactor 489 | 490 | steps: 491 | - uses: actions/checkout@v4 492 | 493 | - name: Cache 494 | if: ${{ env.ACT }} 495 | uses: actions/cache@v4 496 | with: 497 | path: | 498 | ~/.cargo/.crates.toml 499 | ~/.cargo/.crates2.json 500 | ~/.cargo/advisory-db 501 | ~/.cargo/bin 502 | ~/.cargo/registry 503 | ~/.rustup 504 | **/target 505 | key: reactor-${{ matrix.example }}-${{ hashFiles('Cargo.toml') }} 506 | 507 | - name: Install Rustup 508 | if: ${{ env.ACT }} 509 | run: | 510 | curl -OL https://static.rust-lang.org/rustup/rustup-init.sh 511 | chmod +x ./rustup-init.sh 512 | ./rustup-init.sh -y --default-toolchain nightly 513 | rm rustup-init.sh 514 | echo "$HOME/.cargo/bin" >> $GITHUB_PATH 515 | 516 | - name: Update Rust 517 | run: | 518 | rustup toolchain install nightly --component clippy --component rustfmt 519 | rustup default nightly 520 | rustup target add wasm32-wasip1 521 | 522 | - name: Change crate type from library to binary 523 | run: | 524 | grep -v '^\[lib\]' Cargo.toml > Cargo.tmp 525 | grep -v '^crate-type' Cargo.tmp > Cargo.toml 526 | mv src/lib.rs src/main.rs 527 | 528 | - name: Build (wasm32-wasip1) 529 | run: cargo build --release --target=wasm32-wasip1 530 | 531 | - name: Clippy (wasm32-wasip1) 532 | run: cargo clippy --release --target=wasm32-wasip1 533 | 534 | - name: Format (rustfmt) 535 | run: cargo fmt -- --check 536 | 537 | - name: Format (manifest) 538 | run: cargo verify-project 539 | 540 | - name: Rename .wasm to match expected filename 541 | run: | 542 | cd target/wasm32-wasip1/release 543 | for file in $(ls -1 *.wasm); do \ 544 | mv $file $(echo $file | sed 's/-/_/g'); \ 545 | done 546 | 547 | - name: Validate Envoy config 548 | run: | 549 | docker run --rm \ 550 | -v $(pwd)/envoy.yaml:/envoy.yaml \ 551 | -v $(pwd)/target/wasm32-wasip1/release:/etc/envoy/proxy-wasm-plugins \ 552 | envoyproxy/envoy:v1.34-latest \ 553 | --mode validate \ 554 | -c envoy.yaml 555 | -------------------------------------------------------------------------------- /src/traits.rs: -------------------------------------------------------------------------------- 1 | // Copyright 2020 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | use crate::hostcalls; 16 | use crate::types::*; 17 | use std::time::{Duration, SystemTime}; 18 | 19 | pub trait Context { 20 | fn get_current_time(&self) -> SystemTime { 21 | hostcalls::get_current_time().unwrap() 22 | } 23 | 24 | fn get_property(&self, path: Vec<&str>) -> Option { 25 | hostcalls::get_property(path).unwrap() 26 | } 27 | 28 | fn set_property(&self, path: Vec<&str>, value: Option<&[u8]>) { 29 | hostcalls::set_property(path, value).unwrap() 30 | } 31 | 32 | fn get_shared_data(&self, key: &str) -> (Option, Option) { 33 | hostcalls::get_shared_data(key).unwrap() 34 | } 35 | 36 | fn set_shared_data( 37 | &self, 38 | key: &str, 39 | value: Option<&[u8]>, 40 | cas: Option, 41 | ) -> Result<(), Status> { 42 | hostcalls::set_shared_data(key, value, cas) 43 | } 44 | 45 | fn remove_shared_data(&self, key: &str, cas: Option) -> Result<(), Status> { 46 | hostcalls::set_shared_data(key, None, cas) 47 | } 48 | 49 | fn register_shared_queue(&self, name: &str) -> u32 { 50 | hostcalls::register_shared_queue(name).unwrap() 51 | } 52 | 53 | fn resolve_shared_queue(&self, vm_id: &str, name: &str) -> Option { 54 | hostcalls::resolve_shared_queue(vm_id, name).unwrap() 55 | } 56 | 57 | fn dequeue_shared_queue(&self, queue_id: u32) -> Result, Status> { 58 | hostcalls::dequeue_shared_queue(queue_id) 59 | } 60 | 61 | fn enqueue_shared_queue(&self, queue_id: u32, value: Option<&[u8]>) -> Result<(), Status> { 62 | hostcalls::enqueue_shared_queue(queue_id, value) 63 | } 64 | 65 | fn dispatch_http_call( 66 | &self, 67 | upstream: &str, 68 | headers: Vec<(&str, &str)>, 69 | body: Option<&[u8]>, 70 | trailers: Vec<(&str, &str)>, 71 | timeout: Duration, 72 | ) -> Result { 73 | hostcalls::dispatch_http_call(upstream, headers, body, trailers, timeout) 74 | } 75 | 76 | fn on_http_call_response( 77 | &mut self, 78 | _token_id: u32, 79 | _num_headers: usize, 80 | _body_size: usize, 81 | _num_trailers: usize, 82 | ) { 83 | } 84 | 85 | fn get_http_call_response_headers(&self) -> Vec<(String, String)> { 86 | hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap() 87 | } 88 | 89 | fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Bytes)> { 90 | hostcalls::get_map_bytes(MapType::HttpCallResponseHeaders).unwrap() 91 | } 92 | 93 | fn get_http_call_response_header(&self, name: &str) -> Option { 94 | hostcalls::get_map_value(MapType::HttpCallResponseHeaders, name).unwrap() 95 | } 96 | 97 | fn get_http_call_response_header_bytes(&self, name: &str) -> Option { 98 | hostcalls::get_map_value_bytes(MapType::HttpCallResponseHeaders, name).unwrap() 99 | } 100 | 101 | fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option { 102 | hostcalls::get_buffer(BufferType::HttpCallResponseBody, start, max_size).unwrap() 103 | } 104 | 105 | fn get_http_call_response_trailers(&self) -> Vec<(String, String)> { 106 | hostcalls::get_map(MapType::HttpCallResponseTrailers).unwrap() 107 | } 108 | 109 | fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { 110 | hostcalls::get_map_bytes(MapType::HttpCallResponseTrailers).unwrap() 111 | } 112 | 113 | fn get_http_call_response_trailer(&self, name: &str) -> Option { 114 | hostcalls::get_map_value(MapType::HttpCallResponseTrailers, name).unwrap() 115 | } 116 | 117 | fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option { 118 | hostcalls::get_map_value_bytes(MapType::HttpCallResponseTrailers, name).unwrap() 119 | } 120 | 121 | fn dispatch_grpc_call( 122 | &self, 123 | upstream_name: &str, 124 | service_name: &str, 125 | method_name: &str, 126 | initial_metadata: Vec<(&str, &[u8])>, 127 | message: Option<&[u8]>, 128 | timeout: Duration, 129 | ) -> Result { 130 | hostcalls::dispatch_grpc_call( 131 | upstream_name, 132 | service_name, 133 | method_name, 134 | initial_metadata, 135 | message, 136 | timeout, 137 | ) 138 | } 139 | 140 | fn on_grpc_call_response(&mut self, _token_id: u32, _status_code: u32, _response_size: usize) {} 141 | 142 | fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option { 143 | hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() 144 | } 145 | 146 | fn cancel_grpc_call(&self, token_id: u32) { 147 | hostcalls::cancel_grpc_call(token_id).unwrap() 148 | } 149 | 150 | fn open_grpc_stream( 151 | &self, 152 | cluster_name: &str, 153 | service_name: &str, 154 | method_name: &str, 155 | initial_metadata: Vec<(&str, &[u8])>, 156 | ) -> Result { 157 | hostcalls::open_grpc_stream(cluster_name, service_name, method_name, initial_metadata) 158 | } 159 | 160 | fn on_grpc_stream_initial_metadata(&mut self, _token_id: u32, _num_elements: u32) {} 161 | 162 | fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Bytes)> { 163 | hostcalls::get_map_bytes(MapType::GrpcReceiveInitialMetadata).unwrap() 164 | } 165 | 166 | fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option { 167 | hostcalls::get_map_value_bytes(MapType::GrpcReceiveInitialMetadata, name).unwrap() 168 | } 169 | 170 | fn send_grpc_stream_message(&self, token_id: u32, message: Option<&[u8]>, end_stream: bool) { 171 | hostcalls::send_grpc_stream_message(token_id, message, end_stream).unwrap() 172 | } 173 | 174 | fn on_grpc_stream_message(&mut self, _token_id: u32, _message_size: usize) {} 175 | 176 | fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option { 177 | hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() 178 | } 179 | 180 | fn on_grpc_stream_trailing_metadata(&mut self, _token_id: u32, _num_elements: u32) {} 181 | 182 | fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Bytes)> { 183 | hostcalls::get_map_bytes(MapType::GrpcReceiveTrailingMetadata).unwrap() 184 | } 185 | 186 | fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option { 187 | hostcalls::get_map_value_bytes(MapType::GrpcReceiveTrailingMetadata, name).unwrap() 188 | } 189 | 190 | fn cancel_grpc_stream(&self, token_id: u32) { 191 | hostcalls::cancel_grpc_stream(token_id).unwrap() 192 | } 193 | 194 | fn close_grpc_stream(&self, token_id: u32) { 195 | hostcalls::close_grpc_stream(token_id).unwrap() 196 | } 197 | 198 | fn on_grpc_stream_close(&mut self, _token_id: u32, _status_code: u32) {} 199 | 200 | fn get_grpc_status(&self) -> (u32, Option) { 201 | hostcalls::get_grpc_status().unwrap() 202 | } 203 | 204 | fn on_foreign_function(&mut self, _function_id: u32, _arguments_size: usize) {} 205 | 206 | fn call_foreign_function( 207 | &self, 208 | function_name: &str, 209 | arguments: Option<&[u8]>, 210 | ) -> Result, Status> { 211 | hostcalls::call_foreign_function(function_name, arguments) 212 | } 213 | 214 | fn on_done(&mut self) -> bool { 215 | true 216 | } 217 | 218 | fn done(&self) { 219 | hostcalls::done().unwrap() 220 | } 221 | } 222 | 223 | pub trait RootContext: Context { 224 | fn on_vm_start(&mut self, _vm_configuration_size: usize) -> bool { 225 | true 226 | } 227 | 228 | fn get_vm_configuration(&self) -> Option { 229 | hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() 230 | } 231 | 232 | fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { 233 | true 234 | } 235 | 236 | fn get_plugin_configuration(&self) -> Option { 237 | hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() 238 | } 239 | 240 | fn set_tick_period(&self, period: Duration) { 241 | hostcalls::set_tick_period(period).unwrap() 242 | } 243 | 244 | fn on_tick(&mut self) {} 245 | 246 | fn on_queue_ready(&mut self, _queue_id: u32) {} 247 | 248 | fn on_log(&mut self) {} 249 | 250 | fn create_http_context(&self, _context_id: u32) -> Option> { 251 | None 252 | } 253 | 254 | fn create_stream_context(&self, _context_id: u32) -> Option> { 255 | None 256 | } 257 | 258 | fn get_type(&self) -> Option { 259 | None 260 | } 261 | } 262 | 263 | pub trait StreamContext: Context { 264 | fn on_new_connection(&mut self) -> Action { 265 | Action::Continue 266 | } 267 | 268 | fn on_downstream_data(&mut self, _data_size: usize, _end_of_stream: bool) -> Action { 269 | Action::Continue 270 | } 271 | 272 | fn get_downstream_data(&self, start: usize, max_size: usize) -> Option { 273 | hostcalls::get_buffer(BufferType::DownstreamData, start, max_size).unwrap() 274 | } 275 | 276 | fn set_downstream_data(&self, start: usize, size: usize, value: &[u8]) { 277 | hostcalls::set_buffer(BufferType::DownstreamData, start, size, value).unwrap() 278 | } 279 | 280 | fn resume_downstream(&self) { 281 | hostcalls::resume_downstream().unwrap() 282 | } 283 | 284 | fn close_downstream(&self) { 285 | hostcalls::close_downstream().unwrap() 286 | } 287 | 288 | fn on_downstream_close(&mut self, _peer_type: PeerType) {} 289 | 290 | fn on_upstream_data(&mut self, _data_size: usize, _end_of_stream: bool) -> Action { 291 | Action::Continue 292 | } 293 | 294 | fn get_upstream_data(&self, start: usize, max_size: usize) -> Option { 295 | hostcalls::get_buffer(BufferType::UpstreamData, start, max_size).unwrap() 296 | } 297 | 298 | fn set_upstream_data(&self, start: usize, size: usize, value: &[u8]) { 299 | hostcalls::set_buffer(BufferType::UpstreamData, start, size, value).unwrap() 300 | } 301 | 302 | fn resume_upstream(&self) { 303 | hostcalls::resume_upstream().unwrap() 304 | } 305 | 306 | fn close_upstream(&self) { 307 | hostcalls::close_upstream().unwrap() 308 | } 309 | 310 | fn on_upstream_close(&mut self, _peer_type: PeerType) {} 311 | 312 | fn on_log(&mut self) {} 313 | } 314 | 315 | pub trait HttpContext: Context { 316 | fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { 317 | Action::Continue 318 | } 319 | 320 | fn get_http_request_headers(&self) -> Vec<(String, String)> { 321 | hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() 322 | } 323 | 324 | fn get_http_request_headers_bytes(&self) -> Vec<(String, Bytes)> { 325 | hostcalls::get_map_bytes(MapType::HttpRequestHeaders).unwrap() 326 | } 327 | 328 | fn set_http_request_headers(&self, headers: Vec<(&str, &str)>) { 329 | hostcalls::set_map(MapType::HttpRequestHeaders, headers).unwrap() 330 | } 331 | 332 | fn set_http_request_headers_bytes(&self, headers: Vec<(&str, &[u8])>) { 333 | hostcalls::set_map_bytes(MapType::HttpRequestHeaders, headers).unwrap() 334 | } 335 | 336 | fn get_http_request_header(&self, name: &str) -> Option { 337 | hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() 338 | } 339 | 340 | fn get_http_request_header_bytes(&self, name: &str) -> Option { 341 | hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, name).unwrap() 342 | } 343 | 344 | fn set_http_request_header(&self, name: &str, value: Option<&str>) { 345 | hostcalls::set_map_value(MapType::HttpRequestHeaders, name, value).unwrap() 346 | } 347 | 348 | fn set_http_request_header_bytes(&self, name: &str, value: Option<&[u8]>) { 349 | hostcalls::set_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap() 350 | } 351 | 352 | fn add_http_request_header(&self, name: &str, value: &str) { 353 | hostcalls::add_map_value(MapType::HttpRequestHeaders, name, value).unwrap() 354 | } 355 | 356 | fn add_http_request_header_bytes(&self, name: &str, value: &[u8]) { 357 | hostcalls::add_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap() 358 | } 359 | 360 | fn remove_http_request_header(&self, name: &str) { 361 | hostcalls::remove_map_value(MapType::HttpRequestHeaders, name).unwrap() 362 | } 363 | 364 | fn on_http_request_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action { 365 | Action::Continue 366 | } 367 | 368 | fn get_http_request_body(&self, start: usize, max_size: usize) -> Option { 369 | hostcalls::get_buffer(BufferType::HttpRequestBody, start, max_size).unwrap() 370 | } 371 | 372 | fn set_http_request_body(&self, start: usize, size: usize, value: &[u8]) { 373 | hostcalls::set_buffer(BufferType::HttpRequestBody, start, size, value).unwrap() 374 | } 375 | 376 | fn on_http_request_trailers(&mut self, _num_trailers: usize) -> Action { 377 | Action::Continue 378 | } 379 | 380 | fn get_http_request_trailers(&self) -> Vec<(String, String)> { 381 | hostcalls::get_map(MapType::HttpRequestTrailers).unwrap() 382 | } 383 | 384 | fn get_http_request_trailers_bytes(&self) -> Vec<(String, Bytes)> { 385 | hostcalls::get_map_bytes(MapType::HttpRequestTrailers).unwrap() 386 | } 387 | 388 | fn set_http_request_trailers(&self, trailers: Vec<(&str, &str)>) { 389 | hostcalls::set_map(MapType::HttpRequestTrailers, trailers).unwrap() 390 | } 391 | 392 | fn set_http_request_trailers_bytes(&self, trailers: Vec<(&str, &[u8])>) { 393 | hostcalls::set_map_bytes(MapType::HttpRequestTrailers, trailers).unwrap() 394 | } 395 | 396 | fn get_http_request_trailer(&self, name: &str) -> Option { 397 | hostcalls::get_map_value(MapType::HttpRequestTrailers, name).unwrap() 398 | } 399 | 400 | fn get_http_request_trailer_bytes(&self, name: &str) -> Option { 401 | hostcalls::get_map_value_bytes(MapType::HttpRequestTrailers, name).unwrap() 402 | } 403 | 404 | fn set_http_request_trailer(&self, name: &str, value: Option<&str>) { 405 | hostcalls::set_map_value(MapType::HttpRequestTrailers, name, value).unwrap() 406 | } 407 | 408 | fn set_http_request_trailer_bytes(&self, name: &str, value: Option<&[u8]>) { 409 | hostcalls::set_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap() 410 | } 411 | 412 | fn add_http_request_trailer(&self, name: &str, value: &str) { 413 | hostcalls::add_map_value(MapType::HttpRequestTrailers, name, value).unwrap() 414 | } 415 | 416 | fn add_http_request_trailer_bytes(&self, name: &str, value: &[u8]) { 417 | hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap() 418 | } 419 | 420 | fn remove_http_request_trailer(&self, name: &str) { 421 | hostcalls::remove_map_value(MapType::HttpRequestTrailers, name).unwrap() 422 | } 423 | 424 | fn resume_http_request(&self) { 425 | hostcalls::resume_http_request().unwrap() 426 | } 427 | 428 | fn reset_http_request(&self) { 429 | hostcalls::reset_http_request().unwrap() 430 | } 431 | 432 | fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { 433 | Action::Continue 434 | } 435 | 436 | fn get_http_response_headers(&self) -> Vec<(String, String)> { 437 | hostcalls::get_map(MapType::HttpResponseHeaders).unwrap() 438 | } 439 | 440 | fn get_http_response_headers_bytes(&self) -> Vec<(String, Bytes)> { 441 | hostcalls::get_map_bytes(MapType::HttpResponseHeaders).unwrap() 442 | } 443 | 444 | fn set_http_response_headers(&self, headers: Vec<(&str, &str)>) { 445 | hostcalls::set_map(MapType::HttpResponseHeaders, headers).unwrap() 446 | } 447 | 448 | fn set_http_response_headers_bytes(&self, headers: Vec<(&str, &[u8])>) { 449 | hostcalls::set_map_bytes(MapType::HttpResponseHeaders, headers).unwrap() 450 | } 451 | 452 | fn get_http_response_header(&self, name: &str) -> Option { 453 | hostcalls::get_map_value(MapType::HttpResponseHeaders, name).unwrap() 454 | } 455 | 456 | fn get_http_response_header_bytes(&self, name: &str) -> Option { 457 | hostcalls::get_map_value_bytes(MapType::HttpResponseHeaders, name).unwrap() 458 | } 459 | 460 | fn set_http_response_header(&self, name: &str, value: Option<&str>) { 461 | hostcalls::set_map_value(MapType::HttpResponseHeaders, name, value).unwrap() 462 | } 463 | 464 | fn set_http_response_header_bytes(&self, name: &str, value: Option<&[u8]>) { 465 | hostcalls::set_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap() 466 | } 467 | 468 | fn add_http_response_header(&self, name: &str, value: &str) { 469 | hostcalls::add_map_value(MapType::HttpResponseHeaders, name, value).unwrap() 470 | } 471 | 472 | fn add_http_response_header_bytes(&self, name: &str, value: &[u8]) { 473 | hostcalls::add_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap() 474 | } 475 | 476 | fn remove_http_response_header(&self, name: &str) { 477 | hostcalls::remove_map_value(MapType::HttpResponseHeaders, name).unwrap() 478 | } 479 | 480 | fn on_http_response_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action { 481 | Action::Continue 482 | } 483 | 484 | fn get_http_response_body(&self, start: usize, max_size: usize) -> Option { 485 | hostcalls::get_buffer(BufferType::HttpResponseBody, start, max_size).unwrap() 486 | } 487 | 488 | fn set_http_response_body(&self, start: usize, size: usize, value: &[u8]) { 489 | hostcalls::set_buffer(BufferType::HttpResponseBody, start, size, value).unwrap() 490 | } 491 | 492 | fn on_http_response_trailers(&mut self, _num_trailers: usize) -> Action { 493 | Action::Continue 494 | } 495 | 496 | fn get_http_response_trailers(&self) -> Vec<(String, String)> { 497 | hostcalls::get_map(MapType::HttpResponseTrailers).unwrap() 498 | } 499 | 500 | fn get_http_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { 501 | hostcalls::get_map_bytes(MapType::HttpResponseTrailers).unwrap() 502 | } 503 | 504 | fn set_http_response_trailers(&self, trailers: Vec<(&str, &str)>) { 505 | hostcalls::set_map(MapType::HttpResponseTrailers, trailers).unwrap() 506 | } 507 | 508 | fn set_http_response_trailers_bytes(&self, trailers: Vec<(&str, &[u8])>) { 509 | hostcalls::set_map_bytes(MapType::HttpResponseTrailers, trailers).unwrap() 510 | } 511 | 512 | fn get_http_response_trailer(&self, name: &str) -> Option { 513 | hostcalls::get_map_value(MapType::HttpResponseTrailers, name).unwrap() 514 | } 515 | 516 | fn get_http_response_trailer_bytes(&self, name: &str) -> Option { 517 | hostcalls::get_map_value_bytes(MapType::HttpResponseTrailers, name).unwrap() 518 | } 519 | 520 | fn set_http_response_trailer(&self, name: &str, value: Option<&str>) { 521 | hostcalls::set_map_value(MapType::HttpResponseTrailers, name, value).unwrap() 522 | } 523 | 524 | fn set_http_response_trailer_bytes(&self, name: &str, value: Option<&[u8]>) { 525 | hostcalls::set_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap() 526 | } 527 | 528 | fn add_http_response_trailer(&self, name: &str, value: &str) { 529 | hostcalls::add_map_value(MapType::HttpResponseTrailers, name, value).unwrap() 530 | } 531 | 532 | fn add_http_response_trailer_bytes(&self, name: &str, value: &[u8]) { 533 | hostcalls::add_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap() 534 | } 535 | 536 | fn remove_http_response_trailer(&self, name: &str) { 537 | hostcalls::remove_map_value(MapType::HttpResponseTrailers, name).unwrap() 538 | } 539 | 540 | fn resume_http_response(&self) { 541 | hostcalls::resume_http_response().unwrap() 542 | } 543 | 544 | fn reset_http_response(&self) { 545 | hostcalls::reset_http_response().unwrap() 546 | } 547 | 548 | fn send_http_response( 549 | &self, 550 | status_code: u32, 551 | headers: Vec<(&str, &str)>, 552 | body: Option<&[u8]>, 553 | ) { 554 | hostcalls::send_http_response(status_code, headers, body).unwrap() 555 | } 556 | 557 | fn send_grpc_response( 558 | &self, 559 | grpc_status: GrpcStatusCode, 560 | grpc_status_message: Option<&str>, 561 | custom_metadata: Vec<(&str, &[u8])>, 562 | ) { 563 | hostcalls::send_grpc_response(grpc_status, grpc_status_message, custom_metadata).unwrap() 564 | } 565 | 566 | fn on_log(&mut self) {} 567 | } 568 | -------------------------------------------------------------------------------- /bazel/cargo/remote/defs.bzl: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # @generated 3 | # DO NOT MODIFY: This file is auto-generated by a crate_universe tool. To 4 | # regenerate this file, run the following: 5 | # 6 | # bazel run @//bazel/cargo:crates_vendor 7 | ############################################################################### 8 | """ 9 | # `crates_repository` API 10 | 11 | - [aliases](#aliases) 12 | - [crate_deps](#crate_deps) 13 | - [all_crate_deps](#all_crate_deps) 14 | - [crate_repositories](#crate_repositories) 15 | 16 | """ 17 | 18 | load("@bazel_skylib//lib:selects.bzl", "selects") 19 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") 20 | load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") 21 | 22 | ############################################################################### 23 | # MACROS API 24 | ############################################################################### 25 | 26 | # An identifier that represent common dependencies (unconditional). 27 | _COMMON_CONDITION = "" 28 | 29 | def _flatten_dependency_maps(all_dependency_maps): 30 | """Flatten a list of dependency maps into one dictionary. 31 | 32 | Dependency maps have the following structure: 33 | 34 | ```python 35 | DEPENDENCIES_MAP = { 36 | # The first key in the map is a Bazel package 37 | # name of the workspace this file is defined in. 38 | "workspace_member_package": { 39 | 40 | # Not all dependencies are supported for all platforms. 41 | # the condition key is the condition required to be true 42 | # on the host platform. 43 | "condition": { 44 | 45 | # An alias to a crate target. # The label of the crate target the 46 | # Aliases are only crate names. # package name refers to. 47 | "package_name": "@full//:label", 48 | } 49 | } 50 | } 51 | ``` 52 | 53 | Args: 54 | all_dependency_maps (list): A list of dicts as described above 55 | 56 | Returns: 57 | dict: A dictionary as described above 58 | """ 59 | dependencies = {} 60 | 61 | for workspace_deps_map in all_dependency_maps: 62 | for pkg_name, conditional_deps_map in workspace_deps_map.items(): 63 | if pkg_name not in dependencies: 64 | non_frozen_map = dict() 65 | for key, values in conditional_deps_map.items(): 66 | non_frozen_map.update({key: dict(values.items())}) 67 | dependencies.setdefault(pkg_name, non_frozen_map) 68 | continue 69 | 70 | for condition, deps_map in conditional_deps_map.items(): 71 | # If the condition has not been recorded, do so and continue 72 | if condition not in dependencies[pkg_name]: 73 | dependencies[pkg_name].setdefault(condition, dict(deps_map.items())) 74 | continue 75 | 76 | # Alert on any miss-matched dependencies 77 | inconsistent_entries = [] 78 | for crate_name, crate_label in deps_map.items(): 79 | existing = dependencies[pkg_name][condition].get(crate_name) 80 | if existing and existing != crate_label: 81 | inconsistent_entries.append((crate_name, existing, crate_label)) 82 | dependencies[pkg_name][condition].update({crate_name: crate_label}) 83 | 84 | return dependencies 85 | 86 | def crate_deps(deps, package_name = None): 87 | """Finds the fully qualified label of the requested crates for the package where this macro is called. 88 | 89 | Args: 90 | deps (list): The desired list of crate targets. 91 | package_name (str, optional): The package name of the set of dependencies to look up. 92 | Defaults to `native.package_name()`. 93 | 94 | Returns: 95 | list: A list of labels to generated rust targets (str) 96 | """ 97 | 98 | if not deps: 99 | return [] 100 | 101 | if package_name == None: 102 | package_name = native.package_name() 103 | 104 | # Join both sets of dependencies 105 | dependencies = _flatten_dependency_maps([ 106 | _NORMAL_DEPENDENCIES, 107 | _NORMAL_DEV_DEPENDENCIES, 108 | _PROC_MACRO_DEPENDENCIES, 109 | _PROC_MACRO_DEV_DEPENDENCIES, 110 | _BUILD_DEPENDENCIES, 111 | _BUILD_PROC_MACRO_DEPENDENCIES, 112 | ]).pop(package_name, {}) 113 | 114 | # Combine all conditional packages so we can easily index over a flat list 115 | # TODO: Perhaps this should actually return select statements and maintain 116 | # the conditionals of the dependencies 117 | flat_deps = {} 118 | for deps_set in dependencies.values(): 119 | for crate_name, crate_label in deps_set.items(): 120 | flat_deps.update({crate_name: crate_label}) 121 | 122 | missing_crates = [] 123 | crate_targets = [] 124 | for crate_target in deps: 125 | if crate_target not in flat_deps: 126 | missing_crates.append(crate_target) 127 | else: 128 | crate_targets.append(flat_deps[crate_target]) 129 | 130 | if missing_crates: 131 | fail("Could not find crates `{}` among dependencies of `{}`. Available dependencies were `{}`".format( 132 | missing_crates, 133 | package_name, 134 | dependencies, 135 | )) 136 | 137 | return crate_targets 138 | 139 | def all_crate_deps( 140 | normal = False, 141 | normal_dev = False, 142 | proc_macro = False, 143 | proc_macro_dev = False, 144 | build = False, 145 | build_proc_macro = False, 146 | package_name = None): 147 | """Finds the fully qualified label of all requested direct crate dependencies \ 148 | for the package where this macro is called. 149 | 150 | If no parameters are set, all normal dependencies are returned. Setting any one flag will 151 | otherwise impact the contents of the returned list. 152 | 153 | Args: 154 | normal (bool, optional): If True, normal dependencies are included in the 155 | output list. 156 | normal_dev (bool, optional): If True, normal dev dependencies will be 157 | included in the output list.. 158 | proc_macro (bool, optional): If True, proc_macro dependencies are included 159 | in the output list. 160 | proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are 161 | included in the output list. 162 | build (bool, optional): If True, build dependencies are included 163 | in the output list. 164 | build_proc_macro (bool, optional): If True, build proc_macro dependencies are 165 | included in the output list. 166 | package_name (str, optional): The package name of the set of dependencies to look up. 167 | Defaults to `native.package_name()` when unset. 168 | 169 | Returns: 170 | list: A list of labels to generated rust targets (str) 171 | """ 172 | 173 | if package_name == None: 174 | package_name = native.package_name() 175 | 176 | # Determine the relevant maps to use 177 | all_dependency_maps = [] 178 | if normal: 179 | all_dependency_maps.append(_NORMAL_DEPENDENCIES) 180 | if normal_dev: 181 | all_dependency_maps.append(_NORMAL_DEV_DEPENDENCIES) 182 | if proc_macro: 183 | all_dependency_maps.append(_PROC_MACRO_DEPENDENCIES) 184 | if proc_macro_dev: 185 | all_dependency_maps.append(_PROC_MACRO_DEV_DEPENDENCIES) 186 | if build: 187 | all_dependency_maps.append(_BUILD_DEPENDENCIES) 188 | if build_proc_macro: 189 | all_dependency_maps.append(_BUILD_PROC_MACRO_DEPENDENCIES) 190 | 191 | # Default to always using normal dependencies 192 | if not all_dependency_maps: 193 | all_dependency_maps.append(_NORMAL_DEPENDENCIES) 194 | 195 | dependencies = _flatten_dependency_maps(all_dependency_maps).pop(package_name, None) 196 | 197 | if not dependencies: 198 | if dependencies == None: 199 | fail("Tried to get all_crate_deps for package " + package_name + " but that package had no Cargo.toml file") 200 | else: 201 | return [] 202 | 203 | crate_deps = list(dependencies.pop(_COMMON_CONDITION, {}).values()) 204 | for condition, deps in dependencies.items(): 205 | crate_deps += selects.with_or({ 206 | tuple(_CONDITIONS[condition]): deps.values(), 207 | "//conditions:default": [], 208 | }) 209 | 210 | return crate_deps 211 | 212 | def aliases( 213 | normal = False, 214 | normal_dev = False, 215 | proc_macro = False, 216 | proc_macro_dev = False, 217 | build = False, 218 | build_proc_macro = False, 219 | package_name = None): 220 | """Produces a map of Crate alias names to their original label 221 | 222 | If no dependency kinds are specified, `normal` and `proc_macro` are used by default. 223 | Setting any one flag will otherwise determine the contents of the returned dict. 224 | 225 | Args: 226 | normal (bool, optional): If True, normal dependencies are included in the 227 | output list. 228 | normal_dev (bool, optional): If True, normal dev dependencies will be 229 | included in the output list.. 230 | proc_macro (bool, optional): If True, proc_macro dependencies are included 231 | in the output list. 232 | proc_macro_dev (bool, optional): If True, dev proc_macro dependencies are 233 | included in the output list. 234 | build (bool, optional): If True, build dependencies are included 235 | in the output list. 236 | build_proc_macro (bool, optional): If True, build proc_macro dependencies are 237 | included in the output list. 238 | package_name (str, optional): The package name of the set of dependencies to look up. 239 | Defaults to `native.package_name()` when unset. 240 | 241 | Returns: 242 | dict: The aliases of all associated packages 243 | """ 244 | if package_name == None: 245 | package_name = native.package_name() 246 | 247 | # Determine the relevant maps to use 248 | all_aliases_maps = [] 249 | if normal: 250 | all_aliases_maps.append(_NORMAL_ALIASES) 251 | if normal_dev: 252 | all_aliases_maps.append(_NORMAL_DEV_ALIASES) 253 | if proc_macro: 254 | all_aliases_maps.append(_PROC_MACRO_ALIASES) 255 | if proc_macro_dev: 256 | all_aliases_maps.append(_PROC_MACRO_DEV_ALIASES) 257 | if build: 258 | all_aliases_maps.append(_BUILD_ALIASES) 259 | if build_proc_macro: 260 | all_aliases_maps.append(_BUILD_PROC_MACRO_ALIASES) 261 | 262 | # Default to always using normal aliases 263 | if not all_aliases_maps: 264 | all_aliases_maps.append(_NORMAL_ALIASES) 265 | all_aliases_maps.append(_PROC_MACRO_ALIASES) 266 | 267 | aliases = _flatten_dependency_maps(all_aliases_maps).pop(package_name, None) 268 | 269 | if not aliases: 270 | return dict() 271 | 272 | common_items = aliases.pop(_COMMON_CONDITION, {}).items() 273 | 274 | # If there are only common items in the dictionary, immediately return them 275 | if not len(aliases.keys()) == 1: 276 | return dict(common_items) 277 | 278 | # Build a single select statement where each conditional has accounted for the 279 | # common set of aliases. 280 | crate_aliases = {"//conditions:default": dict(common_items)} 281 | for condition, deps in aliases.items(): 282 | condition_triples = _CONDITIONS[condition] 283 | for triple in condition_triples: 284 | if triple in crate_aliases: 285 | crate_aliases[triple].update(deps) 286 | else: 287 | crate_aliases.update({triple: dict(deps.items() + common_items)}) 288 | 289 | return select(crate_aliases) 290 | 291 | ############################################################################### 292 | # WORKSPACE MEMBER DEPS AND ALIASES 293 | ############################################################################### 294 | 295 | _NORMAL_DEPENDENCIES = { 296 | "": { 297 | _COMMON_CONDITION: { 298 | "hashbrown": Label("@crates_vendor//:hashbrown-0.16.0"), 299 | "log": Label("@crates_vendor//:log-0.4.27"), 300 | }, 301 | }, 302 | } 303 | 304 | _NORMAL_ALIASES = { 305 | "": { 306 | _COMMON_CONDITION: { 307 | }, 308 | }, 309 | } 310 | 311 | _NORMAL_DEV_DEPENDENCIES = { 312 | "": { 313 | _COMMON_CONDITION: { 314 | "mockalloc": Label("@crates_vendor//:mockalloc-0.1.2"), 315 | }, 316 | }, 317 | } 318 | 319 | _NORMAL_DEV_ALIASES = { 320 | "": { 321 | _COMMON_CONDITION: { 322 | }, 323 | }, 324 | } 325 | 326 | _PROC_MACRO_DEPENDENCIES = { 327 | "": { 328 | }, 329 | } 330 | 331 | _PROC_MACRO_ALIASES = { 332 | "": { 333 | }, 334 | } 335 | 336 | _PROC_MACRO_DEV_DEPENDENCIES = { 337 | "": { 338 | }, 339 | } 340 | 341 | _PROC_MACRO_DEV_ALIASES = { 342 | "": { 343 | _COMMON_CONDITION: { 344 | }, 345 | }, 346 | } 347 | 348 | _BUILD_DEPENDENCIES = { 349 | "": { 350 | }, 351 | } 352 | 353 | _BUILD_ALIASES = { 354 | "": { 355 | }, 356 | } 357 | 358 | _BUILD_PROC_MACRO_DEPENDENCIES = { 359 | "": { 360 | }, 361 | } 362 | 363 | _BUILD_PROC_MACRO_ALIASES = { 364 | "": { 365 | }, 366 | } 367 | 368 | _CONDITIONS = { 369 | "aarch64-apple-darwin": ["@rules_rust//rust/platform:aarch64-apple-darwin"], 370 | "aarch64-apple-ios": ["@rules_rust//rust/platform:aarch64-apple-ios"], 371 | "aarch64-apple-ios-sim": ["@rules_rust//rust/platform:aarch64-apple-ios-sim"], 372 | "aarch64-linux-android": ["@rules_rust//rust/platform:aarch64-linux-android"], 373 | "aarch64-pc-windows-msvc": ["@rules_rust//rust/platform:aarch64-pc-windows-msvc"], 374 | "aarch64-unknown-fuchsia": ["@rules_rust//rust/platform:aarch64-unknown-fuchsia"], 375 | "aarch64-unknown-linux-gnu": ["@rules_rust//rust/platform:aarch64-unknown-linux-gnu"], 376 | "aarch64-unknown-nixos-gnu": ["@rules_rust//rust/platform:aarch64-unknown-nixos-gnu"], 377 | "aarch64-unknown-nto-qnx710": ["@rules_rust//rust/platform:aarch64-unknown-nto-qnx710"], 378 | "aarch64-unknown-uefi": ["@rules_rust//rust/platform:aarch64-unknown-uefi"], 379 | "arm-unknown-linux-gnueabi": ["@rules_rust//rust/platform:arm-unknown-linux-gnueabi"], 380 | "armv7-linux-androideabi": ["@rules_rust//rust/platform:armv7-linux-androideabi"], 381 | "armv7-unknown-linux-gnueabi": ["@rules_rust//rust/platform:armv7-unknown-linux-gnueabi"], 382 | "i686-apple-darwin": ["@rules_rust//rust/platform:i686-apple-darwin"], 383 | "i686-linux-android": ["@rules_rust//rust/platform:i686-linux-android"], 384 | "i686-pc-windows-msvc": ["@rules_rust//rust/platform:i686-pc-windows-msvc"], 385 | "i686-unknown-freebsd": ["@rules_rust//rust/platform:i686-unknown-freebsd"], 386 | "i686-unknown-linux-gnu": ["@rules_rust//rust/platform:i686-unknown-linux-gnu"], 387 | "powerpc-unknown-linux-gnu": ["@rules_rust//rust/platform:powerpc-unknown-linux-gnu"], 388 | "riscv32imc-unknown-none-elf": ["@rules_rust//rust/platform:riscv32imc-unknown-none-elf"], 389 | "riscv64gc-unknown-linux-gnu": ["@rules_rust//rust/platform:riscv64gc-unknown-linux-gnu"], 390 | "riscv64gc-unknown-none-elf": ["@rules_rust//rust/platform:riscv64gc-unknown-none-elf"], 391 | "s390x-unknown-linux-gnu": ["@rules_rust//rust/platform:s390x-unknown-linux-gnu"], 392 | "thumbv7em-none-eabi": ["@rules_rust//rust/platform:thumbv7em-none-eabi"], 393 | "thumbv8m.main-none-eabi": ["@rules_rust//rust/platform:thumbv8m.main-none-eabi"], 394 | "wasm32-unknown-emscripten": ["@rules_rust//rust/platform:wasm32-unknown-emscripten"], 395 | "wasm32-unknown-unknown": ["@rules_rust//rust/platform:wasm32-unknown-unknown"], 396 | "wasm32-wasip1": ["@rules_rust//rust/platform:wasm32-wasip1"], 397 | "wasm32-wasip1-threads": ["@rules_rust//rust/platform:wasm32-wasip1-threads"], 398 | "wasm32-wasip2": ["@rules_rust//rust/platform:wasm32-wasip2"], 399 | "x86_64-apple-darwin": ["@rules_rust//rust/platform:x86_64-apple-darwin"], 400 | "x86_64-apple-ios": ["@rules_rust//rust/platform:x86_64-apple-ios"], 401 | "x86_64-linux-android": ["@rules_rust//rust/platform:x86_64-linux-android"], 402 | "x86_64-pc-windows-msvc": ["@rules_rust//rust/platform:x86_64-pc-windows-msvc"], 403 | "x86_64-unknown-freebsd": ["@rules_rust//rust/platform:x86_64-unknown-freebsd"], 404 | "x86_64-unknown-fuchsia": ["@rules_rust//rust/platform:x86_64-unknown-fuchsia"], 405 | "x86_64-unknown-linux-gnu": ["@rules_rust//rust/platform:x86_64-unknown-linux-gnu"], 406 | "x86_64-unknown-nixos-gnu": ["@rules_rust//rust/platform:x86_64-unknown-nixos-gnu"], 407 | "x86_64-unknown-none": ["@rules_rust//rust/platform:x86_64-unknown-none"], 408 | "x86_64-unknown-uefi": ["@rules_rust//rust/platform:x86_64-unknown-uefi"], 409 | } 410 | 411 | ############################################################################### 412 | 413 | def crate_repositories(): 414 | """A macro for defining repositories for all generated crates. 415 | 416 | Returns: 417 | A list of repos visible to the module through the module extension. 418 | """ 419 | maybe( 420 | http_archive, 421 | name = "crates_vendor__allocator-api2-0.2.21", 422 | sha256 = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923", 423 | type = "tar.gz", 424 | urls = ["https://static.crates.io/crates/allocator-api2/0.2.21/download"], 425 | strip_prefix = "allocator-api2-0.2.21", 426 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.allocator-api2-0.2.21.bazel"), 427 | ) 428 | 429 | maybe( 430 | http_archive, 431 | name = "crates_vendor__equivalent-1.0.2", 432 | sha256 = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f", 433 | type = "tar.gz", 434 | urls = ["https://static.crates.io/crates/equivalent/1.0.2/download"], 435 | strip_prefix = "equivalent-1.0.2", 436 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.equivalent-1.0.2.bazel"), 437 | ) 438 | 439 | maybe( 440 | http_archive, 441 | name = "crates_vendor__foldhash-0.2.0", 442 | sha256 = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb", 443 | type = "tar.gz", 444 | urls = ["https://static.crates.io/crates/foldhash/0.2.0/download"], 445 | strip_prefix = "foldhash-0.2.0", 446 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.foldhash-0.2.0.bazel"), 447 | ) 448 | 449 | maybe( 450 | http_archive, 451 | name = "crates_vendor__hashbrown-0.16.0", 452 | sha256 = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d", 453 | type = "tar.gz", 454 | urls = ["https://static.crates.io/crates/hashbrown/0.16.0/download"], 455 | strip_prefix = "hashbrown-0.16.0", 456 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.hashbrown-0.16.0.bazel"), 457 | ) 458 | 459 | maybe( 460 | http_archive, 461 | name = "crates_vendor__log-0.4.27", 462 | sha256 = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94", 463 | type = "tar.gz", 464 | urls = ["https://static.crates.io/crates/log/0.4.27/download"], 465 | strip_prefix = "log-0.4.27", 466 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.log-0.4.27.bazel"), 467 | ) 468 | 469 | maybe( 470 | http_archive, 471 | name = "crates_vendor__mockalloc-0.1.2", 472 | sha256 = "5a6c93486116b2ab028d2a2c5f5ff42020407d1c7048b77ca0b196a511a12a94", 473 | type = "tar.gz", 474 | urls = ["https://static.crates.io/crates/mockalloc/0.1.2/download"], 475 | strip_prefix = "mockalloc-0.1.2", 476 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.mockalloc-0.1.2.bazel"), 477 | ) 478 | 479 | maybe( 480 | http_archive, 481 | name = "crates_vendor__mockalloc-macros-0.1.0", 482 | sha256 = "23565dcdaedab64115f722c31d84e5bdb7125724097dcafce160a64806d6fb65", 483 | type = "tar.gz", 484 | urls = ["https://static.crates.io/crates/mockalloc-macros/0.1.0/download"], 485 | strip_prefix = "mockalloc-macros-0.1.0", 486 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.mockalloc-macros-0.1.0.bazel"), 487 | ) 488 | 489 | maybe( 490 | http_archive, 491 | name = "crates_vendor__proc-macro2-1.0.101", 492 | sha256 = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de", 493 | type = "tar.gz", 494 | urls = ["https://static.crates.io/crates/proc-macro2/1.0.101/download"], 495 | strip_prefix = "proc-macro2-1.0.101", 496 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.proc-macro2-1.0.101.bazel"), 497 | ) 498 | 499 | maybe( 500 | http_archive, 501 | name = "crates_vendor__quote-1.0.41", 502 | sha256 = "ce25767e7b499d1b604768e7cde645d14cc8584231ea6b295e9c9eb22c02e1d1", 503 | type = "tar.gz", 504 | urls = ["https://static.crates.io/crates/quote/1.0.41/download"], 505 | strip_prefix = "quote-1.0.41", 506 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.quote-1.0.41.bazel"), 507 | ) 508 | 509 | maybe( 510 | http_archive, 511 | name = "crates_vendor__syn-1.0.109", 512 | sha256 = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237", 513 | type = "tar.gz", 514 | urls = ["https://static.crates.io/crates/syn/1.0.109/download"], 515 | strip_prefix = "syn-1.0.109", 516 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.syn-1.0.109.bazel"), 517 | ) 518 | 519 | maybe( 520 | http_archive, 521 | name = "crates_vendor__unicode-ident-1.0.19", 522 | sha256 = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d", 523 | type = "tar.gz", 524 | urls = ["https://static.crates.io/crates/unicode-ident/1.0.19/download"], 525 | strip_prefix = "unicode-ident-1.0.19", 526 | build_file = Label("@proxy_wasm_rust_sdk//bazel/cargo/remote:BUILD.unicode-ident-1.0.19.bazel"), 527 | ) 528 | 529 | return [ 530 | struct(repo = "crates_vendor__hashbrown-0.16.0", is_dev_dep = False), 531 | struct(repo = "crates_vendor__log-0.4.27", is_dev_dep = False), 532 | struct(repo = "crates_vendor__mockalloc-0.1.2", is_dev_dep = True), 533 | ] 534 | --------------------------------------------------------------------------------