From a9e177f1e766e1592413e6fd5f772f310e09aba1 Mon Sep 17 00:00:00 2001 From: Simon Laux Date: Wed, 8 Jan 2025 13:39:15 +0100 Subject: [PATCH] build!: remove jsonrpc feature flag It is enabled everywhere by default since some time now. Breaking, because existing build scripts might need to be adjusted. --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 2 +- deltachat-ffi/Cargo.toml | 3 +- deltachat-ffi/src/lib.rs | 160 ++++++++++++++++----------------- node/scripts/rebuild-core.js | 2 +- python/doc/cffi/install.rst | 5 +- scripts/make-python-testenv.sh | 2 +- scripts/run-python-test.sh | 2 +- scripts/run_all.sh | 2 +- 9 files changed, 85 insertions(+), 95 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9623bbf3ba..5eab3524b1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -152,7 +152,7 @@ jobs: uses: swatinem/rust-cache@v2 - name: Build C library - run: cargo build -p deltachat_ffi --features jsonrpc + run: cargo build -p deltachat_ffi - name: Upload C library uses: actions/upload-artifact@v4 diff --git a/CMakeLists.txt b/CMakeLists.txt index 15a9b321c4..8f0f2e4501 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,7 +27,7 @@ add_custom_command( PREFIX=${CMAKE_INSTALL_PREFIX} LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR} INCLUDEDIR=${CMAKE_INSTALL_FULL_INCLUDEDIR} - ${CARGO} build --target-dir=${CMAKE_BINARY_DIR}/target --release --features jsonrpc + ${CARGO} build --target-dir=${CMAKE_BINARY_DIR}/target --release WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deltachat-ffi ) diff --git a/deltachat-ffi/Cargo.toml b/deltachat-ffi/Cargo.toml index b06c82494e..20b5a68911 100644 --- a/deltachat-ffi/Cargo.toml +++ b/deltachat-ffi/Cargo.toml @@ -15,7 +15,7 @@ crate-type = ["cdylib", "staticlib"] [dependencies] deltachat = { workspace = true, default-features = false } -deltachat-jsonrpc = { workspace = true, optional = true } +deltachat-jsonrpc = { workspace = true } libc = { workspace = true } human-panic = { version = "2", default-features = false } num-traits = { workspace = true } @@ -30,5 +30,4 @@ yerpc = { workspace = true, features = ["anyhow_expose"] } [features] default = ["vendored"] vendored = ["deltachat/vendored", "deltachat-jsonrpc/vendored"] -jsonrpc = ["dep:deltachat-jsonrpc"] diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index c9c0cf8433..bef03049f6 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -35,6 +35,8 @@ use deltachat::stock_str::StockMessage; use deltachat::webxdc::StatusUpdateSerial; use deltachat::*; use deltachat::{accounts::Accounts, log::LogExt}; +use deltachat_jsonrpc::api::CommandApi; +use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession}; use num_traits::{FromPrimitive, ToPrimitive}; use once_cell::sync::Lazy; use rand::Rng; @@ -4930,105 +4932,97 @@ pub unsafe extern "C" fn dc_accounts_get_event_emitter( Box::into_raw(Box::new(emitter)) } -#[cfg(feature = "jsonrpc")] -mod jsonrpc { - use deltachat_jsonrpc::api::CommandApi; - use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession}; - - use super::*; +pub struct dc_jsonrpc_instance_t { + receiver: OutReceiver, + handle: RpcSession, +} - pub struct dc_jsonrpc_instance_t { - receiver: OutReceiver, - handle: RpcSession, +#[no_mangle] +pub unsafe extern "C" fn dc_jsonrpc_init( + account_manager: *mut dc_accounts_t, +) -> *mut dc_jsonrpc_instance_t { + if account_manager.is_null() { + eprintln!("ignoring careless call to dc_jsonrpc_init()"); + return ptr::null_mut(); } - #[no_mangle] - pub unsafe extern "C" fn dc_jsonrpc_init( - account_manager: *mut dc_accounts_t, - ) -> *mut dc_jsonrpc_instance_t { - if account_manager.is_null() { - eprintln!("ignoring careless call to dc_jsonrpc_init()"); - return ptr::null_mut(); - } + let account_manager = &*account_manager; + let cmd_api = block_on(deltachat_jsonrpc::api::CommandApi::from_arc( + account_manager.inner.clone(), + )); - let account_manager = &*account_manager; - let cmd_api = block_on(deltachat_jsonrpc::api::CommandApi::from_arc( - account_manager.inner.clone(), - )); + let (request_handle, receiver) = RpcClient::new(); + let handle = RpcSession::new(request_handle, cmd_api); - let (request_handle, receiver) = RpcClient::new(); - let handle = RpcSession::new(request_handle, cmd_api); + let instance = dc_jsonrpc_instance_t { receiver, handle }; - let instance = dc_jsonrpc_instance_t { receiver, handle }; + Box::into_raw(Box::new(instance)) +} - Box::into_raw(Box::new(instance)) +#[no_mangle] +pub unsafe extern "C" fn dc_jsonrpc_unref(jsonrpc_instance: *mut dc_jsonrpc_instance_t) { + if jsonrpc_instance.is_null() { + eprintln!("ignoring careless call to dc_jsonrpc_unref()"); + return; } + drop(Box::from_raw(jsonrpc_instance)); +} - #[no_mangle] - pub unsafe extern "C" fn dc_jsonrpc_unref(jsonrpc_instance: *mut dc_jsonrpc_instance_t) { - if jsonrpc_instance.is_null() { - eprintln!("ignoring careless call to dc_jsonrpc_unref()"); - return; - } - drop(Box::from_raw(jsonrpc_instance)); - } +fn spawn_handle_jsonrpc_request(handle: RpcSession, request: String) { + spawn(async move { + handle.handle_incoming(&request).await; + }); +} - fn spawn_handle_jsonrpc_request(handle: RpcSession, request: String) { - spawn(async move { - handle.handle_incoming(&request).await; - }); +#[no_mangle] +pub unsafe extern "C" fn dc_jsonrpc_request( + jsonrpc_instance: *mut dc_jsonrpc_instance_t, + request: *const libc::c_char, +) { + if jsonrpc_instance.is_null() || request.is_null() { + eprintln!("ignoring careless call to dc_jsonrpc_request()"); + return; } - #[no_mangle] - pub unsafe extern "C" fn dc_jsonrpc_request( - jsonrpc_instance: *mut dc_jsonrpc_instance_t, - request: *const libc::c_char, - ) { - if jsonrpc_instance.is_null() || request.is_null() { - eprintln!("ignoring careless call to dc_jsonrpc_request()"); - return; - } + let handle = &(*jsonrpc_instance).handle; + let request = to_string_lossy(request); + spawn_handle_jsonrpc_request(handle.clone(), request); +} - let handle = &(*jsonrpc_instance).handle; - let request = to_string_lossy(request); - spawn_handle_jsonrpc_request(handle.clone(), request); +#[no_mangle] +pub unsafe extern "C" fn dc_jsonrpc_next_response( + jsonrpc_instance: *mut dc_jsonrpc_instance_t, +) -> *mut libc::c_char { + if jsonrpc_instance.is_null() { + eprintln!("ignoring careless call to dc_jsonrpc_next_response()"); + return ptr::null_mut(); } + let api = &*jsonrpc_instance; + block_on(api.receiver.recv()) + .map(|result| serde_json::to_string(&result).unwrap_or_default().strdup()) + .unwrap_or(ptr::null_mut()) +} - #[no_mangle] - pub unsafe extern "C" fn dc_jsonrpc_next_response( - jsonrpc_instance: *mut dc_jsonrpc_instance_t, - ) -> *mut libc::c_char { - if jsonrpc_instance.is_null() { - eprintln!("ignoring careless call to dc_jsonrpc_next_response()"); - return ptr::null_mut(); - } - let api = &*jsonrpc_instance; - block_on(api.receiver.recv()) - .map(|result| serde_json::to_string(&result).unwrap_or_default().strdup()) - .unwrap_or(ptr::null_mut()) - } - - #[no_mangle] - pub unsafe extern "C" fn dc_jsonrpc_blocking_call( - jsonrpc_instance: *mut dc_jsonrpc_instance_t, - input: *const libc::c_char, - ) -> *mut libc::c_char { - if jsonrpc_instance.is_null() { - eprintln!("ignoring careless call to dc_jsonrpc_blocking_call()"); - return ptr::null_mut(); - } - let api = &*jsonrpc_instance; - let input = to_string_lossy(input); - let res = block_on(api.handle.process_incoming(&input)); - match res { - Some(message) => { - if let Ok(message) = serde_json::to_string(&message) { - message.strdup() - } else { - ptr::null_mut() - } +#[no_mangle] +pub unsafe extern "C" fn dc_jsonrpc_blocking_call( + jsonrpc_instance: *mut dc_jsonrpc_instance_t, + input: *const libc::c_char, +) -> *mut libc::c_char { + if jsonrpc_instance.is_null() { + eprintln!("ignoring careless call to dc_jsonrpc_blocking_call()"); + return ptr::null_mut(); + } + let api = &*jsonrpc_instance; + let input = to_string_lossy(input); + let res = block_on(api.handle.process_incoming(&input)); + match res { + Some(message) => { + if let Ok(message) = serde_json::to_string(&message) { + message.strdup() + } else { + ptr::null_mut() } - None => ptr::null_mut(), } + None => ptr::null_mut(), } } diff --git a/node/scripts/rebuild-core.js b/node/scripts/rebuild-core.js index 9ff794773b..80dedcce5a 100644 --- a/node/scripts/rebuild-core.js +++ b/node/scripts/rebuild-core.js @@ -9,7 +9,7 @@ const buildArgs = [ 'build', '--release', '--features', - 'vendored,jsonrpc', + 'vendored', '-p', 'deltachat_ffi' ] diff --git a/python/doc/cffi/install.rst b/python/doc/cffi/install.rst index cdfc850813..5a77557a60 100644 --- a/python/doc/cffi/install.rst +++ b/python/doc/cffi/install.rst @@ -52,10 +52,7 @@ python3-venv` should give you a usable python installation. First, build the core library:: - cargo build --release -p deltachat_ffi --features jsonrpc - -`jsonrpc` feature is required even if not used by the bindings -because `deltachat.h` includes JSON-RPC functions unconditionally. + cargo build --release -p deltachat_ffi Create the virtual environment and activate it:: diff --git a/scripts/make-python-testenv.sh b/scripts/make-python-testenv.sh index ce3d0b71e5..b3fc421c01 100755 --- a/scripts/make-python-testenv.sh +++ b/scripts/make-python-testenv.sh @@ -11,7 +11,7 @@ set -euo pipefail export DCC_RS_TARGET=debug export DCC_RS_DEV="$PWD" -cargo build -p deltachat_ffi --features jsonrpc +cargo build -p deltachat_ffi tox -c python -e py --devenv venv venv/bin/pip install --upgrade pip diff --git a/scripts/run-python-test.sh b/scripts/run-python-test.sh index 544e1e2786..cbe0ef1be1 100755 --- a/scripts/run-python-test.sh +++ b/scripts/run-python-test.sh @@ -12,7 +12,7 @@ export DCC_RS_DEV=`pwd` cd python -cargo build -p deltachat_ffi --features jsonrpc +cargo build -p deltachat_ffi # remove and inhibit writing PYC files rm -rf tests/__pycache__ diff --git a/scripts/run_all.sh b/scripts/run_all.sh index efeab4d877..a93548beca 100755 --- a/scripts/run_all.sh +++ b/scripts/run_all.sh @@ -8,7 +8,7 @@ set -e -x # compile core lib -cargo build --release -p deltachat_ffi --features jsonrpc +cargo build --release -p deltachat_ffi # Statically link against libdeltachat.a. export DCC_RS_DEV="$PWD"