From 22e7328305b8fc682644e1bfbbc33f93b856993d Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Thu, 21 Nov 2024 16:26:45 -0800 Subject: [PATCH] dynamic_modules: enables rustfmt.toml (#37295) Commit Message: dynamic_modules: enables rustfmt.toml Additional Description: This enables the root configuration for rustfmt as a follow up on https://github.com/envoyproxy/envoy/pull/37070#discussion_r1845515368. Only formatting is done in this commit. There's no change in its code. Risk Level: low Testing: n/a Docs Changes: n/a Release Notes: n/a Platform Specific Features: n/a [Optional Runtime guard:] [Optional Fixes #Issue] [Optional Fixes commit #PR or SHA] [Optional Deprecated:] [Optional [API Considerations](https://github.com/envoyproxy/envoy/blob/main/api/review_checklist.md):] Signed-off-by: Takeshi Yoneda --- .bazelrc | 3 + BUILD | 4 + rustfmt.toml | 60 ++++ .../dynamic_modules/sdk/rust/rustfmt.toml | 1 + .../dynamic_modules/sdk/rust/src/lib.rs | 281 +++++++++--------- .../dynamic_modules/test_data/rust/BUILD | 29 +- .../test_data/rust/abi_version_mismatch.rs | 2 +- .../dynamic_modules/test_data/rust/no_op.rs | 36 +-- .../test_data/rust/no_program_init.rs | 2 +- .../test_data/rust/program_init_fail.rs | 2 +- .../test_data/rust/rustfmt.toml | 1 + .../test_data/rust/test_data.bzl | 19 ++ 12 files changed, 258 insertions(+), 182 deletions(-) create mode 100644 rustfmt.toml create mode 120000 source/extensions/dynamic_modules/sdk/rust/rustfmt.toml create mode 120000 test/extensions/dynamic_modules/test_data/rust/rustfmt.toml create mode 100644 test/extensions/dynamic_modules/test_data/rust/test_data.bzl diff --git a/.bazelrc b/.bazelrc index 7df94c77944c..79b6b628faed 100644 --- a/.bazelrc +++ b/.bazelrc @@ -551,6 +551,9 @@ common:remote-envoy-engflow --config=common-envoy-engflow common:remote-envoy-engflow --config=cache-envoy-engflow common:remote-envoy-engflow --config=rbe-envoy-engflow +# Specifies the rustfmt.toml for all rustfmt_test targets. +build --@rules_rust//rust/settings:rustfmt.toml=//:rustfmt.toml + ############################################################################# # debug: Various Bazel debugging flags ############################################################################# diff --git a/BUILD b/BUILD index d3d06671ae7b..6b6d8727f065 100644 --- a/BUILD +++ b/BUILD @@ -74,3 +74,7 @@ package_group( "//mobile/...", ], ) + +exports_files([ + "rustfmt.toml", +]) diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 000000000000..f7abdfb17b8a --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,60 @@ +# This config is copied from https://github.com/bitdriftlabs/shared-core/blob/4114708cafb80103092b7e585987ef275a136f87/rustfmt.toml + +# Rust Autoformatter Config +# ========================= +# +# Note that most of rustfmt's configurable settings are nightly-only, +# so we tend to run that. Typically we don't rely on unstable features, +# but in this case there's honestly not a lot to configure that _isn't_ +# behind the `unstable_features` gate, unfortunately. + +edition = "2021" +unstable_features = true + +# Try to use inline annotations before using this -- disabling autoformatting +# for a file makes it harder for everyone to share their work in that file and +# invites bikeshedding about how code in there should look. +ignore = [] + +# Features are broken up into Stable and Unstable features, listed in order of +# appearance in the Configuring Rustfmt document: +# https://github.com/rust-lang-nursery/rustfmt/blob/master/Configurations.md + +## Stable Features + +force_explicit_abi = true # Default +hard_tabs = false # Default +max_width = 100 +merge_derives = true # Default +newline_style = "Auto" # Default +remove_nested_parens = true # Default +reorder_imports = true # Default +reorder_modules = true # Default +tab_spaces = 2 +use_field_init_shorthand = false # Default +use_small_heuristics = "Default" # Default +use_try_shorthand = true + +## Features that were "unstable" when we configured them +blank_lines_lower_bound = 0 +blank_lines_upper_bound = 3 +combine_control_expr = false +comment_width = 100 +condense_wildcard_suffixes = true +enum_discrim_align_threshold = 20 +error_on_line_overflow = true +error_on_unformatted = false +format_code_in_doc_comments = true +format_macro_bodies = true +format_macro_matchers = true +format_strings = true +group_imports = "One" +imports_granularity = "Module" +imports_layout = "HorizontalVertical" +match_block_trailing_comma = true +normalize_comments = false +normalize_doc_attributes = true +skip_children = false +spaces_around_ranges = true +struct_field_align_threshold = 0 +wrap_comments = true diff --git a/source/extensions/dynamic_modules/sdk/rust/rustfmt.toml b/source/extensions/dynamic_modules/sdk/rust/rustfmt.toml new file mode 120000 index 000000000000..28f20ab8a7a2 --- /dev/null +++ b/source/extensions/dynamic_modules/sdk/rust/rustfmt.toml @@ -0,0 +1 @@ +../../../../../rustfmt.toml \ No newline at end of file diff --git a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs index 864ab825558c..d1f761a1c008 100644 --- a/source/extensions/dynamic_modules/sdk/rust/src/lib.rs +++ b/source/extensions/dynamic_modules/sdk/rust/src/lib.rs @@ -9,14 +9,16 @@ use std::sync::OnceLock; /// /// This is not meant to be used directly. pub mod abi { - include!(concat!(env!("OUT_DIR"), "/bindings.rs")); + include!(concat!(env!("OUT_DIR"), "/bindings.rs")); } /// Declare the init functions for the dynamic module. /// -/// The first argument has [`ProgramInitFunction`] type, and it is called when the dynamic module is loaded. +/// The first argument has [`ProgramInitFunction`] type, and it is called when the dynamic module is +/// loaded. /// -/// The second argument has [`NewHttpFilterConfigFunction`] type, and it is called when the new HTTP filter configuration is created. +/// The second argument has [`NewHttpFilterConfigFunction`] type, and it is called when the new HTTP +/// filter configuration is created. /// /// # Example /// @@ -26,7 +28,7 @@ pub mod abi { /// declare_init_functions!(my_program_init, my_new_http_filter_config_fn); /// /// fn my_program_init() -> bool { -/// true +/// true /// } /// /// fn my_new_http_filter_config_fn( @@ -43,58 +45,59 @@ pub mod abi { /// ``` #[macro_export] macro_rules! declare_init_functions { - ($f:ident,$new_http_filter_config_fn:expr) => { - #[no_mangle] - pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { - envoy_proxy_dynamic_modules_rust_sdk::NEW_HTTP_FILTER_CONFIG_FUNCTION - .get_or_init(|| $new_http_filter_config_fn); - if ($f()) { - envoy_proxy_dynamic_modules_rust_sdk::abi::kAbiVersion.as_ptr() - as *const ::std::os::raw::c_char - } else { - ::std::ptr::null() - } - } - }; + ($f:ident, $new_http_filter_config_fn:expr) => { + #[no_mangle] + pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { + envoy_proxy_dynamic_modules_rust_sdk::NEW_HTTP_FILTER_CONFIG_FUNCTION + .get_or_init(|| $new_http_filter_config_fn); + if ($f()) { + envoy_proxy_dynamic_modules_rust_sdk::abi::kAbiVersion.as_ptr() + as *const ::std::os::raw::c_char + } else { + ::std::ptr::null() + } + } + }; } /// The function signature for the program init function. /// -/// This is called when the dynamic module is loaded, and it must return true on success, and false on failure. When it returns false, -/// the dynamic module will not be loaded. +/// This is called when the dynamic module is loaded, and it 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. pub type ProgramInitFunction = fn() -> bool; /// The function signature for the new HTTP filter configuration function. /// -/// This is called when a new HTTP filter configuration is created, and it must return a new instance of the [`HttpFilterConfig`] object. -/// Returning `None` will cause the HTTP filter configuration to be rejected. +/// This is called when a new HTTP filter configuration is created, and it must return a new +/// instance of the [`HttpFilterConfig`] object. Returning `None` will cause the HTTP filter +/// configuration to be rejected. // // TODO(@mathetake): I guess there would be a way to avoid the use of dyn in the first place. -// E.g. one idea is to accept all concrete type parameters for HttpFilterConfig and HttpFilter traits in declare_init_functions!, -// and generate the match statement based on that. +// E.g. one idea is to accept all concrete type parameters for HttpFilterConfig and HttpFilter +// traits in declare_init_functions!, and generate the match statement based on that. pub type NewHttpFilterConfigFunction = fn( - envoy_filter_config: EnvoyHttpFilterConfig, - name: &str, - config: &str, + envoy_filter_config: EnvoyHttpFilterConfig, + name: &str, + config: &str, ) -> Option>; -/// The global init function for HTTP filter configurations. This is set via the `declare_init_functions` macro, -/// and is not intended to be set directly. +/// The global init function for HTTP filter configurations. This is set via the +/// `declare_init_functions` macro, and is not intended to be set directly. pub static NEW_HTTP_FILTER_CONFIG_FUNCTION: OnceLock = OnceLock::new(); /// The trait that represents the configuration for an Envoy Http filter configuration. /// This has one to one mapping with the [`EnvoyHttpFilterConfig`] object. /// /// The object is created when the corresponding Envoy Http filter config is created, and it is -/// dropped when the corresponding Envoy Http filter config is destroyed. Therefore, the imlementation -/// is recommended to implement the [`Drop`] trait to handle the necessary cleanup. +/// dropped when the corresponding Envoy Http filter config is destroyed. Therefore, the +/// imlementation is recommended to implement the [`Drop`] trait to handle the necessary cleanup. pub trait HttpFilterConfig { - /// This is called when a HTTP filter chain is created for a new stream. - fn new_http_filter(&self) -> Box { - unimplemented!() // TODO. - } + /// This is called when a HTTP filter chain is created for a new stream. + fn new_http_filter(&self) -> Box { + unimplemented!() // TODO. + } } /// The trait that represents an Envoy Http filter for each stream. @@ -106,132 +109,134 @@ pub trait HttpFilter {} // TODO. /// This is a shallow wrapper around the raw pointer to the Envoy HTTP filter config object, and it /// can be copied and used up until the corresponding [`HttpFilterConfig`] is dropped. // -// TODO(@mathetake): make this only avaialble for non-test code, and provide a mock for testing so that users -// can write unit tests for their HttpFilterConfig implementations. +// TODO(@mathetake): make this only avaialble for non-test code, and provide a mock for testing so +// that users can write unit tests for their HttpFilterConfig implementations. #[derive(Debug, Clone, Copy)] pub struct EnvoyHttpFilterConfig { - raw_ptr: abi::envoy_dynamic_module_type_http_filter_config_envoy_ptr, + raw_ptr: abi::envoy_dynamic_module_type_http_filter_config_envoy_ptr, } #[no_mangle] unsafe extern "C" fn envoy_dynamic_module_on_http_filter_config_new( - envoy_filter_config_ptr: abi::envoy_dynamic_module_type_http_filter_config_envoy_ptr, - name_ptr: *const u8, - name_size: usize, - config_ptr: *const u8, - config_size: usize, + envoy_filter_config_ptr: abi::envoy_dynamic_module_type_http_filter_config_envoy_ptr, + name_ptr: *const u8, + name_size: usize, + config_ptr: *const u8, + config_size: usize, ) -> abi::envoy_dynamic_module_type_http_filter_config_module_ptr { - // This assumes that the name and config are valid UTF-8 strings. Should we relax? At the moment, both are String at protobuf level. - let name = - std::str::from_utf8(std::slice::from_raw_parts(name_ptr, name_size)).unwrap_or_default(); - let config = std::str::from_utf8(std::slice::from_raw_parts(config_ptr, config_size)) - .unwrap_or_default(); - - let envoy_filter_config = EnvoyHttpFilterConfig { - raw_ptr: envoy_filter_config_ptr, - }; - - envoy_dynamic_module_on_http_filter_config_new_impl( - envoy_filter_config, - name, - config, - NEW_HTTP_FILTER_CONFIG_FUNCTION - .get() - .expect("NEW_HTTP_FILTER_CONFIG_FUNCTION must be set"), - ) + // This assumes that the name and config are valid UTF-8 strings. Should we relax? At the moment, + // both are String at protobuf level. + let name = + std::str::from_utf8(std::slice::from_raw_parts(name_ptr, name_size)).unwrap_or_default(); + let config = + std::str::from_utf8(std::slice::from_raw_parts(config_ptr, config_size)).unwrap_or_default(); + + let envoy_filter_config = EnvoyHttpFilterConfig { + raw_ptr: envoy_filter_config_ptr, + }; + + envoy_dynamic_module_on_http_filter_config_new_impl( + envoy_filter_config, + name, + config, + NEW_HTTP_FILTER_CONFIG_FUNCTION + .get() + .expect("NEW_HTTP_FILTER_CONFIG_FUNCTION must be set"), + ) } fn envoy_dynamic_module_on_http_filter_config_new_impl( - envoy_filter_config: EnvoyHttpFilterConfig, - name: &str, - config: &str, - new_fn: &NewHttpFilterConfigFunction, + envoy_filter_config: EnvoyHttpFilterConfig, + name: &str, + config: &str, + new_fn: &NewHttpFilterConfigFunction, ) -> abi::envoy_dynamic_module_type_http_filter_config_module_ptr { - if let Some(config) = new_fn(envoy_filter_config, name, config) { - let boxed_filter_config_ptr = Box::into_raw(Box::new(config)); - boxed_filter_config_ptr as abi::envoy_dynamic_module_type_http_filter_config_module_ptr - } else { - std::ptr::null() - } + if let Some(config) = new_fn(envoy_filter_config, name, config) { + let boxed_filter_config_ptr = Box::into_raw(Box::new(config)); + boxed_filter_config_ptr as abi::envoy_dynamic_module_type_http_filter_config_module_ptr + } else { + std::ptr::null() + } } #[no_mangle] unsafe extern "C" fn envoy_dynamic_module_on_http_filter_config_destroy( - config_ptr: abi::envoy_dynamic_module_type_http_filter_config_module_ptr, + config_ptr: abi::envoy_dynamic_module_type_http_filter_config_module_ptr, ) { - let config = config_ptr as *mut *mut dyn HttpFilterConfig; + let config = config_ptr as *mut *mut dyn HttpFilterConfig; - // Drop the Box<*mut dyn HttpFilterConfig>, and then the Box, which also drops the underlying object. - let _outer = Box::from_raw(config); - let _inner = Box::from_raw(*config); + // Drop the Box<*mut dyn HttpFilterConfig>, and then the Box, which also + // drops the underlying object. + let _outer = Box::from_raw(config); + let _inner = Box::from_raw(*config); } #[cfg(test)] mod tests { - use super::*; - - #[test] - fn test_envoy_dynamic_module_on_http_filter_config_new_impl() { - struct TestHttpFilterConfig; - impl HttpFilterConfig for TestHttpFilterConfig {} - - let envoy_filter_config = EnvoyHttpFilterConfig { - raw_ptr: std::ptr::null_mut(), - }; - let mut new_fn: NewHttpFilterConfigFunction = - |_, _, _| Some(Box::new(TestHttpFilterConfig)); - let result = envoy_dynamic_module_on_http_filter_config_new_impl( - envoy_filter_config, - "test_name", - "test_config", - &new_fn, - ); - assert!(!result.is_null()); - - unsafe { - envoy_dynamic_module_on_http_filter_config_destroy(result); - } - - // None should result in null pointer. - new_fn = |_, _, _| None; - let result = envoy_dynamic_module_on_http_filter_config_new_impl( - envoy_filter_config, - "test_name", - "test_config", - &new_fn, - ); - assert!(result.is_null()); + use super::*; + + #[test] + fn test_envoy_dynamic_module_on_http_filter_config_new_impl() { + struct TestHttpFilterConfig; + impl HttpFilterConfig for TestHttpFilterConfig {} + + let envoy_filter_config = EnvoyHttpFilterConfig { + raw_ptr: std::ptr::null_mut(), + }; + let mut new_fn: NewHttpFilterConfigFunction = |_, _, _| Some(Box::new(TestHttpFilterConfig)); + let result = envoy_dynamic_module_on_http_filter_config_new_impl( + envoy_filter_config, + "test_name", + "test_config", + &new_fn, + ); + assert!(!result.is_null()); + + unsafe { + envoy_dynamic_module_on_http_filter_config_destroy(result); + } + + // None should result in null pointer. + new_fn = |_, _, _| None; + let result = envoy_dynamic_module_on_http_filter_config_new_impl( + envoy_filter_config, + "test_name", + "test_config", + &new_fn, + ); + assert!(result.is_null()); + } + + #[test] + fn test_envoy_dynamic_module_on_http_filter_config_destroy() { + use std::sync::atomic::AtomicBool; + + // This test is mainly to check if the drop is called correctly after wrapping/unwrapping the + // Box. + static DROPPED: AtomicBool = AtomicBool::new(false); + struct TestHttpFilterConfig; + impl HttpFilterConfig for TestHttpFilterConfig {} + impl Drop for TestHttpFilterConfig { + fn drop(&mut self) { + DROPPED.store(true, std::sync::atomic::Ordering::SeqCst); + } } - #[test] - fn test_envoy_dynamic_module_on_http_filter_config_destroy() { - use std::sync::atomic::AtomicBool; - - // This test is mainly to check if the drop is called correctly after wrapping/unwrapping the Box. - static DROPPED: AtomicBool = AtomicBool::new(false); - struct TestHttpFilterConfig; - impl HttpFilterConfig for TestHttpFilterConfig {} - impl Drop for TestHttpFilterConfig { - fn drop(&mut self) { - DROPPED.store(true, std::sync::atomic::Ordering::SeqCst); - } - } - - // This is a sort of round-trip to ensure the same control flow as the actual usage. - let new_fn: NewHttpFilterConfigFunction = |_, _, _| Some(Box::new(TestHttpFilterConfig)); - let config_ptr = envoy_dynamic_module_on_http_filter_config_new_impl( - EnvoyHttpFilterConfig { - raw_ptr: std::ptr::null_mut(), - }, - "test_name", - "test_config", - &new_fn, - ); - - unsafe { - envoy_dynamic_module_on_http_filter_config_destroy(config_ptr); - } - // Now that the drop is called, DROPPED must be set to true. - assert!(DROPPED.load(std::sync::atomic::Ordering::SeqCst)); + // This is a sort of round-trip to ensure the same control flow as the actual usage. + let new_fn: NewHttpFilterConfigFunction = |_, _, _| Some(Box::new(TestHttpFilterConfig)); + let config_ptr = envoy_dynamic_module_on_http_filter_config_new_impl( + EnvoyHttpFilterConfig { + raw_ptr: std::ptr::null_mut(), + }, + "test_name", + "test_config", + &new_fn, + ); + + unsafe { + envoy_dynamic_module_on_http_filter_config_destroy(config_ptr); } + // Now that the drop is called, DROPPED must be set to true. + assert!(DROPPED.load(std::sync::atomic::Ordering::SeqCst)); + } } diff --git a/test/extensions/dynamic_modules/test_data/rust/BUILD b/test/extensions/dynamic_modules/test_data/rust/BUILD index df3dd289203d..aff294f7bfd7 100644 --- a/test/extensions/dynamic_modules/test_data/rust/BUILD +++ b/test/extensions/dynamic_modules/test_data/rust/BUILD @@ -1,4 +1,4 @@ -load("@rules_rust//rust:defs.bzl", "rust_shared_library") +load("//test/extensions/dynamic_modules/test_data/rust:test_data.bzl", "test_program") licenses(["notice"]) # Apache 2 @@ -7,29 +7,10 @@ package(default_visibility = [ "//test/extensions/dynamic_modules/http:__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", - ], -) +test_program(name = "no_op") -rust_shared_library( - name = "no_program_init", - srcs = ["no_program_init.rs"], - edition = "2021", -) +test_program(name = "no_program_init") -rust_shared_library( - name = "program_init_fail", - srcs = ["program_init_fail.rs"], - edition = "2021", -) +test_program(name = "program_init_fail") -rust_shared_library( - name = "abi_version_mismatch", - srcs = ["abi_version_mismatch.rs"], - edition = "2021", -) +test_program(name = "abi_version_mismatch") 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 index 8afbd0d965d8..c90aeba76c60 100644 --- a/test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs +++ b/test/extensions/dynamic_modules/test_data/rust/abi_version_mismatch.rs @@ -1,4 +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 + 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 index 3c095d46a6c7..f07a3a8b44c3 100644 --- a/test/extensions/dynamic_modules/test_data/rust/no_op.rs +++ b/test/extensions/dynamic_modules/test_data/rust/no_op.rs @@ -5,39 +5,41 @@ declare_init_functions!(init, new_nop_http_filter_config_fn); /// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::ProgramInitFunction`] signature. fn init() -> bool { - true + true } static SOME_VARIABLE: AtomicI32 = AtomicI32::new(1); #[no_mangle] pub extern "C" fn getSomeVariable() -> i32 { - SOME_VARIABLE.fetch_add(1, Ordering::SeqCst) + SOME_VARIABLE.fetch_add(1, Ordering::SeqCst) } -/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::NewHttpFilterConfigFunction`] signature. +/// This implements the [`envoy_proxy_dynamic_modules_rust_sdk::NewHttpFilterConfigFunction`] +/// signature. fn new_nop_http_filter_config_fn( - _envoy_filter_factory: envoy_proxy_dynamic_modules_rust_sdk::EnvoyHttpFilterConfig, - name: &str, - config: &str, + _envoy_filter_factory: envoy_proxy_dynamic_modules_rust_sdk::EnvoyHttpFilterConfig, + name: &str, + config: &str, ) -> Option> { - let name = name.to_string(); - let config = config.to_string(); - Some(Box::new(NopHttpFilterConfig { name, config })) + let name = name.to_string(); + let config = config.to_string(); + Some(Box::new(NopHttpFilterConfig { name, config })) } -/// A no-op HTTP filter configuration that implements [`envoy_proxy_dynamic_modules_rust_sdk::HttpFilterConfig`] -/// as well as the [`Drop`] to test the cleanup of the configuration. +/// A no-op HTTP filter configuration that implements +/// [`envoy_proxy_dynamic_modules_rust_sdk::HttpFilterConfig`] as well as the [`Drop`] to test the +/// cleanup of the configuration. struct NopHttpFilterConfig { - name: String, - config: String, + name: String, + config: String, } impl envoy_proxy_dynamic_modules_rust_sdk::HttpFilterConfig for NopHttpFilterConfig {} impl Drop for NopHttpFilterConfig { - fn drop(&mut self) { - assert_eq!(self.name, "foo"); - assert_eq!(self.config, "bar"); - } + fn drop(&mut self) { + assert_eq!(self.name, "foo"); + assert_eq!(self.config, "bar"); + } } 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 index db872215ab1d..7bd826bb4b1e 100644 --- a/test/extensions/dynamic_modules/test_data/rust/no_program_init.rs +++ b/test/extensions/dynamic_modules/test_data/rust/no_program_init.rs @@ -1,3 +1,3 @@ pub extern "C" fn foo() -> i32 { - 0 + 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 index e9d7aed01306..19ec1747830d 100644 --- a/test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs +++ b/test/extensions/dynamic_modules/test_data/rust/program_init_fail.rs @@ -1,4 +1,4 @@ #[no_mangle] pub extern "C" fn envoy_dynamic_module_on_program_init() -> *const ::std::os::raw::c_char { - ::std::ptr::null() + std::ptr::null() } diff --git a/test/extensions/dynamic_modules/test_data/rust/rustfmt.toml b/test/extensions/dynamic_modules/test_data/rust/rustfmt.toml new file mode 120000 index 000000000000..28f20ab8a7a2 --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/rustfmt.toml @@ -0,0 +1 @@ +../../../../../rustfmt.toml \ No newline at end of file diff --git a/test/extensions/dynamic_modules/test_data/rust/test_data.bzl b/test/extensions/dynamic_modules/test_data/rust/test_data.bzl new file mode 100644 index 000000000000..527ddb1cf4c9 --- /dev/null +++ b/test/extensions/dynamic_modules/test_data/rust/test_data.bzl @@ -0,0 +1,19 @@ +load("@rules_rust//rust:defs.bzl", "rust_shared_library", "rustfmt_test") + +def test_program(name): + rust_shared_library( + name = name, + srcs = [name + ".rs"], + edition = "2021", + deps = [ + "//source/extensions/dynamic_modules/sdk/rust:envoy_proxy_dynamic_modules_rust_sdk", + ], + ) + + # As per the discussion in https://github.com/envoyproxy/envoy/pull/35627, + # we set the rust_fmt and clippy target here instead of the part of //tools/code_format target for now. + rustfmt_test( + name = "rust_sdk_fmt" + name, + tags = ["nocoverage"], + targets = ["//test/extensions/dynamic_modules/test_data/rust:" + name], + )