From 7b798a7b6dc53583750c027adb24e4fa1f871557 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 28 Aug 2024 18:39:37 +0000 Subject: [PATCH 01/16] dynamic_modules: scaffolds Rust SDK Signed-off-by: Takeshi Yoneda --- WORKSPACE | 4 + bazel/dependency_imports.bzl | 10 + bazel/dependency_imports_extra.bzl | 4 + .../dynamic_modules/sdk/rust/.gitignore | 1 + .../extensions/dynamic_modules/sdk/rust/BUILD | 33 ++ .../dynamic_modules/sdk/rust/Cargo.lock | 369 ++++++++++++++++++ .../dynamic_modules/sdk/rust/Cargo.toml | 15 + .../extensions/dynamic_modules/sdk/rust/abi.h | 68 ++++ .../dynamic_modules/sdk/rust/build.rs | 15 + .../dynamic_modules/sdk/rust/src/lib.rs | 42 ++ test/extensions/dynamic_modules/BUILD | 4 + .../dynamic_modules/dynamic_modules_test.cc | 3 +- .../dynamic_modules/test_data/rust/.gitignore | 2 + .../dynamic_modules/test_data/rust/BUILD | 32 ++ .../dynamic_modules/test_data/rust/Cargo.toml | 29 ++ .../test_data/rust/abi_version_mismatch.rs | 4 + .../dynamic_modules/test_data/rust/no_op.rs | 17 + .../test_data/rust/no_program_init.rs | 3 + .../test_data/rust/program_init_fail.rs | 4 + 19 files changed, 658 insertions(+), 1 deletion(-) create mode 100644 bazel/dependency_imports_extra.bzl create mode 100644 source/extensions/dynamic_modules/sdk/rust/.gitignore create mode 100644 source/extensions/dynamic_modules/sdk/rust/BUILD create mode 100644 source/extensions/dynamic_modules/sdk/rust/Cargo.lock create mode 100644 source/extensions/dynamic_modules/sdk/rust/Cargo.toml create mode 100644 source/extensions/dynamic_modules/sdk/rust/abi.h create mode 100644 source/extensions/dynamic_modules/sdk/rust/build.rs create mode 100644 source/extensions/dynamic_modules/sdk/rust/src/lib.rs create mode 100644 test/extensions/dynamic_modules/test_data/rust/.gitignore create mode 100644 test/extensions/dynamic_modules/test_data/rust/BUILD create mode 100644 test/extensions/dynamic_modules/test_data/rust/Cargo.toml create mode 100644 test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs create mode 100644 test/extensions/dynamic_modules/test_data/rust/no_op.rs create mode 100644 test/extensions/dynamic_modules/test_data/rust/no_program_init.rs create mode 100644 test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs diff --git a/WORKSPACE b/WORKSPACE index 9819ecb5ac1e..e4460bfc5475 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,3 +27,7 @@ envoy_python_dependencies() load("//bazel:dependency_imports.bzl", "envoy_dependency_imports") envoy_dependency_imports() + +load("//bazel:dependency_imports_extra.bzl", "envoy_dependency_imports_extra") + +envoy_dependency_imports_extra() diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 6f782ef73263..3e3b5b0467f4 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -14,6 +14,8 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains") +load("@rules_rust//crate_universe:defs.bzl", "crates_repository") +load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") load("@rules_rust//rust:defs.bzl", "rust_common") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") @@ -171,6 +173,14 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y protoc_gen_jsonschema_go_dependencies() rules_proto_grpc_toolchains() + crate_universe_dependencies(bootstrap = True) + crates_repository( + name = "dynamic_modules_rust_sdk_crate_index", + cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", + generator = "@cargo_bazel_bootstrap//:cargo-bazel", + manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], + ) + def envoy_download_go_sdks(go_version): go_download_sdk( name = "go_linux_amd64", diff --git a/bazel/dependency_imports_extra.bzl b/bazel/dependency_imports_extra.bzl new file mode 100644 index 000000000000..4faae9a3bcdf --- /dev/null +++ b/bazel/dependency_imports_extra.bzl @@ -0,0 +1,4 @@ +load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", crate_repositories_crate_repositories = "crate_repositories") + +def envoy_dependency_imports_extra(): + crate_repositories_crate_repositories() diff --git a/source/extensions/dynamic_modules/sdk/rust/.gitignore b/source/extensions/dynamic_modules/sdk/rust/.gitignore new file mode 100644 index 000000000000..ea8c4bf7f35f --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/.gitignore @@ -0,0 +1 @@ +/target diff --git a/source/extensions/dynamic_modules/sdk/rust/BUILD b/source/extensions/dynamic_modules/sdk/rust/BUILD new file mode 100644 index 000000000000..d9142bc526be --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/BUILD @@ -0,0 +1,33 @@ +load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "all_crate_deps") +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") +load("@rules_rust//rust:defs.bzl", "rust_library") +load( + "//bazel:envoy_build_system.bzl", + "envoy_extension_package", +) + +licenses(["notice"]) # Apache 2 + +envoy_extension_package() + +cargo_build_script( + name = "build_script", + srcs = ["build.rs"], + data = [ + "abi.h", + ], + edition = "2021", + deps = all_crate_deps( + build = True, + normal = True, + ), +) + +rust_library( + name = "envoy_proxy_dynamic_modules_rust_sdk", + srcs = ["src/lib.rs"], + edition = "2021", + deps = all_crate_deps( + normal = True, + ) + [":build_script"], +) diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock new file mode 100644 index 000000000000..f9ca914bad86 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock @@ -0,0 +1,369 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + +[[package]] +name = "envoy-proxy-dynamic-modules-rust-sdk" +version = "0.1.0" +dependencies = [ + "bindgen", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "prettyplease" +version = "0.2.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml new file mode 100644 index 000000000000..fa30cc772069 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "envoy-proxy-dynamic-modules-rust-sdk" +version = "0.1.0" +edition = "2021" +authors = ["Takeshi Yoneda "] +description = "Envoy Proxy Dynamic Modules Rust SDK" +license = "Apache-2.0" +repository = "https://github.com/envoyproxy/envoy" + +[dependencies] + +[build-dependencies] +bindgen = "0.65.1" + +[lib] diff --git a/source/extensions/dynamic_modules/sdk/rust/abi.h b/source/extensions/dynamic_modules/sdk/rust/abi.h new file mode 100644 index 000000000000..460dc00cef58 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/abi.h @@ -0,0 +1,68 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This is a pure C header file that defines the ABI of the core of dynamic modules used by Envoy. +// +// This must not contain any dependencies besides standard library since it is not only used by +// Envoy itself but also by dynamic module SDKs written in non-C++ languages. +// +// Currently, compatibility is only guaranteed by an exact version match between the Envoy +// codebase and the dynamic module SDKs. In the future, after the ABI is stabilized, we will revisit +// this restriction and hopefully provide a wider compatibility guarantee. Until then, Envoy +// checks the hash of the ABI header files to ensure that the dynamic modules are built against the +// same version of the ABI. + +#ifdef __cplusplus +#include + +extern "C" { +#else +#include +#endif + +// ----------------------------------------------------------------------------- +// ---------------------------------- Types ------------------------------------ +// ----------------------------------------------------------------------------- +// +// Types used in the ABI. The name of a type must be prefixed with "envoy_dynamic_module_type_". + +/** + * envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI + * version of the dynamic module. This is used to ensure that the dynamic module is built against + * the compatible version of the ABI. + */ +typedef const char* envoy_dynamic_module_type_abi_version; // NOLINT(modernize-use-using) + +// ----------------------------------------------------------------------------- +// ------------------------------- Event Hooks --------------------------------- +// ----------------------------------------------------------------------------- +// +// Event hooks are functions that are called by Envoy in response to certain events. +// The module must implement and export these functions in the dynamic module object file. +// +// Each event hook is defined as a function prototype. The symbol must be prefixed with +// "envoy_dynamic_module_on_". + +/** + * envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is + * loaded. The function returns the ABI version of the dynamic module. If null is returned, the + * module will be unloaded immediately. + * + * For Envoy, the return value will be used to check the compatibility of the dynamic module. + * + * For dynamic modules, this is useful when they need to perform some process-wide + * initialization or check if the module is compatible with the platform, such as CPU features. + * Note that initialization routines of a dynamic module can also be performed without this function + * through constructor functions in an object file. However, normal constructors cannot be used + * to check compatibility and gracefully fail the initialization because there is no way to + * report an error to Envoy. + * + * @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null + * means the error and the module will be unloaded immediately. + */ +envoy_dynamic_module_type_abi_version envoy_dynamic_module_on_program_init(); + +#ifdef __cplusplus +} +#endif diff --git a/source/extensions/dynamic_modules/sdk/rust/build.rs b/source/extensions/dynamic_modules/sdk/rust/build.rs new file mode 100644 index 000000000000..8afd7bd9b1b9 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/build.rs @@ -0,0 +1,15 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + let bindings = bindgen::Builder::default() + .header("abi.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs new file mode 100644 index 000000000000..9156288b433f --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -0,0 +1,42 @@ +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(dead_code)] + +/// The raw bindings to the Envoy dynamic module ABI generated by bindgen. +/// The generated bindings are not exposed to the user directly. +mod abi { + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} + +/// Declare the entry point for the dynamic module. This function is called when the dynamic module is loaded. +/// The function must return 0 on success, and any other value on failure. When the function returns a non-zero value, +/// the dynamic module will not be loaded. +/// +/// This is useful to perform any process-wide initialization that the dynamic module needs. +/// +/// # Example +/// +/// ``` +/// use envoy_proxy_dynamic_modules_rust_sdk::declare_program_init; +/// +/// declare_program_init!(my_program_init); +/// +/// fn my_program_init() -> bool { +/// true +/// } +/// ``` +#[macro_export] +macro_rules! declare_program_init { + ($f:ident) => { + #[no_mangle] + pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { + if ($f()) { + b"749b1e6bf97309b7d171009700a80e651ac61e35f9770c24a63460d765895a51\0".as_ptr() + as *const ::std::os::raw::c_char + } else { + ::std::ptr::null() + } + } + }; +} diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index 487553679f41..f136dd11269e 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -16,6 +16,10 @@ envoy_cc_test( "//test/extensions/dynamic_modules/test_data/c:no_op", "//test/extensions/dynamic_modules/test_data/c:no_program_init", "//test/extensions/dynamic_modules/test_data/c:program_init_fail", + "//test/extensions/dynamic_modules/test_data/rust:abi_version_mismatch", + "//test/extensions/dynamic_modules/test_data/rust:no_op", + "//test/extensions/dynamic_modules/test_data/rust:no_program_init", + "//test/extensions/dynamic_modules/test_data/rust:program_init_fail", ], deps = [ "//source/extensions/dynamic_modules:dynamic_modules_lib", diff --git a/test/extensions/dynamic_modules/dynamic_modules_test.cc b/test/extensions/dynamic_modules/dynamic_modules_test.cc index 1c02d4e9d4fb..7368af924aa1 100644 --- a/test/extensions/dynamic_modules/dynamic_modules_test.cc +++ b/test/extensions/dynamic_modules/dynamic_modules_test.cc @@ -37,7 +37,7 @@ class DynamicModuleTestLanguages : public ::testing::TestWithParam }; INSTANTIATE_TEST_SUITE_P(LanguageTests, DynamicModuleTestLanguages, - testing::Values("c"), // TODO: Other languages. + testing::Values("c", "rust"), // TODO: add Go. DynamicModuleTestLanguages::languageParamToTestName); TEST_P(DynamicModuleTestLanguages, DoNotClose) { @@ -48,6 +48,7 @@ TEST_P(DynamicModuleTestLanguages, DoNotClose) { EXPECT_TRUE(module.ok()); const auto getSomeVariable = module->get()->getFunctionPointer("getSomeVariable"); + EXPECT_NE(getSomeVariable, nullptr); EXPECT_EQ(getSomeVariable(), 1); EXPECT_EQ(getSomeVariable(), 2); EXPECT_EQ(getSomeVariable(), 3); diff --git a/test/extensions/dynamic_modules/test_data/rust/.gitignore b/test/extensions/dynamic_modules/test_data/rust/.gitignore new file mode 100644 index 000000000000..96ef6c0b944e --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/.gitignore @@ -0,0 +1,2 @@ +/target +Cargo.lock diff --git a/test/extensions/dynamic_modules/test_data/rust/BUILD b/test/extensions/dynamic_modules/test_data/rust/BUILD new file mode 100644 index 000000000000..b9bf03ebf106 --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/BUILD @@ -0,0 +1,32 @@ +load("@rules_rust//rust:defs.bzl", "rust_shared_library") + +licenses(["notice"]) # Apache 2 + +package(default_visibility = ["//test/extensions/dynamic_modules:__pkg__"]) + +rust_shared_library( + name = "no_op", + srcs = ["no_op.rs"], + edition = "2021", + deps = [ + "//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk", + ], +) + +rust_shared_library( + name = "no_program_init", + srcs = ["no_program_init.rs"], + edition = "2021", +) + +rust_shared_library( + name = "program_init_fail", + srcs = ["program_init_fail.rs"], + edition = "2021", +) + +rust_shared_library( + name = "abi_version_mismatch", + srcs = ["abi_version_mismatch.rs"], + edition = "2021", +) diff --git a/test/extensions/dynamic_modules/test_data/rust/Cargo.toml b/test/extensions/dynamic_modules/test_data/rust/Cargo.toml new file mode 100644 index 000000000000..592f3f84b52f --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/Cargo.toml @@ -0,0 +1,29 @@ +[package] +name = "test-programs" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +repository = "https://github.com/envoyproxy/envoy" + +[dependencies] +envoy-proxy-dynamic-modules-rust-sdk = { path = "../../../../../source/extensions/dynamic_modules/sdk/rust" } + +[[example]] +name = "no_op" +path = "no_op.rs" +crate-type = ["cdylib"] + +[[example]] +name = "no_program_init" +path = "no_program_init.rs" +crate-type = ["cdylib"] + +[[example]] +name = "program_init_fail" +path = "program_init_fail.rs" +crate-type = ["cdylib"] + +[[example]] +name = "abi_version_mismatch" +path = "abi_version_mismatch.rs" +crate-type = ["cdylib"] diff --git a/test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs b/test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs new file mode 100644 index 000000000000..8afbd0d965d8 --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { + b"invalid-version-hash\0".as_ptr() as *const ::std::os::raw::c_char +} diff --git a/test/extensions/dynamic_modules/test_data/rust/no_op.rs b/test/extensions/dynamic_modules/test_data/rust/no_op.rs new file mode 100644 index 000000000000..6d3fe6141cfb --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/no_op.rs @@ -0,0 +1,17 @@ +use envoy_proxy_dynamic_modules_rust_sdk::declare_program_init; + +declare_program_init!(init); + +fn init() -> bool { + true +} + +#[no_mangle] +pub extern "C" fn getSomeVariable() -> i32 { + static mut SOME_VARIABLE: i32 = 0; + + unsafe { + SOME_VARIABLE += 1; + SOME_VARIABLE + } +} diff --git a/test/extensions/dynamic_modules/test_data/rust/no_program_init.rs b/test/extensions/dynamic_modules/test_data/rust/no_program_init.rs new file mode 100644 index 000000000000..db872215ab1d --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/no_program_init.rs @@ -0,0 +1,3 @@ +pub extern "C" fn foo() -> i32 { + 0 +} diff --git a/test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs b/test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs new file mode 100644 index 000000000000..e9d7aed01306 --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs @@ -0,0 +1,4 @@ +#[no_mangle] +pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { + ::std::ptr::null() +} From 3cd1bdcb3a200b658ace550a19ea5f8607b628c7 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 28 Aug 2024 18:59:20 +0000 Subject: [PATCH 02/16] Adds README and check Signed-off-by: Takeshi Yoneda --- source/extensions/dynamic_modules/sdk/README.md | 5 +++++ .../extensions/dynamic_modules/sdk/rust/Cargo.toml | 2 +- test/extensions/dynamic_modules/BUILD | 12 ++++++++++++ test/extensions/dynamic_modules/abi_version_test.cc | 12 +++++++++++- 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 source/extensions/dynamic_modules/sdk/README.md diff --git a/source/extensions/dynamic_modules/sdk/README.md b/source/extensions/dynamic_modules/sdk/README.md new file mode 100644 index 000000000000..0d5258b44684 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/README.md @@ -0,0 +1,5 @@ +## Dynamic Modules SDKs + +This directory contains the SDKs for the Dynamic Modules feature. Each SDK holds a hard-copy of the ABI +header files in order to allow out-of-tree module development. Each SDK passes the same set of tests and +is guaranteed to provide the same functionality. diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml index fa30cc772069..b7073aa81d96 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml @@ -2,7 +2,7 @@ name = "envoy-proxy-dynamic-modules-rust-sdk" version = "0.1.0" edition = "2021" -authors = ["Takeshi Yoneda "] +authors = ["Envoy Proxy Authors "] description = "Envoy Proxy Dynamic Modules Rust SDK" license = "Apache-2.0" repository = "https://github.com/envoyproxy/envoy" diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index f136dd11269e..5d88efdd1196 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -1,3 +1,4 @@ +load("@rules_rust//rust:defs.bzl", "rust_clippy", "rustfmt_test") load( "//bazel:envoy_build_system.bzl", "envoy_cc_test", @@ -33,6 +34,7 @@ envoy_cc_test( srcs = ["abi_version_test.cc"], data = [ "//source/extensions/dynamic_modules:abi.h", + "//source/extensions/dynamic_modules/sdk/rust:abi.h", ], deps = [ "//source/common/common:hex_lib", @@ -42,3 +44,13 @@ envoy_cc_test( "//test/test_common:utility_lib", ], ) + +rustfmt_test( + name = "envoy_proxy_dynamic_modules_rust_sdk_fmt", + targets = ["//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk"], +) + +rust_clippy( + name = "envoy_proxy_dynamic_modules_rust_sdk_clippy", + deps = ["//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk"], +) diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index 3f7b4eb74834..077d6ee51d2d 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -15,7 +15,7 @@ namespace Envoy { namespace Extensions { namespace DynamicModules { -// This test ensure that abi_version.h contains the correct sha256 hash of ABI header files. +// This test ensures that abi_version.h contains the correct sha256 hash of ABI header files. TEST(DynamicModules, ABIVersionCheck) { const auto abi_header_path = TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h"); @@ -27,6 +27,16 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } +TEST(DynamicModules, IdenticalABIHeaders) { + const std::string original_abi_header = TestEnvironment::readFileToStringForTest( + TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); + const std::string rust_sdk_abi_header = + TestEnvironment::readFileToStringForTest(TestEnvironment::substitute( + "{{ test_rundir }}/source/extensions/dynamic_modules/sdk/rust/abi.h")); + EXPECT_EQ(original_abi_header, rust_sdk_abi_header); + // TODO: Go SDK. +} + } // namespace DynamicModules } // namespace Extensions } // namespace Envoy From 65af05c34a4cb6ab2b643963f8b38a945eae7773 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Wed, 28 Aug 2024 22:44:53 +0000 Subject: [PATCH 03/16] more Signed-off-by: Takeshi Yoneda --- bazel/dependency_imports.bzl | 28 +++++++++++++------ bazel/dependency_imports_extra.bzl | 5 ++-- source/extensions/dynamic_modules/BUILD | 7 +++++ .../dynamic_modules/sdk/rust/Cargo.lock | 20 ++++++------- 4 files changed, 39 insertions(+), 21 deletions(-) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 3e3b5b0467f4..e1460faff3b0 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -15,9 +15,9 @@ load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains") load("@rules_rust//crate_universe:defs.bzl", "crates_repository") -load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") load("@rules_rust//rust:defs.bzl", "rust_common") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") +load("//bazel:repository_locations.bzl", "REPOSITORY_LOCATIONS_SPEC") # go version for rules_go GO_VERSION = "1.22.5" @@ -172,14 +172,7 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y protoc_gen_jsonschema_go_dependencies() rules_proto_grpc_toolchains() - - crate_universe_dependencies(bootstrap = True) - crates_repository( - name = "dynamic_modules_rust_sdk_crate_index", - cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", - generator = "@cargo_bazel_bootstrap//:cargo-bazel", - manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], - ) + envoy_dynamic_modules_rust_sdk_crate_index() def envoy_download_go_sdks(go_version): go_download_sdk( @@ -206,3 +199,20 @@ def envoy_download_go_sdks(go_version): goarch = "arm64", version = go_version, ) + +def envoy_dynamic_modules_rust_sdk_crate_index(): + rules_rust_version = REPOSITORY_LOCATIONS_SPEC["rules_rust"]["version"] + base_url = "https://github.com/bazelbuild/rules_rust/releases/download/{rules_rust_version}/cargo-bazel-".format(rules_rust_version = rules_rust_version) + + # TODO: skip on non target platforms. + crates_repository( + name = "dynamic_modules_rust_sdk_crate_index", + cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", + generator_urls = { + "x86_64-unknown-linux-gnu": base_url + "x86_64-unknown-linux-gnu", + "aarch64-unknown-linux-gnu": base_url + "aarch64-unknown-linux-gnu", + "aarch64-apple-darwin": base_url + "aarch64-apple-darwin", + "x86_64-apple-darwin": base_url + "x86_64-apple-darwin", + }, + manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], + ) diff --git a/bazel/dependency_imports_extra.bzl b/bazel/dependency_imports_extra.bzl index 4faae9a3bcdf..0b121744248e 100644 --- a/bazel/dependency_imports_extra.bzl +++ b/bazel/dependency_imports_extra.bzl @@ -1,4 +1,5 @@ -load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", crate_repositories_crate_repositories = "crate_repositories") +load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", dynamic_modules_rust_sdk_crate_repositories = "crate_repositories") +# Dependencies that rely on a first stage of dependency loading in envoy_dependencies(). def envoy_dependency_imports_extra(): - crate_repositories_crate_repositories() + dynamic_modules_rust_sdk_crate_repositories() diff --git a/source/extensions/dynamic_modules/BUILD b/source/extensions/dynamic_modules/BUILD index b7e22b2a9edc..96f9e035e003 100644 --- a/source/extensions/dynamic_modules/BUILD +++ b/source/extensions/dynamic_modules/BUILD @@ -27,3 +27,10 @@ envoy_cc_library( "abi_version.h", ], ) + +envoy_cc_library( + name = "abi_lib", + hdrs = [ + "abi.h", + ], +) diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock index f9ca914bad86..ee2ee988225f 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock @@ -124,9 +124,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" @@ -186,9 +186,9 @@ checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" [[package]] name = "prettyplease" -version = "0.2.20" +version = "0.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", "syn", @@ -205,9 +205,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -249,9 +249,9 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" dependencies = [ "bitflags 2.6.0", "errno", @@ -268,9 +268,9 @@ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "syn" -version = "2.0.72" +version = "2.0.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" dependencies = [ "proc-macro2", "quote", From efd1d4ea31dbcf5aa55432f6f9817f3bf62a2914 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 29 Aug 2024 21:16:57 +0000 Subject: [PATCH 04/16] manual bindgen Signed-off-by: Takeshi Yoneda --- WORKSPACE | 4 - bazel/dependency_imports.bzl | 20 - bazel/dependency_imports_extra.bzl | 5 - source/extensions/dynamic_modules/BUILD | 7 - .../extensions/dynamic_modules/sdk/README.md | 3 +- .../extensions/dynamic_modules/sdk/rust/BUILD | 20 +- .../dynamic_modules/sdk/rust/Cargo.lock | 362 ------------------ .../dynamic_modules/sdk/rust/Cargo.toml | 3 - .../extensions/dynamic_modules/sdk/rust/abi.h | 68 ---- .../dynamic_modules/sdk/rust/build.rs | 15 - .../dynamic_modules/sdk/rust/src/abi.rs | 17 + .../dynamic_modules/sdk/rust/src/lib.rs | 12 +- test/extensions/dynamic_modules/BUILD | 1 - .../dynamic_modules/abi_version_test.cc | 10 - 14 files changed, 24 insertions(+), 523 deletions(-) delete mode 100644 bazel/dependency_imports_extra.bzl delete mode 100644 source/extensions/dynamic_modules/sdk/rust/abi.h delete mode 100644 source/extensions/dynamic_modules/sdk/rust/build.rs create mode 100644 source/extensions/dynamic_modules/sdk/rust/src/abi.rs diff --git a/WORKSPACE b/WORKSPACE index e4460bfc5475..9819ecb5ac1e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,7 +27,3 @@ envoy_python_dependencies() load("//bazel:dependency_imports.bzl", "envoy_dependency_imports") envoy_dependency_imports() - -load("//bazel:dependency_imports_extra.bzl", "envoy_dependency_imports_extra") - -envoy_dependency_imports_extra() diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index e1460faff3b0..6f782ef73263 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -14,10 +14,8 @@ load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_depende load("@rules_fuzzing//fuzzing:repositories.bzl", "rules_fuzzing_dependencies") load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") load("@rules_proto_grpc//:repositories.bzl", "rules_proto_grpc_toolchains") -load("@rules_rust//crate_universe:defs.bzl", "crates_repository") load("@rules_rust//rust:defs.bzl", "rust_common") load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_register_toolchains", "rust_repository_set") -load("//bazel:repository_locations.bzl", "REPOSITORY_LOCATIONS_SPEC") # go version for rules_go GO_VERSION = "1.22.5" @@ -172,7 +170,6 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y protoc_gen_jsonschema_go_dependencies() rules_proto_grpc_toolchains() - envoy_dynamic_modules_rust_sdk_crate_index() def envoy_download_go_sdks(go_version): go_download_sdk( @@ -199,20 +196,3 @@ def envoy_download_go_sdks(go_version): goarch = "arm64", version = go_version, ) - -def envoy_dynamic_modules_rust_sdk_crate_index(): - rules_rust_version = REPOSITORY_LOCATIONS_SPEC["rules_rust"]["version"] - base_url = "https://github.com/bazelbuild/rules_rust/releases/download/{rules_rust_version}/cargo-bazel-".format(rules_rust_version = rules_rust_version) - - # TODO: skip on non target platforms. - crates_repository( - name = "dynamic_modules_rust_sdk_crate_index", - cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", - generator_urls = { - "x86_64-unknown-linux-gnu": base_url + "x86_64-unknown-linux-gnu", - "aarch64-unknown-linux-gnu": base_url + "aarch64-unknown-linux-gnu", - "aarch64-apple-darwin": base_url + "aarch64-apple-darwin", - "x86_64-apple-darwin": base_url + "x86_64-apple-darwin", - }, - manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], - ) diff --git a/bazel/dependency_imports_extra.bzl b/bazel/dependency_imports_extra.bzl deleted file mode 100644 index 0b121744248e..000000000000 --- a/bazel/dependency_imports_extra.bzl +++ /dev/null @@ -1,5 +0,0 @@ -load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", dynamic_modules_rust_sdk_crate_repositories = "crate_repositories") - -# Dependencies that rely on a first stage of dependency loading in envoy_dependencies(). -def envoy_dependency_imports_extra(): - dynamic_modules_rust_sdk_crate_repositories() diff --git a/source/extensions/dynamic_modules/BUILD b/source/extensions/dynamic_modules/BUILD index 96f9e035e003..b7e22b2a9edc 100644 --- a/source/extensions/dynamic_modules/BUILD +++ b/source/extensions/dynamic_modules/BUILD @@ -27,10 +27,3 @@ envoy_cc_library( "abi_version.h", ], ) - -envoy_cc_library( - name = "abi_lib", - hdrs = [ - "abi.h", - ], -) diff --git a/source/extensions/dynamic_modules/sdk/README.md b/source/extensions/dynamic_modules/sdk/README.md index 0d5258b44684..64d61baa62f2 100644 --- a/source/extensions/dynamic_modules/sdk/README.md +++ b/source/extensions/dynamic_modules/sdk/README.md @@ -1,5 +1,4 @@ ## Dynamic Modules SDKs -This directory contains the SDKs for the Dynamic Modules feature. Each SDK holds a hard-copy of the ABI -header files in order to allow out-of-tree module development. Each SDK passes the same set of tests and +This directory contains the SDKs for the Dynamic Modules feature. Each SDK passes the same set of tests and is guaranteed to provide the same functionality. diff --git a/source/extensions/dynamic_modules/sdk/rust/BUILD b/source/extensions/dynamic_modules/sdk/rust/BUILD index d9142bc526be..480a9432eb58 100644 --- a/source/extensions/dynamic_modules/sdk/rust/BUILD +++ b/source/extensions/dynamic_modules/sdk/rust/BUILD @@ -1,5 +1,3 @@ -load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "all_crate_deps") -load("@rules_rust//cargo:defs.bzl", "cargo_build_script") load("@rules_rust//rust:defs.bzl", "rust_library") load( "//bazel:envoy_build_system.bzl", @@ -10,24 +8,8 @@ licenses(["notice"]) # Apache 2 envoy_extension_package() -cargo_build_script( - name = "build_script", - srcs = ["build.rs"], - data = [ - "abi.h", - ], - edition = "2021", - deps = all_crate_deps( - build = True, - normal = True, - ), -) - rust_library( name = "envoy_proxy_dynamic_modules_rust_sdk", - srcs = ["src/lib.rs"], + srcs = glob(["src/**/*.rs"]), edition = "2021", - deps = all_crate_deps( - normal = True, - ) + [":build_script"], ) diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock index ee2ee988225f..f6f126e02005 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock @@ -2,368 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "bindgen" -version = "0.65.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", - "which", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - [[package]] name = "envoy-proxy-dynamic-modules-rust-sdk" version = "0.1.0" -dependencies = [ - "bindgen", -] - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "prettyplease" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" -dependencies = [ - "proc-macro2", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustix" -version = "0.38.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" -dependencies = [ - "bitflags 2.6.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "syn" -version = "2.0.76" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578e081a14e0cefc3279b0472138c513f37b41a08d5a3cca9b6e4e8ceb6cd525" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml index b7073aa81d96..3874a8a3301b 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml @@ -9,7 +9,4 @@ repository = "https://github.com/envoyproxy/envoy" [dependencies] -[build-dependencies] -bindgen = "0.65.1" - [lib] diff --git a/source/extensions/dynamic_modules/sdk/rust/abi.h b/source/extensions/dynamic_modules/sdk/rust/abi.h deleted file mode 100644 index 460dc00cef58..000000000000 --- a/source/extensions/dynamic_modules/sdk/rust/abi.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -// NOLINT(namespace-envoy) - -// This is a pure C header file that defines the ABI of the core of dynamic modules used by Envoy. -// -// This must not contain any dependencies besides standard library since it is not only used by -// Envoy itself but also by dynamic module SDKs written in non-C++ languages. -// -// Currently, compatibility is only guaranteed by an exact version match between the Envoy -// codebase and the dynamic module SDKs. In the future, after the ABI is stabilized, we will revisit -// this restriction and hopefully provide a wider compatibility guarantee. Until then, Envoy -// checks the hash of the ABI header files to ensure that the dynamic modules are built against the -// same version of the ABI. - -#ifdef __cplusplus -#include - -extern "C" { -#else -#include -#endif - -// ----------------------------------------------------------------------------- -// ---------------------------------- Types ------------------------------------ -// ----------------------------------------------------------------------------- -// -// Types used in the ABI. The name of a type must be prefixed with "envoy_dynamic_module_type_". - -/** - * envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI - * version of the dynamic module. This is used to ensure that the dynamic module is built against - * the compatible version of the ABI. - */ -typedef const char* envoy_dynamic_module_type_abi_version; // NOLINT(modernize-use-using) - -// ----------------------------------------------------------------------------- -// ------------------------------- Event Hooks --------------------------------- -// ----------------------------------------------------------------------------- -// -// Event hooks are functions that are called by Envoy in response to certain events. -// The module must implement and export these functions in the dynamic module object file. -// -// Each event hook is defined as a function prototype. The symbol must be prefixed with -// "envoy_dynamic_module_on_". - -/** - * envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is - * loaded. The function returns the ABI version of the dynamic module. If null is returned, the - * module will be unloaded immediately. - * - * For Envoy, the return value will be used to check the compatibility of the dynamic module. - * - * For dynamic modules, this is useful when they need to perform some process-wide - * initialization or check if the module is compatible with the platform, such as CPU features. - * Note that initialization routines of a dynamic module can also be performed without this function - * through constructor functions in an object file. However, normal constructors cannot be used - * to check compatibility and gracefully fail the initialization because there is no way to - * report an error to Envoy. - * - * @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null - * means the error and the module will be unloaded immediately. - */ -envoy_dynamic_module_type_abi_version envoy_dynamic_module_on_program_init(); - -#ifdef __cplusplus -} -#endif diff --git a/source/extensions/dynamic_modules/sdk/rust/build.rs b/source/extensions/dynamic_modules/sdk/rust/build.rs deleted file mode 100644 index 8afd7bd9b1b9..000000000000 --- a/source/extensions/dynamic_modules/sdk/rust/build.rs +++ /dev/null @@ -1,15 +0,0 @@ -use std::env; -use std::path::PathBuf; - -fn main() { - let bindings = bindgen::Builder::default() - .header("abi.h") - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) - .generate() - .expect("Unable to generate bindings"); - - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); -} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/abi.rs b/source/extensions/dynamic_modules/sdk/rust/src/abi.rs new file mode 100644 index 000000000000..d673d5b2c599 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/src/abi.rs @@ -0,0 +1,17 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + +pub type wchar_t = ::std::os::raw::c_int; +#[repr(C)] +#[repr(align(16))] +#[derive(Debug, Copy, Clone)] +pub struct max_align_t { + pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, + pub __clang_max_align_nonce2: u128, +} +#[doc = " envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI\n version of the dynamic module. This is used to ensure that the dynamic module is built against\n the compatible version of the ABI."] +pub type envoy_dynamic_module_type_abi_version = *const ::std::os::raw::c_char; +extern "C" { + #[doc = " envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is\n loaded. The function returns the ABI version of the dynamic module. If null is returned, the\n module will be unloaded immediately.\n\n For Envoy, the return value will be used to check the compatibility of the dynamic module.\n\n For dynamic modules, this is useful when they need to perform some process-wide\n initialization or check if the module is compatible with the platform, such as CPU features.\n Note that initialization routines of a dynamic module can also be performed without this function\n through constructor functions in an object file. However, normal constructors cannot be used\n to check compatibility and gracefully fail the initialization because there is no way to\n report an error to Envoy.\n\n @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null\n means the error and the module will be unloaded immediately."] + pub fn envoy_dynamic_module_on_program_init() -> envoy_dynamic_module_type_abi_version; +} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index 9156288b433f..d61017d352d2 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -3,14 +3,10 @@ #![allow(non_snake_case)] #![allow(dead_code)] -/// The raw bindings to the Envoy dynamic module ABI generated by bindgen. -/// The generated bindings are not exposed to the user directly. -mod abi { - include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -} +mod abi; -/// Declare the entry point for the dynamic module. This function is called when the dynamic module is loaded. -/// The function must return 0 on success, and any other value on failure. When the function returns a non-zero value, +/// Declare the init function for the dynamic module. This function is called when the dynamic module is loaded. +/// The function must return true on success, and false on failure. When it returns false, /// the dynamic module will not be loaded. /// /// This is useful to perform any process-wide initialization that the dynamic module needs. @@ -32,6 +28,8 @@ macro_rules! declare_program_init { #[no_mangle] pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { if ($f()) { + // This magic number is the hash of the string "abi.h" which must match the + // value in abi_version.h b"749b1e6bf97309b7d171009700a80e651ac61e35f9770c24a63460d765895a51\0".as_ptr() as *const ::std::os::raw::c_char } else { diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index 5d88efdd1196..209579cceebc 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -34,7 +34,6 @@ envoy_cc_test( srcs = ["abi_version_test.cc"], data = [ "//source/extensions/dynamic_modules:abi.h", - "//source/extensions/dynamic_modules/sdk/rust:abi.h", ], deps = [ "//source/common/common:hex_lib", diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index 077d6ee51d2d..958295281dde 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -27,16 +27,6 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } -TEST(DynamicModules, IdenticalABIHeaders) { - const std::string original_abi_header = TestEnvironment::readFileToStringForTest( - TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); - const std::string rust_sdk_abi_header = - TestEnvironment::readFileToStringForTest(TestEnvironment::substitute( - "{{ test_rundir }}/source/extensions/dynamic_modules/sdk/rust/abi.h")); - EXPECT_EQ(original_abi_header, rust_sdk_abi_header); - // TODO: Go SDK. -} - } // namespace DynamicModules } // namespace Extensions } // namespace Envoy From beac95ec2492fbd03fe3eb47e25759265a0d8b9f Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 29 Aug 2024 21:17:33 +0000 Subject: [PATCH 05/16] comment Signed-off-by: Takeshi Yoneda --- source/extensions/dynamic_modules/sdk/rust/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index d61017d352d2..e8aa578d6c95 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -28,7 +28,7 @@ macro_rules! declare_program_init { #[no_mangle] pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { if ($f()) { - // This magic number is the hash of the string "abi.h" which must match the + // This magic number is sha256 of the ABI headers which must match the // value in abi_version.h b"749b1e6bf97309b7d171009700a80e651ac61e35f9770c24a63460d765895a51\0".as_ptr() as *const ::std::os::raw::c_char From e97427815f4608687e30a209a921023a2d06357e Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 29 Aug 2024 21:21:03 +0000 Subject: [PATCH 06/16] add readme Signed-off-by: Takeshi Yoneda --- source/extensions/dynamic_modules/sdk/rust/README.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 source/extensions/dynamic_modules/sdk/rust/README.md diff --git a/source/extensions/dynamic_modules/sdk/rust/README.md b/source/extensions/dynamic_modules/sdk/rust/README.md new file mode 100644 index 000000000000..4f92bbb0a607 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/README.md @@ -0,0 +1,7 @@ +# Envoy Dynamic Modules Rust SDK + +This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](../../abi.h). + +Currently, the ABI binding ([src/abi.rs](./src/abi.rs)) is manually generated by [`bindgen`](https://github.com/rust-lang/rust-bindgen) for the ABI header. Ideally, we should be able to do the bindgen in the build.rs file. + +TODO(@mathetake): figure out how to properly setup the bindgen in build.rs with rules_rust. The most recommended way is to use [crate_universe](https://bazelbuild.github.io/rules_rust/crate_universe.html#setup) and use bindgen as a dev-dependency. However, it seems that crate_universe tries to use the underlying gcc system linker which we cannot assume always available. From 1add34e76ed8660efd89e590743a8b7a1588a9e3 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 29 Aug 2024 21:30:40 +0000 Subject: [PATCH 07/16] trailing space Signed-off-by: Takeshi Yoneda --- source/extensions/dynamic_modules/sdk/rust/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/extensions/dynamic_modules/sdk/rust/README.md b/source/extensions/dynamic_modules/sdk/rust/README.md index 4f92bbb0a607..9470ff7b65df 100644 --- a/source/extensions/dynamic_modules/sdk/rust/README.md +++ b/source/extensions/dynamic_modules/sdk/rust/README.md @@ -2,6 +2,6 @@ This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](../../abi.h). -Currently, the ABI binding ([src/abi.rs](./src/abi.rs)) is manually generated by [`bindgen`](https://github.com/rust-lang/rust-bindgen) for the ABI header. Ideally, we should be able to do the bindgen in the build.rs file. +Currently, the ABI binding ([src/abi.rs](./src/abi.rs)) is manually generated by [`bindgen`](https://github.com/rust-lang/rust-bindgen) for the ABI header. Ideally, we should be able to do the bindgen in the build.rs file. TODO(@mathetake): figure out how to properly setup the bindgen in build.rs with rules_rust. The most recommended way is to use [crate_universe](https://bazelbuild.github.io/rules_rust/crate_universe.html#setup) and use bindgen as a dev-dependency. However, it seems that crate_universe tries to use the underlying gcc system linker which we cannot assume always available. From 21053c5c7967a721c118b75dd0991355af6d481a Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 29 Aug 2024 21:53:51 +0000 Subject: [PATCH 08/16] more Signed-off-by: Takeshi Yoneda --- test/extensions/dynamic_modules/BUILD | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index 209579cceebc..f136dd11269e 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -1,4 +1,3 @@ -load("@rules_rust//rust:defs.bzl", "rust_clippy", "rustfmt_test") load( "//bazel:envoy_build_system.bzl", "envoy_cc_test", @@ -43,13 +42,3 @@ envoy_cc_test( "//test/test_common:utility_lib", ], ) - -rustfmt_test( - name = "envoy_proxy_dynamic_modules_rust_sdk_fmt", - targets = ["//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk"], -) - -rust_clippy( - name = "envoy_proxy_dynamic_modules_rust_sdk_clippy", - deps = ["//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk"], -) From 7b4bd304fe2d845a763e0dcf081a70a2d925ae0a Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 17:25:58 +0000 Subject: [PATCH 09/16] review: use LazyLock which requires 1.80+ Signed-off-by: Takeshi Yoneda --- bazel/dependency_imports.bzl | 4 ++++ .../dynamic_modules/test_data/rust/no_op.rs | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 6f782ef73263..e466b5f618db 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -20,6 +20,9 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi # go version for rules_go GO_VERSION = "1.22.5" +# Rust version for rules_rust. +RUST_VERSION = "1.80.1" + JQ_VERSION = "1.7" YQ_VERSION = "4.24.4" @@ -46,6 +49,7 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y ) rules_rust_dependencies() rust_register_toolchains( + versions = [RUST_VERSION], extra_target_triples = [ "wasm32-unknown-unknown", "wasm32-wasi", diff --git a/test/extensions/dynamic_modules/test_data/rust/no_op.rs b/test/extensions/dynamic_modules/test_data/rust/no_op.rs index 6d3fe6141cfb..b660a5d972d9 100644 --- a/test/extensions/dynamic_modules/test_data/rust/no_op.rs +++ b/test/extensions/dynamic_modules/test_data/rust/no_op.rs @@ -1,4 +1,5 @@ use envoy_proxy_dynamic_modules_rust_sdk::declare_program_init; +use std::sync::{LazyLock, Mutex}; declare_program_init!(init); @@ -6,12 +7,11 @@ fn init() -> bool { true } +static SOME_VARIABLE: LazyLock> = LazyLock::new(|| Mutex::new(0)); + #[no_mangle] pub extern "C" fn getSomeVariable() -> i32 { - static mut SOME_VARIABLE: i32 = 0; - - unsafe { - SOME_VARIABLE += 1; - SOME_VARIABLE - } + let mut v = SOME_VARIABLE.lock().unwrap(); + *v += 1; + *v } From 7a6e10f66c25dff07f04fad5e3951471e4aadaa4 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 19:12:51 +0000 Subject: [PATCH 10/16] 1.80.0 Signed-off-by: Takeshi Yoneda --- bazel/dependency_imports.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index e466b5f618db..3339d2463579 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -21,7 +21,7 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi GO_VERSION = "1.22.5" # Rust version for rules_rust. -RUST_VERSION = "1.80.1" +RUST_VERSION = "1.80.0" JQ_VERSION = "1.7" YQ_VERSION = "4.24.4" @@ -49,7 +49,7 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y ) rules_rust_dependencies() rust_register_toolchains( - versions = [RUST_VERSION], + versions = ["1.80.1"], extra_target_triples = [ "wasm32-unknown-unknown", "wasm32-wasi", From a9e7a3c447ebf38395f98efed97fc1cdbe70955c Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 19:13:49 +0000 Subject: [PATCH 11/16] more Signed-off-by: Takeshi Yoneda --- bazel/dependency_imports.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 3339d2463579..14188f224bf2 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -49,7 +49,7 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y ) rules_rust_dependencies() rust_register_toolchains( - versions = ["1.80.1"], + versions = [RUST_VERSION], extra_target_triples = [ "wasm32-unknown-unknown", "wasm32-wasi", From 5a24889b5dbcb266a241e7a4fd48745587071d28 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 19:41:02 +0000 Subject: [PATCH 12/16] use Atomic instead of LazyLock LazyLock is stabilized in 1.80 (LazyOnce is in 1.79), but somehoe x64 CI fails with rust version upgrade Signed-off-by: Takeshi Yoneda --- bazel/dependency_imports.bzl | 4 ---- test/extensions/dynamic_modules/test_data/rust/no_op.rs | 8 +++----- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/bazel/dependency_imports.bzl b/bazel/dependency_imports.bzl index 14188f224bf2..6f782ef73263 100644 --- a/bazel/dependency_imports.bzl +++ b/bazel/dependency_imports.bzl @@ -20,9 +20,6 @@ load("@rules_rust//rust:repositories.bzl", "rules_rust_dependencies", "rust_regi # go version for rules_go GO_VERSION = "1.22.5" -# Rust version for rules_rust. -RUST_VERSION = "1.80.0" - JQ_VERSION = "1.7" YQ_VERSION = "4.24.4" @@ -49,7 +46,6 @@ def envoy_dependency_imports(go_version = GO_VERSION, jq_version = JQ_VERSION, y ) rules_rust_dependencies() rust_register_toolchains( - versions = [RUST_VERSION], extra_target_triples = [ "wasm32-unknown-unknown", "wasm32-wasi", diff --git a/test/extensions/dynamic_modules/test_data/rust/no_op.rs b/test/extensions/dynamic_modules/test_data/rust/no_op.rs index b660a5d972d9..309744dd86da 100644 --- a/test/extensions/dynamic_modules/test_data/rust/no_op.rs +++ b/test/extensions/dynamic_modules/test_data/rust/no_op.rs @@ -1,5 +1,5 @@ use envoy_proxy_dynamic_modules_rust_sdk::declare_program_init; -use std::sync::{LazyLock, Mutex}; +use std::sync::atomic::{AtomicI32, Ordering}; declare_program_init!(init); @@ -7,11 +7,9 @@ fn init() -> bool { true } -static SOME_VARIABLE: LazyLock> = LazyLock::new(|| Mutex::new(0)); +static SOME_VARIABLE: AtomicI32 = AtomicI32::new(1); #[no_mangle] pub extern "C" fn getSomeVariable() -> i32 { - let mut v = SOME_VARIABLE.lock().unwrap(); - *v += 1; - *v + SOME_VARIABLE.fetch_add(1, Ordering::SeqCst) } From fff449c1046751549afe0250200c55d8ea61cab2 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 20:41:04 +0000 Subject: [PATCH 13/16] try using the releases of rules_rust Signed-off-by: Takeshi Yoneda --- WORKSPACE | 17 + bazel/repository_locations.bzl | 6 +- .../extensions/dynamic_modules/sdk/README.md | 2 + .../extensions/dynamic_modules/sdk/rust/BUILD | 20 + .../dynamic_modules/sdk/rust/Cargo.lock | 362 ++++++++++++++++++ .../dynamic_modules/sdk/rust/Cargo.toml | 3 + .../dynamic_modules/sdk/rust/README.md | 6 +- .../extensions/dynamic_modules/sdk/rust/abi.h | 68 ++++ .../dynamic_modules/sdk/rust/build.rs | 16 + .../dynamic_modules/sdk/rust/src/abi.rs | 17 - .../dynamic_modules/sdk/rust/src/lib.rs | 4 +- test/extensions/dynamic_modules/BUILD | 1 + .../dynamic_modules/abi_version_test.cc | 12 + 13 files changed, 508 insertions(+), 26 deletions(-) create mode 100644 source/extensions/dynamic_modules/sdk/rust/abi.h create mode 100644 source/extensions/dynamic_modules/sdk/rust/build.rs delete mode 100644 source/extensions/dynamic_modules/sdk/rust/src/abi.rs diff --git a/WORKSPACE b/WORKSPACE index 9819ecb5ac1e..59efef5702f9 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,3 +27,20 @@ envoy_python_dependencies() load("//bazel:dependency_imports.bzl", "envoy_dependency_imports") envoy_dependency_imports() + +# TODO: move them inside proper macros under bazel/** +load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") + +crate_universe_dependencies() + +load("@rules_rust//crate_universe:defs.bzl", "crates_repository") + +crates_repository( + name = "dynamic_modules_rust_sdk_crate_index", + cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", + manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], +) + +load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "crate_repositories") + +crate_repositories() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index e410dfbf506e..c1b3064804ba 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -1466,9 +1466,9 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_desc = "Bazel rust rules (used by Wasm)", project_url = "https://github.com/bazelbuild/rules_rust", version = "0.35.0", - strip_prefix = "rules_rust-{version}", - sha256 = "3120c7aa3a146dfe6be8d5f23f4cf10af7d0f74a5aed8b94a818f88643bd24c3", - urls = ["https://github.com/bazelbuild/rules_rust/archive/{version}.tar.gz"], + sha256 = "d21c328b21f3c9ecfa4c1e92dd61ace63ff22603234067cf0fe495f75ac251ae", + # Note: rules_rust should point to the releases, not archive to avoid the hassle of bootstrapping in crate_universe. + urls = ["https://github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz"], use_category = [ "controlplane", "dataplane_core", diff --git a/source/extensions/dynamic_modules/sdk/README.md b/source/extensions/dynamic_modules/sdk/README.md index 64d61baa62f2..65cae47ec4a9 100644 --- a/source/extensions/dynamic_modules/sdk/README.md +++ b/source/extensions/dynamic_modules/sdk/README.md @@ -2,3 +2,5 @@ This directory contains the SDKs for the Dynamic Modules feature. Each SDK passes the same set of tests and is guaranteed to provide the same functionality. + +Each SDK has a hard copy of the ABI header file in order for them to be able to compile off-tree. Rust and Go build system cannot handle symlinks. diff --git a/source/extensions/dynamic_modules/sdk/rust/BUILD b/source/extensions/dynamic_modules/sdk/rust/BUILD index 480a9432eb58..4b16c62bcdc1 100644 --- a/source/extensions/dynamic_modules/sdk/rust/BUILD +++ b/source/extensions/dynamic_modules/sdk/rust/BUILD @@ -1,3 +1,5 @@ +load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "all_crate_deps") +load("@rules_rust//cargo:defs.bzl", "cargo_build_script") load("@rules_rust//rust:defs.bzl", "rust_library") load( "//bazel:envoy_build_system.bzl", @@ -6,10 +8,28 @@ load( licenses(["notice"]) # Apache 2 +exports_files(["abi.h"]) + envoy_extension_package() +cargo_build_script( + name = "build_script", + srcs = ["build.rs"], + data = [ + "abi.h", + ], + edition = "2021", + deps = all_crate_deps( + build = True, + normal = True, + ), +) + rust_library( name = "envoy_proxy_dynamic_modules_rust_sdk", srcs = glob(["src/**/*.rs"]), edition = "2021", + deps = all_crate_deps( + normal = True, + ) + [":build_script"], ) diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock index f6f126e02005..2676141cf93b 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock @@ -2,6 +2,368 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + +[[package]] +name = "bindgen" +version = "0.65.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" +dependencies = [ + "bitflags 1.3.2", + "cexpr", + "clang-sys", + "lazy_static", + "lazycell", + "log", + "peeking_take_while", + "prettyplease", + "proc-macro2", + "quote", + "regex", + "rustc-hash", + "shlex", + "syn", + "which", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cexpr" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" +dependencies = [ + "nom", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clang-sys" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" +dependencies = [ + "glob", + "libc", + "libloading", +] + +[[package]] +name = "either" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" + [[package]] name = "envoy-proxy-dynamic-modules-rust-sdk" version = "0.1.0" +dependencies = [ + "bindgen", +] + +[[package]] +name = "errno" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "glob" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" + +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "lazycell" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" + +[[package]] +name = "libc" +version = "0.2.158" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" + +[[package]] +name = "libloading" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +dependencies = [ + "cfg-if", + "windows-targets", +] + +[[package]] +name = "linux-raw-sys" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" + +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + +[[package]] +name = "minimal-lexical" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" + +[[package]] +name = "nom" +version = "7.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" +dependencies = [ + "memchr", + "minimal-lexical", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + +[[package]] +name = "peeking_take_while" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" + +[[package]] +name = "prettyplease" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +dependencies = [ + "proc-macro2", + "syn", +] + +[[package]] +name = "proc-macro2" +version = "1.0.86" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + +[[package]] +name = "rustix" +version = "0.38.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" +dependencies = [ + "bitflags 2.6.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + +[[package]] +name = "shlex" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" + +[[package]] +name = "syn" +version = "2.0.77" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml index 3874a8a3301b..b7073aa81d96 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml @@ -9,4 +9,7 @@ repository = "https://github.com/envoyproxy/envoy" [dependencies] +[build-dependencies] +bindgen = "0.65.1" + [lib] diff --git a/source/extensions/dynamic_modules/sdk/rust/README.md b/source/extensions/dynamic_modules/sdk/rust/README.md index 9470ff7b65df..9012fbd54de0 100644 --- a/source/extensions/dynamic_modules/sdk/rust/README.md +++ b/source/extensions/dynamic_modules/sdk/rust/README.md @@ -1,7 +1,3 @@ # Envoy Dynamic Modules Rust SDK -This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](../../abi.h). - -Currently, the ABI binding ([src/abi.rs](./src/abi.rs)) is manually generated by [`bindgen`](https://github.com/rust-lang/rust-bindgen) for the ABI header. Ideally, we should be able to do the bindgen in the build.rs file. - -TODO(@mathetake): figure out how to properly setup the bindgen in build.rs with rules_rust. The most recommended way is to use [crate_universe](https://bazelbuild.github.io/rules_rust/crate_universe.html#setup) and use bindgen as a dev-dependency. However, it seems that crate_universe tries to use the underlying gcc system linker which we cannot assume always available. +This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](abi.h). diff --git a/source/extensions/dynamic_modules/sdk/rust/abi.h b/source/extensions/dynamic_modules/sdk/rust/abi.h new file mode 100644 index 000000000000..460dc00cef58 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/abi.h @@ -0,0 +1,68 @@ +#pragma once + +// NOLINT(namespace-envoy) + +// This is a pure C header file that defines the ABI of the core of dynamic modules used by Envoy. +// +// This must not contain any dependencies besides standard library since it is not only used by +// Envoy itself but also by dynamic module SDKs written in non-C++ languages. +// +// Currently, compatibility is only guaranteed by an exact version match between the Envoy +// codebase and the dynamic module SDKs. In the future, after the ABI is stabilized, we will revisit +// this restriction and hopefully provide a wider compatibility guarantee. Until then, Envoy +// checks the hash of the ABI header files to ensure that the dynamic modules are built against the +// same version of the ABI. + +#ifdef __cplusplus +#include + +extern "C" { +#else +#include +#endif + +// ----------------------------------------------------------------------------- +// ---------------------------------- Types ------------------------------------ +// ----------------------------------------------------------------------------- +// +// Types used in the ABI. The name of a type must be prefixed with "envoy_dynamic_module_type_". + +/** + * envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI + * version of the dynamic module. This is used to ensure that the dynamic module is built against + * the compatible version of the ABI. + */ +typedef const char* envoy_dynamic_module_type_abi_version; // NOLINT(modernize-use-using) + +// ----------------------------------------------------------------------------- +// ------------------------------- Event Hooks --------------------------------- +// ----------------------------------------------------------------------------- +// +// Event hooks are functions that are called by Envoy in response to certain events. +// The module must implement and export these functions in the dynamic module object file. +// +// Each event hook is defined as a function prototype. The symbol must be prefixed with +// "envoy_dynamic_module_on_". + +/** + * envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is + * loaded. The function returns the ABI version of the dynamic module. If null is returned, the + * module will be unloaded immediately. + * + * For Envoy, the return value will be used to check the compatibility of the dynamic module. + * + * For dynamic modules, this is useful when they need to perform some process-wide + * initialization or check if the module is compatible with the platform, such as CPU features. + * Note that initialization routines of a dynamic module can also be performed without this function + * through constructor functions in an object file. However, normal constructors cannot be used + * to check compatibility and gracefully fail the initialization because there is no way to + * report an error to Envoy. + * + * @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null + * means the error and the module will be unloaded immediately. + */ +envoy_dynamic_module_type_abi_version envoy_dynamic_module_on_program_init(); + +#ifdef __cplusplus +} +#endif diff --git a/source/extensions/dynamic_modules/sdk/rust/build.rs b/source/extensions/dynamic_modules/sdk/rust/build.rs new file mode 100644 index 000000000000..37622b5ca4a9 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/build.rs @@ -0,0 +1,16 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + println!("cargo:rerun-if-changed=abi.h"); + let bindings = bindgen::Builder::default() + .header("abi.h") + .parse_callbacks(Box::new(bindgen::CargoCallbacks)) + .generate() + .expect("Unable to generate bindings"); + + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + bindings + .write_to_file(out_path.join("bindings.rs")) + .expect("Couldn't write bindings!"); +} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/abi.rs b/source/extensions/dynamic_modules/sdk/rust/src/abi.rs deleted file mode 100644 index d673d5b2c599..000000000000 --- a/source/extensions/dynamic_modules/sdk/rust/src/abi.rs +++ /dev/null @@ -1,17 +0,0 @@ -/* automatically generated by rust-bindgen 0.70.1 */ - -pub type wchar_t = ::std::os::raw::c_int; -#[repr(C)] -#[repr(align(16))] -#[derive(Debug, Copy, Clone)] -pub struct max_align_t { - pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, - pub __bindgen_padding_0: u64, - pub __clang_max_align_nonce2: u128, -} -#[doc = " envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI\n version of the dynamic module. This is used to ensure that the dynamic module is built against\n the compatible version of the ABI."] -pub type envoy_dynamic_module_type_abi_version = *const ::std::os::raw::c_char; -extern "C" { - #[doc = " envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is\n loaded. The function returns the ABI version of the dynamic module. If null is returned, the\n module will be unloaded immediately.\n\n For Envoy, the return value will be used to check the compatibility of the dynamic module.\n\n For dynamic modules, this is useful when they need to perform some process-wide\n initialization or check if the module is compatible with the platform, such as CPU features.\n Note that initialization routines of a dynamic module can also be performed without this function\n through constructor functions in an object file. However, normal constructors cannot be used\n to check compatibility and gracefully fail the initialization because there is no way to\n report an error to Envoy.\n\n @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null\n means the error and the module will be unloaded immediately."] - pub fn envoy_dynamic_module_on_program_init() -> envoy_dynamic_module_type_abi_version; -} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index e8aa578d6c95..3a806c0f2eee 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -3,7 +3,9 @@ #![allow(non_snake_case)] #![allow(dead_code)] -mod abi; +mod abi { + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +} /// Declare the init function for the dynamic module. This function is called when the dynamic module is loaded. /// The function must return true on success, and false on failure. When it returns false, diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index f136dd11269e..5d1ce3838748 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -33,6 +33,7 @@ envoy_cc_test( srcs = ["abi_version_test.cc"], data = [ "//source/extensions/dynamic_modules:abi.h", + "//source/extensions/dynamic_modules/sdk/rust:abi.h", ], deps = [ "//source/common/common:hex_lib", diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index 958295281dde..73990723e200 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -27,6 +27,18 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } +// This test ensures that the copied ABI header files in the SDK directory are identical to the original ABI headers. +TEST(DynamicModules, ABIHeaderIdentical) { + const std::string original_abi_header = TestEnvironment::readFileToStringForTest( + TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); + const std::string rust_abi_header = + TestEnvironment::readFileToStringForTest(TestEnvironment::substitute( + "{{ test_rundir }}/source/extensions/dynamic_modules/sdk/rust/abi.h")); + EXPECT_EQ(original_abi_header, rust_abi_header); + // TODO: Add Go SDK. +} + + } // namespace DynamicModules } // namespace Extensions } // namespace Envoy From 6923b75b2c7a4255f1368fba795b701e29ec32a0 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 20:58:49 +0000 Subject: [PATCH 14/16] format Signed-off-by: Takeshi Yoneda --- test/extensions/dynamic_modules/abi_version_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index 73990723e200..d3a558c84558 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -27,7 +27,8 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } -// This test ensures that the copied ABI header files in the SDK directory are identical to the original ABI headers. +// This test ensures that the copied ABI header files in the SDK directory are identical to the +// original ABI headers. TEST(DynamicModules, ABIHeaderIdentical) { const std::string original_abi_header = TestEnvironment::readFileToStringForTest( TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); @@ -38,7 +39,6 @@ TEST(DynamicModules, ABIHeaderIdentical) { // TODO: Add Go SDK. } - } // namespace DynamicModules } // namespace Extensions } // namespace Envoy From ee43ed38b68432c172c3963d3543658ffa633736 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 22:39:14 +0000 Subject: [PATCH 15/16] Revert "format" This reverts commit 6923b75b2c7a4255f1368fba795b701e29ec32a0. Signed-off-by: Takeshi Yoneda --- test/extensions/dynamic_modules/abi_version_test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index d3a558c84558..73990723e200 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -27,8 +27,7 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } -// This test ensures that the copied ABI header files in the SDK directory are identical to the -// original ABI headers. +// This test ensures that the copied ABI header files in the SDK directory are identical to the original ABI headers. TEST(DynamicModules, ABIHeaderIdentical) { const std::string original_abi_header = TestEnvironment::readFileToStringForTest( TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); @@ -39,6 +38,7 @@ TEST(DynamicModules, ABIHeaderIdentical) { // TODO: Add Go SDK. } + } // namespace DynamicModules } // namespace Extensions } // namespace Envoy From ef12250860badd746016931700a8433a045974e2 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Tue, 3 Sep 2024 22:39:59 +0000 Subject: [PATCH 16/16] Revert "try using the releases of rules_rust" This reverts commit fff449c1046751549afe0250200c55d8ea61cab2. Signed-off-by: Takeshi Yoneda --- WORKSPACE | 17 - bazel/repository_locations.bzl | 6 +- .../extensions/dynamic_modules/sdk/README.md | 2 - .../extensions/dynamic_modules/sdk/rust/BUILD | 20 - .../dynamic_modules/sdk/rust/Cargo.lock | 362 ------------------ .../dynamic_modules/sdk/rust/Cargo.toml | 3 - .../dynamic_modules/sdk/rust/README.md | 6 +- .../extensions/dynamic_modules/sdk/rust/abi.h | 68 ---- .../dynamic_modules/sdk/rust/build.rs | 16 - .../dynamic_modules/sdk/rust/src/abi.rs | 17 + .../dynamic_modules/sdk/rust/src/lib.rs | 4 +- test/extensions/dynamic_modules/BUILD | 1 - .../dynamic_modules/abi_version_test.cc | 12 - 13 files changed, 26 insertions(+), 508 deletions(-) delete mode 100644 source/extensions/dynamic_modules/sdk/rust/abi.h delete mode 100644 source/extensions/dynamic_modules/sdk/rust/build.rs create mode 100644 source/extensions/dynamic_modules/sdk/rust/src/abi.rs diff --git a/WORKSPACE b/WORKSPACE index 59efef5702f9..9819ecb5ac1e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -27,20 +27,3 @@ envoy_python_dependencies() load("//bazel:dependency_imports.bzl", "envoy_dependency_imports") envoy_dependency_imports() - -# TODO: move them inside proper macros under bazel/** -load("@rules_rust//crate_universe:repositories.bzl", "crate_universe_dependencies") - -crate_universe_dependencies() - -load("@rules_rust//crate_universe:defs.bzl", "crates_repository") - -crates_repository( - name = "dynamic_modules_rust_sdk_crate_index", - cargo_lockfile = "//source/extensions/dynamic_modules/sdk/rust:Cargo.lock", - manifests = ["//source/extensions/dynamic_modules/sdk/rust:Cargo.toml"], -) - -load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "crate_repositories") - -crate_repositories() diff --git a/bazel/repository_locations.bzl b/bazel/repository_locations.bzl index c1b3064804ba..e410dfbf506e 100644 --- a/bazel/repository_locations.bzl +++ b/bazel/repository_locations.bzl @@ -1466,9 +1466,9 @@ REPOSITORY_LOCATIONS_SPEC = dict( project_desc = "Bazel rust rules (used by Wasm)", project_url = "https://github.com/bazelbuild/rules_rust", version = "0.35.0", - sha256 = "d21c328b21f3c9ecfa4c1e92dd61ace63ff22603234067cf0fe495f75ac251ae", - # Note: rules_rust should point to the releases, not archive to avoid the hassle of bootstrapping in crate_universe. - urls = ["https://github.com/bazelbuild/rules_rust/releases/download/{version}/rules_rust-v{version}.tar.gz"], + strip_prefix = "rules_rust-{version}", + sha256 = "3120c7aa3a146dfe6be8d5f23f4cf10af7d0f74a5aed8b94a818f88643bd24c3", + urls = ["https://github.com/bazelbuild/rules_rust/archive/{version}.tar.gz"], use_category = [ "controlplane", "dataplane_core", diff --git a/source/extensions/dynamic_modules/sdk/README.md b/source/extensions/dynamic_modules/sdk/README.md index 65cae47ec4a9..64d61baa62f2 100644 --- a/source/extensions/dynamic_modules/sdk/README.md +++ b/source/extensions/dynamic_modules/sdk/README.md @@ -2,5 +2,3 @@ This directory contains the SDKs for the Dynamic Modules feature. Each SDK passes the same set of tests and is guaranteed to provide the same functionality. - -Each SDK has a hard copy of the ABI header file in order for them to be able to compile off-tree. Rust and Go build system cannot handle symlinks. diff --git a/source/extensions/dynamic_modules/sdk/rust/BUILD b/source/extensions/dynamic_modules/sdk/rust/BUILD index 4b16c62bcdc1..480a9432eb58 100644 --- a/source/extensions/dynamic_modules/sdk/rust/BUILD +++ b/source/extensions/dynamic_modules/sdk/rust/BUILD @@ -1,5 +1,3 @@ -load("@dynamic_modules_rust_sdk_crate_index//:defs.bzl", "all_crate_deps") -load("@rules_rust//cargo:defs.bzl", "cargo_build_script") load("@rules_rust//rust:defs.bzl", "rust_library") load( "//bazel:envoy_build_system.bzl", @@ -8,28 +6,10 @@ load( licenses(["notice"]) # Apache 2 -exports_files(["abi.h"]) - envoy_extension_package() -cargo_build_script( - name = "build_script", - srcs = ["build.rs"], - data = [ - "abi.h", - ], - edition = "2021", - deps = all_crate_deps( - build = True, - normal = True, - ), -) - rust_library( name = "envoy_proxy_dynamic_modules_rust_sdk", srcs = glob(["src/**/*.rs"]), edition = "2021", - deps = all_crate_deps( - normal = True, - ) + [":build_script"], ) diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock index 2676141cf93b..f6f126e02005 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.lock +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.lock @@ -2,368 +2,6 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "aho-corasick" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" -dependencies = [ - "memchr", -] - -[[package]] -name = "bindgen" -version = "0.65.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfdf7b466f9a4903edc73f95d6d2bcd5baf8ae620638762244d3f60143643cc5" -dependencies = [ - "bitflags 1.3.2", - "cexpr", - "clang-sys", - "lazy_static", - "lazycell", - "log", - "peeking_take_while", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", - "which", -] - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "bitflags" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" - -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - -[[package]] -name = "either" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" - [[package]] name = "envoy-proxy-dynamic-modules-rust-sdk" version = "0.1.0" -dependencies = [ - "bindgen", -] - -[[package]] -name = "errno" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "glob" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" - -[[package]] -name = "home" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - -[[package]] -name = "libc" -version = "0.2.158" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" - -[[package]] -name = "libloading" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" -dependencies = [ - "cfg-if", - "windows-targets", -] - -[[package]] -name = "linux-raw-sys" -version = "0.4.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" - -[[package]] -name = "log" -version = "0.4.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" - -[[package]] -name = "memchr" -version = "2.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" - -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - -[[package]] -name = "once_cell" -version = "1.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" - -[[package]] -name = "peeking_take_while" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" - -[[package]] -name = "prettyplease" -version = "0.2.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" -dependencies = [ - "proc-macro2", - "syn", -] - -[[package]] -name = "proc-macro2" -version = "1.0.86" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.10.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" -dependencies = [ - "aho-corasick", - "memchr", - "regex-automata", - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.4.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" -dependencies = [ - "aho-corasick", - "memchr", - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.8.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - -[[package]] -name = "rustix" -version = "0.38.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a85d50532239da68e9addb745ba38ff4612a242c1c7ceea689c4bc7c2f43c36f" -dependencies = [ - "bitflags 2.6.0", - "errno", - "libc", - "linux-raw-sys", - "windows-sys", -] - -[[package]] -name = "shlex" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" - -[[package]] -name = "syn" -version = "2.0.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "unicode-ident" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" - -[[package]] -name = "which" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" -dependencies = [ - "either", - "home", - "once_cell", - "rustix", -] - -[[package]] -name = "windows-sys" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" -dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" - -[[package]] -name = "windows_i686_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" diff --git a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml index b7073aa81d96..3874a8a3301b 100644 --- a/source/extensions/dynamic_modules/sdk/rust/Cargo.toml +++ b/source/extensions/dynamic_modules/sdk/rust/Cargo.toml @@ -9,7 +9,4 @@ repository = "https://github.com/envoyproxy/envoy" [dependencies] -[build-dependencies] -bindgen = "0.65.1" - [lib] diff --git a/source/extensions/dynamic_modules/sdk/rust/README.md b/source/extensions/dynamic_modules/sdk/rust/README.md index 9012fbd54de0..9470ff7b65df 100644 --- a/source/extensions/dynamic_modules/sdk/rust/README.md +++ b/source/extensions/dynamic_modules/sdk/rust/README.md @@ -1,3 +1,7 @@ # Envoy Dynamic Modules Rust SDK -This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](abi.h). +This directory contains the Rust SDK for the Dynamic Modules feature. The SDK passes the same set of tests and is guaranteed to provide the same functionality as the other SDKs. This directory is organized in the way that it can be used as a standalone Rust crate. The SDK is basically the high-level abstraction layer for the Dynamic Modules ABI defined in the [abi.h](../../abi.h). + +Currently, the ABI binding ([src/abi.rs](./src/abi.rs)) is manually generated by [`bindgen`](https://github.com/rust-lang/rust-bindgen) for the ABI header. Ideally, we should be able to do the bindgen in the build.rs file. + +TODO(@mathetake): figure out how to properly setup the bindgen in build.rs with rules_rust. The most recommended way is to use [crate_universe](https://bazelbuild.github.io/rules_rust/crate_universe.html#setup) and use bindgen as a dev-dependency. However, it seems that crate_universe tries to use the underlying gcc system linker which we cannot assume always available. diff --git a/source/extensions/dynamic_modules/sdk/rust/abi.h b/source/extensions/dynamic_modules/sdk/rust/abi.h deleted file mode 100644 index 460dc00cef58..000000000000 --- a/source/extensions/dynamic_modules/sdk/rust/abi.h +++ /dev/null @@ -1,68 +0,0 @@ -#pragma once - -// NOLINT(namespace-envoy) - -// This is a pure C header file that defines the ABI of the core of dynamic modules used by Envoy. -// -// This must not contain any dependencies besides standard library since it is not only used by -// Envoy itself but also by dynamic module SDKs written in non-C++ languages. -// -// Currently, compatibility is only guaranteed by an exact version match between the Envoy -// codebase and the dynamic module SDKs. In the future, after the ABI is stabilized, we will revisit -// this restriction and hopefully provide a wider compatibility guarantee. Until then, Envoy -// checks the hash of the ABI header files to ensure that the dynamic modules are built against the -// same version of the ABI. - -#ifdef __cplusplus -#include - -extern "C" { -#else -#include -#endif - -// ----------------------------------------------------------------------------- -// ---------------------------------- Types ------------------------------------ -// ----------------------------------------------------------------------------- -// -// Types used in the ABI. The name of a type must be prefixed with "envoy_dynamic_module_type_". - -/** - * envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI - * version of the dynamic module. This is used to ensure that the dynamic module is built against - * the compatible version of the ABI. - */ -typedef const char* envoy_dynamic_module_type_abi_version; // NOLINT(modernize-use-using) - -// ----------------------------------------------------------------------------- -// ------------------------------- Event Hooks --------------------------------- -// ----------------------------------------------------------------------------- -// -// Event hooks are functions that are called by Envoy in response to certain events. -// The module must implement and export these functions in the dynamic module object file. -// -// Each event hook is defined as a function prototype. The symbol must be prefixed with -// "envoy_dynamic_module_on_". - -/** - * envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is - * loaded. The function returns the ABI version of the dynamic module. If null is returned, the - * module will be unloaded immediately. - * - * For Envoy, the return value will be used to check the compatibility of the dynamic module. - * - * For dynamic modules, this is useful when they need to perform some process-wide - * initialization or check if the module is compatible with the platform, such as CPU features. - * Note that initialization routines of a dynamic module can also be performed without this function - * through constructor functions in an object file. However, normal constructors cannot be used - * to check compatibility and gracefully fail the initialization because there is no way to - * report an error to Envoy. - * - * @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null - * means the error and the module will be unloaded immediately. - */ -envoy_dynamic_module_type_abi_version envoy_dynamic_module_on_program_init(); - -#ifdef __cplusplus -} -#endif diff --git a/source/extensions/dynamic_modules/sdk/rust/build.rs b/source/extensions/dynamic_modules/sdk/rust/build.rs deleted file mode 100644 index 37622b5ca4a9..000000000000 --- a/source/extensions/dynamic_modules/sdk/rust/build.rs +++ /dev/null @@ -1,16 +0,0 @@ -use std::env; -use std::path::PathBuf; - -fn main() { - println!("cargo:rerun-if-changed=abi.h"); - let bindings = bindgen::Builder::default() - .header("abi.h") - .parse_callbacks(Box::new(bindgen::CargoCallbacks)) - .generate() - .expect("Unable to generate bindings"); - - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); -} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/abi.rs b/source/extensions/dynamic_modules/sdk/rust/src/abi.rs new file mode 100644 index 000000000000..d673d5b2c599 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/src/abi.rs @@ -0,0 +1,17 @@ +/* automatically generated by rust-bindgen 0.70.1 */ + +pub type wchar_t = ::std::os::raw::c_int; +#[repr(C)] +#[repr(align(16))] +#[derive(Debug, Copy, Clone)] +pub struct max_align_t { + pub __clang_max_align_nonce1: ::std::os::raw::c_longlong, + pub __bindgen_padding_0: u64, + pub __clang_max_align_nonce2: u128, +} +#[doc = " envoy_dynamic_module_type_abi_version represents a null-terminated string that contains the ABI\n version of the dynamic module. This is used to ensure that the dynamic module is built against\n the compatible version of the ABI."] +pub type envoy_dynamic_module_type_abi_version = *const ::std::os::raw::c_char; +extern "C" { + #[doc = " envoy_dynamic_module_on_program_init is called by the main thread exactly when the module is\n loaded. The function returns the ABI version of the dynamic module. If null is returned, the\n module will be unloaded immediately.\n\n For Envoy, the return value will be used to check the compatibility of the dynamic module.\n\n For dynamic modules, this is useful when they need to perform some process-wide\n initialization or check if the module is compatible with the platform, such as CPU features.\n Note that initialization routines of a dynamic module can also be performed without this function\n through constructor functions in an object file. However, normal constructors cannot be used\n to check compatibility and gracefully fail the initialization because there is no way to\n report an error to Envoy.\n\n @return envoy_dynamic_module_type_abi_version is the ABI version of the dynamic module. Null\n means the error and the module will be unloaded immediately."] + pub fn envoy_dynamic_module_on_program_init() -> envoy_dynamic_module_type_abi_version; +} diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index 3a806c0f2eee..e8aa578d6c95 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -3,9 +3,7 @@ #![allow(non_snake_case)] #![allow(dead_code)] -mod abi { - include!(concat!(env!("OUT_DIR"), "/bindings.rs")); -} +mod abi; /// Declare the init function for the dynamic module. This function is called when the dynamic module is loaded. /// The function must return true on success, and false on failure. When it returns false, diff --git a/test/extensions/dynamic_modules/BUILD b/test/extensions/dynamic_modules/BUILD index 5d1ce3838748..f136dd11269e 100644 --- a/test/extensions/dynamic_modules/BUILD +++ b/test/extensions/dynamic_modules/BUILD @@ -33,7 +33,6 @@ envoy_cc_test( srcs = ["abi_version_test.cc"], data = [ "//source/extensions/dynamic_modules:abi.h", - "//source/extensions/dynamic_modules/sdk/rust:abi.h", ], deps = [ "//source/common/common:hex_lib", diff --git a/test/extensions/dynamic_modules/abi_version_test.cc b/test/extensions/dynamic_modules/abi_version_test.cc index 73990723e200..958295281dde 100644 --- a/test/extensions/dynamic_modules/abi_version_test.cc +++ b/test/extensions/dynamic_modules/abi_version_test.cc @@ -27,18 +27,6 @@ TEST(DynamicModules, ABIVersionCheck) { EXPECT_EQ(sha256, kAbiVersion); } -// This test ensures that the copied ABI header files in the SDK directory are identical to the original ABI headers. -TEST(DynamicModules, ABIHeaderIdentical) { - const std::string original_abi_header = TestEnvironment::readFileToStringForTest( - TestEnvironment::substitute("{{ test_rundir }}/source/extensions/dynamic_modules/abi.h")); - const std::string rust_abi_header = - TestEnvironment::readFileToStringForTest(TestEnvironment::substitute( - "{{ test_rundir }}/source/extensions/dynamic_modules/sdk/rust/abi.h")); - EXPECT_EQ(original_abi_header, rust_abi_header); - // TODO: Add Go SDK. -} - - } // namespace DynamicModules } // namespace Extensions } // namespace Envoy