Initial C Bindings for Cosmos DB SDK for Rust - #3347
Merged
Ashley Stanton-Nurse (analogrelay) merged 30 commits intoJan 8, 2026
Merged
Initial C Bindings for Cosmos DB SDK for Rust#3347Ashley Stanton-Nurse (analogrelay) merged 30 commits into
Ashley Stanton-Nurse (analogrelay) merged 30 commits into
Conversation
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
Ashley Stanton-Nurse (analogrelay)
force-pushed
the
ashleyst/port-c-bindings
branch
from
November 18, 2025 00:46
4393c1b to
aeaba92
Compare
Ashley Stanton-Nurse (analogrelay)
marked this pull request as ready for review
November 20, 2025 00:03
Ashley Stanton-Nurse (analogrelay)
requested a review
from a team
as a code owner
November 20, 2025 00:03
Copilot started reviewing on behalf of
Ashley Stanton-Nurse (analogrelay)
November 20, 2025 00:03
View session
Contributor
There was a problem hiding this comment.
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).
Kevin Pilch (Pilchie)
approved these changes
Dec 2, 2025
Member
Author
|
/azp run rust - pullrequest |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Ashley Stanton-Nurse (analogrelay)
force-pushed
the
ashleyst/port-c-bindings
branch
from
December 15, 2025 22:49
0e06cc1 to
d5fa04b
Compare
Ashley Stanton-Nurse (analogrelay)
force-pushed
the
ashleyst/port-c-bindings
branch
from
December 16, 2025 21:16
d5fa04b to
0c28da3
Compare
Kevin Pilch (Pilchie)
approved these changes
Dec 18, 2025
Member
Author
|
/azp run rust - pullrequest |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Author
|
Hopefully, a simple rebuild should catch the fixes from #3461 and give us a green build 🤞🏻 |
Heath Stewart (heaths)
approved these changes
Jan 7, 2026
Heath Stewart (heaths)
left a comment
Member
There was a problem hiding this comment.
Signing off on Cargo.lock (only non-Cosmos change) and to unblock the PR.
Ashley Stanton-Nurse (analogrelay)
merged commit Jan 8, 2026
583455e
into
Azure:main
17 checks passed
Ashley Stanton-Nurse (analogrelay)
added a commit
that referenced
this pull request
Jan 9, 2026
This PR just deletes the `cosmosclient.h` header file, which was the name prior to #3347 . I just forgot to properly delete the old file in that PR.
Charles Lowell (chlowell)
pushed a commit
that referenced
this pull request
Jan 16, 2026
This PR introduces C language bindings (FFI) for the `azure_data_cosmos` Rust SDK, enabling C/C++ applications to interact with Azure Cosmos DB. ### Key Changes **New `azure_data_cosmos_native` Package:** - Complete C API with FFI layer exposing core Cosmos DB operations (originally developed by a partner team) - Runtime and call context management for async/sync bridging. The Runtime Context defines the threads on which async operations will run, and the Call Context provides a place for call-specific reporting of error details. This is based on the pattern found in the [AMQP package](https://github.com/Azure/azure-sdk-for-cpp/blob/main/sdk/core/azure-core-amqp/src/impl/rust_amqp/rust_amqp/rust_wrapper/src/call_context.rs) for C++ - Comprehensive error handling with optional detailed error information - CRUD operations for databases, containers, and items - Connection string support **C Tests:** - Shared test infrastructure (`test_common.h`) with automatic test discovery - Basic tests of item/container/database CRUD. - Integration with CMake/CTest **Build System:** - CMake build configuration with organized output directories - `cbindgen` integration for automatic header generation - pkg-config file generation for library integration - Cross-platform support (Linux, macOS, Windows) Closes #3444
Charles Lowell (chlowell)
pushed a commit
that referenced
this pull request
Jan 16, 2026
This PR just deletes the `cosmosclient.h` header file, which was the name prior to #3347 . I just forgot to properly delete the old file in that PR.
Debdatta Kunda (kundadebdatta)
pushed a commit
that referenced
this pull request
May 23, 2026
…PER_SPEC Blocking fixes: - §6 / §4.7: bind cosmos_driver_execute to execute_singleton_operation, document Result<Option<CosmosResponse>> handling and FEED_EXHAUSTED. - §4.6: remove cosmos_operation_with_partition_key; PK now lives on item / feed factory args (ItemReference::from_name requires PK at construction). - §4.4: add normative driver-cache documentation (endpoint-only key, options dropped on cache hit, credential collision caveat) plus a new COSMOS_ERROR_CODE_OPTIONS_IGNORED_ON_CACHE_HIT advisory. - §3.5 / §6: rewrite error model for azure_data_cosmos::Error from #4442 (Kind enum, typed accessors, predicates, synthetic sub-status codes, non_exhaustive future-proofing via COSMOS_ERROR_KIND_UNKNOWN). - §4.2: fix DriverOptions surface to mirror the actual 3-field type; builder takes account, with_operation_options for per-call defaults; removed allow_emulator_invalid_certs (lives on runtime instead). - §5.2: fix Cargo features (default = tokio + rustls; drop fake reqwest_native_tls / tracing feature; native_tls is the correct name). - §4.6.3: normative execute-consumption contract (sentinel, free always safe, failed execute does not consume, double-execute returns 4005). Recommended fixes: - §4.6.2: split with_precondition into IF_MATCH / IF_NONE_MATCH with a PRECONDITION_ALREADY_SET error to enforce single-precondition rule. - §4.3: document resource-token routing via master-key Secret path; add with_credential mirror. - §4.6.1: add missing factories — read_all_items_cross_partition, query_items, batch, query/read/replace_offer. - §4.3 / §4.5 / §3.4: define cosmos_*_clone functions promised in §3.4. - §5.3: Phase 0 ancillary-tooling re-introduction checklist for entries PR #4103 removed (cbindgen as [build-dependencies] only per heaths, dict files, .cspell.json, verify-dependencies.rs, AGENTS.md, skills). - §3 / §5.1: tighten inheritance attribution between #2906 and #3347. - §7: loosen strict ABI version equality to major-equal / minor->= so the spec's additive-growth promise actually holds. - §2.2: add cbindgen export.rename / item_types policy so the generated header matches the naming table (avoids cosmos_cosmos_* double-prefix and prevents driver-internal types from leaking). Other: - §9: replaced single open question on RuntimeAlreadyInitialized with 9 questions covering implementation parking-lot items (header-visitor borrow vs copy, continuation-token format, multi-part body, C++ companion header, credential identity in cache, ConnectionString parser ownership, symbol stripping, pager continuation-token resume). - §8: updated Phase 0 / 1 / 2 / 3 / 5 / 6 acceptance criteria to match the new contracts (header check-in, error accessor coverage, cache-hit advisory test, error-mapped 404 surfaces as is_not_found). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces C language bindings (FFI) for the
azure_data_cosmosRust SDK, enabling C/C++ applications to interact with Azure Cosmos DB.Key Changes
New
azure_data_cosmos_nativePackage:C Tests:
test_common.h) with automatic test discoveryBuild System:
cbindgenintegration for automatic header generationCloses #3444