diff --git a/.bazelversion b/.bazelversion index 7c69a55d..0062ac97 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -3.7.0 +5.0.0 diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 89e5164d..c0f9b47f 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -34,10 +34,13 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.16' - name: Check licenses run: | - go get -u github.com/google/addlicense + go install github.com/google/addlicense@latest export PATH=$PATH:$(go env GOPATH)/bin addlicense -check . @@ -46,6 +49,9 @@ jobs: steps: - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.16' - name: Cache uses: actions/cache@v2 @@ -60,14 +66,14 @@ jobs: key: ${{ hashFiles('WORKSPACE', '.bazelrc', '.bazelversion', 'bazel/cargo/Cargo.raze.lock', 'bazel/dependencies.bzl', 'bazel/repositories.bzl') }} - name: Build (wasm32-unknown-unknown) - run: bazelisk --bazelrc=/dev/null build --platforms=@rules_rust//rust/platform:wasm //... + run: bazelisk --noworkspace_rc build --platforms=@rules_rust//rust/platform:wasm //... - name: Build (wasm32-wasi) - run: bazelisk --bazelrc=/dev/null build --platforms=@rules_rust//rust/platform:wasi //... + run: bazelisk --noworkspace_rc build --platforms=@rules_rust//rust/platform:wasi //... - name: Format (buildifier) run: | - GO111MODULE=on go get -u github.com/bazelbuild/buildtools/buildifier@3.4.0 + go install github.com/bazelbuild/buildtools/buildifier@latest export PATH=$PATH:$(go env GOPATH)/bin buildifier -mode=check WORKSPACE buildifier -mode=check BUILD @@ -76,9 +82,7 @@ jobs: - name: Format (cargo raze) run: | mv bazel/cargo/Cargo.raze.lock Cargo.lock - rm -rf bazel/cargo/ - cargo install cargo-raze --version 0.9.2 - cargo raze --output=bazel/cargo + bazelisk --noworkspace_rc run @cargo_raze//:raze -- --manifest-path=$(pwd)/Cargo.toml mv Cargo.lock bazel/cargo/Cargo.raze.lock git diff --exit-code @@ -200,12 +204,6 @@ jobs: - name: Run cargo outdated run: cargo outdated --root-deps-only --exit-code 1 - - name: Check freshness of bazel/cargo/Cargo.raze.lock - run: | - cargo generate-lockfile - mv Cargo.lock bazel/cargo/Cargo.raze.lock - git diff --exit-code - audit: runs-on: ubuntu-latest diff --git a/BUILD b/BUILD index d905fbbf..6d5f6672 100644 --- a/BUILD +++ b/BUILD @@ -1,4 +1,4 @@ -load("@rules_rust//rust:rust.bzl", "rust_library") +load("@rules_rust//rust:defs.bzl", "rust_library") rust_library( name = "proxy_wasm", diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c9ca036..f3516cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,19 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [Unreleased] + +### Changed + +- Updated ABI to Proxy-Wasm ABI v0.2.1. + +## [0.1.4] - 2021-07-01 + +### Added + +- Added support for gRPC callouts. + Thanks [@Shikugawa](https://github.com/Shikugawa)! + ## [0.1.3] - 2020-12-04 ### Fixed @@ -46,6 +59,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Initial release. +[Unreleased]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.4...HEAD +[0.1.4]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.3...v0.1.4 [0.1.3]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.2...v0.1.3 [0.1.2]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.1...v0.1.2 [0.1.1]: https://github.com/proxy-wasm/proxy-wasm-rust-sdk/compare/v0.1.0...v0.1.1 diff --git a/Cargo.toml b/Cargo.toml index 0790cc5f..22eebd9b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "proxy-wasm" -version = "0.1.3" +version = "0.1.4" authors = ["Piotr Sikora "] description = "WebAssembly for Proxies" readme = "README.md" @@ -12,7 +12,7 @@ edition = "2018" wee-alloc = ["wee_alloc"] [dependencies] -hashbrown = "0.9" +hashbrown = "0.12" log = "0.4" wee_alloc = { version = "0.4", optional = true } @@ -29,7 +29,6 @@ opt-level = 3 panic = "abort" [package.metadata.raze] -rust_rules_workspace_name = "rules_rust" package_aliases_dir = "bazel/cargo" workspace_path = "//bazel/cargo" genmode = "Remote" diff --git a/README.md b/README.md index bb9b5a32..303d178b 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,6 @@ When updating dependencies, you need to regenerate Bazel `BUILD` files to match updated `Cargo.toml`: ``` -cargo install cargo-raze --version 0.9.2 -cargo raze --generate-lockfile --output=bazel/cargo +cargo install cargo-raze --version 0.14.1 +cargo raze --generate-lockfile ``` diff --git a/WORKSPACE b/WORKSPACE index 4261aeed..61837f79 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -7,3 +7,22 @@ proxy_wasm_rust_sdk_repositories() load("@proxy_wasm_rust_sdk//bazel:dependencies.bzl", "proxy_wasm_rust_sdk_dependencies") proxy_wasm_rust_sdk_dependencies() + +# Needed only when using @cargo_raze//:raze to generate BUILD files in //bazel/cargo. + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +http_archive( + name = "cargo_raze", + sha256 = "75192fdcb2777527c70e1053a318a9aa0beac3c093401921c1e7c4d53084caa8", + strip_prefix = "cargo-raze-0.14.1", + url = "https://github.com/google/cargo-raze/archive/v0.14.1.tar.gz", +) + +load("@cargo_raze//:repositories.bzl", "cargo_raze_repositories") + +cargo_raze_repositories() + +load("@cargo_raze//:transitive_deps.bzl", "cargo_raze_transitive_deps") + +cargo_raze_transitive_deps() diff --git a/bazel/cargo/BUILD.bazel b/bazel/cargo/BUILD.bazel index b9db7826..9bdf8bb8 100644 --- a/bazel/cargo/BUILD.bazel +++ b/bazel/cargo/BUILD.bazel @@ -32,7 +32,7 @@ alias( alias( name = "getrandom", - actual = "@raze__getrandom__0_2_2//:getrandom", + actual = "@raze__getrandom__0_2_4//:getrandom", tags = [ "cargo-raze", "manual", @@ -41,7 +41,7 @@ alias( alias( name = "hashbrown", - actual = "@raze__hashbrown__0_9_1//:hashbrown", + actual = "@raze__hashbrown__0_12_0//:hashbrown", tags = [ "cargo-raze", "manual", diff --git a/bazel/cargo/Cargo.raze.lock b/bazel/cargo/Cargo.raze.lock index bb8f732a..77da91cd 100644 --- a/bazel/cargo/Cargo.raze.lock +++ b/bazel/cargo/Cargo.raze.lock @@ -2,9 +2,14 @@ # It is not intended for manual editing. [[package]] name = "ahash" -version = "0.4.7" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] [[package]] name = "autocfg" @@ -39,9 +44,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ "cfg-if 1.0.0", "libc", @@ -50,18 +55,18 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.9.1" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +checksum = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758" dependencies = [ "ahash", ] [[package]] name = "libc" -version = "0.2.86" +version = "0.2.116" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74" [[package]] name = "log" @@ -97,9 +102,15 @@ dependencies = [ "autocfg", ] +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + [[package]] name = "proxy-wasm" -version = "0.1.3" +version = "0.1.4" dependencies = [ "cfg-if 1.0.0", "chrono", @@ -119,6 +130,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "wasi" version = "0.10.2+wasi-snapshot-preview1" diff --git a/bazel/cargo/crates.bzl b/bazel/cargo/crates.bzl index a49ac2e7..44ed1395 100644 --- a/bazel/cargo/crates.bzl +++ b/bazel/cargo/crates.bzl @@ -13,12 +13,12 @@ def raze_fetch_remote_crates(): """This function defines a collection of repos and should be called in a WORKSPACE file""" maybe( http_archive, - name = "raze__ahash__0_4_7", - url = "https://crates.io/api/v1/crates/ahash/0.4.7/download", + name = "raze__ahash__0_7_6", + url = "https://crates.io/api/v1/crates/ahash/0.7.6/download", type = "tar.gz", - sha256 = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e", - strip_prefix = "ahash-0.4.7", - build_file = Label("//bazel/cargo/remote:BUILD.ahash-0.4.7.bazel"), + sha256 = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47", + strip_prefix = "ahash-0.7.6", + build_file = Label("//bazel/cargo/remote:BUILD.ahash-0.7.6.bazel"), ) maybe( @@ -53,32 +53,32 @@ def raze_fetch_remote_crates(): maybe( http_archive, - name = "raze__getrandom__0_2_2", - url = "https://crates.io/api/v1/crates/getrandom/0.2.2/download", + name = "raze__getrandom__0_2_4", + url = "https://crates.io/api/v1/crates/getrandom/0.2.4/download", type = "tar.gz", - sha256 = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8", - strip_prefix = "getrandom-0.2.2", - build_file = Label("//bazel/cargo/remote:BUILD.getrandom-0.2.2.bazel"), + sha256 = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c", + strip_prefix = "getrandom-0.2.4", + build_file = Label("//bazel/cargo/remote:BUILD.getrandom-0.2.4.bazel"), ) maybe( http_archive, - name = "raze__hashbrown__0_9_1", - url = "https://crates.io/api/v1/crates/hashbrown/0.9.1/download", + name = "raze__hashbrown__0_12_0", + url = "https://crates.io/api/v1/crates/hashbrown/0.12.0/download", type = "tar.gz", - sha256 = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04", - strip_prefix = "hashbrown-0.9.1", - build_file = Label("//bazel/cargo/remote:BUILD.hashbrown-0.9.1.bazel"), + sha256 = "8c21d40587b92fa6a6c6e3c1bdbf87d75511db5672f9c93175574b3a00df1758", + strip_prefix = "hashbrown-0.12.0", + build_file = Label("//bazel/cargo/remote:BUILD.hashbrown-0.12.0.bazel"), ) maybe( http_archive, - name = "raze__libc__0_2_86", - url = "https://crates.io/api/v1/crates/libc/0.2.86/download", + name = "raze__libc__0_2_116", + url = "https://crates.io/api/v1/crates/libc/0.2.116/download", type = "tar.gz", - sha256 = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c", - strip_prefix = "libc-0.2.86", - build_file = Label("//bazel/cargo/remote:BUILD.libc-0.2.86.bazel"), + sha256 = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74", + strip_prefix = "libc-0.2.116", + build_file = Label("//bazel/cargo/remote:BUILD.libc-0.2.116.bazel"), ) maybe( @@ -111,6 +111,16 @@ def raze_fetch_remote_crates(): build_file = Label("//bazel/cargo/remote:BUILD.num-traits-0.2.14.bazel"), ) + maybe( + http_archive, + name = "raze__once_cell__1_9_0", + url = "https://crates.io/api/v1/crates/once_cell/1.9.0/download", + type = "tar.gz", + sha256 = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5", + strip_prefix = "once_cell-1.9.0", + build_file = Label("//bazel/cargo/remote:BUILD.once_cell-1.9.0.bazel"), + ) + maybe( http_archive, name = "raze__time__0_1_43", @@ -121,6 +131,16 @@ def raze_fetch_remote_crates(): build_file = Label("//bazel/cargo/remote:BUILD.time-0.1.43.bazel"), ) + maybe( + http_archive, + name = "raze__version_check__0_9_4", + url = "https://crates.io/api/v1/crates/version_check/0.9.4/download", + type = "tar.gz", + sha256 = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f", + strip_prefix = "version_check-0.9.4", + build_file = Label("//bazel/cargo/remote:BUILD.version_check-0.9.4.bazel"), + ) + maybe( http_archive, name = "raze__wasi__0_10_2_wasi_snapshot_preview1", diff --git a/bazel/cargo/remote/BUILD.ahash-0.7.6.bazel b/bazel/cargo/remote/BUILD.ahash-0.7.6.bazel new file mode 100644 index 00000000..1187b9b5 --- /dev/null +++ b/bazel/cargo/remote/BUILD.ahash-0.7.6.bazel @@ -0,0 +1,201 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:defs.bzl", + "rust_binary", + "rust_library", + "rust_proc_macro", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//bazel/cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets +# buildifier: disable=out-of-order-load +# buildifier: disable=load-on-top +load( + "@rules_rust//cargo:cargo_build_script.bzl", + "cargo_build_script", +) + +cargo_build_script( + name = "ahash_build_script", + srcs = glob(["**/*.rs"]), + build_script_env = { + }, + crate_features = [ + ], + crate_root = "build.rs", + data = glob(["**"]), + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "manual", + ], + version = "0.7.6", + visibility = ["//visibility:private"], + deps = [ + "@raze__version_check__0_9_4//:version_check", + ] + selects.with_or({ + # cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi")) + ( + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + "@rules_rust//rust/platform:aarch64-apple-darwin", + "@rules_rust//rust/platform:aarch64-apple-ios", + "@rules_rust//rust/platform:aarch64-linux-android", + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@rules_rust//rust/platform:i686-linux-android", + "@rules_rust//rust/platform:i686-unknown-freebsd", + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@rules_rust//rust/platform:wasm32-wasi", + "@rules_rust//rust/platform:x86_64-apple-ios", + "@rules_rust//rust/platform:x86_64-linux-android", + "@rules_rust//rust/platform:x86_64-unknown-freebsd", + ): [ + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(not(all(target_arch = "arm", target_os = "none"))) + ( + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + "@rules_rust//rust/platform:aarch64-apple-darwin", + "@rules_rust//rust/platform:aarch64-apple-ios", + "@rules_rust//rust/platform:aarch64-linux-android", + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@rules_rust//rust/platform:i686-linux-android", + "@rules_rust//rust/platform:i686-unknown-freebsd", + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@rules_rust//rust/platform:wasm32-unknown-unknown", + "@rules_rust//rust/platform:wasm32-wasi", + "@rules_rust//rust/platform:x86_64-apple-ios", + "@rules_rust//rust/platform:x86_64-linux-android", + "@rules_rust//rust/platform:x86_64-unknown-freebsd", + ): [ + ], + "//conditions:default": [], + }), +) + +# Unsupported target "ahash" with type "bench" omitted + +# Unsupported target "map" with type "bench" omitted + +rust_library( + name = "ahash", + srcs = glob(["**/*.rs"]), + aliases = { + }, + crate_features = [ + ], + crate_root = "src/lib.rs", + data = [], + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "crate-name=ahash", + "manual", + ], + version = "0.7.6", + # buildifier: leave-alone + deps = [ + ":ahash_build_script", + ] + selects.with_or({ + # cfg(any(target_os = "linux", target_os = "android", target_os = "windows", target_os = "macos", target_os = "ios", target_os = "freebsd", target_os = "openbsd", target_os = "netbsd", target_os = "dragonfly", target_os = "solaris", target_os = "illumos", target_os = "fuchsia", target_os = "redox", target_os = "cloudabi", target_os = "haiku", target_os = "vxworks", target_os = "emscripten", target_os = "wasi")) + ( + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + "@rules_rust//rust/platform:aarch64-apple-darwin", + "@rules_rust//rust/platform:aarch64-apple-ios", + "@rules_rust//rust/platform:aarch64-linux-android", + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@rules_rust//rust/platform:i686-linux-android", + "@rules_rust//rust/platform:i686-unknown-freebsd", + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@rules_rust//rust/platform:wasm32-wasi", + "@rules_rust//rust/platform:x86_64-apple-ios", + "@rules_rust//rust/platform:x86_64-linux-android", + "@rules_rust//rust/platform:x86_64-unknown-freebsd", + ): [ + "@raze__getrandom__0_2_4//:getrandom", + ], + "//conditions:default": [], + }) + selects.with_or({ + # cfg(not(all(target_arch = "arm", target_os = "none"))) + ( + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-pc-windows-msvc", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-pc-windows-msvc", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", + "@rules_rust//rust/platform:aarch64-apple-darwin", + "@rules_rust//rust/platform:aarch64-apple-ios", + "@rules_rust//rust/platform:aarch64-linux-android", + "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", + "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", + "@rules_rust//rust/platform:i686-linux-android", + "@rules_rust//rust/platform:i686-unknown-freebsd", + "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", + "@rules_rust//rust/platform:s390x-unknown-linux-gnu", + "@rules_rust//rust/platform:wasm32-unknown-unknown", + "@rules_rust//rust/platform:wasm32-wasi", + "@rules_rust//rust/platform:x86_64-apple-ios", + "@rules_rust//rust/platform:x86_64-linux-android", + "@rules_rust//rust/platform:x86_64-unknown-freebsd", + ): [ + "@raze__once_cell__1_9_0//:once_cell", + ], + "//conditions:default": [], + }), +) + +# Unsupported target "bench" with type "test" omitted + +# Unsupported target "map_tests" with type "test" omitted + +# Unsupported target "nopanic" with type "test" omitted diff --git a/bazel/cargo/remote/BUILD.autocfg-1.0.1.bazel b/bazel/cargo/remote/BUILD.autocfg-1.0.1.bazel index d348f9b4..2e0c8bca 100644 --- a/bazel/cargo/remote/BUILD.autocfg-1.0.1.bazel +++ b/bazel/cargo/remote/BUILD.autocfg-1.0.1.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -44,7 +45,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -52,6 +52,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=autocfg", "manual", ], version = "1.0.1", diff --git a/bazel/cargo/remote/BUILD.cfg-if-1.0.0.bazel b/bazel/cargo/remote/BUILD.cfg-if-1.0.0.bazel index f3bd70dd..6408a6f8 100644 --- a/bazel/cargo/remote/BUILD.cfg-if-1.0.0.bazel +++ b/bazel/cargo/remote/BUILD.cfg-if-1.0.0.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -36,7 +37,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2018", rustc_flags = [ @@ -44,6 +44,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=cfg-if", "manual", ], version = "1.0.0", diff --git a/bazel/cargo/remote/BUILD.chrono-0.4.19.bazel b/bazel/cargo/remote/BUILD.chrono-0.4.19.bazel index d1a4543d..60a69912 100644 --- a/bazel/cargo/remote/BUILD.chrono-0.4.19.bazel +++ b/bazel/cargo/remote/BUILD.chrono-0.4.19.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -49,7 +50,6 @@ rust_library( "winapi", ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -57,23 +57,17 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=chrono", "manual", ], version = "0.4.19", # buildifier: leave-alone deps = [ - "@raze__libc__0_2_86//:libc", + "@raze__libc__0_2_116//:libc", "@raze__num_integer__0_1_44//:num_integer", "@raze__num_traits__0_2_14//:num_traits", "@raze__time__0_1_43//:time", ] + selects.with_or({ - # cfg(all(target_arch = "wasm32", not(any(target_os = "emscripten", target_os = "wasi")))) - ( - "@rules_rust//rust/platform:wasm32-unknown-unknown", - ): [ - ], - "//conditions:default": [], - }) + selects.with_or({ # cfg(windows) ( "@rules_rust//rust/platform:i686-pc-windows-msvc", diff --git a/bazel/cargo/remote/BUILD.getrandom-0.2.2.bazel b/bazel/cargo/remote/BUILD.getrandom-0.2.4.bazel similarity index 51% rename from bazel/cargo/remote/BUILD.getrandom-0.2.2.bazel rename to bazel/cargo/remote/BUILD.getrandom-0.2.4.bazel index 50bbff0f..6c9a40e2 100644 --- a/bazel/cargo/remote/BUILD.getrandom-0.2.2.bazel +++ b/bazel/cargo/remote/BUILD.getrandom-0.2.4.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,70 +30,6 @@ licenses([ ]) # Generated Targets -# buildifier: disable=load-on-top -load( - "@rules_rust//cargo:cargo_build_script.bzl", - "cargo_build_script", -) - -cargo_build_script( - name = "getrandom_build_script", - srcs = glob(["**/*.rs"]), - build_script_env = { - }, - crate_features = [ - ], - crate_root = "build.rs", - data = glob(["**"]), - edition = "2018", - rustc_flags = [ - "--cap-lints=allow", - ], - tags = [ - "cargo-raze", - "manual", - ], - version = "0.2.2", - visibility = ["//visibility:private"], - deps = [ - ] + selects.with_or({ - # cfg(all(target_arch = "wasm32", target_os = "unknown")) - ( - "@rules_rust//rust/platform:wasm32-unknown-unknown", - ): [ - ], - "//conditions:default": [], - }) + selects.with_or({ - # cfg(target_os = "wasi") - ( - "@rules_rust//rust/platform:wasm32-wasi", - ): [ - ], - "//conditions:default": [], - }) + selects.with_or({ - # cfg(unix) - ( - "@rules_rust//rust/platform:aarch64-apple-darwin", - "@rules_rust//rust/platform:aarch64-apple-ios", - "@rules_rust//rust/platform:aarch64-linux-android", - "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", - "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", - "@rules_rust//rust/platform:i686-apple-darwin", - "@rules_rust//rust/platform:i686-linux-android", - "@rules_rust//rust/platform:i686-unknown-freebsd", - "@rules_rust//rust/platform:i686-unknown-linux-gnu", - "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", - "@rules_rust//rust/platform:s390x-unknown-linux-gnu", - "@rules_rust//rust/platform:x86_64-apple-darwin", - "@rules_rust//rust/platform:x86_64-apple-ios", - "@rules_rust//rust/platform:x86_64-linux-android", - "@rules_rust//rust/platform:x86_64-unknown-freebsd", - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", - ): [ - ], - "//conditions:default": [], - }), -) # Unsupported target "mod" with type "bench" omitted @@ -104,7 +41,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2018", rustc_flags = [ @@ -112,21 +48,14 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=getrandom", "manual", ], - version = "0.2.2", + version = "0.2.4", # buildifier: leave-alone deps = [ - ":getrandom_build_script", "@raze__cfg_if__1_0_0//:cfg_if", ] + selects.with_or({ - # cfg(all(target_arch = "wasm32", target_os = "unknown")) - ( - "@rules_rust//rust/platform:wasm32-unknown-unknown", - ): [ - ], - "//conditions:default": [], - }) + selects.with_or({ # cfg(target_os = "wasi") ( "@rules_rust//rust/platform:wasm32-wasi", @@ -137,24 +66,24 @@ rust_library( }) + selects.with_or({ # cfg(unix) ( + "@rules_rust//rust/platform:i686-apple-darwin", + "@rules_rust//rust/platform:i686-unknown-linux-gnu", + "@rules_rust//rust/platform:x86_64-apple-darwin", + "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", "@rules_rust//rust/platform:aarch64-apple-darwin", "@rules_rust//rust/platform:aarch64-apple-ios", "@rules_rust//rust/platform:aarch64-linux-android", "@rules_rust//rust/platform:aarch64-unknown-linux-gnu", "@rules_rust//rust/platform:arm-unknown-linux-gnueabi", - "@rules_rust//rust/platform:i686-apple-darwin", "@rules_rust//rust/platform:i686-linux-android", "@rules_rust//rust/platform:i686-unknown-freebsd", - "@rules_rust//rust/platform:i686-unknown-linux-gnu", "@rules_rust//rust/platform:powerpc-unknown-linux-gnu", "@rules_rust//rust/platform:s390x-unknown-linux-gnu", - "@rules_rust//rust/platform:x86_64-apple-darwin", "@rules_rust//rust/platform:x86_64-apple-ios", "@rules_rust//rust/platform:x86_64-linux-android", "@rules_rust//rust/platform:x86_64-unknown-freebsd", - "@rules_rust//rust/platform:x86_64-unknown-linux-gnu", ): [ - "@raze__libc__0_2_86//:libc", + "@raze__libc__0_2_116//:libc", ], "//conditions:default": [], }), diff --git a/bazel/cargo/remote/BUILD.hashbrown-0.9.1.bazel b/bazel/cargo/remote/BUILD.hashbrown-0.12.0.bazel similarity index 83% rename from bazel/cargo/remote/BUILD.hashbrown-0.9.1.bazel rename to bazel/cargo/remote/BUILD.hashbrown-0.12.0.bazel index 72fbe248..7624fceb 100644 --- a/bazel/cargo/remote/BUILD.hashbrown-0.9.1.bazel +++ b/bazel/cargo/remote/BUILD.hashbrown-0.12.0.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -32,6 +33,8 @@ licenses([ # Unsupported target "bench" with type "bench" omitted +# Unsupported target "insert_unique_unchecked" with type "bench" omitted + rust_library( name = "hashbrown", srcs = glob(["**/*.rs"]), @@ -41,20 +44,20 @@ rust_library( "inline-more", ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], - edition = "2018", + edition = "2021", rustc_flags = [ "--cap-lints=allow", ], tags = [ "cargo-raze", + "crate-name=hashbrown", "manual", ], - version = "0.9.1", + version = "0.12.0", # buildifier: leave-alone deps = [ - "@raze__ahash__0_4_7//:ahash", + "@raze__ahash__0_7_6//:ahash", ], ) diff --git a/bazel/cargo/remote/BUILD.libc-0.2.86.bazel b/bazel/cargo/remote/BUILD.libc-0.2.116.bazel similarity index 90% rename from bazel/cargo/remote/BUILD.libc-0.2.86.bazel rename to bazel/cargo/remote/BUILD.libc-0.2.116.bazel index f9726919..6c50ad60 100644 --- a/bazel/cargo/remote/BUILD.libc-0.2.86.bazel +++ b/bazel/cargo/remote/BUILD.libc-0.2.116.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -54,7 +56,7 @@ cargo_build_script( "cargo-raze", "manual", ], - version = "0.2.86", + version = "0.2.116", visibility = ["//visibility:private"], deps = [ ], @@ -68,7 +70,6 @@ rust_library( "std", ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -76,9 +77,10 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=libc", "manual", ], - version = "0.2.86", + version = "0.2.116", # buildifier: leave-alone deps = [ ":libc_build_script", diff --git a/bazel/cargo/remote/BUILD.log-0.4.14.bazel b/bazel/cargo/remote/BUILD.log-0.4.14.bazel index 2946014f..3fc05989 100644 --- a/bazel/cargo/remote/BUILD.log-0.4.14.bazel +++ b/bazel/cargo/remote/BUILD.log-0.4.14.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -66,7 +68,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -74,6 +75,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=log", "manual", ], version = "0.4.14", diff --git a/bazel/cargo/remote/BUILD.num-integer-0.1.44.bazel b/bazel/cargo/remote/BUILD.num-integer-0.1.44.bazel index b2a2a986..2443ab89 100644 --- a/bazel/cargo/remote/BUILD.num-integer-0.1.44.bazel +++ b/bazel/cargo/remote/BUILD.num-integer-0.1.44.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -71,7 +73,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -79,6 +80,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=num-integer", "manual", ], version = "0.1.44", diff --git a/bazel/cargo/remote/BUILD.num-traits-0.2.14.bazel b/bazel/cargo/remote/BUILD.num-traits-0.2.14.bazel index debef725..46e7d19b 100644 --- a/bazel/cargo/remote/BUILD.num-traits-0.2.14.bazel +++ b/bazel/cargo/remote/BUILD.num-traits-0.2.14.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -65,7 +67,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -73,6 +74,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=num-traits", "manual", ], version = "0.2.14", diff --git a/bazel/cargo/remote/BUILD.once_cell-1.9.0.bazel b/bazel/cargo/remote/BUILD.once_cell-1.9.0.bazel new file mode 100644 index 00000000..68eb1d8d --- /dev/null +++ b/bazel/cargo/remote/BUILD.once_cell-1.9.0.bazel @@ -0,0 +1,72 @@ +""" +@generated +cargo-raze crate build file. + +DO NOT EDIT! Replaced on runs of cargo-raze +""" + +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + +# buildifier: disable=load +load( + "@rules_rust//rust:defs.bzl", + "rust_binary", + "rust_library", + "rust_proc_macro", + "rust_test", +) + +package(default_visibility = [ + # Public for visibility by "@raze__crate__version//" targets. + # + # Prefer access through "//bazel/cargo", which limits external + # visibility to explicit Cargo.toml dependencies. + "//visibility:public", +]) + +licenses([ + "notice", # MIT from expression "MIT OR Apache-2.0" +]) + +# Generated Targets + +# Unsupported target "bench" with type "example" omitted + +# Unsupported target "bench_acquire" with type "example" omitted + +# Unsupported target "bench_vs_lazy_static" with type "example" omitted + +# Unsupported target "lazy_static" with type "example" omitted + +# Unsupported target "reentrant_init_deadlocks" with type "example" omitted + +# Unsupported target "regex" with type "example" omitted + +# Unsupported target "test_synchronization" with type "example" omitted + +rust_library( + name = "once_cell", + srcs = glob(["**/*.rs"]), + crate_features = [ + "alloc", + "race", + ], + crate_root = "src/lib.rs", + data = [], + edition = "2018", + rustc_flags = [ + "--cap-lints=allow", + ], + tags = [ + "cargo-raze", + "crate-name=once_cell", + "manual", + ], + version = "1.9.0", + # buildifier: leave-alone + deps = [ + ], +) + +# Unsupported target "it" with type "test" omitted diff --git a/bazel/cargo/remote/BUILD.time-0.1.43.bazel b/bazel/cargo/remote/BUILD.time-0.1.43.bazel index 123cc612..f7699e88 100644 --- a/bazel/cargo/remote/BUILD.time-0.1.43.bazel +++ b/bazel/cargo/remote/BUILD.time-0.1.43.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -38,7 +39,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -46,12 +46,13 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=time", "manual", ], version = "0.1.43", # buildifier: leave-alone deps = [ - "@raze__libc__0_2_86//:libc", + "@raze__libc__0_2_116//:libc", ] + selects.with_or({ # cfg(windows) ( diff --git a/bazel/cargo/remote/BUILD.ahash-0.4.7.bazel b/bazel/cargo/remote/BUILD.version_check-0.9.4.bazel similarity index 69% rename from bazel/cargo/remote/BUILD.ahash-0.4.7.bazel rename to bazel/cargo/remote/BUILD.version_check-0.9.4.bazel index 3646eb2d..5c8bf925 100644 --- a/bazel/cargo/remote/BUILD.ahash-0.4.7.bazel +++ b/bazel/cargo/remote/BUILD.version_check-0.9.4.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -30,34 +31,24 @@ licenses([ # Generated Targets -# Unsupported target "ahash" with type "bench" omitted - -# Unsupported target "map" with type "bench" omitted - rust_library( - name = "ahash", + name = "version_check", srcs = glob(["**/*.rs"]), crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], - edition = "2018", + edition = "2015", rustc_flags = [ "--cap-lints=allow", ], tags = [ "cargo-raze", + "crate-name=version_check", "manual", ], - version = "0.4.7", + version = "0.9.4", # buildifier: leave-alone deps = [ ], ) - -# Unsupported target "bench" with type "test" omitted - -# Unsupported target "map_tests" with type "test" omitted - -# Unsupported target "nopanic" with type "test" omitted diff --git a/bazel/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel b/bazel/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel index dc3e3fef..9a4447f6 100644 --- a/bazel/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel +++ b/bazel/cargo/remote/BUILD.wasi-0.10.2+wasi-snapshot-preview1.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -38,7 +39,6 @@ rust_library( "std", ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2018", rustc_flags = [ @@ -46,6 +46,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=wasi", "manual", ], version = "0.10.2+wasi-snapshot-preview1", diff --git a/bazel/cargo/remote/BUILD.winapi-0.3.9.bazel b/bazel/cargo/remote/BUILD.winapi-0.3.9.bazel index f4a8eeed..690f1920 100644 --- a/bazel/cargo/remote/BUILD.winapi-0.3.9.bazel +++ b/bazel/cargo/remote/BUILD.winapi-0.3.9.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -78,7 +80,6 @@ rust_library( "timezoneapi", ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -86,6 +87,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=winapi", "manual", ], version = "0.3.9", diff --git a/bazel/cargo/remote/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel b/bazel/cargo/remote/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel index 7882e51b..f9649644 100644 --- a/bazel/cargo/remote/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel +++ b/bazel/cargo/remote/BUILD.winapi-i686-pc-windows-gnu-0.4.0.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -64,7 +66,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -72,6 +73,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=winapi-i686-pc-windows-gnu", "manual", ], version = "0.4.0", diff --git a/bazel/cargo/remote/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel b/bazel/cargo/remote/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel index b061a534..8274514d 100644 --- a/bazel/cargo/remote/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel +++ b/bazel/cargo/remote/BUILD.winapi-x86_64-pc-windows-gnu-0.4.0.bazel @@ -5,17 +5,18 @@ cargo-raze crate build file. DO NOT EDIT! Replaced on runs of cargo-raze """ +# buildifier: disable=load +load("@bazel_skylib//lib:selects.bzl", "selects") + # buildifier: disable=load load( - "@rules_rust//rust:rust.bzl", + "@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", + "rust_proc_macro", "rust_test", ) -# buildifier: disable=load -load("@bazel_skylib//lib:selects.bzl", "selects") - package(default_visibility = [ # Public for visibility by "@raze__crate__version//" targets. # @@ -29,6 +30,7 @@ licenses([ ]) # Generated Targets +# buildifier: disable=out-of-order-load # buildifier: disable=load-on-top load( "@rules_rust//cargo:cargo_build_script.bzl", @@ -64,7 +66,6 @@ rust_library( crate_features = [ ], crate_root = "src/lib.rs", - crate_type = "lib", data = [], edition = "2015", rustc_flags = [ @@ -72,6 +73,7 @@ rust_library( ], tags = [ "cargo-raze", + "crate-name=winapi-x86_64-pc-windows-gnu", "manual", ], version = "0.4.0", diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 2e780b96..ce3ead96 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -13,11 +13,13 @@ # limitations under the License. load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") def proxy_wasm_rust_sdk_repositories(): - http_archive( + maybe( + http_archive, name = "rules_rust", - sha256 = "f2d9f804e1a8042a41ad41e1aeeca55ad0fc2d294ecd52e34ef8c63f7ce350fd", - strip_prefix = "rules_rust-3b02397bde43b1eeee1528227ceb3da6c6bdadd6", - url = "https://github.com/bazelbuild/rules_rust/archive/3b02397bde43b1eeee1528227ceb3da6c6bdadd6.tar.gz", + sha256 = "6c26af1bb98276917fcf29ea942615ab375cf9d3c52f15c27fdd176ced3ee906", + strip_prefix = "rules_rust-b3ddf6f096887b757ab1a661662a95d6b2699fa7", + url = "https://github.com/bazelbuild/rules_rust/archive/b3ddf6f096887b757ab1a661662a95d6b2699fa7.tar.gz", ) diff --git a/examples/BUILD b/examples/BUILD index a5aec0a4..d2bd0764 100644 --- a/examples/BUILD +++ b/examples/BUILD @@ -1,4 +1,4 @@ -load("@rules_rust//rust:rust.bzl", "rust_binary") +load("@rules_rust//rust:defs.bzl", "rust_binary") rust_binary( name = "hello_world", diff --git a/examples/http_auth_random.rs b/examples/http_auth_random.rs index b9e747c6..732b2f5f 100644 --- a/examples/http_auth_random.rs +++ b/examples/http_auth_random.rs @@ -26,7 +26,7 @@ pub fn _start() { struct HttpAuthRandom; impl HttpContext for HttpAuthRandom { - fn on_http_request_headers(&mut self, _: usize) -> Action { + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { self.dispatch_http_call( "httpbin", vec![ @@ -42,7 +42,7 @@ impl HttpContext for HttpAuthRandom { Action::Pause } - fn on_http_response_headers(&mut self, _: usize) -> Action { + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { self.set_http_response_header("Powered-By", Some("proxy-wasm")); Action::Continue } diff --git a/examples/http_body.rs b/examples/http_body.rs index ff884648..41eec096 100644 --- a/examples/http_body.rs +++ b/examples/http_body.rs @@ -40,7 +40,7 @@ struct HttpBody; impl Context for HttpBody {} impl HttpContext for HttpBody { - fn on_http_response_headers(&mut self, _: usize) -> Action { + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { // If there is a Content-Length header and we change the length of // the body later, then clients will break. So remove it. // We must do this here, because once we exit this function we diff --git a/examples/http_config.rs b/examples/http_config.rs index d912ae03..790c259c 100644 --- a/examples/http_config.rs +++ b/examples/http_config.rs @@ -32,7 +32,7 @@ struct HttpConfigHeader { impl Context for HttpConfigHeader {} impl HttpContext for HttpConfigHeader { - fn on_http_response_headers(&mut self, _: usize) -> Action { + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { self.add_http_response_header("custom-header", self.header_content.as_str()); Action::Continue } @@ -46,7 +46,7 @@ impl Context for HttpConfigHeaderRoot {} impl RootContext for HttpConfigHeaderRoot { fn on_configure(&mut self, _: usize) -> bool { - if let Some(config_bytes) = self.get_configuration() { + if let Some(config_bytes) = self.get_plugin_configuration() { self.header_content = String::from_utf8(config_bytes).unwrap() } true diff --git a/examples/http_headers.rs b/examples/http_headers.rs index b0f1a745..0af2b528 100644 --- a/examples/http_headers.rs +++ b/examples/http_headers.rs @@ -43,7 +43,7 @@ struct HttpHeaders { impl Context for HttpHeaders {} impl HttpContext for HttpHeaders { - fn on_http_request_headers(&mut self, _: usize) -> Action { + fn on_http_request_headers(&mut self, _: usize, _: bool) -> Action { for (name, value) in &self.get_http_request_headers() { trace!("#{} -> {}: {}", self.context_id, name, value); } @@ -61,7 +61,7 @@ impl HttpContext for HttpHeaders { } } - fn on_http_response_headers(&mut self, _: usize) -> Action { + fn on_http_response_headers(&mut self, _: usize, _: bool) -> Action { for (name, value) in &self.get_http_response_headers() { trace!("#{} <- {}: {}", self.context_id, name, value); } diff --git a/src/allocator.rs b/src/allocator.rs index c7e1199c..e84202b6 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -12,6 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::mem::MaybeUninit; + #[cfg(feature = "wee-alloc")] #[global_allocator] static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; @@ -22,7 +24,7 @@ static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; )] #[no_mangle] pub extern "C" fn proxy_on_memory_allocate(size: usize) -> *mut u8 { - let mut vec: Vec = Vec::with_capacity(size); + let mut vec: Vec> = Vec::with_capacity(size); unsafe { vec.set_len(size); } diff --git a/src/dispatcher.rs b/src/dispatcher.rs index d9c9d491..43db79b8 100644 --- a/src/dispatcher.rs +++ b/src/dispatcher.rs @@ -38,6 +38,14 @@ pub(crate) fn register_callout(token_id: u32) { DISPATCHER.with(|dispatcher| dispatcher.register_callout(token_id)); } +pub(crate) fn register_grpc_callout(token_id: u32) { + DISPATCHER.with(|dispatcher| dispatcher.register_grpc_callout(token_id)); +} + +pub(crate) fn register_grpc_stream(token_id: u32) { + DISPATCHER.with(|dispatcher| dispatcher.register_grpc_stream(token_id)); +} + struct NoopRoot; impl Context for NoopRoot {} @@ -52,6 +60,8 @@ struct Dispatcher { http_streams: RefCell>>, active_id: Cell, callouts: RefCell>, + grpc_callouts: RefCell>, + grpc_streams: RefCell>, } impl Dispatcher { @@ -65,6 +75,8 @@ impl Dispatcher { http_streams: RefCell::new(HashMap::new()), active_id: Cell::new(0), callouts: RefCell::new(HashMap::new()), + grpc_callouts: RefCell::new(HashMap::new()), + grpc_streams: RefCell::new(HashMap::new()), } } @@ -91,6 +103,28 @@ impl Dispatcher { } } + fn register_grpc_stream(&self, token_id: u32) { + if self + .grpc_streams + .borrow_mut() + .insert(token_id, self.active_id.get()) + .is_some() + { + panic!("duplicate token_id") + } + } + + fn register_grpc_callout(&self, token_id: u32) { + if self + .grpc_callouts + .borrow_mut() + .insert(token_id, self.active_id.get()) + .is_some() + { + panic!("duplicate token_id") + } + } + fn create_root_context(&self, context_id: u32) { let new_context = match self.new_root.get() { Some(f) => f(context_id), @@ -290,10 +324,15 @@ impl Dispatcher { } } - fn on_http_request_headers(&self, context_id: u32, num_headers: usize) -> Action { + fn on_http_request_headers( + &self, + context_id: u32, + num_headers: usize, + end_of_stream: bool, + ) -> Action { if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { self.active_id.set(context_id); - http_stream.on_http_request_headers(num_headers) + http_stream.on_http_request_headers(num_headers, end_of_stream) } else { panic!("invalid context_id") } @@ -322,10 +361,15 @@ impl Dispatcher { } } - fn on_http_response_headers(&self, context_id: u32, num_headers: usize) -> Action { + fn on_http_response_headers( + &self, + context_id: u32, + num_headers: usize, + end_of_stream: bool, + ) -> Action { if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { self.active_id.set(context_id); - http_stream.on_http_response_headers(num_headers) + http_stream.on_http_response_headers(num_headers, end_of_stream) } else { panic!("invalid context_id") } @@ -381,6 +425,119 @@ impl Dispatcher { root.on_http_call_response(token_id, num_headers, body_size, num_trailers) } } + + fn on_grpc_receive_initial_metadata(&self, token_id: u32, headers: u32) { + let context_id = *self + .grpc_streams + .borrow_mut() + .get(&token_id) + .expect("invalid token_id"); + + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_stream_initial_metadata(token_id, headers); + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_stream_initial_metadata(token_id, headers); + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_stream_initial_metadata(token_id, headers); + } + } + + fn on_grpc_receive(&self, token_id: u32, response_size: usize) { + if let Some(context_id) = self.grpc_callouts.borrow_mut().remove(&token_id) { + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_call_response(token_id, 0, response_size); + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_call_response(token_id, 0, response_size); + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_call_response(token_id, 0, response_size); + } + } else if let Some(context_id) = self.grpc_streams.borrow_mut().get(&token_id) { + let context_id = *context_id; + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_stream_message(token_id, response_size); + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_stream_message(token_id, response_size); + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_stream_message(token_id, response_size); + } + } else { + panic!("invalid token_id") + } + } + + fn on_grpc_receive_trailing_metadata(&self, token_id: u32, trailers: u32) { + let context_id = *self + .grpc_streams + .borrow_mut() + .get(&token_id) + .expect("invalid token_id"); + + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_stream_trailing_metadata(token_id, trailers); + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_stream_trailing_metadata(token_id, trailers); + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_stream_trailing_metadata(token_id, trailers); + } + } + + fn on_grpc_close(&self, token_id: u32, status_code: u32) { + if let Some(context_id) = self.grpc_callouts.borrow_mut().remove(&token_id) { + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_call_response(token_id, status_code, 0); + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_call_response(token_id, status_code, 0); + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_call_response(token_id, status_code, 0); + } + } else if let Some(context_id) = self.grpc_streams.borrow_mut().remove(&token_id) { + if let Some(http_stream) = self.http_streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + http_stream.on_grpc_stream_close(token_id, status_code) + } else if let Some(stream) = self.streams.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + stream.on_grpc_stream_close(token_id, status_code) + } else if let Some(root) = self.roots.borrow_mut().get_mut(&context_id) { + self.active_id.set(context_id); + hostcalls::set_effective_context(context_id).unwrap(); + root.on_grpc_stream_close(token_id, status_code) + } + } else { + panic!("invalid token_id") + } + } } #[no_mangle] @@ -458,8 +615,14 @@ pub extern "C" fn proxy_on_upstream_connection_close(context_id: u32, peer_type: } #[no_mangle] -pub extern "C" fn proxy_on_request_headers(context_id: u32, num_headers: usize) -> Action { - DISPATCHER.with(|dispatcher| dispatcher.on_http_request_headers(context_id, num_headers)) +pub extern "C" fn proxy_on_request_headers( + context_id: u32, + num_headers: usize, + end_of_stream: bool, +) -> Action { + DISPATCHER.with(|dispatcher| { + dispatcher.on_http_request_headers(context_id, num_headers, end_of_stream) + }) } #[no_mangle] @@ -478,8 +641,14 @@ pub extern "C" fn proxy_on_request_trailers(context_id: u32, num_trailers: usize } #[no_mangle] -pub extern "C" fn proxy_on_response_headers(context_id: u32, num_headers: usize) -> Action { - DISPATCHER.with(|dispatcher| dispatcher.on_http_response_headers(context_id, num_headers)) +pub extern "C" fn proxy_on_response_headers( + context_id: u32, + num_headers: usize, + end_of_stream: bool, +) -> Action { + DISPATCHER.with(|dispatcher| { + dispatcher.on_http_response_headers(context_id, num_headers, end_of_stream) + }) } #[no_mangle] @@ -509,3 +678,31 @@ pub extern "C" fn proxy_on_http_call_response( dispatcher.on_http_call_response(token_id, num_headers, body_size, num_trailers) }) } + +#[no_mangle] +pub extern "C" fn proxy_on_grpc_receive_initial_metadata( + _context_id: u32, + token_id: u32, + headers: u32, +) { + DISPATCHER.with(|dispatcher| dispatcher.on_grpc_receive_initial_metadata(token_id, headers)) +} + +#[no_mangle] +pub extern "C" fn proxy_on_grpc_receive(_context_id: u32, token_id: u32, response_size: usize) { + DISPATCHER.with(|dispatcher| dispatcher.on_grpc_receive(token_id, response_size)) +} + +#[no_mangle] +pub extern "C" fn proxy_on_grpc_receive_trailing_metadata( + _context_id: u32, + token_id: u32, + trailers: u32, +) { + DISPATCHER.with(|dispatcher| dispatcher.on_grpc_receive_trailing_metadata(token_id, trailers)) +} + +#[no_mangle] +pub extern "C" fn proxy_on_grpc_close(_context_id: u32, token_id: u32, status_code: u32) { + DISPATCHER.with(|dispatcher| dispatcher.on_grpc_close(token_id, status_code)) +} diff --git a/src/hostcalls.rs b/src/hostcalls.rs index 8f37f2ae..93c77840 100644 --- a/src/hostcalls.rs +++ b/src/hostcalls.rs @@ -31,55 +31,41 @@ pub fn log(level: LogLevel, message: &str) -> Result<(), Status> { } extern "C" { - fn proxy_get_current_time_nanoseconds(return_time: *mut u64) -> Status; + fn proxy_get_log_level(return_level: *mut LogLevel) -> Status; } -pub fn get_current_time() -> Result { - let mut return_time: u64 = 0; +pub fn get_log_level() -> Result { + let mut return_level: LogLevel = LogLevel::Trace; unsafe { - match proxy_get_current_time_nanoseconds(&mut return_time) { - Status::Ok => Ok(UNIX_EPOCH + Duration::from_nanos(return_time)), + match proxy_get_log_level(&mut return_level) { + Status::Ok => Ok(return_level), status => panic!("unexpected status: {}", status as u32), } } } extern "C" { - fn proxy_set_tick_period_milliseconds(period: u32) -> Status; + fn proxy_get_current_time_nanoseconds(return_time: *mut u64) -> Status; } -pub fn set_tick_period(period: Duration) -> Result<(), Status> { +pub fn get_current_time() -> Result { + let mut return_time: u64 = 0; unsafe { - match proxy_set_tick_period_milliseconds(period.as_millis() as u32) { - Status::Ok => Ok(()), + match proxy_get_current_time_nanoseconds(&mut return_time) { + Status::Ok => Ok(UNIX_EPOCH + Duration::from_nanos(return_time)), status => panic!("unexpected status: {}", status as u32), } } } extern "C" { - fn proxy_get_configuration( - return_buffer_data: *mut *mut u8, - return_buffer_size: *mut usize, - ) -> Status; + fn proxy_set_tick_period_milliseconds(period: u32) -> Status; } -pub fn get_configuration() -> Result, Status> { - let mut return_data: *mut u8 = null_mut(); - let mut return_size: usize = 0; +pub fn set_tick_period(period: Duration) -> Result<(), Status> { unsafe { - match proxy_get_configuration(&mut return_data, &mut return_size) { - Status::Ok => { - if !return_data.is_null() { - Ok(Some(Vec::from_raw_parts( - return_data, - return_size, - return_size, - ))) - } else { - Ok(None) - } - } + match proxy_set_tick_period_milliseconds(period.as_millis() as u32) { + Status::Ok => Ok(()), status => panic!("unexpected status: {}", status as u32), } } @@ -177,6 +163,24 @@ pub fn get_map(map_type: MapType) -> Result, Status> { } } +pub fn get_map_bytes(map_type: MapType) -> Result, Status> { + unsafe { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + match proxy_get_header_map_pairs(map_type, &mut return_data, &mut return_size) { + Status::Ok => { + if !return_data.is_null() { + let serialized_map = Vec::from_raw_parts(return_data, return_size, return_size); + Ok(utils::deserialize_map_bytes(&serialized_map)) + } else { + Ok(Vec::new()) + } + } + status => panic!("unexpected status: {}", status as u32), + } + } +} + extern "C" { fn proxy_set_header_map_pairs( map_type: MapType, @@ -195,6 +199,16 @@ pub fn set_map(map_type: MapType, map: Vec<(&str, &str)>) -> Result<(), Status> } } +pub fn set_map_bytes(map_type: MapType, map: Vec<(&str, &[u8])>) -> Result<(), Status> { + let serialized_map = utils::serialize_map_bytes(map); + unsafe { + match proxy_set_header_map_pairs(map_type, serialized_map.as_ptr(), serialized_map.len()) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + extern "C" { fn proxy_get_header_map_value( map_type: MapType, @@ -230,6 +244,35 @@ pub fn get_map_value(map_type: MapType, key: &str) -> Result, Sta Ok(None) } } + Status::NotFound => Ok(None), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn get_map_value_bytes(map_type: MapType, key: &str) -> Result, Status> { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + unsafe { + match proxy_get_header_map_value( + map_type, + key.as_ptr(), + key.len(), + &mut return_data, + &mut return_size, + ) { + Status::Ok => { + if !return_data.is_null() { + Ok(Some(Vec::from_raw_parts( + return_data, + return_size, + return_size, + ))) + } else { + Ok(None) + } + } + Status::NotFound => Ok(None), status => panic!("unexpected status: {}", status as u32), } } @@ -275,6 +318,32 @@ pub fn set_map_value(map_type: MapType, key: &str, value: Option<&str>) -> Resul } } +pub fn set_map_value_bytes( + map_type: MapType, + key: &str, + value: Option<&[u8]>, +) -> Result<(), Status> { + unsafe { + if let Some(value) = value { + match proxy_replace_header_map_value( + map_type, + key.as_ptr(), + key.len(), + value.as_ptr(), + value.len(), + ) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } else { + match proxy_remove_header_map_value(map_type, key.as_ptr(), key.len()) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } + } +} + extern "C" { fn proxy_add_header_map_value( map_type: MapType, @@ -300,6 +369,21 @@ pub fn add_map_value(map_type: MapType, key: &str, value: &str) -> Result<(), St } } +pub fn add_map_value_bytes(map_type: MapType, key: &str, value: &[u8]) -> Result<(), Status> { + unsafe { + match proxy_add_header_map_value( + map_type, + key.as_ptr(), + key.len(), + value.as_ptr(), + value.len(), + ) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + extern "C" { fn proxy_get_property( path_data: *const u8, @@ -528,12 +612,39 @@ pub fn enqueue_shared_queue(queue_id: u32, value: Option<&[u8]>) -> Result<(), S } extern "C" { - fn proxy_continue_request() -> Status; + fn proxy_continue_stream(stream_type: StreamType) -> Status; +} + +pub fn resume_downstream() -> Result<(), Status> { + unsafe { + match proxy_continue_stream(StreamType::Downstream) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn resume_upstream() -> Result<(), Status> { + unsafe { + match proxy_continue_stream(StreamType::Upstream) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } } pub fn resume_http_request() -> Result<(), Status> { unsafe { - match proxy_continue_request() { + match proxy_continue_stream(StreamType::HttpRequest) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn resume_http_response() -> Result<(), Status> { + unsafe { + match proxy_continue_stream(StreamType::HttpResponse) { Status::Ok => Ok(()), status => panic!("unexpected status: {}", status as u32), } @@ -541,12 +652,38 @@ pub fn resume_http_request() -> Result<(), Status> { } extern "C" { - fn proxy_continue_response() -> Status; + fn proxy_close_stream(stream_type: StreamType) -> Status; } -pub fn resume_http_response() -> Result<(), Status> { +pub fn close_downstream() -> Result<(), Status> { + unsafe { + match proxy_close_stream(StreamType::Downstream) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} +pub fn close_upstream() -> Result<(), Status> { unsafe { - match proxy_continue_response() { + match proxy_close_stream(StreamType::Upstream) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn reset_http_request() -> Result<(), Status> { + unsafe { + match proxy_close_stream(StreamType::HttpRequest) { + Status::Ok => Ok(()), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn reset_http_response() -> Result<(), Status> { + unsafe { + match proxy_close_stream(StreamType::HttpResponse) { Status::Ok => Ok(()), status => panic!("unexpected status: {}", status as u32), } @@ -589,19 +726,6 @@ pub fn send_http_response( } } -extern "C" { - fn proxy_clear_route_cache() -> Status; -} - -pub fn clear_http_route_cache() -> Result<(), Status> { - unsafe { - match proxy_clear_route_cache() { - Status::Ok => Ok(()), - status => panic!("unexpected status: {}", status as u32), - } - } -} - extern "C" { fn proxy_http_call( upstream_data: *const u8, @@ -651,6 +775,207 @@ pub fn dispatch_http_call( } } +extern "C" { + fn proxy_grpc_call( + upstream_data: *const u8, + upstream_size: usize, + service_name_data: *const u8, + service_name_size: usize, + method_name_data: *const u8, + method_name_size: usize, + initial_metadata_data: *const u8, + initial_metadata_size: usize, + message_data_data: *const u8, + message_data_size: usize, + timeout: u32, + return_callout_id: *mut u32, + ) -> Status; +} + +pub fn dispatch_grpc_call( + upstream_name: &str, + service_name: &str, + method_name: &str, + initial_metadata: Vec<(&str, &[u8])>, + message: Option<&[u8]>, + timeout: Duration, +) -> Result { + let mut return_callout_id = 0; + let serialized_initial_metadata = utils::serialize_map_bytes(initial_metadata); + unsafe { + match proxy_grpc_call( + upstream_name.as_ptr(), + upstream_name.len(), + service_name.as_ptr(), + service_name.len(), + method_name.as_ptr(), + method_name.len(), + serialized_initial_metadata.as_ptr(), + serialized_initial_metadata.len(), + message.map_or(null(), |message| message.as_ptr()), + message.map_or(0, |message| message.len()), + timeout.as_millis() as u32, + &mut return_callout_id, + ) { + Status::Ok => { + dispatcher::register_grpc_callout(return_callout_id); + Ok(return_callout_id) + } + Status::ParseFailure => Err(Status::ParseFailure), + Status::InternalFailure => Err(Status::InternalFailure), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +extern "C" { + fn proxy_grpc_stream( + upstream_data: *const u8, + upstream_size: usize, + service_name_data: *const u8, + service_name_size: usize, + method_name_data: *const u8, + method_name_size: usize, + initial_metadata_data: *const u8, + initial_metadata_size: usize, + return_stream_id: *mut u32, + ) -> Status; +} + +pub fn open_grpc_stream( + upstream_name: &str, + service_name: &str, + method_name: &str, + initial_metadata: Vec<(&str, &[u8])>, +) -> Result { + let mut return_stream_id = 0; + let serialized_initial_metadata = utils::serialize_map_bytes(initial_metadata); + unsafe { + match proxy_grpc_stream( + upstream_name.as_ptr(), + upstream_name.len(), + service_name.as_ptr(), + service_name.len(), + method_name.as_ptr(), + method_name.len(), + serialized_initial_metadata.as_ptr(), + serialized_initial_metadata.len(), + &mut return_stream_id, + ) { + Status::Ok => { + dispatcher::register_grpc_stream(return_stream_id); + Ok(return_stream_id) + } + Status::ParseFailure => Err(Status::ParseFailure), + Status::InternalFailure => Err(Status::InternalFailure), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +extern "C" { + fn proxy_grpc_send( + token: u32, + message_ptr: *const u8, + message_len: usize, + end_stream: bool, + ) -> Status; +} + +pub fn send_grpc_stream_message( + token: u32, + message: Option<&[u8]>, + end_stream: bool, +) -> Result<(), Status> { + unsafe { + match proxy_grpc_send( + token, + message.map_or(null(), |message| message.as_ptr()), + message.map_or(0, |message| message.len()), + end_stream, + ) { + Status::Ok => Ok(()), + Status::BadArgument => Err(Status::BadArgument), + Status::NotFound => Err(Status::NotFound), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +extern "C" { + fn proxy_grpc_cancel(token_id: u32) -> Status; +} + +pub fn cancel_grpc_call(token_id: u32) -> Result<(), Status> { + unsafe { + match proxy_grpc_cancel(token_id) { + Status::Ok => Ok(()), + Status::NotFound => Err(Status::NotFound), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +pub fn cancel_grpc_stream(token_id: u32) -> Result<(), Status> { + unsafe { + match proxy_grpc_cancel(token_id) { + Status::Ok => Ok(()), + Status::NotFound => Err(Status::NotFound), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +extern "C" { + fn proxy_grpc_close(token_id: u32) -> Status; +} + +pub fn close_grpc_stream(token_id: u32) -> Result<(), Status> { + unsafe { + match proxy_grpc_close(token_id) { + Status::Ok => Ok(()), + Status::NotFound => Err(Status::NotFound), + status => panic!("unexpected status: {}", status as u32), + } + } +} + +extern "C" { + fn proxy_get_status( + return_code: *mut u32, + return_message_data: *mut *mut u8, + return_message_size: *mut usize, + ) -> Status; +} + +pub fn get_grpc_status() -> Result<(u32, Option), Status> { + let mut return_code: u32 = 0; + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + unsafe { + match proxy_get_status(&mut return_code, &mut return_data, &mut return_size) { + Status::Ok => { + if !return_data.is_null() { + Ok(( + return_code, + Some( + String::from_utf8(Vec::from_raw_parts( + return_data, + return_size, + return_size, + )) + .unwrap(), + ), + )) + } else { + Ok((return_code, None)) + } + } + status => panic!("unexpected status: {}", status as u32), + } + } +} + extern "C" { fn proxy_set_effective_context(context_id: u32) -> Status; } @@ -742,6 +1067,49 @@ pub fn increment_metric(metric_id: u32, offset: i64) -> Result<(), Status> { } } +extern "C" { + fn proxy_call_foreign_function( + function_name_data: *const u8, + function_name_size: usize, + arguments_data: *const u8, + arguments_size: usize, + results_data: *mut *mut u8, + results_size: *mut usize, + ) -> Status; +} + +pub fn call_foreign_function( + function_name: &str, + arguments: Option<&[u8]>, +) -> Result, Status> { + let mut return_data: *mut u8 = null_mut(); + let mut return_size: usize = 0; + unsafe { + match proxy_call_foreign_function( + function_name.as_ptr(), + function_name.len(), + arguments.map_or(null(), |arguments| arguments.as_ptr()), + arguments.map_or(0, |arguments| arguments.len()), + &mut return_data, + &mut return_size, + ) { + Status::Ok => { + if !return_data.is_null() { + Ok(Some(Vec::from_raw_parts( + return_data, + return_size, + return_size, + ))) + } else { + Ok(None) + } + } + Status::NotFound => Err(Status::NotFound), + status => panic!("unexpected status: {}", status as u32), + } + } +} + mod utils { use crate::types::Bytes; use std::convert::TryFrom; @@ -756,7 +1124,7 @@ mod utils { } let mut bytes: Bytes = Vec::with_capacity(size); for part in &path { - bytes.extend_from_slice(&part.as_bytes()); + bytes.extend_from_slice(part.as_bytes()); bytes.push(0); } bytes.pop(); @@ -775,9 +1143,29 @@ mod utils { bytes.extend_from_slice(&value.len().to_le_bytes()); } for (name, value) in &map { - bytes.extend_from_slice(&name.as_bytes()); + bytes.extend_from_slice(name.as_bytes()); + bytes.push(0); + bytes.extend_from_slice(value.as_bytes()); + bytes.push(0); + } + bytes + } + + pub(super) fn serialize_map_bytes(map: Vec<(&str, &[u8])>) -> Bytes { + let mut size: usize = 4; + for (name, value) in &map { + size += name.len() + value.len() + 10; + } + let mut bytes: Bytes = Vec::with_capacity(size); + bytes.extend_from_slice(&map.len().to_le_bytes()); + for (name, value) in &map { + bytes.extend_from_slice(&name.len().to_le_bytes()); + bytes.extend_from_slice(&value.len().to_le_bytes()); + } + for (name, value) in &map { + bytes.extend_from_slice(name.as_bytes()); bytes.push(0); - bytes.extend_from_slice(&value.as_bytes()); + bytes.extend_from_slice(value); bytes.push(0); } bytes @@ -806,4 +1194,25 @@ mod utils { } map } + + pub(super) fn deserialize_map_bytes(bytes: &[u8]) -> Vec<(String, Bytes)> { + let mut map = Vec::new(); + if bytes.is_empty() { + return map; + } + let size = u32::from_le_bytes(<[u8; 4]>::try_from(&bytes[0..4]).unwrap()) as usize; + let mut p = 4 + size * 8; + for n in 0..size { + let s = 4 + n * 8; + let size = u32::from_le_bytes(<[u8; 4]>::try_from(&bytes[s..s + 4]).unwrap()) as usize; + let key = bytes[p..p + size].to_vec(); + p += size + 1; + let size = + u32::from_le_bytes(<[u8; 4]>::try_from(&bytes[s + 4..s + 8]).unwrap()) as usize; + let value = bytes[p..p + size].to_vec(); + p += size + 1; + map.push((String::from_utf8(key).unwrap(), value)); + } + map + } } diff --git a/src/lib.rs b/src/lib.rs index cee98b72..fa8c7ca5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -37,4 +37,4 @@ pub fn set_http_context(callback: types::NewHttpContext) { } #[no_mangle] -pub extern "C" fn proxy_abi_version_0_1_0() {} +pub extern "C" fn proxy_abi_version_0_2_1() {} diff --git a/src/traits.rs b/src/traits.rs index 5b7fc4be..ef6206df 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -82,6 +82,18 @@ pub trait Context { hostcalls::get_map(MapType::HttpCallResponseHeaders).unwrap() } + fn get_http_call_response_headers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpCallResponseHeaders).unwrap() + } + + fn get_http_call_response_header(&self, name: &str) -> Option { + hostcalls::get_map_value(MapType::HttpCallResponseHeaders, name).unwrap() + } + + fn get_http_call_response_header_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpCallResponseHeaders, name).unwrap() + } + fn get_http_call_response_body(&self, start: usize, max_size: usize) -> Option { hostcalls::get_buffer(BufferType::HttpCallResponseBody, start, max_size).unwrap() } @@ -90,6 +102,110 @@ pub trait Context { hostcalls::get_map(MapType::HttpCallResponseTrailers).unwrap() } + fn get_http_call_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpCallResponseTrailers).unwrap() + } + + fn get_http_call_response_trailer(&self, name: &str) -> Option { + hostcalls::get_map_value(MapType::HttpCallResponseTrailers, name).unwrap() + } + + fn get_http_call_response_trailer_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpCallResponseTrailers, name).unwrap() + } + + fn dispatch_grpc_call( + &self, + upstream_name: &str, + service_name: &str, + method_name: &str, + initial_metadata: Vec<(&str, &[u8])>, + message: Option<&[u8]>, + timeout: Duration, + ) -> Result { + hostcalls::dispatch_grpc_call( + upstream_name, + service_name, + method_name, + initial_metadata, + message, + timeout, + ) + } + + fn on_grpc_call_response(&mut self, _token_id: u32, _status_code: u32, _response_size: usize) {} + + fn get_grpc_call_response_body(&self, start: usize, max_size: usize) -> Option { + hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() + } + + fn cancel_grpc_call(&self, token_id: u32) { + hostcalls::cancel_grpc_call(token_id).unwrap() + } + + fn open_grpc_stream( + &self, + cluster_name: &str, + service_name: &str, + method_name: &str, + initial_metadata: Vec<(&str, &[u8])>, + ) -> Result { + hostcalls::open_grpc_stream(cluster_name, service_name, method_name, initial_metadata) + } + + fn on_grpc_stream_initial_metadata(&mut self, _token_id: u32, _num_elements: u32) {} + + fn get_grpc_stream_initial_metadata(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::GrpcReceiveInitialMetadata).unwrap() + } + + fn get_grpc_stream_initial_metadata_value(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::GrpcReceiveInitialMetadata, name).unwrap() + } + + fn send_grpc_stream_message(&self, token_id: u32, message: Option<&[u8]>, end_stream: bool) { + hostcalls::send_grpc_stream_message(token_id, message, end_stream).unwrap() + } + + fn on_grpc_stream_message(&mut self, _token_id: u32, _message_size: usize) {} + + fn get_grpc_stream_message(&mut self, start: usize, max_size: usize) -> Option { + hostcalls::get_buffer(BufferType::GrpcReceiveBuffer, start, max_size).unwrap() + } + + fn on_grpc_stream_trailing_metadata(&mut self, _token_id: u32, _num_elements: u32) {} + + fn get_grpc_stream_trailing_metadata(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::GrpcReceiveTrailingMetadata).unwrap() + } + + fn get_grpc_stream_trailing_metadata_value(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::GrpcReceiveTrailingMetadata, name).unwrap() + } + + fn cancel_grpc_stream(&self, token_id: u32) { + hostcalls::cancel_grpc_stream(token_id).unwrap() + } + + fn close_grpc_stream(&self, token_id: u32) { + hostcalls::close_grpc_stream(token_id).unwrap() + } + + fn on_grpc_stream_close(&mut self, _token_id: u32, _status_code: u32) {} + + fn get_grpc_status(&self) -> (u32, Option) { + hostcalls::get_grpc_status().unwrap() + } + + fn call_foreign_function( + &self, + function_name: &str, + arguments: Option<&[u8]>, + ) -> Result, Status> { + hostcalls::call_foreign_function(function_name, arguments) + + } + fn on_done(&mut self) -> bool { true } @@ -104,12 +220,16 @@ pub trait RootContext: Context { true } + fn get_vm_configuration(&self) -> Option { + hostcalls::get_buffer(BufferType::VmConfiguration, 0, usize::MAX).unwrap() + } + fn on_configure(&mut self, _plugin_configuration_size: usize) -> bool { true } - fn get_configuration(&self) -> Option { - hostcalls::get_configuration().unwrap() + fn get_plugin_configuration(&self) -> Option { + hostcalls::get_buffer(BufferType::PluginConfiguration, 0, usize::MAX).unwrap() } fn set_tick_period(&self, period: Duration) { @@ -152,6 +272,14 @@ pub trait StreamContext: Context { hostcalls::set_buffer(BufferType::DownstreamData, start, size, value).unwrap() } + fn resume_downstream(&self) { + hostcalls::resume_downstream().unwrap() + } + + fn close_downstream(&self) { + hostcalls::close_downstream().unwrap() + } + fn on_downstream_close(&mut self, _peer_type: PeerType) {} fn on_upstream_data(&mut self, _data_size: usize, _end_of_stream: bool) -> Action { @@ -166,13 +294,21 @@ pub trait StreamContext: Context { hostcalls::set_buffer(BufferType::UpstreamData, start, size, value).unwrap() } + fn resume_upstream(&self) { + hostcalls::resume_upstream().unwrap() + } + + fn close_upstream(&self) { + hostcalls::close_upstream().unwrap() + } + fn on_upstream_close(&mut self, _peer_type: PeerType) {} fn on_log(&mut self) {} } pub trait HttpContext: Context { - fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { + fn on_http_request_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { Action::Continue } @@ -180,20 +316,40 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpRequestHeaders).unwrap() } + fn get_http_request_headers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpRequestHeaders).unwrap() + } + fn set_http_request_headers(&self, headers: Vec<(&str, &str)>) { hostcalls::set_map(MapType::HttpRequestHeaders, headers).unwrap() } + fn set_http_request_headers_bytes(&self, headers: Vec<(&str, &[u8])>) { + hostcalls::set_map_bytes(MapType::HttpRequestHeaders, headers).unwrap() + } + fn get_http_request_header(&self, name: &str) -> Option { - hostcalls::get_map_value(MapType::HttpRequestHeaders, &name).unwrap() + hostcalls::get_map_value(MapType::HttpRequestHeaders, name).unwrap() + } + + fn get_http_request_header_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpRequestHeaders, name).unwrap() } fn set_http_request_header(&self, name: &str, value: Option<&str>) { - hostcalls::set_map_value(MapType::HttpRequestHeaders, &name, value).unwrap() + hostcalls::set_map_value(MapType::HttpRequestHeaders, name, value).unwrap() + } + + fn set_http_request_header_bytes(&self, name: &str, value: Option<&[u8]>) { + hostcalls::set_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap() } fn add_http_request_header(&self, name: &str, value: &str) { - hostcalls::add_map_value(MapType::HttpRequestHeaders, &name, value).unwrap() + hostcalls::add_map_value(MapType::HttpRequestHeaders, name, value).unwrap() + } + + fn add_http_request_header_bytes(&self, name: &str, value: &[u8]) { + hostcalls::add_map_value_bytes(MapType::HttpRequestHeaders, name, value).unwrap() } fn on_http_request_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action { @@ -216,27 +372,51 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpRequestTrailers).unwrap() } + fn get_http_request_trailers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpRequestTrailers).unwrap() + } + fn set_http_request_trailers(&self, trailers: Vec<(&str, &str)>) { hostcalls::set_map(MapType::HttpRequestTrailers, trailers).unwrap() } + fn set_http_request_trailers_bytes(&self, trailers: Vec<(&str, &[u8])>) { + hostcalls::set_map_bytes(MapType::HttpRequestTrailers, trailers).unwrap() + } + fn get_http_request_trailer(&self, name: &str) -> Option { - hostcalls::get_map_value(MapType::HttpRequestTrailers, &name).unwrap() + hostcalls::get_map_value(MapType::HttpRequestTrailers, name).unwrap() + } + + fn get_http_request_trailer_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpRequestTrailers, name).unwrap() } fn set_http_request_trailer(&self, name: &str, value: Option<&str>) { - hostcalls::set_map_value(MapType::HttpRequestTrailers, &name, value).unwrap() + hostcalls::set_map_value(MapType::HttpRequestTrailers, name, value).unwrap() + } + + fn set_http_request_trailer_bytes(&self, name: &str, value: Option<&[u8]>) { + hostcalls::set_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap() } fn add_http_request_trailer(&self, name: &str, value: &str) { - hostcalls::add_map_value(MapType::HttpRequestTrailers, &name, value).unwrap() + hostcalls::add_map_value(MapType::HttpRequestTrailers, name, value).unwrap() + } + + fn add_http_request_trailer_bytes(&self, name: &str, value: &[u8]) { + hostcalls::add_map_value_bytes(MapType::HttpRequestTrailers, name, value).unwrap() } fn resume_http_request(&self) { hostcalls::resume_http_request().unwrap() } - fn on_http_response_headers(&mut self, _num_headers: usize) -> Action { + fn reset_http_request(&self) { + hostcalls::reset_http_request().unwrap() + } + + fn on_http_response_headers(&mut self, _num_headers: usize, _end_of_stream: bool) -> Action { Action::Continue } @@ -244,20 +424,40 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpResponseHeaders).unwrap() } + fn get_http_response_headers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpResponseHeaders).unwrap() + } + fn set_http_response_headers(&self, headers: Vec<(&str, &str)>) { hostcalls::set_map(MapType::HttpResponseHeaders, headers).unwrap() } + fn set_http_response_headers_bytes(&self, headers: Vec<(&str, &[u8])>) { + hostcalls::set_map_bytes(MapType::HttpResponseHeaders, headers).unwrap() + } + fn get_http_response_header(&self, name: &str) -> Option { - hostcalls::get_map_value(MapType::HttpResponseHeaders, &name).unwrap() + hostcalls::get_map_value(MapType::HttpResponseHeaders, name).unwrap() + } + + fn get_http_response_header_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpResponseHeaders, name).unwrap() } fn set_http_response_header(&self, name: &str, value: Option<&str>) { - hostcalls::set_map_value(MapType::HttpResponseHeaders, &name, value).unwrap() + hostcalls::set_map_value(MapType::HttpResponseHeaders, name, value).unwrap() + } + + fn set_http_response_header_bytes(&self, name: &str, value: Option<&[u8]>) { + hostcalls::set_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap() } fn add_http_response_header(&self, name: &str, value: &str) { - hostcalls::add_map_value(MapType::HttpResponseHeaders, &name, value).unwrap() + hostcalls::add_map_value(MapType::HttpResponseHeaders, name, value).unwrap() + } + + fn add_http_response_header_bytes(&self, name: &str, value: &[u8]) { + hostcalls::add_map_value_bytes(MapType::HttpResponseHeaders, name, value).unwrap() } fn on_http_response_body(&mut self, _body_size: usize, _end_of_stream: bool) -> Action { @@ -280,26 +480,50 @@ pub trait HttpContext: Context { hostcalls::get_map(MapType::HttpResponseTrailers).unwrap() } - fn set_http_response_trailers(&self, headers: Vec<(&str, &str)>) { - hostcalls::set_map(MapType::HttpResponseTrailers, headers).unwrap() + fn get_http_response_trailers_bytes(&self) -> Vec<(String, Bytes)> { + hostcalls::get_map_bytes(MapType::HttpResponseTrailers).unwrap() + } + + fn set_http_response_trailers(&self, trailers: Vec<(&str, &str)>) { + hostcalls::set_map(MapType::HttpResponseTrailers, trailers).unwrap() + } + + fn set_http_response_trailers_bytes(&self, trailers: Vec<(&str, &[u8])>) { + hostcalls::set_map_bytes(MapType::HttpResponseTrailers, trailers).unwrap() } fn get_http_response_trailer(&self, name: &str) -> Option { - hostcalls::get_map_value(MapType::HttpResponseTrailers, &name).unwrap() + hostcalls::get_map_value(MapType::HttpResponseTrailers, name).unwrap() + } + + fn get_http_response_trailer_bytes(&self, name: &str) -> Option { + hostcalls::get_map_value_bytes(MapType::HttpResponseTrailers, name).unwrap() } fn set_http_response_trailer(&self, name: &str, value: Option<&str>) { - hostcalls::set_map_value(MapType::HttpResponseTrailers, &name, value).unwrap() + hostcalls::set_map_value(MapType::HttpResponseTrailers, name, value).unwrap() + } + + fn set_http_response_trailer_bytes(&self, name: &str, value: Option<&[u8]>) { + hostcalls::set_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap() } fn add_http_response_trailer(&self, name: &str, value: &str) { - hostcalls::add_map_value(MapType::HttpResponseTrailers, &name, value).unwrap() + hostcalls::add_map_value(MapType::HttpResponseTrailers, name, value).unwrap() + } + + fn add_http_response_trailer_bytes(&self, name: &str, value: &[u8]) { + hostcalls::add_map_value_bytes(MapType::HttpResponseTrailers, name, value).unwrap() } fn resume_http_response(&self) { hostcalls::resume_http_response().unwrap() } + fn reset_http_response(&self) { + hostcalls::reset_http_response().unwrap() + } + fn send_http_response( &self, status_code: u32, @@ -309,9 +533,5 @@ pub trait HttpContext: Context { hostcalls::send_http_response(status_code, headers, body).unwrap() } - fn clear_http_route_cache(&self) { - hostcalls::clear_http_route_cache().unwrap() - } - fn on_log(&mut self) {} } diff --git a/src/types.rs b/src/types.rs index 855a414b..cddb898f 100644 --- a/src/types.rs +++ b/src/types.rs @@ -19,7 +19,7 @@ pub type NewStreamContext = fn(context_id: u32, root_context_id: u32) -> Box Box; #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub enum LogLevel { Trace = 0, Debug = 1, @@ -30,53 +30,75 @@ pub enum LogLevel { } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum Action { Continue = 0, Pause = 1, } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum Status { Ok = 0, NotFound = 1, BadArgument = 2, + ParseFailure = 4, Empty = 7, CasMismatch = 8, InternalFailure = 10, } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum ContextType { HttpContext = 0, StreamContext = 1, } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] +pub enum StreamType { + HttpRequest = 0, + HttpResponse = 1, + Downstream = 2, + Upstream = 3, +} + +#[repr(u32)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum BufferType { HttpRequestBody = 0, HttpResponseBody = 1, DownstreamData = 2, UpstreamData = 3, HttpCallResponseBody = 4, + GrpcReceiveBuffer = 5, + VmConfiguration = 6, + PluginConfiguration = 7, } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum MapType { HttpRequestHeaders = 0, HttpRequestTrailers = 1, HttpResponseHeaders = 2, HttpResponseTrailers = 3, + GrpcReceiveInitialMetadata = 4, + GrpcReceiveTrailingMetadata = 5, HttpCallResponseHeaders = 6, HttpCallResponseTrailers = 7, } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum PeerType { Unknown = 0, Local = 1, @@ -84,7 +106,8 @@ pub enum PeerType { } #[repr(u32)] -#[derive(Debug)] +#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] +#[non_exhaustive] pub enum MetricType { Counter = 0, Gauge = 1,