Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bindgen refactors #2358

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion tools/publish-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ done
set -ex

# Note: make sure these are ordered so that dependencies come before the crates that depend on them
cargo publish -p uniffi_checksum_derive
cargo publish -p uniffi_internal_macros
cargo publish -p uniffi_meta
cargo publish -p uniffi_core
cargo publish -p uniffi_testing
Expand Down
22 changes: 14 additions & 8 deletions uniffi_bindgen/src/interface/enum_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,20 @@ impl Enum {
// in those cases, so by the time this get's run we can be confident these
// error cases can't exist.
pub fn variant_discr(&self, variant_index: usize) -> Result<Literal> {
if variant_index >= self.variants.len() {
anyhow::bail!("Invalid variant index {variant_index}");
for (i, lit) in self.variant_discr_iter().enumerate() {
let lit = lit?;
if i == variant_index {
return Ok(lit);
}
}
anyhow::bail!("Invalid variant index {variant_index}");
}

// Iterate over variant discriminants
pub fn variant_discr_iter(&self) -> impl Iterator<Item = Result<Literal>> + '_ {
let mut next = 0;
let mut this;
let mut this_lit = Literal::new_uint(0);
for v in self.variants().iter().take(variant_index + 1) {
(this, this_lit) = match v.discr {
self.variants().iter().map(move |v| {
let (this, this_lit) = match v.discr {
None => (
next,
if (next as i64) < 0 {
Expand All @@ -231,8 +237,8 @@ impl Enum {
_ => anyhow::bail!("Invalid literal type {v:?}"),
};
next = this.wrapping_add(1);
}
Ok(this_lit)
Ok(this_lit)
})
}

pub fn variant_discr_type(&self) -> &Option<Type> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "uniffi_checksum_derive"
name = "uniffi_internal_macros"
version = "0.28.3"
description = "a multi-language bindings generator for rust (checksum custom derive)"
description = "a multi-language bindings generator for rust (interal macro crate)"
documentation = "https://mozilla.github.io/uniffi-rs"
homepage = "https://mozilla.github.io/uniffi-rs"
repository = "https://github.com/mozilla/uniffi-rs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* 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/. */

//! Custom derive for uniffi_meta::Checksum

use proc_macro::TokenStream;
use quote::{format_ident, quote};
use syn::{
Expand All @@ -23,6 +21,7 @@ fn has_ignore_attribute(attrs: &[Attribute]) -> bool {
})
}

/// Custom derive for uniffi_meta::Checksum
#[proc_macro_derive(Checksum, attributes(checksum_ignore))]
pub fn checksum_derive(input: TokenStream) -> TokenStream {
let input: DeriveInput = parse_macro_input!(input);
Expand Down
2 changes: 1 addition & 1 deletion uniffi_meta/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ readme = "../README.md"
anyhow = "1"
bytes = "1.3"
siphasher = "0.3"
uniffi_checksum_derive = { version = "0.28.3", path = "../uniffi_checksum_derive" }
uniffi_internal_macros = { version = "0.28.3", path = "../uniffi_internal_macros" }
2 changes: 1 addition & 1 deletion uniffi_meta/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use std::{collections::BTreeMap, hash::Hasher};
pub use uniffi_checksum_derive::Checksum;
pub use uniffi_internal_macros::Checksum;

mod ffi_names;
pub use ffi_names::*;
Expand Down