Skip to content

Commit

Permalink
Merge branch 'cbindgen-ci' into 'main'
Browse files Browse the repository at this point in the history
Test cbindgen correctness in CI

Closes #1502

See merge request tpo/core/arti!2320
  • Loading branch information
dgoulet-tor committed Aug 7, 2024
2 parents d73c300 + 383787c commit 91db4e2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ maint-check-ownership:
# a chance to run `cargo add`.
- if: $CI_COMMIT_BRANCH == "main"

maint-check-cbindgen:
stage: test
# cbindgen needs nightly rust to do macro expansion
image: rustlang/rust:nightly
script:
- ./maint/common/apt-install python3-toml
- ./maint/common/via-cargo-install-in-ci cbindgen
- ./maint/cbindgen --check

# non-blocking for now, see
# https://gitlab.torproject.org/tpo/core/arti/-/issues/581
# https://gitlab.torproject.org/tpo/core/arti/-/issues/601
Expand Down
28 changes: 28 additions & 0 deletions crates/arti-rpc-client-core/arti-rpc-client-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ ArtiRpcStatus arti_rpc_connect(const char *connection_string,
ArtiRpcConn **rpc_conn_out,
ArtiRpcError **error_out);

/**
* Given a pointer to an RPC connection, return the object ID for its negotiated session.
*
* (The session was negotiated as part of establishing the connection.
* Its object ID is necessary to invoke most other functionality on Arti.)
*
* The caller should be prepared for a possible NULL return, in case somehow
* no session was negotiated.
*
* # Ownership
*
* The resulting string is a reference to part of the `ArtiRpcConn`.
* It lives for no longer than the underlying `ArtiRpcConn` object.
*/
const char *arti_rpc_conn_get_session_id(const ArtiRpcConn *rpc_conn);

/**
* Run an RPC request over `rpc_conn` and wait for a successful response.
*
Expand Down Expand Up @@ -356,6 +372,18 @@ const char *arti_status_to_str(ArtiRpcStatus status);
*/
ArtiRpcStatus arti_rpc_err_status(const ArtiRpcError *err);

/**
* Return the OS error code underlying `err`, if any.
*
* This is typically an `errno` on unix-like systems , or the result of `GetLastError()`
* on Windows. It is only present when `err` was caused by the failure of some
* OS library call, like a `connect()` or `read()`.
*
* Returns 0 if `err` is NULL, or if `err` was not caused by the failure of an
* OS library call.
*/
int arti_rpc_err_os_error_code(const ArtiRpcError *err);

/**
* Return a human-readable error message associated with a given error.
*
Expand Down
5 changes: 5 additions & 0 deletions crates/arti-rpc-client-core/cbindgen.warnings
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Skip arti-rpc-client-core::_ - (not `pub`).
WARN: Cannot find a mangling for generic path GenericPath { path: Path { name: "Map" }, export_name: "Map", generics: [Type(Path(GenericPath { path: Path { name: "String" }, export_name: "String", generics: [], ctype: None })), Type(Path(GenericPath { path: Path { name: "Value" }, export_name: "Value", generics: [], ctype: None }))], ctype: None }. This usually means that a type referenced by this generic was incompatible or not found.
WARN: Can't find RpcConn. This usually means that this type was incompatible or not found.
WARN: Can't find FfiError. This usually means that this type was incompatible or not found.
Expand Down Expand Up @@ -50,3 +53,5 @@ WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
WARN: Missing `[defines]` entry for `feature = "ffi"` in cbindgen config.
2 changes: 1 addition & 1 deletion maint/cbindgen
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ while true; do
shift
;;
-c | --check)
fail_on_change=0
fail_on_change=1
replace=0
shift
;;
Expand Down

0 comments on commit 91db4e2

Please sign in to comment.