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.
This commit is contained in:
Simon Laux
2025-01-08 13:39:15 +01:00
committed by l
parent 6e8668e348
commit a9e177f1e7
9 changed files with 88 additions and 98 deletions

View File

@@ -152,7 +152,7 @@ jobs:
uses: swatinem/rust-cache@v2 uses: swatinem/rust-cache@v2
- name: Build C library - name: Build C library
run: cargo build -p deltachat_ffi --features jsonrpc run: cargo build -p deltachat_ffi
- name: Upload C library - name: Upload C library
uses: actions/upload-artifact@v4 uses: actions/upload-artifact@v4

View File

@@ -27,7 +27,7 @@ add_custom_command(
PREFIX=${CMAKE_INSTALL_PREFIX} PREFIX=${CMAKE_INSTALL_PREFIX}
LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR} LIBDIR=${CMAKE_INSTALL_FULL_LIBDIR}
INCLUDEDIR=${CMAKE_INSTALL_FULL_INCLUDEDIR} 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 WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/deltachat-ffi
) )

View File

@@ -15,7 +15,7 @@ crate-type = ["cdylib", "staticlib"]
[dependencies] [dependencies]
deltachat = { workspace = true, default-features = false } deltachat = { workspace = true, default-features = false }
deltachat-jsonrpc = { workspace = true, optional = true } deltachat-jsonrpc = { workspace = true }
libc = { workspace = true } libc = { workspace = true }
human-panic = { version = "2", default-features = false } human-panic = { version = "2", default-features = false }
num-traits = { workspace = true } num-traits = { workspace = true }
@@ -30,5 +30,4 @@ yerpc = { workspace = true, features = ["anyhow_expose"] }
[features] [features]
default = ["vendored"] default = ["vendored"]
vendored = ["deltachat/vendored", "deltachat-jsonrpc/vendored"] vendored = ["deltachat/vendored", "deltachat-jsonrpc/vendored"]
jsonrpc = ["dep:deltachat-jsonrpc"]

View File

@@ -35,6 +35,8 @@ use deltachat::stock_str::StockMessage;
use deltachat::webxdc::StatusUpdateSerial; use deltachat::webxdc::StatusUpdateSerial;
use deltachat::*; use deltachat::*;
use deltachat::{accounts::Accounts, log::LogExt}; use deltachat::{accounts::Accounts, log::LogExt};
use deltachat_jsonrpc::api::CommandApi;
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
use num_traits::{FromPrimitive, ToPrimitive}; use num_traits::{FromPrimitive, ToPrimitive};
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use rand::Rng; use rand::Rng;
@@ -4930,105 +4932,97 @@ pub unsafe extern "C" fn dc_accounts_get_event_emitter(
Box::into_raw(Box::new(emitter)) Box::into_raw(Box::new(emitter))
} }
#[cfg(feature = "jsonrpc")] pub struct dc_jsonrpc_instance_t {
mod jsonrpc { receiver: OutReceiver,
use deltachat_jsonrpc::api::CommandApi; handle: RpcSession<CommandApi>,
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession}; }
use super::*; #[no_mangle]
pub unsafe extern "C" fn dc_jsonrpc_init(
pub struct dc_jsonrpc_instance_t { account_manager: *mut dc_accounts_t,
receiver: OutReceiver, ) -> *mut dc_jsonrpc_instance_t {
handle: RpcSession<CommandApi>, if account_manager.is_null() {
eprintln!("ignoring careless call to dc_jsonrpc_init()");
return ptr::null_mut();
} }
#[no_mangle] let account_manager = &*account_manager;
pub unsafe extern "C" fn dc_jsonrpc_init( let cmd_api = block_on(deltachat_jsonrpc::api::CommandApi::from_arc(
account_manager: *mut dc_accounts_t, account_manager.inner.clone(),
) -> *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 (request_handle, receiver) = RpcClient::new();
let cmd_api = block_on(deltachat_jsonrpc::api::CommandApi::from_arc( let handle = RpcSession::new(request_handle, cmd_api);
account_manager.inner.clone(),
));
let (request_handle, receiver) = RpcClient::new(); let instance = dc_jsonrpc_instance_t { receiver, handle };
let handle = RpcSession::new(request_handle, cmd_api);
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));
}
fn spawn_handle_jsonrpc_request(handle: RpcSession<CommandApi>, 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] let handle = &(*jsonrpc_instance).handle;
pub unsafe extern "C" fn dc_jsonrpc_unref(jsonrpc_instance: *mut dc_jsonrpc_instance_t) { let request = to_string_lossy(request);
if jsonrpc_instance.is_null() { spawn_handle_jsonrpc_request(handle.clone(), request);
eprintln!("ignoring careless call to dc_jsonrpc_unref()"); }
return;
} #[no_mangle]
drop(Box::from_raw(jsonrpc_instance)); 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())
}
fn spawn_handle_jsonrpc_request(handle: RpcSession<CommandApi>, request: String) { #[no_mangle]
spawn(async move { pub unsafe extern "C" fn dc_jsonrpc_blocking_call(
handle.handle_incoming(&request).await; 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;
#[no_mangle] let input = to_string_lossy(input);
pub unsafe extern "C" fn dc_jsonrpc_request( let res = block_on(api.handle.process_incoming(&input));
jsonrpc_instance: *mut dc_jsonrpc_instance_t, match res {
request: *const libc::c_char, Some(message) => {
) { if let Ok(message) = serde_json::to_string(&message) {
if jsonrpc_instance.is_null() || request.is_null() { message.strdup()
eprintln!("ignoring careless call to dc_jsonrpc_request()"); } else {
return; ptr::null_mut()
}
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_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(),
} }
} }

View File

@@ -9,7 +9,7 @@ const buildArgs = [
'build', 'build',
'--release', '--release',
'--features', '--features',
'vendored,jsonrpc', 'vendored',
'-p', '-p',
'deltachat_ffi' 'deltachat_ffi'
] ]

View File

@@ -52,10 +52,7 @@ python3-venv` should give you a usable python installation.
First, build the core library:: First, build the core library::
cargo build --release -p deltachat_ffi --features jsonrpc cargo build --release -p deltachat_ffi
`jsonrpc` feature is required even if not used by the bindings
because `deltachat.h` includes JSON-RPC functions unconditionally.
Create the virtual environment and activate it:: Create the virtual environment and activate it::

View File

@@ -11,7 +11,7 @@ set -euo pipefail
export DCC_RS_TARGET=debug export DCC_RS_TARGET=debug
export DCC_RS_DEV="$PWD" export DCC_RS_DEV="$PWD"
cargo build -p deltachat_ffi --features jsonrpc cargo build -p deltachat_ffi
tox -c python -e py --devenv venv tox -c python -e py --devenv venv
venv/bin/pip install --upgrade pip venv/bin/pip install --upgrade pip

View File

@@ -12,7 +12,7 @@ export DCC_RS_DEV=`pwd`
cd python cd python
cargo build -p deltachat_ffi --features jsonrpc cargo build -p deltachat_ffi
# remove and inhibit writing PYC files # remove and inhibit writing PYC files
rm -rf tests/__pycache__ rm -rf tests/__pycache__

View File

@@ -8,7 +8,7 @@ set -e -x
# compile core lib # compile core lib
cargo build --release -p deltachat_ffi --features jsonrpc cargo build --release -p deltachat_ffi
# Statically link against libdeltachat.a. # Statically link against libdeltachat.a.
export DCC_RS_DEV="$PWD" export DCC_RS_DEV="$PWD"