Skip to content

Commit de5bf3b

Browse files
authored
cosmos: add experimental c wrapper around cosmos sdk (#2906)
We want to explore the option of publishing a C library of the Azure Cosmos DB SDK for Rust. This PR adds the basic framework to start that effort: * A new package `cosmosclient` that depends on `azure_data_cosmos`. This package builds a `cdylib` and `staticlib` target (`libcosmosclient.a`/`libcosmosclient.so`/`cosmosclient.dll`/etc.) that exports a C-compatible API. For now, that API is extremely simple (`cosmosclient_version`). * A simple test infrastructure (NOT currently integrated into anything). There are C programs in `sdk/cosmos/cosmosclient/c_tests` that will be built and linked against the cosmosclient library. The tests are simple pass/fail programs. If the test returns a `0` exit code, it passed, otherwise, it failed. * `build.rs` script in `cosmosclient` to produce `sdk/cosmos/cosmosclient/include/cosmosclient.h`, which is a C header file defining the API surface of `cosmosclient`. We should publish this as an artifact at some point, but for now it's there to be used by tests.
1 parent 327b4fc commit de5bf3b

File tree

17 files changed

+293
-4
lines changed

17 files changed

+293
-4
lines changed

.vscode/cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,4 @@
234234
]
235235
}
236236
]
237-
}
237+
}

Cargo.lock

Lines changed: 60 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ members = [
1313
"sdk/core/azure_core_test_macros",
1414
"sdk/core/azure_core_opentelemetry",
1515
"sdk/cosmos/azure_data_cosmos",
16+
"sdk/cosmos/azure_data_cosmos_native",
1617
"sdk/identity/azure_identity",
1718
"sdk/eventhubs/azure_messaging_eventhubs",
1819
"sdk/eventhubs/azure_messaging_eventhubs_checkpointstore_blob",

deny.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ allow = [
1313
"BSL-1.0",
1414
"ISC",
1515
"MIT",
16+
"MPL-2.0",
1617
# "OpenSSL",
1718
"Unicode-3.0",
1819
"Zlib",

eng/dict/crates.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ azure_messaging_eventhubs
1616
azure_security_keyvault_keys
1717
azure_security_keyvault_secrets
1818
azure_storage_blob
19-
azure_canary
20-
azure_canary_core
19+
azure_storage_common
20+
azure_template
21+
azure_template_core
2122
base64
2223
bytes
2324
cargo_metadata

eng/dict/rust-custom.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,7 @@ rustflags
1212
rustls
1313
rustsec
1414
turbofish
15+
dylib
16+
cdylib
17+
staticlib
18+
cbindgen

sdk/cosmos/.dict.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,7 @@ udfs
88

99
# Cosmos' docs all use "Autoscale" as a single word, rather than a compound "AutoScale" or "Auto Scale"
1010
autoscale
11+
12+
# Words used within the Cosmos Native Client (azure_data_cosmos_native)
13+
azurecosmos
14+
cosmosclient

sdk/cosmos/azure_data_cosmos/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ hmac_rust = ["azure_core/hmac_rust"]
4343
hmac_openssl = ["azure_core/hmac_openssl"]
4444

4545
[package.metadata.docs.rs]
46-
features = ["key_auth"]
46+
features = [
47+
"key_auth",
48+
"preview_query_engine",
49+
"hmac_rust",
50+
"hmac_openssl",
51+
]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# cSpell:ignore cosmosctest CRATETYPES endforeach
2+
3+
project(cosmosctest C)
4+
cmake_minimum_required(VERSION 4.1)
5+
6+
# CMake automatically uses this option, but we should define it.
7+
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
8+
9+
include(FetchContent)
10+
include(CTest)
11+
12+
FetchContent_Declare(
13+
Corrosion
14+
GIT_REPOSITORY https://github.com/corrosion-rs/corrosion.git
15+
GIT_TAG v0.5.2
16+
)
17+
FetchContent_MakeAvailable(Corrosion)
18+
19+
corrosion_import_crate(
20+
MANIFEST_PATH ./Cargo.toml
21+
CRATETYPES staticlib cdylib
22+
)
23+
24+
set(TEST_FILES
25+
./c_tests/version.c)
26+
27+
foreach(test_file ${TEST_FILES})
28+
get_filename_component(test_name ${test_file} NAME_WE)
29+
add_executable(${test_name} ${test_file})
30+
target_link_libraries(${test_name} PRIVATE azurecosmos)
31+
add_test(${test_name} ${test_name})
32+
endforeach()
33+

0 commit comments

Comments
 (0)