From 0f7dbfd53bc15954ff4696cb515ec07e5f936d4b Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 13 Aug 2025 18:11:42 +0000 Subject: [PATCH 01/19] cosmos: add experimental c wrapper around cosmos sdk --- Cargo.lock | 60 ++++++++++++++++++++++ Cargo.toml | 1 + sdk/cosmos/azure_data_cosmos/Cargo.toml | 1 + sdk/cosmos/cosmosclient/.gitignore | 1 + sdk/cosmos/cosmosclient/CMakeLists.txt | 31 +++++++++++ sdk/cosmos/cosmosclient/Cargo.toml | 21 ++++++++ sdk/cosmos/cosmosclient/build.rs | 38 ++++++++++++++ sdk/cosmos/cosmosclient/c_tests/README.md | 5 ++ sdk/cosmos/cosmosclient/c_tests/version.c | 17 ++++++ sdk/cosmos/cosmosclient/include/.gitignore | 3 ++ sdk/cosmos/cosmosclient/src/lib.rs | 33 ++++++++++++ 11 files changed, 211 insertions(+) create mode 100644 sdk/cosmos/cosmosclient/.gitignore create mode 100644 sdk/cosmos/cosmosclient/CMakeLists.txt create mode 100644 sdk/cosmos/cosmosclient/Cargo.toml create mode 100644 sdk/cosmos/cosmosclient/build.rs create mode 100644 sdk/cosmos/cosmosclient/c_tests/README.md create mode 100644 sdk/cosmos/cosmosclient/c_tests/version.c create mode 100644 sdk/cosmos/cosmosclient/include/.gitignore create mode 100644 sdk/cosmos/cosmosclient/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 289136ca88..f745fe2c54 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -691,6 +691,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cbindgen" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684" +dependencies = [ + "clap", + "heck", + "indexmap", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.104", + "tempfile", + "toml", +] + [[package]] name = "cc" version = "1.2.32" @@ -828,6 +847,14 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "cosmosclient" +version = "0.27.0" +dependencies = [ + "azure_data_cosmos", + "cbindgen", +] + [[package]] name = "cpufeatures" version = "0.2.17" @@ -2614,6 +2641,15 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + [[package]] name = "serde_test" version = "1.0.177" @@ -2998,11 +3034,26 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -3011,10 +3062,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + [[package]] name = "tower" version = "0.5.2" diff --git a/Cargo.toml b/Cargo.toml index 270868cf15..4a66ebef83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "sdk/storage/azure_storage_common", "sdk/storage/azure_storage_blob", "sdk/storage/azure_storage_queue", + "sdk/cosmos/cosmosclient", ] exclude = [ "eng/scripts", diff --git a/sdk/cosmos/azure_data_cosmos/Cargo.toml b/sdk/cosmos/azure_data_cosmos/Cargo.toml index 22dce2f890..2d7c711fa9 100644 --- a/sdk/cosmos/azure_data_cosmos/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos/Cargo.toml @@ -37,6 +37,7 @@ workspace = true [features] default = ["hmac_rust"] +_internal_c = [] # Internal feature used to expose additional types/functions as needed to build libcosmosclient. key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) preview_query_engine = ["serde_json/raw_value"] # Enables support for the PREVIEW external query engine hmac_rust = ["azure_core/hmac_rust"] diff --git a/sdk/cosmos/cosmosclient/.gitignore b/sdk/cosmos/cosmosclient/.gitignore new file mode 100644 index 0000000000..567609b123 --- /dev/null +++ b/sdk/cosmos/cosmosclient/.gitignore @@ -0,0 +1 @@ +build/ diff --git a/sdk/cosmos/cosmosclient/CMakeLists.txt b/sdk/cosmos/cosmosclient/CMakeLists.txt new file mode 100644 index 0000000000..69019873a8 --- /dev/null +++ b/sdk/cosmos/cosmosclient/CMakeLists.txt @@ -0,0 +1,31 @@ +project(cosmosctest C) +cmake_minimum_required(VERSION 4.1) + +# CMake automatically uses this option, but we should define it. +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) + +include(FetchContent) +include(CTest) + +FetchContent_Declare( + Corrosion + GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git + GIT_TAG v0.5.2 +) +FetchContent_MakeAvailable(Corrosion) + +corrosion_import_crate( + MANIFEST_PATH ./Cargo.toml + CRATETYPES staticlib cdylib +) + +set(TEST_FILES + ./c_tests/version.c) + +foreach(test_file ${TEST_FILES}) + get_filename_component(test_name ${test_file} NAME_WE) + add_executable(${test_name} ${test_file}) + target_link_libraries(${test_name} PRIVATE cosmosclient) + add_test(${test_name} ${test_name}) +endforeach() + diff --git a/sdk/cosmos/cosmosclient/Cargo.toml b/sdk/cosmos/cosmosclient/Cargo.toml new file mode 100644 index 0000000000..132c93ba10 --- /dev/null +++ b/sdk/cosmos/cosmosclient/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "cosmosclient" +description = "C library wrapping the Azure CosmosDB SDK for Rust" +version = "0.27.0" +authors.workspace = true +edition.workspace = true +license.workspace = true +repository.workspace = true +rust-version.workspace = true + +[lib] +crate-type = ["cdylib", "staticlib"] + +[dependencies] +azure_data_cosmos = { path = "../azure_data_cosmos", features = ["_internal_c"] } + +[build-dependencies] +cbindgen = "0.29.0" + +[lints] +workspace = true diff --git a/sdk/cosmos/cosmosclient/build.rs b/sdk/cosmos/cosmosclient/build.rs new file mode 100644 index 0000000000..c47d0cbd1e --- /dev/null +++ b/sdk/cosmos/cosmosclient/build.rs @@ -0,0 +1,38 @@ +fn main() { + let build_id = format!( + "$Id: {}, Version: {}, Commit: {}, Branch: {}, Build ID: {}, Build Number: {}, Timestamp: {}$", + env!("CARGO_PKG_NAME"), + env!("CARGO_PKG_VERSION"), + option_env!("BUILD_SOURCEVERSION").unwrap_or("unknown"), + option_env!("BUILD_SOURCEBRANCH").unwrap_or("unknown"), + option_env!("BUILD_BUILDID").unwrap_or("unknown"), + option_env!("BUILD_BUILDNUMBER").unwrap_or("unknown"), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .as_secs(), + ); + println!("cargo:rustc-env=BUILD_IDENTIFIER={}", build_id); + + let mut header: String = r"// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This file is auto-generated by cbindgen. Do not edit manually. +" + .to_string(); + header.push_str(&format!("// Build identifier: {}\n", build_id)); + + let crate_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + cbindgen::Builder::new() + .with_crate(crate_dir) + .with_language(cbindgen::Language::C) + .with_after_include(format!( + "\n// Specifies the version of cosmosclient this header file was generated from.\n// This should match the version of libcosmosclient you are referencing.\n#define COSMOSCLIENT_H_VERSION \"{}\"", + env!("CARGO_PKG_VERSION") + )) + .with_cpp_compat(true) + .with_header(header) + .generate() + .expect("unable to generate bindings") + .write_to_file("include/cosmosclient.h"); +} diff --git a/sdk/cosmos/cosmosclient/c_tests/README.md b/sdk/cosmos/cosmosclient/c_tests/README.md new file mode 100644 index 0000000000..80263e8273 --- /dev/null +++ b/sdk/cosmos/cosmosclient/c_tests/README.md @@ -0,0 +1,5 @@ +# Cosmos Client C Tests + +This directory contains tests written in C that utilize the Cosmos Client library. The tests are designed to validate the functionality of the Cosmos Client C API, ensuring that it correctly interacts with the Azure CosmosDB service. + +Building this directory requires CMake, Rust, and a C compiler. diff --git a/sdk/cosmos/cosmosclient/c_tests/version.c b/sdk/cosmos/cosmosclient/c_tests/version.c new file mode 100644 index 0000000000..c6b75b8cdb --- /dev/null +++ b/sdk/cosmos/cosmosclient/c_tests/version.c @@ -0,0 +1,17 @@ +#include +#include +#include "../include/cosmosclient.h" + +int main() { + const char *version = cosmosclient_version(); + const char *header_version = COSMOSCLIENT_H_VERSION; + printf("Cosmos Client Version: %s\n", version); + printf("Header Version: %s\n", header_version); + if (!strcmp(version, header_version)) { + printf("Version match successful.\n"); + return 0; + } else { + printf("Version mismatch: %s != %s\n", version, header_version); + return 1; + } +} diff --git a/sdk/cosmos/cosmosclient/include/.gitignore b/sdk/cosmos/cosmosclient/include/.gitignore new file mode 100644 index 0000000000..b429f3066b --- /dev/null +++ b/sdk/cosmos/cosmosclient/include/.gitignore @@ -0,0 +1,3 @@ +# Ignore everything except this ignore file, this directory contains build artifacts +* +!.gitignore diff --git a/sdk/cosmos/cosmosclient/src/lib.rs b/sdk/cosmos/cosmosclient/src/lib.rs new file mode 100644 index 0000000000..1c202c59f8 --- /dev/null +++ b/sdk/cosmos/cosmosclient/src/lib.rs @@ -0,0 +1,33 @@ +use std::ffi::{c_char, CStr, CString}; + +#[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing +/// cbindgen:ignore +pub static BUILD_IDENTIFIER: &CStr = const { + // This does a few funky things to make sure we can stay in a const context + // Which ensures the string is generated as a c-str at compile time + // and thus appears properly if you run `strings [lib] | grep "\$Id:"` + const BUILD_IDENTIFIER_STR: &str = env!("BUILD_IDENTIFIER"); + const BUILD_IDENTIFIER_BYTES: [u8; BUILD_IDENTIFIER_STR.len() + 1] = const { + let mut cstrbuf: [u8; BUILD_IDENTIFIER_STR.len() + 1] = [0; BUILD_IDENTIFIER_STR.len() + 1]; + let mut i = 0; + // For loops over ranges don't really work in const contexts. + while i < BUILD_IDENTIFIER_STR.len() { + cstrbuf[i] = BUILD_IDENTIFIER_STR.as_bytes()[i]; + i += 1; + } + cstrbuf + }; + match CStr::from_bytes_with_nul(&BUILD_IDENTIFIER_BYTES) { + Ok(cstr) => cstr, + Err(_) => panic!("BUILD_IDENTIFIER is not a valid C string"), + } +}; + +#[no_mangle] +/// Returns a constant C string containing the version of the Cosmos Client library. +pub extern "C" fn cosmosclient_version() -> *const c_char { + let version = env!("CARGO_PKG_VERSION"); + CString::new(version) + .expect("failed to create CString from version") + .into_raw() +} From beef9c7f34eab4ed8c067f2631ad60813ed3d8c8 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 13 Aug 2025 18:17:41 +0000 Subject: [PATCH 02/19] readme on how to run the test --- sdk/cosmos/cosmosclient/c_tests/README.md | 39 +++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/sdk/cosmos/cosmosclient/c_tests/README.md b/sdk/cosmos/cosmosclient/c_tests/README.md index 80263e8273..962e1103cd 100644 --- a/sdk/cosmos/cosmosclient/c_tests/README.md +++ b/sdk/cosmos/cosmosclient/c_tests/README.md @@ -3,3 +3,42 @@ This directory contains tests written in C that utilize the Cosmos Client library. The tests are designed to validate the functionality of the Cosmos Client C API, ensuring that it correctly interacts with the Azure CosmosDB service. Building this directory requires CMake, Rust, and a C compiler. + +## Running the tests + +To run the tests, follow these steps: + +1. Create a `build` directory: + +```bash +mkdir build +cd build +``` + +1. Configure the project with CMake: + +```bash +cmake .. +``` + +1. Run the build AND tests: + +```bash +make && make test +``` + +## Test Structure + +Each test is a separate C program located in the `c_tests` directory. +The tests are compiled into executables that can be run independently. +Tests must be manually listed in `CMakeLists.txt` to be included in the build process: + +```cmake +set(TEST_FILES + ./c_tests/version.c + ./c_tests/your_test_here.c) +``` + +Once a test is present in the `TEST_FILES` list, it will be automatically compiled and linked against the Cosmos Client library (either static, or dynamic, depending on the value of `BUILD_SHARED_LIBS` when `cmake` is run, which defaults to `ON`). + +Helper code should be added to an include file in the `c_tests` directory, such as `c_tests/test_helpers.h`, and included in the test files as needed. From 2e34864d2c61cf43746ca659bf2dce3d0418b600 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 13 Aug 2025 20:27:19 +0000 Subject: [PATCH 03/19] pr feedback --- sdk/cosmos/azure_data_cosmos/Cargo.toml | 9 +++++++-- sdk/cosmos/cosmosclient/Cargo.toml | 3 ++- sdk/cosmos/cosmosclient/build.rs | 3 +++ sdk/cosmos/cosmosclient/c_tests/version.c | 3 +++ sdk/cosmos/cosmosclient/src/lib.rs | 3 +++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/sdk/cosmos/azure_data_cosmos/Cargo.toml b/sdk/cosmos/azure_data_cosmos/Cargo.toml index 2d7c711fa9..6eb0970ef8 100644 --- a/sdk/cosmos/azure_data_cosmos/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos/Cargo.toml @@ -37,11 +37,16 @@ workspace = true [features] default = ["hmac_rust"] -_internal_c = [] # Internal feature used to expose additional types/functions as needed to build libcosmosclient. +c = [] # Internal feature used to expose additional types/functions as needed to build libcosmosclient. key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) preview_query_engine = ["serde_json/raw_value"] # Enables support for the PREVIEW external query engine hmac_rust = ["azure_core/hmac_rust"] hmac_openssl = ["azure_core/hmac_openssl"] [package.metadata.docs.rs] -features = ["key_auth"] +features = [ + "key_auth", + "preview_query_engine", + "hmac_rust", + "hmac_openssl", +] diff --git a/sdk/cosmos/cosmosclient/Cargo.toml b/sdk/cosmos/cosmosclient/Cargo.toml index 132c93ba10..7c3e4cd775 100644 --- a/sdk/cosmos/cosmosclient/Cargo.toml +++ b/sdk/cosmos/cosmosclient/Cargo.toml @@ -1,5 +1,6 @@ [package] name = "cosmosclient" +publish = false description = "C library wrapping the Azure CosmosDB SDK for Rust" version = "0.27.0" authors.workspace = true @@ -12,7 +13,7 @@ rust-version.workspace = true crate-type = ["cdylib", "staticlib"] [dependencies] -azure_data_cosmos = { path = "../azure_data_cosmos", features = ["_internal_c"] } +azure_data_cosmos = { path = "../azure_data_cosmos", features = ["c"] } [build-dependencies] cbindgen = "0.29.0" diff --git a/sdk/cosmos/cosmosclient/build.rs b/sdk/cosmos/cosmosclient/build.rs index c47d0cbd1e..5c5a620dec 100644 --- a/sdk/cosmos/cosmosclient/build.rs +++ b/sdk/cosmos/cosmosclient/build.rs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + fn main() { let build_id = format!( "$Id: {}, Version: {}, Commit: {}, Branch: {}, Build ID: {}, Build Number: {}, Timestamp: {}$", diff --git a/sdk/cosmos/cosmosclient/c_tests/version.c b/sdk/cosmos/cosmosclient/c_tests/version.c index c6b75b8cdb..bf193c926d 100644 --- a/sdk/cosmos/cosmosclient/c_tests/version.c +++ b/sdk/cosmos/cosmosclient/c_tests/version.c @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + #include #include #include "../include/cosmosclient.h" diff --git a/sdk/cosmos/cosmosclient/src/lib.rs b/sdk/cosmos/cosmosclient/src/lib.rs index 1c202c59f8..2885570f15 100644 --- a/sdk/cosmos/cosmosclient/src/lib.rs +++ b/sdk/cosmos/cosmosclient/src/lib.rs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + use std::ffi::{c_char, CStr, CString}; #[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing From fa3e844e36da2fc387e72e2f515a5b1ee73152eb Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 13 Aug 2025 21:12:57 +0000 Subject: [PATCH 04/19] make version a static --- sdk/cosmos/cosmosclient/src/lib.rs | 31 ++++++--------------------- sdk/cosmos/cosmosclient/src/macros.rs | 21 ++++++++++++++++++ 2 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 sdk/cosmos/cosmosclient/src/macros.rs diff --git a/sdk/cosmos/cosmosclient/src/lib.rs b/sdk/cosmos/cosmosclient/src/lib.rs index 2885570f15..05b90c84c7 100644 --- a/sdk/cosmos/cosmosclient/src/lib.rs +++ b/sdk/cosmos/cosmosclient/src/lib.rs @@ -3,34 +3,17 @@ use std::ffi::{c_char, CStr, CString}; +#[macro_use] +mod macros; + #[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing /// cbindgen:ignore -pub static BUILD_IDENTIFIER: &CStr = const { - // This does a few funky things to make sure we can stay in a const context - // Which ensures the string is generated as a c-str at compile time - // and thus appears properly if you run `strings [lib] | grep "\$Id:"` - const BUILD_IDENTIFIER_STR: &str = env!("BUILD_IDENTIFIER"); - const BUILD_IDENTIFIER_BYTES: [u8; BUILD_IDENTIFIER_STR.len() + 1] = const { - let mut cstrbuf: [u8; BUILD_IDENTIFIER_STR.len() + 1] = [0; BUILD_IDENTIFIER_STR.len() + 1]; - let mut i = 0; - // For loops over ranges don't really work in const contexts. - while i < BUILD_IDENTIFIER_STR.len() { - cstrbuf[i] = BUILD_IDENTIFIER_STR.as_bytes()[i]; - i += 1; - } - cstrbuf - }; - match CStr::from_bytes_with_nul(&BUILD_IDENTIFIER_BYTES) { - Ok(cstr) => cstr, - Err(_) => panic!("BUILD_IDENTIFIER is not a valid C string"), - } -}; +pub static BUILD_IDENTIFIER: &CStr = c_str!(env!("BUILD_IDENTIFIER")); + +const VERSION: &CStr = c_str!(env!("CARGO_PKG_VERSION")); #[no_mangle] /// Returns a constant C string containing the version of the Cosmos Client library. pub extern "C" fn cosmosclient_version() -> *const c_char { - let version = env!("CARGO_PKG_VERSION"); - CString::new(version) - .expect("failed to create CString from version") - .into_raw() + VERSION.as_ptr() } diff --git a/sdk/cosmos/cosmosclient/src/macros.rs b/sdk/cosmos/cosmosclient/src/macros.rs new file mode 100644 index 0000000000..2aa3131953 --- /dev/null +++ b/sdk/cosmos/cosmosclient/src/macros.rs @@ -0,0 +1,21 @@ +macro_rules! c_str { + ($s:expr) => { const { + // This does a few funky things to make sure we can stay in a const context + // Which ensures the string is generated as a c-str at compile time + const STR: &str = $s + const BYTES: [u8; STR.len() + 1] = const { + let mut cstrbuf: [u8; STR.len() + 1] = [0; STR.len() + 1]; + let mut i = 0; + // For loops over ranges don't really work in const contexts. + while i < STR.len() { + cstrbuf[i] = STR.as_bytes()[i]; + i += 1; + } + cstrbuf + }; + match CStr::from_bytes_with_nul(&BYTES) { + Ok(cstr) => cstr, + Err(_) => panic!("failed to convert value to C string"), + } + } }, +} From 53dd2d96a942b31d7a323f3effc177c50aceb2a4 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 13 Aug 2025 21:13:08 +0000 Subject: [PATCH 05/19] allow MPL-2.0 license in dependencies --- deny.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/deny.toml b/deny.toml index 249310d38f..42e142afde 100644 --- a/deny.toml +++ b/deny.toml @@ -13,6 +13,7 @@ allow = [ "BSL-1.0", "ISC", "MIT", + "MPL-2.0", # "OpenSSL", "Unicode-3.0", "Zlib", From a47cf8a9e6225c3c42b5a80377fee925d021a2c5 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 14 Aug 2025 17:21:05 +0000 Subject: [PATCH 06/19] copyright header :facepalm: --- sdk/cosmos/cosmosclient/src/macros.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sdk/cosmos/cosmosclient/src/macros.rs b/sdk/cosmos/cosmosclient/src/macros.rs index 2aa3131953..dd9f5402c0 100644 --- a/sdk/cosmos/cosmosclient/src/macros.rs +++ b/sdk/cosmos/cosmosclient/src/macros.rs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + macro_rules! c_str { ($s:expr) => { const { // This does a few funky things to make sure we can stay in a const context From 88b67165553230a0cceefce2062ecab7593500c3 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Wed, 3 Sep 2025 20:59:32 +0000 Subject: [PATCH 07/19] pr feedback --- Cargo.lock | 16 +++++------ Cargo.toml | 2 +- .../.gitignore | 0 .../CMakeLists.txt | 0 .../Cargo.toml | 5 ++-- .../build.rs | 0 .../c_tests/README.md | 0 .../c_tests/version.c | 0 .../include/.gitignore | 0 .../src/lib.rs | 6 ++-- .../azure_data_cosmos_native/src/macros.rs | 26 +++++++++++++++++ .../cosmosclient/include/cosmosclient.h | 28 +++++++++++++++++++ sdk/cosmos/cosmosclient/src/macros.rs | 24 ---------------- 13 files changed, 69 insertions(+), 38 deletions(-) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/.gitignore (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/CMakeLists.txt (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/Cargo.toml (68%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/build.rs (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/c_tests/README.md (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/c_tests/version.c (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/include/.gitignore (100%) rename sdk/cosmos/{cosmosclient => azure_data_cosmos_native}/src/lib.rs (93%) create mode 100644 sdk/cosmos/azure_data_cosmos_native/src/macros.rs create mode 100644 sdk/cosmos/cosmosclient/include/cosmosclient.h delete mode 100644 sdk/cosmos/cosmosclient/src/macros.rs diff --git a/Cargo.lock b/Cargo.lock index f745fe2c54..eda1fead4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,6 +332,14 @@ dependencies = [ "url", ] +[[package]] +name = "azure_data_cosmos_native" +version = "0.27.0" +dependencies = [ + "azure_data_cosmos", + "cbindgen", +] + [[package]] name = "azure_identity" version = "0.29.0" @@ -847,14 +855,6 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" -[[package]] -name = "cosmosclient" -version = "0.27.0" -dependencies = [ - "azure_data_cosmos", - "cbindgen", -] - [[package]] name = "cpufeatures" version = "0.2.17" diff --git a/Cargo.toml b/Cargo.toml index 4a66ebef83..973264acaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "sdk/core/azure_core_test_macros", "sdk/core/azure_core_opentelemetry", "sdk/cosmos/azure_data_cosmos", + "sdk/cosmos/azure_data_cosmos_native", "sdk/identity/azure_identity", "sdk/eventhubs/azure_messaging_eventhubs", "sdk/eventhubs/azure_messaging_eventhubs_checkpointstore_blob", @@ -25,7 +26,6 @@ members = [ "sdk/storage/azure_storage_common", "sdk/storage/azure_storage_blob", "sdk/storage/azure_storage_queue", - "sdk/cosmos/cosmosclient", ] exclude = [ "eng/scripts", diff --git a/sdk/cosmos/cosmosclient/.gitignore b/sdk/cosmos/azure_data_cosmos_native/.gitignore similarity index 100% rename from sdk/cosmos/cosmosclient/.gitignore rename to sdk/cosmos/azure_data_cosmos_native/.gitignore diff --git a/sdk/cosmos/cosmosclient/CMakeLists.txt b/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt similarity index 100% rename from sdk/cosmos/cosmosclient/CMakeLists.txt rename to sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt diff --git a/sdk/cosmos/cosmosclient/Cargo.toml b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml similarity index 68% rename from sdk/cosmos/cosmosclient/Cargo.toml rename to sdk/cosmos/azure_data_cosmos_native/Cargo.toml index 7c3e4cd775..8bf861c4c9 100644 --- a/sdk/cosmos/cosmosclient/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "cosmosclient" +name = "azure_data_cosmos_native" publish = false -description = "C library wrapping the Azure CosmosDB SDK for Rust" +description = "The Cosmos Native Client is a C library, written in Rust but exporting a C-compatible API, that provides a full SDK for Azure Cosmos DB." version = "0.27.0" authors.workspace = true edition.workspace = true @@ -10,6 +10,7 @@ repository.workspace = true rust-version.workspace = true [lib] +name = "cosmosclient" crate-type = ["cdylib", "staticlib"] [dependencies] diff --git a/sdk/cosmos/cosmosclient/build.rs b/sdk/cosmos/azure_data_cosmos_native/build.rs similarity index 100% rename from sdk/cosmos/cosmosclient/build.rs rename to sdk/cosmos/azure_data_cosmos_native/build.rs diff --git a/sdk/cosmos/cosmosclient/c_tests/README.md b/sdk/cosmos/azure_data_cosmos_native/c_tests/README.md similarity index 100% rename from sdk/cosmos/cosmosclient/c_tests/README.md rename to sdk/cosmos/azure_data_cosmos_native/c_tests/README.md diff --git a/sdk/cosmos/cosmosclient/c_tests/version.c b/sdk/cosmos/azure_data_cosmos_native/c_tests/version.c similarity index 100% rename from sdk/cosmos/cosmosclient/c_tests/version.c rename to sdk/cosmos/azure_data_cosmos_native/c_tests/version.c diff --git a/sdk/cosmos/cosmosclient/include/.gitignore b/sdk/cosmos/azure_data_cosmos_native/include/.gitignore similarity index 100% rename from sdk/cosmos/cosmosclient/include/.gitignore rename to sdk/cosmos/azure_data_cosmos_native/include/.gitignore diff --git a/sdk/cosmos/cosmosclient/src/lib.rs b/sdk/cosmos/azure_data_cosmos_native/src/lib.rs similarity index 93% rename from sdk/cosmos/cosmosclient/src/lib.rs rename to sdk/cosmos/azure_data_cosmos_native/src/lib.rs index 05b90c84c7..6ad18528ce 100644 --- a/sdk/cosmos/cosmosclient/src/lib.rs +++ b/sdk/cosmos/azure_data_cosmos_native/src/lib.rs @@ -1,19 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -use std::ffi::{c_char, CStr, CString}; +use std::ffi::{c_char, CStr}; #[macro_use] mod macros; -#[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing /// cbindgen:ignore +#[no_mangle] // Necessary to prevent the compiler from stripping it when optimizing pub static BUILD_IDENTIFIER: &CStr = c_str!(env!("BUILD_IDENTIFIER")); const VERSION: &CStr = c_str!(env!("CARGO_PKG_VERSION")); -#[no_mangle] /// Returns a constant C string containing the version of the Cosmos Client library. +#[no_mangle] pub extern "C" fn cosmosclient_version() -> *const c_char { VERSION.as_ptr() } diff --git a/sdk/cosmos/azure_data_cosmos_native/src/macros.rs b/sdk/cosmos/azure_data_cosmos_native/src/macros.rs new file mode 100644 index 0000000000..f1175ed540 --- /dev/null +++ b/sdk/cosmos/azure_data_cosmos_native/src/macros.rs @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +macro_rules! c_str { + ($s:expr) => { + const { + // This does a few funky things to make sure we can stay in a const context + // Which ensures the string is generated as a c-str at compile time + const STR: &str = $s; + const BYTES: [u8; STR.len() + 1] = const { + let mut cstrbuf: [u8; STR.len() + 1] = [0; STR.len() + 1]; + let mut i = 0; + // For loops over ranges don't work in const contexts yet. + while i < STR.len() { + cstrbuf[i] = STR.as_bytes()[i]; + i += 1; + } + cstrbuf + }; + match CStr::from_bytes_with_nul(&BYTES) { + Ok(cstr) => cstr, + Err(_) => panic!("failed to convert value to C string"), + } + } + }; +} diff --git a/sdk/cosmos/cosmosclient/include/cosmosclient.h b/sdk/cosmos/cosmosclient/include/cosmosclient.h new file mode 100644 index 0000000000..29ca8c1164 --- /dev/null +++ b/sdk/cosmos/cosmosclient/include/cosmosclient.h @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// This file is auto-generated by cbindgen. Do not edit manually. +// Build identifier: $Id: cosmosclient, Version: 0.27.0, Commit: unknown, Branch: unknown, Build ID: unknown, Build Number: unknown, Timestamp: 1757003404$ + + +#include +#include +#include +#include + +// Specifies the version of cosmosclient this header file was generated from. +// This should match the version of libcosmosclient you are referencing. +#define COSMOSCLIENT_H_VERSION "0.27.0" + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/** + * Returns a constant C string containing the version of the Cosmos Client library. + */ +const char *cosmosclient_version(void); + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus diff --git a/sdk/cosmos/cosmosclient/src/macros.rs b/sdk/cosmos/cosmosclient/src/macros.rs deleted file mode 100644 index dd9f5402c0..0000000000 --- a/sdk/cosmos/cosmosclient/src/macros.rs +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -macro_rules! c_str { - ($s:expr) => { const { - // This does a few funky things to make sure we can stay in a const context - // Which ensures the string is generated as a c-str at compile time - const STR: &str = $s - const BYTES: [u8; STR.len() + 1] = const { - let mut cstrbuf: [u8; STR.len() + 1] = [0; STR.len() + 1]; - let mut i = 0; - // For loops over ranges don't really work in const contexts. - while i < STR.len() { - cstrbuf[i] = STR.as_bytes()[i]; - i += 1; - } - cstrbuf - }; - match CStr::from_bytes_with_nul(&BYTES) { - Ok(cstr) => cstr, - Err(_) => panic!("failed to convert value to C string"), - } - } }, -} From 205340f880bd7e254525f4b6bc2945beeaf4983e Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Sep 2025 17:12:50 +0000 Subject: [PATCH 08/19] cspell fixes --- eng/dict/rust-custom.txt | 3 +++ sdk/cosmos/.dict.txt | 4 ++++ sdk/cosmos/azure_data_cosmos_native/build.rs | 2 ++ sdk/cosmos/azure_data_cosmos_native/src/macros.rs | 6 +++--- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/eng/dict/rust-custom.txt b/eng/dict/rust-custom.txt index b3b37a5653..399d7666d8 100644 --- a/eng/dict/rust-custom.txt +++ b/eng/dict/rust-custom.txt @@ -12,3 +12,6 @@ rustflags rustls rustsec turbofish +dylib +cdylib +staticlib diff --git a/sdk/cosmos/.dict.txt b/sdk/cosmos/.dict.txt index f6b563e481..4d65959a65 100644 --- a/sdk/cosmos/.dict.txt +++ b/sdk/cosmos/.dict.txt @@ -8,3 +8,7 @@ udfs # Cosmos' docs all use "Autoscale" as a single word, rather than a compound "AutoScale" or "Auto Scale" autoscale + +cosmosclient +libcosmosclient +COSMOSCLIENT diff --git a/sdk/cosmos/azure_data_cosmos_native/build.rs b/sdk/cosmos/azure_data_cosmos_native/build.rs index 5c5a620dec..6eb3e13024 100644 --- a/sdk/cosmos/azure_data_cosmos_native/build.rs +++ b/sdk/cosmos/azure_data_cosmos_native/build.rs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +// cSpell:ignore SOURCEVERSION, SOURCEBRANCH, BUILDID, BUILDNUMBER + fn main() { let build_id = format!( "$Id: {}, Version: {}, Commit: {}, Branch: {}, Build ID: {}, Build Number: {}, Timestamp: {}$", diff --git a/sdk/cosmos/azure_data_cosmos_native/src/macros.rs b/sdk/cosmos/azure_data_cosmos_native/src/macros.rs index f1175ed540..a5ba7d4360 100644 --- a/sdk/cosmos/azure_data_cosmos_native/src/macros.rs +++ b/sdk/cosmos/azure_data_cosmos_native/src/macros.rs @@ -8,14 +8,14 @@ macro_rules! c_str { // Which ensures the string is generated as a c-str at compile time const STR: &str = $s; const BYTES: [u8; STR.len() + 1] = const { - let mut cstrbuf: [u8; STR.len() + 1] = [0; STR.len() + 1]; + let mut cstr_buf: [u8; STR.len() + 1] = [0; STR.len() + 1]; let mut i = 0; // For loops over ranges don't work in const contexts yet. while i < STR.len() { - cstrbuf[i] = STR.as_bytes()[i]; + cstr_buf[i] = STR.as_bytes()[i]; i += 1; } - cstrbuf + cstr_buf }; match CStr::from_bytes_with_nul(&BYTES) { Ok(cstr) => cstr, From f39d5387bc6c5d77783e788951d23948b986b2dd Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Sep 2025 21:12:47 +0000 Subject: [PATCH 09/19] update crates.txt using script --- eng/dict/crates.txt | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/eng/dict/crates.txt b/eng/dict/crates.txt index 7af9fde24f..ce0cfaec6d 100644 --- a/eng/dict/crates.txt +++ b/eng/dict/crates.txt @@ -5,24 +5,35 @@ azure_core azure_core azure_core_amqp azure_core_amqp +azure_core_macros +azure_core_macros +azure_core_opentelemetry +azure_core_opentelemetry azure_core_test azure_core_test azure_core_test_macros azure_core_test_macros azure_data_cosmos +azure_data_cosmos_native azure_identity azure_identity azure_messaging_eventhubs +azure_messaging_eventhubs +azure_messaging_eventhubs_checkpointstore_blob +azure_messaging_servicebus +azure_security_keyvault_certificates azure_security_keyvault_keys azure_security_keyvault_secrets azure_storage_blob -azure_canary -azure_canary_core +azure_storage_common +azure_template +azure_template_core base64 bytes cargo_metadata +cbindgen clap -dotenvy +criterion dyn-clone fe2o3-amqp fe2o3-amqp-cbs @@ -32,11 +43,14 @@ fe2o3-amqp-types flate2 futures getrandom -gloo +gloo-timers hmac litemap log openssl +opentelemetry +opentelemetry-http +opentelemetry_sdk pin-project proc-macro2 quick-xml @@ -44,6 +58,7 @@ quote rand rand_chacha reqwest +rust_decimal rustc_version serde serde_amqp @@ -52,7 +67,6 @@ serde_json serde_test serial_test sha2 -storage syn tar thiserror @@ -66,8 +80,9 @@ typespec_client_core typespec_client_core typespec_macros typespec_macros -ureq url uuid +wasm-bindgen-futures +wasm-bindgen-test zerofrom zip From 6df647d66e5c5ed17b1bc91f76ceac070e0d555c Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Sep 2025 21:23:50 +0000 Subject: [PATCH 10/19] add '_' variant of crate to crates.txt in update-cratenames.rs --- eng/dict/crates.txt | 19 +++++++++++++++++++ eng/scripts/update-cratenames.rs | 11 ++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/eng/dict/crates.txt b/eng/dict/crates.txt index ce0cfaec6d..ddde759002 100644 --- a/eng/dict/crates.txt +++ b/eng/dict/crates.txt @@ -1,6 +1,9 @@ async-lock async-stream async-trait +async_lock +async_stream +async_trait azure_core azure_core azure_core_amqp @@ -34,26 +37,38 @@ cargo_metadata cbindgen clap criterion +dotenvy dyn-clone +dyn_clone fe2o3-amqp fe2o3-amqp-cbs fe2o3-amqp-ext fe2o3-amqp-management fe2o3-amqp-types +fe2o3_amqp +fe2o3_amqp_cbs +fe2o3_amqp_ext +fe2o3_amqp_management +fe2o3_amqp_types flate2 futures getrandom gloo-timers +gloo_timers hmac litemap log openssl opentelemetry opentelemetry-http +opentelemetry_http opentelemetry_sdk pin-project +pin_project proc-macro2 +proc_macro2 quick-xml +quick_xml quote rand rand_chacha @@ -74,15 +89,19 @@ time tokio tracing tracing-subscriber +tracing_subscriber typespec typespec typespec_client_core typespec_client_core typespec_macros typespec_macros +ureq url uuid wasm-bindgen-futures wasm-bindgen-test +wasm_bindgen_futures +wasm_bindgen_test zerofrom zip diff --git a/eng/scripts/update-cratenames.rs b/eng/scripts/update-cratenames.rs index e3259dd6e9..96055287dd 100755 --- a/eng/scripts/update-cratenames.rs +++ b/eng/scripts/update-cratenames.rs @@ -29,7 +29,15 @@ fn main() { .dependencies .as_ref() .expect("expected workspace dependencies"); - let mut crate_names: Vec = dependencies.iter().map(|(name, _)| name.to_string()).collect(); + let mut crate_names: Vec = Vec::new(); + for (name, _) in dependencies.iter() { + let name = name.to_string(); + if name.contains('-') { + // When used in Rust code, hyphens are replaced with underscores. + crate_names.push(name.replace('-', "_")); + } + crate_names.push(name); + } // Extract workspace members. for relative_path in workspace_manifest @@ -45,6 +53,7 @@ fn main() { .and_then(OsStr::to_str) .expect("expected crate name") .to_string(); + crate_names.push(crate_name); } From 3c9338f460e7254f66df01a2ff607c26b513fbab Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Sep 2025 21:24:29 +0000 Subject: [PATCH 11/19] move some dependencies to root Cargo.toml so update-cratenames.rs finds them --- Cargo.toml | 6 ++++++ sdk/core/azure_core/Cargo.toml | 5 +---- sdk/core/azure_core_test/Cargo.toml | 2 +- sdk/cosmos/azure_data_cosmos_native/Cargo.toml | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 973264acaa..b10379bbc6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,8 +96,10 @@ async-trait = "0.1" base64 = "0.22" bytes = "1.0" cargo_metadata = "0.18.1" +cbindgen = "0.29.0" clap = { version = "4.5.45", features = ["derive"] } criterion = { version = "0.5", features = ["async_tokio"] } +dotenvy = "0.15.7" dyn-clone = "1.0" fe2o3-amqp = { version = "0.14", features = ["uuid"] } fe2o3-amqp-ext = { version = "0.14" } @@ -148,6 +150,10 @@ tracing = "0.1.40" tracing-subscriber = "0.3" url = "2.2" uuid = { version = "1.18", features = ["v4"] } +ureq = { version = "3", default-features = false, features = [ + "gzip", + "native-tls", +] } wasm-bindgen-futures = "0.4" wasm-bindgen-test = "0.3" zerofrom = "0.1.5" diff --git a/sdk/core/azure_core/Cargo.toml b/sdk/core/azure_core/Cargo.toml index f91e65038b..bf719e60b6 100644 --- a/sdk/core/azure_core/Cargo.toml +++ b/sdk/core/azure_core/Cargo.toml @@ -49,10 +49,7 @@ reqwest.workspace = true thiserror.workspace = true tokio.workspace = true tracing-subscriber.workspace = true -ureq = { version = "3", default-features = false, features = [ - "gzip", - "native-tls", -] } +ureq.workspace = true [features] default = [ diff --git a/sdk/core/azure_core_test/Cargo.toml b/sdk/core/azure_core_test/Cargo.toml index 13dc3eb703..a6dc43f9e0 100644 --- a/sdk/core/azure_core_test/Cargo.toml +++ b/sdk/core/azure_core_test/Cargo.toml @@ -23,7 +23,7 @@ async-trait.workspace = true azure_core = { workspace = true, features = ["test"] } azure_core_test_macros.workspace = true azure_identity.workspace = true -dotenvy = "0.15.7" +dotenvy.workspace = true futures.workspace = true rand.workspace = true rand_chacha.workspace = true diff --git a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml index 8bf861c4c9..c47680050e 100644 --- a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml @@ -17,7 +17,7 @@ crate-type = ["cdylib", "staticlib"] azure_data_cosmos = { path = "../azure_data_cosmos", features = ["c"] } [build-dependencies] -cbindgen = "0.29.0" +cbindgen.workspace = true [lints] workspace = true From b63c0b3c25fa7180c438163bc9bca77516164fd9 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 4 Sep 2025 21:24:38 +0000 Subject: [PATCH 12/19] other cspell fixes in cosmos --- sdk/cosmos/.dict.txt | 3 +- sdk/cosmos/azure_data_cosmos/Cargo.toml | 2 +- .../azure_data_cosmos_native/CMakeLists.txt | 2 ++ sdk/cosmos/azure_data_cosmos_native/build.rs | 3 +- .../cosmosclient/include/cosmosclient.h | 28 ------------------- 5 files changed, 6 insertions(+), 32 deletions(-) delete mode 100644 sdk/cosmos/cosmosclient/include/cosmosclient.h diff --git a/sdk/cosmos/.dict.txt b/sdk/cosmos/.dict.txt index 4d65959a65..7d5bae540f 100644 --- a/sdk/cosmos/.dict.txt +++ b/sdk/cosmos/.dict.txt @@ -9,6 +9,5 @@ udfs # Cosmos' docs all use "Autoscale" as a single word, rather than a compound "AutoScale" or "Auto Scale" autoscale +# Words used within the Cosmos Native Client (azure_data_cosmos_native) cosmosclient -libcosmosclient -COSMOSCLIENT diff --git a/sdk/cosmos/azure_data_cosmos/Cargo.toml b/sdk/cosmos/azure_data_cosmos/Cargo.toml index 6eb0970ef8..ae14dfe34f 100644 --- a/sdk/cosmos/azure_data_cosmos/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos/Cargo.toml @@ -37,7 +37,7 @@ workspace = true [features] default = ["hmac_rust"] -c = [] # Internal feature used to expose additional types/functions as needed to build libcosmosclient. +c = [] # Internal feature used to expose additional types/functions as needed to build the Cosmos native client key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) preview_query_engine = ["serde_json/raw_value"] # Enables support for the PREVIEW external query engine hmac_rust = ["azure_core/hmac_rust"] diff --git a/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt b/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt index 69019873a8..ce8871b4da 100644 --- a/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt +++ b/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt @@ -1,3 +1,5 @@ +# cSpell:ignore cosmosctest CRATETYPES endforeach + project(cosmosctest C) cmake_minimum_required(VERSION 4.1) diff --git a/sdk/cosmos/azure_data_cosmos_native/build.rs b/sdk/cosmos/azure_data_cosmos_native/build.rs index 6eb3e13024..9546699488 100644 --- a/sdk/cosmos/azure_data_cosmos_native/build.rs +++ b/sdk/cosmos/azure_data_cosmos_native/build.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -// cSpell:ignore SOURCEVERSION, SOURCEBRANCH, BUILDID, BUILDNUMBER +// cSpell:ignore SOURCEVERSION, SOURCEBRANCH, BUILDID, BUILDNUMBER, COSMOSCLIENT, cosmosclient, libcosmosclient, cbindgen fn main() { let build_id = format!( @@ -23,6 +23,7 @@ fn main() { // Licensed under the MIT License. // This file is auto-generated by cbindgen. Do not edit manually. +// cSpell: disable " .to_string(); header.push_str(&format!("// Build identifier: {}\n", build_id)); diff --git a/sdk/cosmos/cosmosclient/include/cosmosclient.h b/sdk/cosmos/cosmosclient/include/cosmosclient.h deleted file mode 100644 index 29ca8c1164..0000000000 --- a/sdk/cosmos/cosmosclient/include/cosmosclient.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -// This file is auto-generated by cbindgen. Do not edit manually. -// Build identifier: $Id: cosmosclient, Version: 0.27.0, Commit: unknown, Branch: unknown, Build ID: unknown, Build Number: unknown, Timestamp: 1757003404$ - - -#include -#include -#include -#include - -// Specifies the version of cosmosclient this header file was generated from. -// This should match the version of libcosmosclient you are referencing. -#define COSMOSCLIENT_H_VERSION "0.27.0" - -#ifdef __cplusplus -extern "C" { -#endif // __cplusplus - -/** - * Returns a constant C string containing the version of the Cosmos Client library. - */ -const char *cosmosclient_version(void); - -#ifdef __cplusplus -} // extern "C" -#endif // __cplusplus From 60e2c524ad7b1e776f9fb318a1f100b18ee08eca Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Tue, 9 Sep 2025 21:24:15 +0000 Subject: [PATCH 13/19] undo crate dep reorganization --- Cargo.toml | 7 ------ eng/dict/crates.txt | 37 ++--------------------------- eng/scripts/update-cratenames.rs | 11 +-------- sdk/core/azure_core/Cargo.toml | 5 +++- sdk/core/azure_core_test/Cargo.toml | 2 +- 5 files changed, 8 insertions(+), 54 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b10379bbc6..270868cf15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ members = [ "sdk/core/azure_core_test_macros", "sdk/core/azure_core_opentelemetry", "sdk/cosmos/azure_data_cosmos", - "sdk/cosmos/azure_data_cosmos_native", "sdk/identity/azure_identity", "sdk/eventhubs/azure_messaging_eventhubs", "sdk/eventhubs/azure_messaging_eventhubs_checkpointstore_blob", @@ -96,10 +95,8 @@ async-trait = "0.1" base64 = "0.22" bytes = "1.0" cargo_metadata = "0.18.1" -cbindgen = "0.29.0" clap = { version = "4.5.45", features = ["derive"] } criterion = { version = "0.5", features = ["async_tokio"] } -dotenvy = "0.15.7" dyn-clone = "1.0" fe2o3-amqp = { version = "0.14", features = ["uuid"] } fe2o3-amqp-ext = { version = "0.14" } @@ -150,10 +147,6 @@ tracing = "0.1.40" tracing-subscriber = "0.3" url = "2.2" uuid = { version = "1.18", features = ["v4"] } -ureq = { version = "3", default-features = false, features = [ - "gzip", - "native-tls", -] } wasm-bindgen-futures = "0.4" wasm-bindgen-test = "0.3" zerofrom = "0.1.5" diff --git a/eng/dict/crates.txt b/eng/dict/crates.txt index ddde759002..8fa4cd83d6 100644 --- a/eng/dict/crates.txt +++ b/eng/dict/crates.txt @@ -1,30 +1,18 @@ async-lock async-stream async-trait -async_lock -async_stream -async_trait azure_core azure_core azure_core_amqp azure_core_amqp -azure_core_macros -azure_core_macros -azure_core_opentelemetry -azure_core_opentelemetry azure_core_test azure_core_test azure_core_test_macros azure_core_test_macros azure_data_cosmos -azure_data_cosmos_native azure_identity azure_identity azure_messaging_eventhubs -azure_messaging_eventhubs -azure_messaging_eventhubs_checkpointstore_blob -azure_messaging_servicebus -azure_security_keyvault_certificates azure_security_keyvault_keys azure_security_keyvault_secrets azure_storage_blob @@ -34,46 +22,29 @@ azure_template_core base64 bytes cargo_metadata -cbindgen clap -criterion dotenvy dyn-clone -dyn_clone fe2o3-amqp fe2o3-amqp-cbs fe2o3-amqp-ext fe2o3-amqp-management fe2o3-amqp-types -fe2o3_amqp -fe2o3_amqp_cbs -fe2o3_amqp_ext -fe2o3_amqp_management -fe2o3_amqp_types flate2 futures getrandom -gloo-timers -gloo_timers +gloo hmac litemap log openssl -opentelemetry -opentelemetry-http -opentelemetry_http -opentelemetry_sdk pin-project -pin_project proc-macro2 -proc_macro2 quick-xml -quick_xml quote rand rand_chacha reqwest -rust_decimal rustc_version serde serde_amqp @@ -82,6 +53,7 @@ serde_json serde_test serial_test sha2 +storage syn tar thiserror @@ -89,7 +61,6 @@ time tokio tracing tracing-subscriber -tracing_subscriber typespec typespec typespec_client_core @@ -99,9 +70,5 @@ typespec_macros ureq url uuid -wasm-bindgen-futures -wasm-bindgen-test -wasm_bindgen_futures -wasm_bindgen_test zerofrom zip diff --git a/eng/scripts/update-cratenames.rs b/eng/scripts/update-cratenames.rs index 96055287dd..e3259dd6e9 100755 --- a/eng/scripts/update-cratenames.rs +++ b/eng/scripts/update-cratenames.rs @@ -29,15 +29,7 @@ fn main() { .dependencies .as_ref() .expect("expected workspace dependencies"); - let mut crate_names: Vec = Vec::new(); - for (name, _) in dependencies.iter() { - let name = name.to_string(); - if name.contains('-') { - // When used in Rust code, hyphens are replaced with underscores. - crate_names.push(name.replace('-', "_")); - } - crate_names.push(name); - } + let mut crate_names: Vec = dependencies.iter().map(|(name, _)| name.to_string()).collect(); // Extract workspace members. for relative_path in workspace_manifest @@ -53,7 +45,6 @@ fn main() { .and_then(OsStr::to_str) .expect("expected crate name") .to_string(); - crate_names.push(crate_name); } diff --git a/sdk/core/azure_core/Cargo.toml b/sdk/core/azure_core/Cargo.toml index bf719e60b6..f91e65038b 100644 --- a/sdk/core/azure_core/Cargo.toml +++ b/sdk/core/azure_core/Cargo.toml @@ -49,7 +49,10 @@ reqwest.workspace = true thiserror.workspace = true tokio.workspace = true tracing-subscriber.workspace = true -ureq.workspace = true +ureq = { version = "3", default-features = false, features = [ + "gzip", + "native-tls", +] } [features] default = [ diff --git a/sdk/core/azure_core_test/Cargo.toml b/sdk/core/azure_core_test/Cargo.toml index a6dc43f9e0..13dc3eb703 100644 --- a/sdk/core/azure_core_test/Cargo.toml +++ b/sdk/core/azure_core_test/Cargo.toml @@ -23,7 +23,7 @@ async-trait.workspace = true azure_core = { workspace = true, features = ["test"] } azure_core_test_macros.workspace = true azure_identity.workspace = true -dotenvy.workspace = true +dotenvy = "0.15.7" futures.workspace = true rand.workspace = true rand_chacha.workspace = true From 783acd8c48594c6a447b750536d33958764e7729 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Tue, 9 Sep 2025 21:24:56 +0000 Subject: [PATCH 14/19] update Cargo.lock --- Cargo.lock | 60 ------------------------------------------------------ 1 file changed, 60 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eda1fead4d..289136ca88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,14 +332,6 @@ dependencies = [ "url", ] -[[package]] -name = "azure_data_cosmos_native" -version = "0.27.0" -dependencies = [ - "azure_data_cosmos", - "cbindgen", -] - [[package]] name = "azure_identity" version = "0.29.0" @@ -699,25 +691,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" -[[package]] -name = "cbindgen" -version = "0.29.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684" -dependencies = [ - "clap", - "heck", - "indexmap", - "log", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn 2.0.104", - "tempfile", - "toml", -] - [[package]] name = "cc" version = "1.2.32" @@ -2641,15 +2614,6 @@ dependencies = [ "syn 2.0.104", ] -[[package]] -name = "serde_spanned" -version = "0.6.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" -dependencies = [ - "serde", -] - [[package]] name = "serde_test" version = "1.0.177" @@ -3034,26 +2998,11 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml" -version = "0.8.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" -dependencies = [ - "serde", - "serde_spanned", - "toml_datetime", - "toml_edit", -] - [[package]] name = "toml_datetime" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" -dependencies = [ - "serde", -] [[package]] name = "toml_edit" @@ -3062,19 +3011,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", - "serde", - "serde_spanned", "toml_datetime", - "toml_write", "winnow", ] -[[package]] -name = "toml_write" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" - [[package]] name = "tower" version = "0.5.2" From 35696677af736e13d505616e2f77e1b75b0db565 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 11 Sep 2025 18:45:02 +0000 Subject: [PATCH 15/19] restore azure_data_cosmos_native to workspace --- Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Cargo.toml b/Cargo.toml index 270868cf15..973264acaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,7 @@ members = [ "sdk/core/azure_core_test_macros", "sdk/core/azure_core_opentelemetry", "sdk/cosmos/azure_data_cosmos", + "sdk/cosmos/azure_data_cosmos_native", "sdk/identity/azure_identity", "sdk/eventhubs/azure_messaging_eventhubs", "sdk/eventhubs/azure_messaging_eventhubs_checkpointstore_blob", From eb890a0c17d0a04f2f9b0187fd94eef764e841b9 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 11 Sep 2025 18:45:13 +0000 Subject: [PATCH 16/19] add cbindgen to rust dictionary --- eng/dict/rust-custom.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/eng/dict/rust-custom.txt b/eng/dict/rust-custom.txt index 399d7666d8..174812db94 100644 --- a/eng/dict/rust-custom.txt +++ b/eng/dict/rust-custom.txt @@ -15,3 +15,4 @@ turbofish dylib cdylib staticlib +cbindgen From a2810401b0062d07348870a36369448028243d02 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 2 Oct 2025 19:04:11 +0000 Subject: [PATCH 17/19] remove workspace reference to cbindgen --- Cargo.lock | 60 +++++++++++++++++++ .../azure_data_cosmos_native/Cargo.toml | 2 +- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 289136ca88..eda1fead4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -332,6 +332,14 @@ dependencies = [ "url", ] +[[package]] +name = "azure_data_cosmos_native" +version = "0.27.0" +dependencies = [ + "azure_data_cosmos", + "cbindgen", +] + [[package]] name = "azure_identity" version = "0.29.0" @@ -691,6 +699,25 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" +[[package]] +name = "cbindgen" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "975982cdb7ad6a142be15bdf84aea7ec6a9e5d4d797c004d43185b24cfe4e684" +dependencies = [ + "clap", + "heck", + "indexmap", + "log", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 2.0.104", + "tempfile", + "toml", +] + [[package]] name = "cc" version = "1.2.32" @@ -2614,6 +2641,15 @@ dependencies = [ "syn 2.0.104", ] +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + [[package]] name = "serde_test" version = "1.0.177" @@ -2998,11 +3034,26 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362" +dependencies = [ + "serde", + "serde_spanned", + "toml_datetime", + "toml_edit", +] + [[package]] name = "toml_datetime" version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" +dependencies = [ + "serde", +] [[package]] name = "toml_edit" @@ -3011,10 +3062,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a" dependencies = [ "indexmap", + "serde", + "serde_spanned", "toml_datetime", + "toml_write", "winnow", ] +[[package]] +name = "toml_write" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801" + [[package]] name = "tower" version = "0.5.2" diff --git a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml index c47680050e..8bf861c4c9 100644 --- a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml @@ -17,7 +17,7 @@ crate-type = ["cdylib", "staticlib"] azure_data_cosmos = { path = "../azure_data_cosmos", features = ["c"] } [build-dependencies] -cbindgen.workspace = true +cbindgen = "0.29.0" [lints] workspace = true From 6c997b096563145df2e881d6b4a841700f8a4405 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 2 Oct 2025 20:24:32 +0000 Subject: [PATCH 18/19] rename Cosmos native lib, and rename 'c' feature flag to ffi --- sdk/cosmos/azure_data_cosmos/Cargo.toml | 2 +- sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt | 2 +- sdk/cosmos/azure_data_cosmos_native/Cargo.toml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sdk/cosmos/azure_data_cosmos/Cargo.toml b/sdk/cosmos/azure_data_cosmos/Cargo.toml index ae14dfe34f..22deffff07 100644 --- a/sdk/cosmos/azure_data_cosmos/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos/Cargo.toml @@ -37,7 +37,7 @@ workspace = true [features] default = ["hmac_rust"] -c = [] # Internal feature used to expose additional types/functions as needed to build the Cosmos native client +ffi = [] # Internal feature used to expose additional types/functions as needed to build the Cosmos native client key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) preview_query_engine = ["serde_json/raw_value"] # Enables support for the PREVIEW external query engine hmac_rust = ["azure_core/hmac_rust"] diff --git a/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt b/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt index ce8871b4da..e1b8b7289b 100644 --- a/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt +++ b/sdk/cosmos/azure_data_cosmos_native/CMakeLists.txt @@ -27,7 +27,7 @@ set(TEST_FILES foreach(test_file ${TEST_FILES}) get_filename_component(test_name ${test_file} NAME_WE) add_executable(${test_name} ${test_file}) - target_link_libraries(${test_name} PRIVATE cosmosclient) + target_link_libraries(${test_name} PRIVATE azurecosmos) add_test(${test_name} ${test_name}) endforeach() diff --git a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml index 8bf861c4c9..0d1a803226 100644 --- a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml @@ -10,11 +10,11 @@ repository.workspace = true rust-version.workspace = true [lib] -name = "cosmosclient" +name = "azurecosmos" crate-type = ["cdylib", "staticlib"] [dependencies] -azure_data_cosmos = { path = "../azure_data_cosmos", features = ["c"] } +azure_data_cosmos = { path = "../azure_data_cosmos", features = ["ffi"] } [build-dependencies] cbindgen = "0.29.0" From 333d81d22bd671e5702084fe7c68a1d49ccc6c42 Mon Sep 17 00:00:00 2001 From: Ashley Stanton-Nurse Date: Thu, 2 Oct 2025 20:25:31 +0000 Subject: [PATCH 19/19] just remove ffi feature, we're not using it yet --- sdk/cosmos/azure_data_cosmos/Cargo.toml | 1 - sdk/cosmos/azure_data_cosmos_native/Cargo.toml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/sdk/cosmos/azure_data_cosmos/Cargo.toml b/sdk/cosmos/azure_data_cosmos/Cargo.toml index 22deffff07..e16d9f86ce 100644 --- a/sdk/cosmos/azure_data_cosmos/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos/Cargo.toml @@ -37,7 +37,6 @@ workspace = true [features] default = ["hmac_rust"] -ffi = [] # Internal feature used to expose additional types/functions as needed to build the Cosmos native client key_auth = [] # Enables support for key-based authentication (Primary Keys and Resource Tokens) preview_query_engine = ["serde_json/raw_value"] # Enables support for the PREVIEW external query engine hmac_rust = ["azure_core/hmac_rust"] diff --git a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml index 0d1a803226..504ff19443 100644 --- a/sdk/cosmos/azure_data_cosmos_native/Cargo.toml +++ b/sdk/cosmos/azure_data_cosmos_native/Cargo.toml @@ -14,7 +14,7 @@ name = "azurecosmos" crate-type = ["cdylib", "staticlib"] [dependencies] -azure_data_cosmos = { path = "../azure_data_cosmos", features = ["ffi"] } +azure_data_cosmos = { path = "../azure_data_cosmos" } [build-dependencies] cbindgen = "0.29.0"