diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 8ac9a8fc..4b200bc7 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,7 +13,7 @@ jobs: build: runs-on: ubuntu-latest container: - image: rust:1.70 + image: rust:1.72-bullseye steps: - uses: actions/checkout@v3 with: diff --git a/3rd-party/uniffi-rs b/3rd-party/uniffi-rs index 1e217634..de1e7732 160000 --- a/3rd-party/uniffi-rs +++ b/3rd-party/uniffi-rs @@ -1 +1 @@ -Subproject commit 1e217634ab9aff4dddfb49d01b6efabdc0f768a3 +Subproject commit de1e773204d0ddcda58faac0a77570f1f8056679 diff --git a/Cargo.lock b/Cargo.lock index 31159dbe..7498c116 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -388,17 +388,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" -[[package]] -name = "crate_one" -version = "0.22.0" - -[[package]] -name = "crate_two" -version = "0.22.0" -dependencies = [ - "crate_one", -] - [[package]] name = "extend" version = "1.1.2" @@ -438,6 +427,19 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +[[package]] +name = "generator" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5cc16584ff22b460a382b7feec54b23d2908d858152e5739a120b949293bd74e" +dependencies = [ + "cc", + "libc", + "log", + "rustversion", + "windows", +] + [[package]] name = "getrandom" version = "0.2.9" @@ -532,6 +534,12 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libc" version = "0.2.145" @@ -547,6 +555,29 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "loom" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff50ecb28bb86013e935fb6683ab1f6d3a20016f123c76fd4c27470076ac30f5" +dependencies = [ + "cfg-if", + "generator", + "pin-utils", + "scoped-tls", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "matchers" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" +dependencies = [ + "regex-automata", +] + [[package]] name = "memchr" version = "2.5.0" @@ -594,6 +625,16 @@ dependencies = [ "minimal-lexical", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -628,12 +669,27 @@ version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" +[[package]] +name = "oneshot" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f6640c6bda7731b1fdbab747981a0f896dd1fedaf9f4a53fa237a04a84431f4" +dependencies = [ + "loom", +] + [[package]] name = "os_str_bytes" version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "paste" version = "1.0.9" @@ -652,6 +708,12 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + [[package]] name = "plain" version = "0.2.3" @@ -708,9 +770,24 @@ checksum = "81ca098a9821bd52d6b24fd8b10bd081f47d39c22778cafaa75a2857a62c6390" dependencies = [ "aho-corasick", "memchr", - "regex-syntax", + "regex-syntax 0.7.2", +] + +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +dependencies = [ + "regex-syntax 0.6.29", ] +[[package]] +name = "regex-syntax" +version = "0.6.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" + [[package]] name = "regex-syntax" version = "0.7.2" @@ -723,12 +800,24 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustversion" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" + [[package]] name = "ryu" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scroll" version = "0.11.0" @@ -789,12 +878,27 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + [[package]] name = "siphasher" version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de" +[[package]] +name = "smallvec" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "942b4a808e05215192e39f4ab80813e599068285906cc91aa64f923db842bd5a" + [[package]] name = "smawk" version = "0.3.1" @@ -881,6 +985,16 @@ dependencies = [ "syn 1.0.101", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "tinyvec" version = "1.6.0" @@ -915,6 +1029,67 @@ dependencies = [ "serde", ] +[[package]] +name = "tracing" +version = "0.1.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "tracing-core" +version = "0.1.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "matchers", + "nu-ansi-term", + "once_cell", + "regex", + "sharded-slab", + "smallvec", + "thread_local", + "tracing", + "tracing-core", + "tracing-log", +] + [[package]] name = "trybuild" version = "1.0.80" @@ -978,7 +1153,7 @@ checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "uniffi" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "camino", @@ -992,7 +1167,7 @@ dependencies = [ [[package]] name = "uniffi-bindgen-cs" -version = "0.2.4+v0.23.0" +version = "0.6.0+v0.25.0" dependencies = [ "anyhow", "askama 0.11.1", @@ -1026,7 +1201,6 @@ dependencies = [ "uniffi-fixture-callbacks", "uniffi-fixture-coverall", "uniffi-fixture-docstring", - "uniffi-fixture-external-types", "uniffi-fixture-time", ] @@ -1073,7 +1247,6 @@ version = "0.22.0" dependencies = [ "anyhow", "bytes", - "serde_json", "uniffi", "url", ] @@ -1137,17 +1310,6 @@ dependencies = [ "uniffi_testing", ] -[[package]] -name = "uniffi-fixture-external-types" -version = "0.22.0" -dependencies = [ - "anyhow", - "bytes", - "crate_one", - "crate_two", - "uniffi", -] - [[package]] name = "uniffi-fixture-time" version = "0.22.0" @@ -1159,7 +1321,7 @@ dependencies = [ [[package]] name = "uniffi_bindgen" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "askama 0.12.1", @@ -1173,17 +1335,16 @@ dependencies = [ "once_cell", "paste", "serde", - "serde_json", "textwrap 0.16.0", "toml", "uniffi_meta", "uniffi_testing", - "weedle2", + "uniffi_udl", ] [[package]] name = "uniffi_build" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "camino", @@ -1192,7 +1353,7 @@ dependencies = [ [[package]] name = "uniffi_checksum_derive" -version = "0.24.3" +version = "0.25.0" dependencies = [ "quote", "syn 2.0.37", @@ -1200,22 +1361,22 @@ dependencies = [ [[package]] name = "uniffi_core" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "async-compat", "bytes", "camino", - "cargo_metadata", "log", "once_cell", + "oneshot", "paste", "static_assertions", ] [[package]] name = "uniffi_macros" -version = "0.24.3" +version = "0.25.0" dependencies = [ "bincode", "camino", @@ -1232,26 +1393,33 @@ dependencies = [ [[package]] name = "uniffi_meta" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "bytes", - "serde", "siphasher", "uniffi_checksum_derive", ] [[package]] name = "uniffi_testing" -version = "0.24.3" +version = "0.25.0" dependencies = [ "anyhow", "camino", "cargo_metadata", "fs-err", "once_cell", - "serde", - "serde_json", +] + +[[package]] +name = "uniffi_udl" +version = "0.25.0" +dependencies = [ + "anyhow", + "uniffi_meta", + "uniffi_testing", + "weedle2", ] [[package]] @@ -1271,6 +1439,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version_check" version = "0.9.4" @@ -1322,6 +1496,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo.toml b/Cargo.toml index 089d128d..96d012b8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,5 @@ [workspace] +resolver = "2" members = [ "bindgen", diff --git a/README.md b/README.md index 165819d4..fe699e20 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,11 @@ as a separate project from `uniffi-rs`, as per # How to install -Minimum Rust version required to install `uniffi-bindgen-cs` is `1.70`. +Minimum Rust version required to install `uniffi-bindgen-cs` is `1.72`. Newer Rust versions should also work fine. ```bash -cargo install uniffi-bindgen-cs --git https://github.com/NordSecurity/uniffi-bindgen-cs --tag v0.2.4+v0.23.0 +cargo install uniffi-bindgen-cs --git https://github.com/NordSecurity/uniffi-bindgen-cs --tag v0.6.0+v0.25.0 ``` # How to generate bindings @@ -129,6 +129,7 @@ The table shows `uniffi-rs` version history for tags that were published before | uniffi-bindgen-cs version | uniffi-rs version | |------------------------------------------|--------------------------------------------------| +| v0.6.0 | v0.25.0 | | v0.5.0 | v0.24.0 | | ~~v0.3.0~~ (DONT USE, UNFINISHED) | ~~3142151e v0.24.0?~~ | | v0.2.0 | v0.23.0 | diff --git a/bindgen/Cargo.toml b/bindgen/Cargo.toml index 6e29f6ea..f0fe4b35 100644 --- a/bindgen/Cargo.toml +++ b/bindgen/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "uniffi-bindgen-cs" -version = "0.5.1+v0.24.0" +version = "0.6.0+v0.25.0" edition = "2021" [lib] diff --git a/bindgen/src/gen_cs/error.rs b/bindgen/src/gen_cs/error.rs index 5725ad46..a3bbeb7a 100644 --- a/bindgen/src/gen_cs/error.rs +++ b/bindgen/src/gen_cs/error.rs @@ -7,22 +7,22 @@ use uniffi_bindgen::backend::{CodeType, Literal}; #[derive(Debug)] pub struct ErrorCodeType { - id: String, + name: String, } impl ErrorCodeType { - pub fn new(id: String) -> Self { - Self { id } + pub fn new(name: String) -> Self { + Self { name } } } impl CodeType for ErrorCodeType { fn type_label(&self) -> String { - CsCodeOracle.error_name(&self.id) + CsCodeOracle.error_name(&self.name) } fn canonical_name(&self) -> String { - format!("Type{}", CsCodeOracle.error_name(&self.id)) + format!("Type{}", CsCodeOracle.error_name(&self.name)) } fn literal(&self, _literal: &Literal) -> String { @@ -31,11 +31,11 @@ impl CodeType for ErrorCodeType { } pub struct ErrorCodeTypeProvider<'a> { - pub id: &'a String, + pub name: &'a String, } impl<'a> AsCodeType for ErrorCodeTypeProvider<'a> { fn as_codetype(&self) -> Box { - Box::new(ErrorCodeType::new(self.id.clone())) + Box::new(ErrorCodeType::new(self.name.clone())) } } diff --git a/bindgen/src/gen_cs/mod.rs b/bindgen/src/gen_cs/mod.rs index 0a05f288..de43a6b6 100644 --- a/bindgen/src/gen_cs/mod.rs +++ b/bindgen/src/gen_cs/mod.rs @@ -120,10 +120,13 @@ impl<'a> TypeRenderer<'a> { } // Get the package name for an external type - fn external_type_package_name(&self, crate_name: &str) -> String { + fn external_type_package_name(&self, module_path: &str, namespace: &str) -> String { + // config overrides are keyed by the crate name, default fallback is the namespace. + let crate_name = module_path.split("::").next().unwrap(); match self.cs_config.external_packages.get(crate_name) { Some(name) => name.clone(), - None => crate_name.to_string(), + // unreachable in library mode - all deps are in our config with correct namespace. + None => format!("uniffi.{namespace}"), } } @@ -248,16 +251,23 @@ impl AsCodeType for T { Type::Timestamp => Box::new(miscellany::TimestampCodeType), Type::Duration => Box::new(miscellany::DurationCodeType), - Type::Enum(id) => Box::new(enum_::EnumCodeType::new(id)), + Type::Enum { name, .. } => Box::new(enum_::EnumCodeType::new(name)), Type::Object { name, .. } => Box::new(object::ObjectCodeType::new(name)), - Type::Record(id) => Box::new(record::RecordCodeType::new(id)), - Type::CallbackInterface(id) => { - Box::new(callback_interface::CallbackInterfaceCodeType::new(id)) + Type::Record { name, .. } => Box::new(record::RecordCodeType::new(name)), + Type::CallbackInterface { name, .. } => { + Box::new(callback_interface::CallbackInterfaceCodeType::new(name)) } Type::ForeignExecutor => panic!("TODO implement async"), - Type::Optional(inner) => Box::new(compounds::OptionalCodeType::new(*inner)), - Type::Sequence(inner) => Box::new(compounds::SequenceCodeType::new(*inner)), - Type::Map(key, value) => Box::new(compounds::MapCodeType::new(*key, *value)), + Type::Optional { inner_type } => { + Box::new(compounds::OptionalCodeType::new(*inner_type)) + } + Type::Sequence { inner_type } => { + Box::new(compounds::SequenceCodeType::new(*inner_type)) + } + Type::Map { + key_type, + value_type, + } => Box::new(compounds::MapCodeType::new(*key_type, *value_type)), Type::External { name, .. } => Box::new(external::ExternalCodeType::new(name)), Type::Custom { name, .. } => Box::new(custom::CustomCodeType::new(name)), } @@ -324,10 +334,9 @@ impl CsCodeOracle { FfiType::ForeignCallback => "ForeignCallback".to_string(), FfiType::ForeignExecutorHandle => panic!("TODO implement async"), FfiType::ForeignExecutorCallback => panic!("TODO implement async"), - FfiType::FutureCallback { .. } => { - panic!("TODO implement async") - } - FfiType::FutureCallbackData => panic!("TODO implement async"), + FfiType::RustFutureHandle => "IntPtr".to_string(), + FfiType::RustFutureContinuationCallback => "IntPtr".to_string(), + FfiType::RustFutureContinuationData => "IntPtr".to_string(), } } } @@ -417,6 +426,10 @@ pub mod filters { Ok(as_ct.as_codetype().literal(literal)) } + pub fn ffi_type(type_: &impl AsType) -> Result { + Ok(type_.as_type().into()) + } + /// Get the C# syntax for representing a given low-level `FFIType`. pub fn ffi_type_name(type_: &FfiType) -> Result { Ok(oracle().ffi_type_label(type_)) @@ -451,7 +464,7 @@ pub mod filters { // Get C# error code type representation. pub fn as_error(type_: &Type) -> Result { match type_ { - Type::Enum(id) => Ok(error::ErrorCodeTypeProvider { id }), + Type::Enum { name, .. } => Ok(error::ErrorCodeTypeProvider { name }), // XXX - not sure how we are supposed to return askama::Error? _ => panic!("unsupported type for error: {type_:?}"), } diff --git a/bindgen/src/gen_cs/primitives.rs b/bindgen/src/gen_cs/primitives.rs index 914478ac..1b9f720c 100644 --- a/bindgen/src/gen_cs/primitives.rs +++ b/bindgen/src/gen_cs/primitives.rs @@ -4,7 +4,7 @@ use paste::paste; use uniffi_bindgen::backend::{CodeType, Literal}; -use uniffi_bindgen::interface::{types::Type, Radix}; +use uniffi_bindgen::interface::{Radix, Type}; fn render_literal(literal: &Literal) -> String { fn typed_number(type_: &Type, num_str: String) -> String { diff --git a/bindgen/src/lib.rs b/bindgen/src/lib.rs index a0744700..d4e7f07c 100644 --- a/bindgen/src/lib.rs +++ b/bindgen/src/lib.rs @@ -113,6 +113,7 @@ pub fn main() -> Result<()> { BindingGenerator {}, &cli.source, cli.crate_name, + cli.config.as_deref(), &out_dir, ) .map(|_| ()) @@ -123,6 +124,7 @@ pub fn main() -> Result<()> { cli.config.as_deref(), cli.out_dir.as_deref(), cli.lib_file.as_deref(), + cli.crate_name.as_deref(), ) } } diff --git a/bindgen/templates/CustomTypeTemplate.cs b/bindgen/templates/CustomTypeTemplate.cs index 190cb528..27fac9ad 100644 --- a/bindgen/templates/CustomTypeTemplate.cs +++ b/bindgen/templates/CustomTypeTemplate.cs @@ -15,7 +15,7 @@ {%- when Some with (config) %} -{%- let ffi_type_name=builtin.ffi_type().borrow()|ffi_type_name %} +{%- let ffi_type_name = builtin|ffi_type|ffi_type_name %} {# When the config specifies a different type name, create a typealias for it #} {%- match config.type_name %} diff --git a/bindgen/templates/EnumTemplate.cs b/bindgen/templates/EnumTemplate.cs index 74d3ad15..97d02725 100644 --- a/bindgen/templates/EnumTemplate.cs +++ b/bindgen/templates/EnumTemplate.cs @@ -6,7 +6,6 @@ // C# doesn't support enums with associated data. Use regular `enum` for flat // enums, and `record` for enums with associated data. #} -{%- let e = ci.get_enum_definition(name).unwrap() %} {%- if e.is_flat() %} diff --git a/bindgen/templates/ExternalTypeTemplate.cs b/bindgen/templates/ExternalTypeTemplate.cs index 7b52353f..7109fb4a 100644 --- a/bindgen/templates/ExternalTypeTemplate.cs +++ b/bindgen/templates/ExternalTypeTemplate.cs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */#} -{%- let package_name=self.external_type_package_name(crate_name) %} +{%- let package_name=self.external_type_package_name(module_path, namespace) %} {%- let fully_qualified_type_name = "{}.{}"|format(package_name, name) %} {%- let fully_qualified_ffi_converter_name = "{}.FfiConverterType{}"|format(package_name, name) %} diff --git a/bindgen/templates/Types.cs b/bindgen/templates/Types.cs index c4f73ba3..f4f95046 100644 --- a/bindgen/templates/Types.cs +++ b/bindgen/templates/Types.cs @@ -57,7 +57,7 @@ {%- when Type::String %} {%- include "StringHelper.cs" %} -{%- when Type::Enum(name) %} +{%- when Type::Enum { name, module_path } %} {%- let e = ci.get_enum_definition(name).unwrap() %} {%- if !ci.is_name_used_as_error(name) %} {% include "EnumTemplate.cs" %} @@ -65,26 +65,26 @@ {% include "ErrorTemplate.cs" %} {%- endif -%} -{%- when Type::Object{ name, imp } %} +{%- when Type::Object{ name, imp, module_path } %} {% include "ObjectTemplate.cs" %} -{%- when Type::Record(name) %} +{%- when Type::Record{ name, module_path } %} {% include "RecordTemplate.cs" %} -{%- when Type::Optional(inner_type) %} +{%- when Type::Optional { inner_type } %} {% include "OptionalTemplate.cs" %} -{%- when Type::Sequence(inner_type) %} +{%- when Type::Sequence { inner_type } %} {% include "SequenceTemplate.cs" %} {%- when Type::Bytes %} {%- let inner_type = Type::UInt8 %} {% include "SequenceTemplate.cs" %} -{%- when Type::Map(key_type, value_type) %} +{%- when Type::Map { key_type, value_type } %} {% include "MapTemplate.cs" %} -{%- when Type::CallbackInterface(name) %} +{%- when Type::CallbackInterface { name, module_path } %} {% include "CallbackInterfaceTemplate.cs" %} {%- when Type::Timestamp %} @@ -93,10 +93,10 @@ {%- when Type::Duration %} {% include "DurationHelper.cs" %} -{%- when Type::Custom { name, builtin } %} +{%- when Type::Custom { module_path, name, builtin } %} {% include "CustomTypeTemplate.cs" %} -{%- when Type::External { crate_name, name, kind } %} +{%- when Type::External { module_path, name, namespace, kind, tagged } %} {% include "ExternalTypeTemplate.cs" %} {%- when Type::ForeignExecutor %} diff --git a/bindgen/templates/macros.cs b/bindgen/templates/macros.cs index 0dfc2262..42b6f474 100644 --- a/bindgen/templates/macros.cs +++ b/bindgen/templates/macros.cs @@ -69,7 +69,7 @@ IntPtr ptr, {%- else %} {%- for arg in func.arguments() %} - {{- arg.type_().borrow()|ffi_type_name }} {{ arg.name()|var_name -}}, + {{- arg.type_().borrow()|ffi_type_name }} {{ arg.name()|var_name -}}{%- if !loop.last || func.has_rust_call_status_arg() -%},{%- endif -%} {%- endfor %} {%- endif %} {%- if func.has_rust_call_status_arg() %}ref RustCallStatus _uniffi_out_err{% endif %} diff --git a/docker_build.sh b/docker_build.sh index ce98c6a3..11969890 100755 --- a/docker_build.sh +++ b/docker_build.sh @@ -6,4 +6,4 @@ docker run \ --volume $HOME/.cargo/registry:/usr/local/cargo/registry \ --volume $PWD:/mounted_workdir \ --workdir /mounted_workdir \ - rust:1.70 ./build.sh + rust:1.72-bullseye ./build.sh diff --git a/dotnet-tests/UniffiCS.binding_tests/TestDocstring.cs b/dotnet-tests/UniffiCS.binding_tests/TestDocstring.cs index 7d268fe7..bf1ab6c6 100644 --- a/dotnet-tests/UniffiCS.binding_tests/TestDocstring.cs +++ b/dotnet-tests/UniffiCS.binding_tests/TestDocstring.cs @@ -21,12 +21,16 @@ public void DocstringWorks() { UniffiDocstringMethods.Test(); _ = EnumTest.One; + _ = EnumTest.Two; - _ = new AssociatedEnumTest.Test(); + _ = new AssociatedEnumTest.Test(0); + _ = new AssociatedEnumTest.Test2(0); _ = new ErrorTest.One("hello"); + _ = new ErrorTest.Two("hello"); - _ = new AssociatedErrorTest.Test(); + _ = new AssociatedErrorTest.Test(0); + _ = new AssociatedErrorTest.Test2(0); var obj1 = new ObjectTest(); var obj2 = ObjectTest.NewAlternate(); diff --git a/dotnet-tests/UniffiCS.binding_tests/TestExternalTypes.cs b/dotnet-tests/UniffiCS.binding_tests/TestExternalTypes.cs deleted file mode 100644 index 28a2cf2a..00000000 --- a/dotnet-tests/UniffiCS.binding_tests/TestExternalTypes.cs +++ /dev/null @@ -1,22 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -using System; -using uniffi.external_types_lib; - -public class TestExternalTypes { - [Fact] - public void ExternalTypesWork() { - var ct = ExternalTypesLibMethods.GetCombinedType( - new CombinedType( - new CrateOneType("test"), - new CrateTwoType(42))); - Assert.Equal("test", ct.cot.sval); - Assert.Equal(42, ct.ctt.ival); - - var ct2 = ExternalTypesLibMethods.GetCombinedType(null); - Assert.Equal("hello", ct2.cot.sval); - Assert.Equal(1, ct2.ctt.ival); - } -} diff --git a/fixtures/Cargo.toml b/fixtures/Cargo.toml index 8f510f81..eb01bf0e 100644 --- a/fixtures/Cargo.toml +++ b/fixtures/Cargo.toml @@ -22,5 +22,4 @@ uniffi-example-todolist = { path = "../3rd-party/uniffi-rs/examples/todolist" } uniffi-fixture-callbacks = { path = "../3rd-party/uniffi-rs/fixtures/callbacks" } uniffi-fixture-coverall = { path = "../3rd-party/uniffi-rs/fixtures/coverall" } uniffi-fixture-docstring = { path = "../3rd-party/uniffi-rs/fixtures/docstring" } -uniffi-fixture-external-types = { path = "../3rd-party/uniffi-rs/fixtures/external-types/lib" } uniffi-fixture-time = { path = "../3rd-party/uniffi-rs/fixtures/uniffi-fixture-time" } diff --git a/fixtures/src/lib.rs b/fixtures/src/lib.rs index 371cf2c2..005fc233 100644 --- a/fixtures/src/lib.rs +++ b/fixtures/src/lib.rs @@ -13,7 +13,6 @@ mod uniffi_fixtures { uniffi_chronological::uniffi_reexport_scaffolding!(); uniffi_coverall::uniffi_reexport_scaffolding!(); - uniffi_external_types_lib::uniffi_reexport_scaffolding!(); uniffi_fixture_callbacks::uniffi_reexport_scaffolding!(); uniffi_fixture_docstring::uniffi_reexport_scaffolding!();