-
Notifications
You must be signed in to change notification settings - Fork 320
Initial C Bindings for Cosmos DB SDK for Rust #3347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
4393c1b to
aeaba92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces C bindings for the Azure Cosmos DB SDK for Rust, allowing the SDK to be used from C and other languages. Key changes include:
- New FFI layer with runtime context, call context, and error handling infrastructure
- C bindings for CosmosClient, DatabaseClient, and ContainerClient
- Support for CRUD operations, queries, and resource management
- Auto-generated C header file (
azurecosmos.h) - Comprehensive C test suite covering CRUD operations, error handling, and memory management
Reviewed Changes
Copilot reviewed 22 out of 23 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/string.rs |
String utilities and FFI string conversion helpers |
src/runtime/tokio.rs |
Tokio runtime wrapper for async operations |
src/runtime/mod.rs |
Runtime context FFI functions |
src/options/mod.rs |
Empty option structs for future extensibility |
src/lib.rs |
Main library entry, version function, and tracing setup |
src/error.rs |
Error types, codes, and conversion from Azure SDK errors |
src/context.rs |
Call context for FFI operations and helper macros |
src/clients/mod.rs |
Client module exports |
src/clients/database_client.rs |
Database operations FFI functions |
src/clients/cosmos_client.rs |
Cosmos client creation and database operations |
src/clients/container_client.rs |
Container and item operations FFI functions |
include/azurecosmos.h |
Auto-generated C header file |
c_tests/*.c |
C test suite for FFI functionality |
build.rs |
cbindgen configuration for header generation |
Cargo.toml |
Dependencies and features for native bindings |
CMakeLists.txt |
CMake build configuration for C tests |
Comments suppressed due to low confidence (1)
sdk/cosmos/azure_data_cosmos_native/src/string.rs:37
- The
safe_cstring_newfunction callsexpect()which can panic, but this panic behavior is not documented. Add a# Panicssection to the function documentation explaining when this function panics (when the string contains interior NUL bytes).
|
|
||
| #[repr(C)] | ||
| pub struct DeleteDatabaseOptions { | ||
| // Placeholder for future read database options |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected comment from 'read database options' to 'delete database options'.
| // Placeholder for future read database options | |
| // Placeholder for future delete database options |
|
|
||
| #[repr(C)] | ||
| pub struct DeleteContainerOptions { | ||
| // Placeholder for future read container options |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Corrected comment from 'read container options' to 'delete container options'.
| // Placeholder for future read container options | |
| // Placeholder for future delete container options |
| let pk = partition_key.to_string(); | ||
| container.replace_item(pk, item_id, raw_value, None).await?; |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The partition_key is already converted to String on line 161. This .to_string() call creates an unnecessary allocation. Use partition_key directly instead of creating pk.
| let pk = partition_key.to_string(); | |
| container.replace_item(pk, item_id, raw_value, None).await?; | |
| container.replace_item(partition_key, item_id, raw_value, None).await?; |
| } | ||
|
|
||
| // Heap-allocated context | ||
| cosmos_call_context *ctx = cosmos_call_context_create(runtime, false); |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cosmos_call_context_create function expects a pointer to CallContextOptions as its second parameter (const struct cosmos_call_context_options *options), but false (a boolean literal) is being passed instead. This should either be NULL or a pointer to a properly initialized cosmos_call_context_options struct with include_error_details set to false.
| cosmos_call_context *ctx = cosmos_call_context_create(runtime, false); | |
| struct cosmos_call_context_options options = { 0 }; | |
| options.include_error_details = false; | |
| cosmos_call_context *ctx = cosmos_call_context_create(runtime, &options); |
| # cSpell:ignore cosmosctest CRATETYPES endforeach | ||
|
|
||
| project(cosmosctest C) | ||
| cmake_minimum_required(VERSION 4.1) |
Copilot
AI
Nov 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project() command should be called before cmake_minimum_required() according to CMake best practices. While this code moves project() after cmake_minimum_required() (which is correct), the version 4.1 appears incorrect as CMake versions follow a 3.x numbering scheme. This should likely be VERSION 3.1 or higher.
| cmake_minimum_required(VERSION 4.1) | |
| cmake_minimum_required(VERSION 3.15) |
This PR ports over the initial C bindings, contributed by a partner team, to this repository.
The bindings are defined in the
azure_data_cosmos_nativecrate, which buildslibazurecosmos.aandlibazurecosmos.so(and others on other platforms). That project also creates theazurecosmos.hheader file.