Skip to content

Commit

Permalink
External types (#20)
Browse files Browse the repository at this point in the history
* Checkpointing external types

* Thread `config` all over the place, dev uniffi-rs

Will need to PR breaking changes to uniffi-rs if this works, which
likely means running off this fork for a while

* Mostly working

Need a test extension to be able to add to the uniffi-toml of an
external crate.

* Working external types

* Sort deps
  • Loading branch information
skeet70 authored Jul 23, 2024
1 parent 61e2d40 commit 95c9560
Show file tree
Hide file tree
Showing 32 changed files with 489 additions and 354 deletions.
89 changes: 71 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 12 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,20 @@ regex = "1.10.4"
serde = "1"
textwrap = "0.16.1"
toml = "0.5" # can't be on 8, `Value` is part of public interface
uniffi_bindgen = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi_meta = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi_bindgen = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi_meta = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }

[dev-dependencies]
cargo_metadata = "0.18.1"
glob = "0.3"
itertools = "0.13.0"
uniffi-example-arithmetic = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-example-custom-types = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-example-futures = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-example-geometry = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-example-rondpoint = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-fixture-coverall = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-fixture-futures = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-fixture-time = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi_testing = { git = "https://github.com/mozilla/uniffi-rs.git", branch = "main" }
uniffi-example-arithmetic = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-example-custom-types = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-example-futures = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-example-geometry = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-example-rondpoint = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-fixture-coverall = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-fixture-ext-types = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-fixture-futures = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi-fixture-time = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
uniffi_testing = { git = "https://github.com/skeet70/uniffi-rs.git", branch = "thread-external-type-metadata-rustbuffer" }
4 changes: 2 additions & 2 deletions src/gen_java/callback_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/. */

use super::CodeType;
use super::{CodeType, Config};
use crate::ComponentInterface;

#[derive(Debug)]
Expand All @@ -17,7 +17,7 @@ impl CallbackInterfaceCodeType {
}

impl CodeType for CallbackInterfaceCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
fn type_label(&self, ci: &ComponentInterface, _config: &Config) -> String {
super::JavaCodeOracle.class_name(ci, &self.id)
}

Expand Down
32 changes: 20 additions & 12 deletions src/gen_java/compounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/. */

use super::{AsCodeType, CodeType};
use super::{AsCodeType, CodeType, Config};
use uniffi_bindgen::{
backend::{Literal, Type},
ComponentInterface,
Expand All @@ -23,10 +23,10 @@ impl OptionalCodeType {
}

impl CodeType for OptionalCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
fn type_label(&self, ci: &ComponentInterface, config: &Config) -> String {
super::JavaCodeOracle
.find(self.inner())
.type_label(ci)
.type_label(ci, config)
.to_string()
}

Expand All @@ -37,10 +37,12 @@ impl CodeType for OptionalCodeType {
)
}

fn literal(&self, literal: &Literal, ci: &ComponentInterface) -> String {
fn literal(&self, literal: &Literal, ci: &ComponentInterface, config: &Config) -> String {
match literal {
Literal::None => "null".into(),
Literal::Some { inner } => super::JavaCodeOracle.find(&self.inner).literal(inner, ci),
Literal::Some { inner } => super::JavaCodeOracle
.find(&self.inner)
.literal(inner, ci, config),
_ => panic!("Invalid literal for Optional type: {literal:?}"),
}
}
Expand All @@ -61,10 +63,12 @@ impl SequenceCodeType {
}

impl CodeType for SequenceCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
fn type_label(&self, ci: &ComponentInterface, config: &Config) -> String {
format!(
"List<{}>",
super::JavaCodeOracle.find(self.inner()).type_label(ci)
super::JavaCodeOracle
.find(self.inner())
.type_label(ci, config)
)
}

Expand All @@ -75,7 +79,7 @@ impl CodeType for SequenceCodeType {
)
}

fn literal(&self, literal: &Literal, _ci: &ComponentInterface) -> String {
fn literal(&self, literal: &Literal, _ci: &ComponentInterface, _config: &Config) -> String {
match literal {
Literal::EmptySequence => "List.of()".into(),
_ => panic!("Invalid literal for List type: {literal:?}"),
Expand Down Expand Up @@ -104,11 +108,15 @@ impl MapCodeType {
}

impl CodeType for MapCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
fn type_label(&self, ci: &ComponentInterface, config: &Config) -> String {
format!(
"Map<{}, {}>",
super::JavaCodeOracle.find(self.key()).type_label(ci),
super::JavaCodeOracle.find(self.value()).type_label(ci),
super::JavaCodeOracle
.find(self.key())
.type_label(ci, config),
super::JavaCodeOracle
.find(self.value())
.type_label(ci, config),
)
}

Expand All @@ -120,7 +128,7 @@ impl CodeType for MapCodeType {
)
}

fn literal(&self, literal: &Literal, _ci: &ComponentInterface) -> String {
fn literal(&self, literal: &Literal, _ci: &ComponentInterface, _config: &Config) -> String {
match literal {
Literal::EmptyMap => "Map.of()".into(),
_ => panic!("Invalid literal for Map type: {literal:?}"),
Expand Down
4 changes: 2 additions & 2 deletions src/gen_java/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/. */

use super::CodeType;
use super::{CodeType, Config};
use crate::ComponentInterface;

#[derive(Debug)]
Expand All @@ -17,7 +17,7 @@ impl CustomCodeType {
}

impl CodeType for CustomCodeType {
fn type_label(&self, ci: &ComponentInterface) -> String {
fn type_label(&self, ci: &ComponentInterface, _config: &Config) -> String {
super::JavaCodeOracle.class_name(ci, &self.name)
}

Expand Down
Loading

0 comments on commit 95c9560

Please sign in to comment.