From 86ad8991e7f4e80ef7d5e45e0e60e66e7c4b9d0e Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 7 Aug 2024 09:11:18 -0400 Subject: [PATCH 1/3] cbindgen script: Fix behavior of --check Previously it didn't actually fail if there was a change. --- maint/cbindgen | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maint/cbindgen b/maint/cbindgen index 895a71ac2..0687f5c5d 100755 --- a/maint/cbindgen +++ b/maint/cbindgen @@ -71,7 +71,7 @@ while true; do shift ;; -c | --check) - fail_on_change=0 + fail_on_change=1 replace=0 shift ;; From 1f90e7c6958bcab03f5359a039a8b1f7600630ad Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 7 Aug 2024 08:28:05 -0400 Subject: [PATCH 2/3] Test cbindgen correctness in CI With the introduction of FFI, we ship generated header files that we need to keep up-to-date. This CI test double-checks that the generated files match those that we would generate from cbindgen. --- .gitlab-ci.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2bccd79c3..36fdc9568 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 From 383787c72a4b56a746af9702deb003907daf75e1 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 7 Aug 2024 09:27:59 -0400 Subject: [PATCH 3/3] Re-run cbindgen to update our generated header. (This is kind of thing that the CI script should remind us to do.) --- .../arti-rpc-client-core.h | 28 +++++++++++++++++++ crates/arti-rpc-client-core/cbindgen.warnings | 5 ++++ 2 files changed, 33 insertions(+) diff --git a/crates/arti-rpc-client-core/arti-rpc-client-core.h b/crates/arti-rpc-client-core/arti-rpc-client-core.h index d7bb581a4..faa99eaba 100644 --- a/crates/arti-rpc-client-core/arti-rpc-client-core.h +++ b/crates/arti-rpc-client-core/arti-rpc-client-core.h @@ -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. * @@ -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. * diff --git a/crates/arti-rpc-client-core/cbindgen.warnings b/crates/arti-rpc-client-core/cbindgen.warnings index 4d6df5252..47bc7bf96 100644 --- a/crates/arti-rpc-client-core/cbindgen.warnings +++ b/crates/arti-rpc-client-core/cbindgen.warnings @@ -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. @@ -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.