diff --git a/mountpoint-s3-client/tests/common/mod.rs b/mountpoint-s3-client/tests/common/mod.rs index f61960711..b81ebc334 100644 --- a/mountpoint-s3-client/tests/common/mod.rs +++ b/mountpoint-s3-client/tests/common/mod.rs @@ -32,6 +32,12 @@ fn init_tracing_subscriber() { let _ = subscriber.try_init(); } +#[ctor::ctor] +fn init_crt() { + mountpoint_s3_crt::io::io_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); + mountpoint_s3_crt::s3::s3_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); +} + pub enum AccessPointType { SingleRegion, ObjectLambda, diff --git a/mountpoint-s3-crt/src/io.rs b/mountpoint-s3-crt/src/io.rs index 5b86454f0..07f222fb3 100644 --- a/mountpoint-s3-crt/src/io.rs +++ b/mountpoint-s3-crt/src/io.rs @@ -15,7 +15,7 @@ pub mod retry_strategy; static IO_LIBRARY_INIT: Once = Once::new(); /// Set up the aws-c-io library using the given allocator. -fn io_library_init(allocator: &Allocator) { +pub fn io_library_init(allocator: &Allocator) { IO_LIBRARY_INIT.call_once(|| { // Safety: the CRT ensures this call happens only once. unsafe { diff --git a/mountpoint-s3-crt/src/lib.rs b/mountpoint-s3-crt/src/lib.rs index 3c6cb8d9d..4b2ff628d 100644 --- a/mountpoint-s3-crt/src/lib.rs +++ b/mountpoint-s3-crt/src/lib.rs @@ -138,6 +138,12 @@ mod test { tracing_subscriber::fmt::init(); } + #[ctor::ctor] + fn init_crt() { + crate::io::io_library_init(&crate::common::allocator::Allocator::default()); + crate::s3::s3_library_init(&crate::common::allocator::Allocator::default()); + } + /// Validate that ASan is working across both Rust and the CRT by intentionally provoking a /// use-after-free that crosses the boundary: the allocation is created and freed by Rust, but /// accessed by the CRT. Ignored by default, and run only by ASan in CI. diff --git a/mountpoint-s3-crt/src/s3.rs b/mountpoint-s3-crt/src/s3.rs index c10d01572..9be95762f 100644 --- a/mountpoint-s3-crt/src/s3.rs +++ b/mountpoint-s3-crt/src/s3.rs @@ -12,7 +12,7 @@ pub mod endpoint_resolver; static S3_LIBRARY_INIT: Once = Once::new(); /// Set up the aws-c-io library using the given allocator. -fn s3_library_init(allocator: &Allocator) { +pub fn s3_library_init(allocator: &Allocator) { S3_LIBRARY_INIT.call_once(|| { // Safety: the CRT ensures this call happens only once. unsafe { diff --git a/mountpoint-s3/src/lib.rs b/mountpoint-s3/src/lib.rs index 44fd70087..084cd3cc9 100644 --- a/mountpoint-s3/src/lib.rs +++ b/mountpoint-s3/src/lib.rs @@ -24,3 +24,10 @@ fn init_tracing_subscriber() { let _ = mountpoint_s3_crt::common::rust_log_adapter::RustLogAdapter::try_init(); let _ = tracing_subscriber::fmt::try_init(); } + +#[cfg(test)] +#[ctor::ctor] +fn init_crt() { + mountpoint_s3_crt::io::io_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); + mountpoint_s3_crt::s3::s3_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); +} diff --git a/mountpoint-s3/tests/common/mod.rs b/mountpoint-s3/tests/common/mod.rs index a43bb63b7..9b800eddc 100644 --- a/mountpoint-s3/tests/common/mod.rs +++ b/mountpoint-s3/tests/common/mod.rs @@ -107,3 +107,9 @@ fn init_tracing_subscriber() { let _ = RustLogAdapter::try_init(); let _ = tracing_subscriber::fmt::try_init(); } + +#[ctor::ctor] +fn init_crt() { + mountpoint_s3_crt::io::io_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); + mountpoint_s3_crt::s3::s3_library_init(&mountpoint_s3_crt::common::allocator::Allocator::default()); +}