diff --git a/Cargo.lock b/Cargo.lock index dcc1ba66743..78fd5e5da63 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -159,9 +159,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "e16d2d3311acee920a9eb8d33b8cbc1787ce4a264e85f964c2404b969bdcd487" [[package]] name = "anymap2" @@ -212,43 +212,44 @@ checksum = "9dbc3a507a82b17ba0d98f6ce8fd6954ea0c8152e98009d36a40d8dcc8ce078a" [[package]] name = "askama" -version = "0.12.1" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b79091df18a97caea757e28cd2d5fda49c6cd4bd01ddffd7ff01ace0c0ad2c28" +checksum = "5d4744ed2eef2645831b441d8f5459689ade2ab27c854488fbab1fbe94fce1a7" dependencies = [ "askama_derive", - "askama_escape", + "itoa", + "percent-encoding", + "serde", + "serde_json", ] [[package]] name = "askama_derive" -version = "0.12.5" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19fe8d6cb13c4714962c072ea496f3392015f0989b1a2847bb4b2d9effd71d83" +checksum = "d661e0f57be36a5c14c48f78d09011e67e0cb618f269cca9f2fd8d15b68c46ac" dependencies = [ "askama_parser", "basic-toml", - "mime", - "mime_guess", + "memchr", "proc-macro2", "quote", + "rustc-hash 2.0.0", "serde", + "serde_derive", "syn", ] -[[package]] -name = "askama_escape" -version = "0.10.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "619743e34b5ba4e9703bba34deac3427c72507c7159f5fd030aea8cac0cfe341" - [[package]] name = "askama_parser" -version = "0.2.1" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acb1161c6b64d1c3d83108213c2a2533a342ac225aabd0bda218278c2ddb00c0" +checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f" dependencies = [ - "nom", + "memchr", + "serde", + "serde_derive", + "winnow 0.7.10", ] [[package]] @@ -498,15 +499,6 @@ dependencies = [ "wiremock", ] -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -635,16 +627,16 @@ dependencies = [ [[package]] name = "cargo_metadata" -version = "0.15.4" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee4243f1f26fc7a42710e7439c149e2b10b05472f88090acce52632f231a73a" +checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" dependencies = [ "camino", "cargo-platform", "semver", "serde", "serde_json", - "thiserror 1.0.63", + "thiserror 2.0.11", ] [[package]] @@ -3369,16 +3361,6 @@ version = "0.1.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "515a63dc9666c865e848b043ab52fe9a5c713ae89cde4b5fbaae67cfd614b93a" -[[package]] -name = "mime_guess" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "minicov" version = "0.3.7" @@ -5576,7 +5558,7 @@ dependencies = [ "serde", "serde_spanned", "toml_datetime", - "winnow", + "winnow 0.6.20", ] [[package]] @@ -5824,17 +5806,19 @@ checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" [[package]] name = "uniffi" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31bff6daf87277a9014bcdefbc2842b0553392919d1096843c5aad899ca4588" +checksum = "b334fd69b3cf198b63616c096aabf9820ab21ed9b2aa1367ddd4b411068bf520" dependencies = [ "anyhow", "camino", + "cargo_metadata", "clap", "uniffi_bindgen", "uniffi_build", "uniffi_core", "uniffi_macros", + "uniffi_pipeline", ] [[package]] @@ -5846,9 +5830,9 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96061d7e01b185aa405f7c9b134741ab3e50cc6796a47d6fd8ab9a5364b5feed" +checksum = "2ff0132b533483cf19abb30bba5c72c24d9f3e4d9a2ff71cb3e22e73899fd46e" dependencies = [ "anyhow", "askama", @@ -5858,60 +5842,61 @@ dependencies = [ "glob", "goblin", "heck", + "indexmap", "once_cell", - "paste", "serde", + "tempfile", "textwrap", "toml 0.5.11", + "uniffi_internal_macros", "uniffi_meta", - "uniffi_testing", + "uniffi_pipeline", "uniffi_udl", ] [[package]] name = "uniffi_build" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d6b86f9b221046af0c533eafe09ece04e2f1ded04ccdc9bba0ec09aec1c52bd" +checksum = "0d84d607076008df3c32dd2100ee4e727269f11d3faa35691af70d144598f666" dependencies = [ "anyhow", "camino", "uniffi_bindgen", ] -[[package]] -name = "uniffi_checksum_derive" -version = "0.28.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "802d2051a700e3ec894c79f80d2705b69d85844dafbbe5d1a92776f8f48b563a" -dependencies = [ - "quote", - "syn", -] - [[package]] name = "uniffi_core" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3210d57d6ab6065ab47a2898dacdb7c606fd6a4156196831fa3bf82e34ac58a6" +checksum = "53e3b997192dc15ef1778c842001811ec7f241a093a693ac864e1fc938e64fa9" dependencies = [ "anyhow", "async-compat", "bytes", - "camino", - "log", "once_cell", - "paste", "static_assertions", ] +[[package]] +name = "uniffi_internal_macros" +version = "0.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64bec2f3a33f2f08df8150e67fa45ba59a2ca740bf20c1beb010d4d791f9a1b" +dependencies = [ + "anyhow", + "indexmap", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "uniffi_macros" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b58691741080935437dc862122e68d7414432a11824ac1137868de46181a0bd2" +checksum = "5d8708716d2582e4f3d7e9f320290b5966eb951ca421d7630571183615453efc" dependencies = [ - "bincode", "camino", "fs-err", "once_cell", @@ -5925,39 +5910,38 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7663eacdbd9fbf4a88907ddcfe2e6fa85838eb6dc2418a7d91eebb3786f8e20b" +checksum = "3d226fc167754ce548c5ece9828c8a06f03bf1eea525d2659ba6bd648bd8e2f3" dependencies = [ "anyhow", - "bytes", "siphasher", - "uniffi_checksum_derive", + "uniffi_internal_macros", + "uniffi_pipeline", ] [[package]] -name = "uniffi_testing" -version = "0.28.0" +name = "uniffi_pipeline" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f922465f7566f25f8fe766920205fdfa9a3fcdc209c6bfb7557f0b5bf45b04dd" +checksum = "b925b6421df15cf4bedee27714022cd9626fb4d7eee0923522a608b274ba4371" dependencies = [ "anyhow", - "camino", - "cargo_metadata", - "fs-err", - "once_cell", + "heck", + "indexmap", + "tempfile", + "uniffi_internal_macros", ] [[package]] name = "uniffi_udl" -version = "0.28.0" +version = "0.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cef408229a3a407fafa4c36dc4f6ece78a6fb258ab28d2b64bddd49c8cb680f6" +checksum = "9c42649b721df759d9d4692a376b82b62ce3028ec9fc466f4780fb8cdf728996" dependencies = [ "anyhow", "textwrap", "uniffi_meta", - "uniffi_testing", "weedle2", ] @@ -6588,6 +6572,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "winnow" +version = "0.7.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06928c8748d81b05c9be96aad92e1b6ff01833332f281e8cfca3be4b35fc9ec" +dependencies = [ + "memchr", +] + [[package]] name = "wiremock" version = "0.6.2" @@ -6664,11 +6657,14 @@ checksum = "88301b56c26dd9bf5c43d858538f82d6f3f7764767defbc5d34e59459901c41a" name = "xtask" version = "0.1.0" dependencies = [ + "anyhow", "camino", + "cargo_metadata", "clap", "fs_extra", "serde", "serde_json", + "toml 0.5.11", "uniffi_bindgen", "xshell", ] diff --git a/Cargo.toml b/Cargo.toml index feaae18c6fa..a51d7767eaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -94,8 +94,8 @@ tracing = { version = "0.1.40", default-features = false, features = ["std"] } tracing-core = "0.1.32" tracing-subscriber = "0.3.18" unicode-normalization = "0.1.24" -uniffi = { version = "0.28.0" } -uniffi_bindgen = { version = "0.28.0" } +uniffi = "0.29.3" +uniffi_bindgen = "0.29.3" url = "2.5.4" uuid = "1.12.1" vodozemac = { version = "0.9.0", features = ["insecure-pk-encryption"] } diff --git a/bindings/matrix-sdk-ffi/src/api.udl b/bindings/matrix-sdk-ffi/src/api.udl index c7caa1afb0b..c5fa1c1ffbb 100644 --- a/bindings/matrix-sdk-ffi/src/api.udl +++ b/bindings/matrix-sdk-ffi/src/api.udl @@ -1,10 +1,12 @@ namespace matrix_sdk_ffi {}; +[Remote] dictionary Mentions { sequence user_ids; boolean room; }; +[Remote] interface RoomMessageEventContentWithoutRelation { RoomMessageEventContentWithoutRelation with_mentions(Mentions mentions); }; diff --git a/bindings/matrix-sdk-ffi/uniffi.toml b/bindings/matrix-sdk-ffi/uniffi.toml index 92ed4de9c63..0284aee488f 100644 --- a/bindings/matrix-sdk-ffi/uniffi.toml +++ b/bindings/matrix-sdk-ffi/uniffi.toml @@ -1,4 +1,14 @@ [bindings.kotlin] package_name = "org.matrix.rustcomponents.sdk" cdylib_name = "matrix_sdk_ffi" -android_cleaner = true \ No newline at end of file +android_cleaner = true + +[bindings.typescript] +[bindings.typescript.customTypes.Date64] +typeName = "Date" +intoCustom = """((v: FfiType) => { + return new Date(Number(v)); +})({})""" +fromCustom = """((v: TsType) => { + return BigInt(v.getTime()); +})({})""" diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 3e4f689c9aa..c94790abab9 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -13,10 +13,13 @@ name = "xtask" test = false [dependencies] +anyhow = "1.0.96" camino = "1.0.8" +cargo_metadata = "0.19.2" clap = { version = "4.0.18", features = ["derive"] } fs_extra = "1" serde = { workspace = true, features = ["derive"] } serde_json.workspace = true +toml = "0.5.11" uniffi_bindgen.workspace = true xshell = "0.2.2" diff --git a/xtask/src/config_supplier.rs b/xtask/src/config_supplier.rs new file mode 100644 index 00000000000..5d49f2348b5 --- /dev/null +++ b/xtask/src/config_supplier.rs @@ -0,0 +1,76 @@ +use std::{collections::HashMap, fs}; + +use anyhow::{bail, Context}; +use camino::Utf8PathBuf; +use cargo_metadata::Metadata; +use toml::value::Table; +use uniffi_bindgen::BindgenCrateConfigSupplier; + +/// An implementation of `BindgenCrateConfigSupplier` that uses the +/// `uniffi.toml` files found in the crates of a Cargo workspace. +#[derive(Debug, Clone, Default)] +pub struct CrateConfigSupplier { + paths: HashMap, +} + +fn load_toml_file(path: Option<&Utf8PathBuf>) -> anyhow::Result> { + if let Some(path) = path { + if path.exists() { + let contents = fs::read_to_string(path)?; + let table: Table = toml::from_str(&contents)?; + Ok(Some(table)) + } else { + Ok(None) + } + } else { + Ok(None) + } +} + +impl BindgenCrateConfigSupplier for CrateConfigSupplier { + fn get_toml(&self, crate_name: &str) -> anyhow::Result> { + load_toml_file(self.get_toml_path(crate_name).as_ref()) + } + + fn get_toml_path(&self, crate_name: &str) -> Option { + self.paths.get(crate_name).map(|p| p.join("uniffi.toml")) + } + + fn get_udl(&self, crate_name: &str, udl_name: &str) -> anyhow::Result { + let path = self + .paths + .get(crate_name) + .context(format!("No path known to UDL files for '{crate_name}'"))? + .join("src") + .join(format!("{udl_name}.udl")); + if path.exists() { + Ok(fs::read_to_string(path)?) + } else { + bail!(format!("No UDL file found at '{path}'")); + } + } +} + +impl From for CrateConfigSupplier { + fn from(metadata: Metadata) -> Self { + let paths: HashMap = metadata + .packages + .iter() + .flat_map(|p| { + p.targets + .iter() + .filter(|t| { + !t.is_bin() + && !t.is_example() + && !t.is_test() + && !t.is_bench() + && !t.is_custom_build() + }) + .filter_map(|t| { + p.manifest_path.parent().map(|p| (t.name.replace('-', "_"), p.to_owned())) + }) + }) + .collect(); + Self { paths } + } +} diff --git a/xtask/src/kotlin.rs b/xtask/src/kotlin.rs index 6ee768bce17..072b9d5464c 100644 --- a/xtask/src/kotlin.rs +++ b/xtask/src/kotlin.rs @@ -1,11 +1,12 @@ use std::fs::create_dir_all; use camino::{Utf8Path, Utf8PathBuf}; +use cargo_metadata::MetadataCommand; use clap::{Args, Subcommand, ValueEnum}; use uniffi_bindgen::{bindings::KotlinBindingGenerator, library_mode::generate_bindings}; use xshell::cmd; -use crate::{sh, workspace, Result}; +use crate::{config_supplier::CrateConfigSupplier, sh, workspace, Result}; struct PackageValues { name: &'static str, @@ -121,7 +122,22 @@ fn build_android_library( fn generate_uniffi_bindings(library_path: &Utf8Path, ffi_generated_dir: &Utf8Path) -> Result<()> { println!("-- library_path = {library_path}"); - generate_bindings(library_path, None, &KotlinBindingGenerator, None, ffi_generated_dir, false)?; + let manifest_path = std::env::current_dir()?.join("Cargo.toml"); + println!("manifest path {:?}", manifest_path); + + let metadata = MetadataCommand::new().manifest_path(&manifest_path).exec()?; + + let config_supplier = CrateConfigSupplier::from(metadata); + + generate_bindings( + library_path, + None, + &KotlinBindingGenerator, + &config_supplier, + None, + ffi_generated_dir, + false, + )?; Ok(()) } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 12f29df96c2..7254c951a3a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -1,6 +1,7 @@ #![allow(unexpected_cfgs)] mod ci; +mod config_supplier; mod fixup; mod kotlin; mod release; diff --git a/xtask/src/swift.rs b/xtask/src/swift.rs index cf41e2600a6..832030aac58 100644 --- a/xtask/src/swift.rs +++ b/xtask/src/swift.rs @@ -4,11 +4,12 @@ use std::{ }; use camino::{Utf8Path, Utf8PathBuf}; +use cargo_metadata::MetadataCommand; use clap::{Args, Subcommand}; use uniffi_bindgen::{bindings::SwiftBindingGenerator, library_mode::generate_bindings}; use xshell::cmd; -use crate::{sh, workspace, Result}; +use crate::{config_supplier::CrateConfigSupplier, sh, workspace, Result}; /// Builds the SDK for Swift as a Static Library or XCFramework. #[derive(Args)] @@ -168,7 +169,22 @@ fn build_library() -> Result<()> { } fn generate_uniffi(library_path: &Utf8Path, ffi_directory: &Utf8Path) -> Result<()> { - generate_bindings(library_path, None, &SwiftBindingGenerator, None, ffi_directory, false)?; + let manifest_path = std::env::current_dir()?.join("Cargo.toml"); + println!("manifest path {:?}", manifest_path); + + let metadata = MetadataCommand::new().manifest_path(&manifest_path).exec()?; + + let config_supplier = CrateConfigSupplier::from(metadata); + + generate_bindings( + library_path, + None, + &SwiftBindingGenerator, + &config_supplier, + None, + ffi_directory, + false, + )?; Ok(()) }