зеркало из https://github.com/mozilla/gecko-dev.git
Backed out changeset a5df97f61fec (bug 1793786) for causing build bustages. CLOSED TREE
This commit is contained in:
Родитель
6bf79e87b2
Коммит
1bed1fd6e7
|
@ -2219,9 +2219,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "glean"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb26e81939b071ae23dfa27fcbda5d5766684ac0f546bd37103b6fac47a4e6a"
|
||||
checksum = "692dfb4494ad83161b7d596656c3e1f08b06bc2fa62a0eb8a3f4b7f83594025e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
|
@ -2239,9 +2239,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "glean-core"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8013c5aced55a42f509e108378097f486ebff428a8f2537e7ea615b70c94f00a"
|
||||
checksum = "0e26d3c442090135439a6c6618f60653b139ee5a89116605eab947d18b5d64e7"
|
||||
dependencies = [
|
||||
"android_logger",
|
||||
"bincode",
|
||||
|
@ -5625,9 +5625,9 @@ checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04"
|
|||
|
||||
[[package]]
|
||||
name = "uniffi"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ff9d73a665e4e94d566f069fc0c6b92d13fc7de25ae128dd20402023884b551"
|
||||
checksum = "ea179ddeb64c249977c165b1d9f94af9c0a12a4f623e5986f553276612ea8796"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes 1.2.1",
|
||||
|
@ -5669,7 +5669,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi-example-custom-types"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes 1.2.1",
|
||||
|
@ -5724,9 +5724,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_bindgen"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "195251b1b0dbb221759ea4d79e3090e5c08a60fc4040c9e945b255def155ea90"
|
||||
checksum = "8849753c67126dd7e4f309d09b696378481bfe9b3f5cec0a0c2b8e27391789c8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"askama",
|
||||
|
@ -5747,9 +5747,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_build"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74b65ae1c0bac70369bb0d9df6fae578b1ca130bf4cb6203e2636e2d6969dba5"
|
||||
checksum = "8d6c6fedf97b345227270837fcfd8d9a799f202af7fa843298c788fb943b159f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
|
@ -5758,9 +5758,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_macros"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5efddfb993c5b394a75042c0d144665388af2ad3db628401ab8f4fb6f6d07e54"
|
||||
checksum = "090e5a993b51dc02faa0dc135ce94f02f050791bda283a5ae9f40fc9a4389a39"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"camino",
|
||||
|
@ -5777,9 +5777,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_meta"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe1767e693cbd11fc22c37a4033d82eb9d891c3862e45329b4a891c1d8395df5"
|
||||
checksum = "10d099cea0c721294ec11ae6c39d661c96d13d8994247ffadaf1576b065e38e6"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -168,8 +168,8 @@ path = "third_party/rust/mio-0.6.23"
|
|||
# duplicate crates.
|
||||
|
||||
[patch."https://github.com/mozilla/uniffi-rs.git"]
|
||||
uniffi = "=0.20.0"
|
||||
uniffi_bindgen = "=0.20.0"
|
||||
uniffi_build = "=0.20.0"
|
||||
uniffi_macros = "=0.20.0"
|
||||
uniffi = "=0.19.6"
|
||||
uniffi_bindgen = "=0.19.6"
|
||||
uniffi_build = "=0.19.6"
|
||||
uniffi_macros = "=0.19.6"
|
||||
weedle2 = "=4.0.0"
|
||||
|
|
|
@ -36,7 +36,7 @@ allprojects {
|
|||
topsrcdir = gradle.mozconfig.topsrcdir
|
||||
topobjdir = gradle.mozconfig.topobjdir
|
||||
|
||||
gleanVersion = "51.4.0"
|
||||
gleanVersion = "51.2.0"
|
||||
if (gleanVersion != getRustVersionFor("glean")) {
|
||||
throw new StopExecutionException("Mismatched Glean version, expected: ${gleanVersion}," +
|
||||
" found ${getRustVersionFor("glean")}")
|
||||
|
|
|
@ -865,9 +865,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "glean"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5bb26e81939b071ae23dfa27fcbda5d5766684ac0f546bd37103b6fac47a4e6a"
|
||||
checksum = "692dfb4494ad83161b7d596656c3e1f08b06bc2fa62a0eb8a3f4b7f83594025e"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"crossbeam-channel",
|
||||
|
@ -885,9 +885,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "glean-core"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8013c5aced55a42f509e108378097f486ebff428a8f2537e7ea615b70c94f00a"
|
||||
checksum = "0e26d3c442090135439a6c6618f60653b139ee5a89116605eab947d18b5d64e7"
|
||||
dependencies = [
|
||||
"android_logger",
|
||||
"bincode",
|
||||
|
@ -2222,9 +2222,9 @@ checksum = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
|||
|
||||
[[package]]
|
||||
name = "uniffi"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ff9d73a665e4e94d566f069fc0c6b92d13fc7de25ae128dd20402023884b551"
|
||||
checksum = "ea179ddeb64c249977c165b1d9f94af9c0a12a4f623e5986f553276612ea8796"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bytes",
|
||||
|
@ -2239,9 +2239,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_bindgen"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "195251b1b0dbb221759ea4d79e3090e5c08a60fc4040c9e945b255def155ea90"
|
||||
checksum = "8849753c67126dd7e4f309d09b696378481bfe9b3f5cec0a0c2b8e27391789c8"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"askama",
|
||||
|
@ -2262,9 +2262,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_build"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "74b65ae1c0bac70369bb0d9df6fae578b1ca130bf4cb6203e2636e2d6969dba5"
|
||||
checksum = "8d6c6fedf97b345227270837fcfd8d9a799f202af7fa843298c788fb943b159f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"camino",
|
||||
|
@ -2273,9 +2273,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_macros"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5efddfb993c5b394a75042c0d144665388af2ad3db628401ab8f4fb6f6d07e54"
|
||||
checksum = "090e5a993b51dc02faa0dc135ce94f02f050791bda283a5ae9f40fc9a4389a39"
|
||||
dependencies = [
|
||||
"bincode",
|
||||
"camino",
|
||||
|
@ -2292,9 +2292,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_meta"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe1767e693cbd11fc22c37a4033d82eb9d891c3862e45329b4a891c1d8395df5"
|
||||
checksum = "10d099cea0c721294ec11ae6c39d661c96d13d8994247ffadaf1576b065e38e6"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -51,7 +51,7 @@ svg_fmt = "0.4"
|
|||
tracy-rs = "0.1.2"
|
||||
derive_more = { version = "0.99", default-features = false, features = ["add_assign"] }
|
||||
etagere = "0.2.6"
|
||||
glean = "51.4.0"
|
||||
glean = "51.2.0"
|
||||
fog = { version = "0.1.0", optional = true }
|
||||
swgl = { path = "../swgl", optional = true }
|
||||
topological-sort = "0.1"
|
||||
|
|
|
@ -11,7 +11,7 @@ use neqo_http3::{Error as Http3Error, Priority};
|
|||
use neqo_http3::{Http3Client, Http3ClientEvent, Http3Parameters, Http3State};
|
||||
use neqo_transport::{
|
||||
stream_id::StreamType, CongestionControlAlgorithm, ConnectionParameters,
|
||||
Error as TransportError, Output, RandomConnectionIdGenerator, StreamId, Version,
|
||||
Error as TransportError, Output, Version, RandomConnectionIdGenerator, StreamId,
|
||||
};
|
||||
use nserror::*;
|
||||
use nsstring::*;
|
||||
|
|
|
@ -132,7 +132,7 @@ pth:xpcom/geckoprocesstypes_generator
|
|||
pth:xpcom/idl-parser
|
||||
# glean-sdk may not be installable if a wheel isn't available
|
||||
# and it has to be built from source.
|
||||
pypi-optional:glean-sdk==51.4.0:telemetry will not be collected
|
||||
pypi-optional:glean-sdk==51.2.0:telemetry will not be collected
|
||||
# Mach gracefully handles the case where `psutil` is unavailable.
|
||||
# We aren't (yet) able to pin packages in automation, so we have to
|
||||
# support down to the oldest locally-installed version (5.4.2).
|
||||
|
|
|
@ -522,11 +522,6 @@ criteria = "safe-to-deploy"
|
|||
delta = "51.1.0 -> 51.2.0"
|
||||
notes = "Maintained by the Glean team at Mozilla"
|
||||
|
||||
[[audits.glean]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "51.2.0 -> 51.4.0"
|
||||
|
||||
[[audits.glean-core]]
|
||||
who = "Jan-Erik Rediger <jrediger@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
@ -563,11 +558,6 @@ criteria = "safe-to-deploy"
|
|||
delta = "51.1.0 -> 51.2.0"
|
||||
notes = "Bug fix release with minimal changes, changes done by myself"
|
||||
|
||||
[[audits.glean-core]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "51.2.0 -> 51.4.0"
|
||||
|
||||
[[audits.goblin]]
|
||||
who = "Jan-Erik Rediger <jrediger@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
@ -1224,11 +1214,6 @@ criteria = "safe-to-deploy"
|
|||
delta = "0.19.3 -> 0.19.6"
|
||||
notes = "Maintained by the Glean and Application Services team."
|
||||
|
||||
[[audits.uniffi]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.19.6 -> 0.20.0"
|
||||
|
||||
[[audits.uniffi_bindgen]]
|
||||
who = "Travis Long <tlong@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
@ -1241,11 +1226,6 @@ criteria = "safe-to-deploy"
|
|||
delta = "0.19.3 -> 0.19.6"
|
||||
notes = "Maintained by the Glean and Application Services team."
|
||||
|
||||
[[audits.uniffi_bindgen]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.19.6 -> 0.20.0"
|
||||
|
||||
[[audits.uniffi_build]]
|
||||
who = "Travis Long <tlong@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
@ -1258,11 +1238,6 @@ criteria = "safe-to-deploy"
|
|||
delta = "0.19.3 -> 0.19.6"
|
||||
notes = "Maintained by the Glean and Application Services team."
|
||||
|
||||
[[audits.uniffi_build]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.19.6 -> 0.20.0"
|
||||
|
||||
[[audits.uniffi_macros]]
|
||||
who = "Travis Long <tlong@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
@ -1275,22 +1250,12 @@ criteria = "safe-to-deploy"
|
|||
delta = "0.19.3 -> 0.19.6"
|
||||
notes = "Maintained by the Glean and Application Services team."
|
||||
|
||||
[[audits.uniffi_macros]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.19.6 -> 0.20.0"
|
||||
|
||||
[[audits.uniffi_meta]]
|
||||
who = "Jan-Erik Rediger <jrediger@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
version = "0.19.6"
|
||||
notes = "Maintained by the Glean and Application Services team."
|
||||
|
||||
[[audits.uniffi_meta]]
|
||||
who = "Perry McManis <pmcmanis@mozilla.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
delta = "0.19.6 -> 0.20.0"
|
||||
|
||||
[[audits.void]]
|
||||
who = "Bobby Holley <bobbyholley@gmail.com>"
|
||||
criteria = "safe-to-deploy"
|
||||
|
|
|
@ -277,7 +277,7 @@ impl RemoteBrowser {
|
|||
Ok(RemoteBrowser {
|
||||
handler,
|
||||
marionette_port,
|
||||
prefs_backup,
|
||||
prefs_backup
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "glean-core"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
authors = [
|
||||
"Jan-Erik Rediger <jrediger@mozilla.com>",
|
||||
"The Glean Team <glean-team@mozilla.com>",
|
||||
|
@ -73,10 +73,10 @@ version = "1.0.4"
|
|||
version = "0.1.40"
|
||||
|
||||
[dependencies.uniffi]
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
|
||||
[dependencies.uniffi_macros]
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "0.8.1"
|
||||
|
@ -107,7 +107,7 @@ version = "0.4"
|
|||
version = "3.1.0"
|
||||
|
||||
[build-dependencies.uniffi_build]
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
features = ["builtin-bindgen"]
|
||||
|
||||
[target."cfg(not(target_os = \"android\"))".dependencies.env_logger]
|
||||
|
|
|
@ -265,7 +265,7 @@ impl Database {
|
|||
|
||||
/// Creates the storage directories and inits rkv.
|
||||
fn open_rkv(path: &Path) -> Result<Rkv> {
|
||||
fs::create_dir_all(path)?;
|
||||
fs::create_dir_all(&path)?;
|
||||
|
||||
let rkv = rkv_new(path)?;
|
||||
migrate(path, &rkv);
|
||||
|
@ -620,10 +620,10 @@ impl Database {
|
|||
self.write_with_store(Lifetime::Ping, |mut writer, store| {
|
||||
let mut metrics = Vec::new();
|
||||
{
|
||||
let mut iter = store.iter_from(&writer, storage_name)?;
|
||||
let mut iter = store.iter_from(&writer, &storage_name)?;
|
||||
while let Some(Ok((metric_id, _))) = iter.next() {
|
||||
if let Ok(metric_id) = std::str::from_utf8(metric_id) {
|
||||
if !metric_id.starts_with(storage_name) {
|
||||
if !metric_id.starts_with(&storage_name) {
|
||||
break;
|
||||
}
|
||||
metrics.push(metric_id.to_owned());
|
||||
|
@ -753,7 +753,7 @@ impl Database {
|
|||
// There is no need for `get_storage_key` here because
|
||||
// the key is already formatted from when it was saved
|
||||
// to ping_lifetime_data.
|
||||
store.put(&mut writer, key, &rkv::Value::Blob(&encoded))?;
|
||||
store.put(&mut writer, &key, &rkv::Value::Blob(&encoded))?;
|
||||
}
|
||||
writer.commit()?;
|
||||
Ok(())
|
||||
|
|
|
@ -8,12 +8,11 @@ use crate::error_recording::{record_error, test_get_num_recorded_errors, ErrorTy
|
|||
use crate::metrics::Metric;
|
||||
use crate::metrics::MetricType;
|
||||
use crate::storage::StorageManager;
|
||||
use crate::util::truncate_string_at_boundary_with_error;
|
||||
use crate::CommonMetricData;
|
||||
use crate::Glean;
|
||||
|
||||
// The maximum number of characters a URL Metric may have, before encoding.
|
||||
const MAX_URL_LENGTH: usize = 8192;
|
||||
const MAX_URL_LENGTH: usize = 2048;
|
||||
|
||||
/// A URL metric.
|
||||
///
|
||||
|
@ -81,7 +80,16 @@ impl UrlMetric {
|
|||
return;
|
||||
}
|
||||
|
||||
let s = truncate_string_at_boundary_with_error(glean, &self.meta, value, MAX_URL_LENGTH);
|
||||
let s = value.into();
|
||||
if s.len() > MAX_URL_LENGTH {
|
||||
let msg = format!(
|
||||
"Value length {} exceeds maximum of {}",
|
||||
s.len(),
|
||||
MAX_URL_LENGTH
|
||||
);
|
||||
record_error(glean, &self.meta, ErrorType::InvalidOverflow, msg, None);
|
||||
return;
|
||||
}
|
||||
|
||||
if s.starts_with("data:") {
|
||||
record_error(
|
||||
|
@ -196,24 +204,12 @@ mod test {
|
|||
dynamic_label: None,
|
||||
});
|
||||
|
||||
// Whenever the URL is longer than our MAX_URL_LENGTH, we truncate the URL to the
|
||||
// MAX_URL_LENGTH.
|
||||
//
|
||||
// This 8-character string was chosen so we could have an even number that is
|
||||
// a divisor of our MAX_URL_LENGTH.
|
||||
let long_path_base = "abcdefgh";
|
||||
|
||||
// Using 2000 creates a string > 16000 characters, well over MAX_URL_LENGTH.
|
||||
let test_url = format!("glean://{}", long_path_base.repeat(2000));
|
||||
let long_path = "testing".repeat(2000);
|
||||
let test_url = format!("glean://{}", long_path);
|
||||
metric.set_sync(&glean, test_url);
|
||||
|
||||
// "glean://" is 8 characters
|
||||
// "abcdefgh" (long_path_base) is 8 characters
|
||||
// `long_path_base` is repeated 1023 times (8184)
|
||||
// 8 + 8184 = 8192 (MAX_URL_LENGTH)
|
||||
let expected = format!("glean://{}", long_path_base.repeat(1023));
|
||||
assert!(metric.get_value(&glean, "store1").is_none());
|
||||
|
||||
assert_eq!(metric.get_value(&glean, "store1").unwrap(), expected);
|
||||
assert_eq!(
|
||||
1,
|
||||
test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidOverflow)
|
||||
|
|
|
@ -335,7 +335,7 @@ mod test {
|
|||
// Submit the ping to populate the pending_pings directory
|
||||
ping_type.submit_sync(&glean, None);
|
||||
|
||||
let directory_manager = PingDirectoryManager::new(dir.path());
|
||||
let directory_manager = PingDirectoryManager::new(&dir.path());
|
||||
|
||||
let not_uuid_path = dir
|
||||
.path()
|
||||
|
@ -370,7 +370,7 @@ mod test {
|
|||
// Submit the ping to populate the pending_pings directory
|
||||
ping_type.submit_sync(&glean, None);
|
||||
|
||||
let directory_manager = PingDirectoryManager::new(dir.path());
|
||||
let directory_manager = PingDirectoryManager::new(&dir.path());
|
||||
|
||||
let wrong_contents_file_path = dir
|
||||
.path()
|
||||
|
|
|
@ -125,6 +125,8 @@ impl RateLimiter {
|
|||
///
|
||||
/// When asking for the next ping request to upload,
|
||||
/// the requester may receive one out of three possible tasks.
|
||||
///
|
||||
/// If new variants are added, this should be reflected in `glean-core/ffi/src/upload.rs` as well.
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
pub enum PingUploadTask {
|
||||
/// An upload task
|
||||
|
|
|
@ -87,14 +87,14 @@ fn storage_is_thread_safe() {
|
|||
let threadsafe_metric_clone = threadsafe_metric.clone();
|
||||
let glean_clone = glean.clone();
|
||||
let child = thread::spawn(move || {
|
||||
threadsafe_metric_clone.add_sync(&glean_clone.lock().unwrap(), 1);
|
||||
threadsafe_metric_clone.add_sync(&*glean_clone.lock().unwrap(), 1);
|
||||
c.wait();
|
||||
threadsafe_metric_clone.add_sync(&glean_clone.lock().unwrap(), 1);
|
||||
threadsafe_metric_clone.add_sync(&*glean_clone.lock().unwrap(), 1);
|
||||
});
|
||||
|
||||
threadsafe_metric.add_sync(&glean.lock().unwrap(), 1);
|
||||
threadsafe_metric.add_sync(&*glean.lock().unwrap(), 1);
|
||||
barrier.wait();
|
||||
threadsafe_metric.add_sync(&glean.lock().unwrap(), 1);
|
||||
threadsafe_metric.add_sync(&*glean.lock().unwrap(), 1);
|
||||
|
||||
child.join().unwrap();
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"58114c64b540f977de8bf5e4d461185e36edd5e575a54fe37eebd36a4fc4acef","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5bc5b1c46695f628e1023662752272e938a963b535d5686bd1ecc433f9e018c4","src/common_test.rs":"68f6d408cb7b683fa32c8b38a4df1e6c45bfd77c0c90ca35976ea7548bbc4b2f","src/configuration.rs":"37ad5b3e7d4e31dd04a7d6690179168b5f2768d87dd36056dee5d08bdbe20fb2","src/core_metrics.rs":"76ac5350cb6f82d9a193d519b085a08f138dceba77da3514bd0c636bcdefefca","src/lib.rs":"e342d497d60abceca3c84d35523a54d187b0282220a112da53e4ab1cf76da205","src/net/http_uploader.rs":"43812a70d19a38e8d7a093c8076c2b6345372c3c861b0f3511428762700a65e0","src/net/mod.rs":"e05e61860f5828caa529c3ea75a2fff7371bfa3dce057077a74c09baf41a568a","src/private/event.rs":"02bbebf545695812e5055741cc0b5f3c99eda2039e684e26fcdd5f087ed15fe3","src/private/mod.rs":"0364ecf5f0439443a5b209583f4ff2c474b79f7c253c981ab0b7cdc528368698","src/private/ping.rs":"cbdc57f41fc9d46e56b4dfff91ac683753d1f8b3ecd0aa9bc3419e3595b8b81b","src/system.rs":"4e0ec743f6d06a9c83e46c95d0286d5745f4642398c942fce8ae7a1ea5202d37","src/test.rs":"1d9a01fa6befdc04e97caeb58ccebd67c840965ff0417b6b2ba9e53aa108a069","tests/common/mod.rs":"37cd4c48e140c793b852ae09fb3e812da28a4412977295015bcbffd632fcf294","tests/init_fails.rs":"9b78226a4e3220de5b64a205a97b8d5778d1700391b5b71c7819b6cdd120747e","tests/never_init.rs":"1f33b8ce7ca3514b57b48cc16d98408974c85cf8aa7d13257ffc2ad878ebb295","tests/no_time_to_init.rs":"494dcddce49f279c6508f484ee59cf8bb83e7324de07bdbc1142f2a066b7f6a1","tests/overflowing_preinit.rs":"396206d5078b7e6c148bbf2aecb0f963cfaa4d7eff3fc7bf6590125076ee6113","tests/persist_ping_lifetime.rs":"2297d4b208e14188e6dcca2d4806b805cfc7dd824d21bd143a7803b95e0709f4","tests/persist_ping_lifetime_nopanic.rs":"06f1f3ca3b8a6c8b7fc4d6fc48d0e1d2ccffd32139f080db0a95003e9edd507d","tests/schema.rs":"a96089f828928b6be1fad7815e3269f5693af1b773e570312b357a29af28122a","tests/simple.rs":"a1d72af899293390bb955ca379baafb89c29bb746630409f8c51f453d222dbad"},"package":"5bb26e81939b071ae23dfa27fcbda5d5766684ac0f546bd37103b6fac47a4e6a"}
|
||||
{"files":{"Cargo.toml":"182756cc94cd25fab16c27a7207b58d869746561f36f744b009813d1b9d55978","LICENSE":"1f256ecad192880510e84ad60474eab7589218784b9a50bc7ceee34c2b91f1d5","README.md":"5bc5b1c46695f628e1023662752272e938a963b535d5686bd1ecc433f9e018c4","src/common_test.rs":"68f6d408cb7b683fa32c8b38a4df1e6c45bfd77c0c90ca35976ea7548bbc4b2f","src/configuration.rs":"37ad5b3e7d4e31dd04a7d6690179168b5f2768d87dd36056dee5d08bdbe20fb2","src/core_metrics.rs":"76ac5350cb6f82d9a193d519b085a08f138dceba77da3514bd0c636bcdefefca","src/lib.rs":"e342d497d60abceca3c84d35523a54d187b0282220a112da53e4ab1cf76da205","src/net/http_uploader.rs":"43812a70d19a38e8d7a093c8076c2b6345372c3c861b0f3511428762700a65e0","src/net/mod.rs":"e05e61860f5828caa529c3ea75a2fff7371bfa3dce057077a74c09baf41a568a","src/private/event.rs":"02bbebf545695812e5055741cc0b5f3c99eda2039e684e26fcdd5f087ed15fe3","src/private/mod.rs":"0364ecf5f0439443a5b209583f4ff2c474b79f7c253c981ab0b7cdc528368698","src/private/ping.rs":"cbdc57f41fc9d46e56b4dfff91ac683753d1f8b3ecd0aa9bc3419e3595b8b81b","src/system.rs":"4e0ec743f6d06a9c83e46c95d0286d5745f4642398c942fce8ae7a1ea5202d37","src/test.rs":"1d9a01fa6befdc04e97caeb58ccebd67c840965ff0417b6b2ba9e53aa108a069","tests/common/mod.rs":"37cd4c48e140c793b852ae09fb3e812da28a4412977295015bcbffd632fcf294","tests/init_fails.rs":"9b78226a4e3220de5b64a205a97b8d5778d1700391b5b71c7819b6cdd120747e","tests/never_init.rs":"1f33b8ce7ca3514b57b48cc16d98408974c85cf8aa7d13257ffc2ad878ebb295","tests/no_time_to_init.rs":"494dcddce49f279c6508f484ee59cf8bb83e7324de07bdbc1142f2a066b7f6a1","tests/overflowing_preinit.rs":"396206d5078b7e6c148bbf2aecb0f963cfaa4d7eff3fc7bf6590125076ee6113","tests/persist_ping_lifetime.rs":"2297d4b208e14188e6dcca2d4806b805cfc7dd824d21bd143a7803b95e0709f4","tests/persist_ping_lifetime_nopanic.rs":"06f1f3ca3b8a6c8b7fc4d6fc48d0e1d2ccffd32139f080db0a95003e9edd507d","tests/schema.rs":"a96089f828928b6be1fad7815e3269f5693af1b773e570312b357a29af28122a","tests/simple.rs":"a1d72af899293390bb955ca379baafb89c29bb746630409f8c51f453d222dbad"},"package":"692dfb4494ad83161b7d596656c3e1f08b06bc2fa62a0eb8a3f4b7f83594025e"}
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2018"
|
||||
name = "glean"
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
authors = [
|
||||
"Jan-Erik Rediger <jrediger@mozilla.com>",
|
||||
"The Glean Team <glean-team@mozilla.com>",
|
||||
|
@ -41,7 +41,7 @@ features = ["serde"]
|
|||
version = "0.5"
|
||||
|
||||
[dependencies.glean-core]
|
||||
version = "51.4.0"
|
||||
version = "51.2.0"
|
||||
|
||||
[dependencies.inherent]
|
||||
version = "1"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"1fa92f36003b702379d069bab1c7141859eea0b29a558ea5e7b18c050c93cd35","release.toml":"a6602545cd6eb46e44d89ce946d7954957ac00f1c955de54c736fa2cb560b1df","src/ffi/ffidefault.rs":"c7ab752fffed17c3fabb60e818ad1d093482f95dd0bdeae6871287695c583e48","src/ffi/foreignbytes.rs":"37061e2da7135576abccb86fe27b4fefc054586a040f2ca81fe9858d5649e887","src/ffi/foreigncallbacks.rs":"e19a038128d25e7d945034935f0d296ea8603ad2f5a8da4bfe6d95c78a5f76b3","src/ffi/mod.rs":"3fb3b74607066e0052fc91168e9473dbf82dbae562f85c33774a7f5f6b350616","src/ffi/rustbuffer.rs":"b773637d9e4651b80cd16f7a02ed75846d02ce0a9e32b718ce644cdba3a83cdd","src/ffi/rustcalls.rs":"4a85a90b0d46974ab9e80e403a1cddaa252337b227e1a672bb6fdbbca5a66259","src/lib.rs":"bb38cf2bad092f4fffca0d072d176d4160e93331e702a9cca5bf8381b18f96d8","src/panichook.rs":"9f49c7994a8e5489c1105c488bb3f8c5571bc5f813e7be90441eca15da5c9851","src/testing.rs":"f287d682a8f27465838b2aba91993c635a4dcd281d802dc12c7c75794324123f","tests/ui/proc_macro_arc.rs":"d766dffee3fe6a93522d40f44a7f15592db141fd674034fa5f016e06f510e87b","tests/ui/proc_macro_arc.stderr":"201ed96a09989e19d874469fa73b8f0ae96de3d179497111c32eb77ccd8c9246","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"aadbd8f3847f5663022d8dd75d6afa3b25dfc8abccd30b386a681f98587d4ceb"},"package":"3ff9d73a665e4e94d566f069fc0c6b92d13fc7de25ae128dd20402023884b551"}
|
||||
{"files":{"Cargo.toml":"b890c85729dc11e074788bfe365ca5409dd41c08ec0b6098a59b300f3d3ad2c4","release.toml":"a6602545cd6eb46e44d89ce946d7954957ac00f1c955de54c736fa2cb560b1df","src/ffi/ffidefault.rs":"c7ab752fffed17c3fabb60e818ad1d093482f95dd0bdeae6871287695c583e48","src/ffi/foreignbytes.rs":"37061e2da7135576abccb86fe27b4fefc054586a040f2ca81fe9858d5649e887","src/ffi/foreigncallbacks.rs":"e19a038128d25e7d945034935f0d296ea8603ad2f5a8da4bfe6d95c78a5f76b3","src/ffi/mod.rs":"3fb3b74607066e0052fc91168e9473dbf82dbae562f85c33774a7f5f6b350616","src/ffi/rustbuffer.rs":"b773637d9e4651b80cd16f7a02ed75846d02ce0a9e32b718ce644cdba3a83cdd","src/ffi/rustcalls.rs":"4a85a90b0d46974ab9e80e403a1cddaa252337b227e1a672bb6fdbbca5a66259","src/lib.rs":"bb38cf2bad092f4fffca0d072d176d4160e93331e702a9cca5bf8381b18f96d8","src/panichook.rs":"9f49c7994a8e5489c1105c488bb3f8c5571bc5f813e7be90441eca15da5c9851","src/testing.rs":"f287d682a8f27465838b2aba91993c635a4dcd281d802dc12c7c75794324123f","tests/ui/version_mismatch.rs":"16ea359e5853517ee0d0704c015ae8c825533109fbefd715130d0f4a51f15898","tests/ui/version_mismatch.stderr":"aadbd8f3847f5663022d8dd75d6afa3b25dfc8abccd30b386a681f98587d4ceb"},"package":"ea179ddeb64c249977c165b1d9f94af9c0a12a4f623e5986f553276612ea8796"}
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "uniffi"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
|
||||
description = "a multi-language bindings generator for rust (runtime support code)"
|
||||
homepage = "https://mozilla.github.io/uniffi-rs"
|
||||
|
@ -50,11 +50,11 @@ version = "1.0"
|
|||
version = "1.1.0"
|
||||
|
||||
[dependencies.uniffi_bindgen]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
optional = true
|
||||
|
||||
[dependencies.uniffi_macros]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
|
||||
[dev-dependencies.trybuild]
|
||||
version = "1"
|
||||
|
|
|
@ -1,25 +0,0 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
fn main() {}
|
||||
|
||||
pub struct Foo;
|
||||
|
||||
#[uniffi::export]
|
||||
fn make_foo() -> Arc<Foo> {
|
||||
Arc::new(Foo)
|
||||
}
|
||||
|
||||
mod child {
|
||||
use std::sync::Arc;
|
||||
|
||||
enum Foo {}
|
||||
|
||||
#[uniffi::export]
|
||||
fn take_foo(foo: Arc<Foo>) {
|
||||
match &*foo {}
|
||||
}
|
||||
}
|
||||
|
||||
mod uniffi_types {
|
||||
pub use super::Foo;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
error[E0271]: type mismatch resolving `<Arc<child::Foo> as child::_::{closure#0}::TypeEq>::This == Arc<Foo>`
|
||||
--> tests/ui/proc_macro_arc.rs:17:5
|
||||
|
|
||||
17 | #[uniffi::export]
|
||||
| ^^^^^^^^^^^^^^^^^ type mismatch resolving `<Arc<child::Foo> as child::_::{closure#0}::TypeEq>::This == Arc<Foo>`
|
||||
|
|
||||
note: expected this to be `Arc<Foo>`
|
||||
--> tests/ui/proc_macro_arc.rs:17:5
|
||||
|
|
||||
17 | #[uniffi::export]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
= note: expected struct `Arc<Foo>`
|
||||
found struct `Arc<child::Foo>`
|
||||
note: required by a bound in `child::_::{closure#0}::assert_type_eq_all`
|
||||
--> tests/ui/proc_macro_arc.rs:17:5
|
||||
|
|
||||
17 | #[uniffi::export]
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| required by a bound in this
|
||||
| required by this bound in `child::_::{closure#0}::assert_type_eq_all`
|
||||
= note: this error originates in the macro `::uniffi::deps::static_assertions::assert_type_eq_all` (in Nightly builds, run with -Z macro-backtrace for more info)
|
Различия файлов скрыты, потому что одна или несколько строк слишком длинны
|
@ -4,9 +4,9 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.64"
|
||||
version = "1.0.63"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b9a8f622bcf6ff3df478e9deba3e03e4e04b300f8e6a139e192c05fa3490afc7"
|
||||
checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a"
|
||||
|
||||
[[package]]
|
||||
name = "askama"
|
||||
|
@ -99,9 +99,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "3.2.21"
|
||||
version = "3.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1ed5341b2301a26ab80be5cbdced622e80ed808483c52e45e3310a877d3b37d7"
|
||||
checksum = "68d43934757334b5c0519ff882e1ab9647ac0258b47c24c4f490d78e42697fd5"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"bitflags",
|
||||
|
@ -245,9 +245,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.14.0"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
|
||||
checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e"
|
||||
|
||||
[[package]]
|
||||
name = "os_str_bytes"
|
||||
|
@ -424,7 +424,7 @@ checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_bindgen"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"askama",
|
||||
|
@ -445,9 +445,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "uniffi_meta"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fe1767e693cbd11fc22c37a4033d82eb9d891c3862e45329b4a891c1d8395df5"
|
||||
checksum = "10d099cea0c721294ec11ae6c39d661c96d13d8994247ffadaf1576b065e38e6"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "uniffi_bindgen"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
|
||||
description = "a multi-language bindings generator for rust (codegen and cli tooling)"
|
||||
homepage = "https://mozilla.github.io/uniffi-rs"
|
||||
|
@ -76,7 +76,7 @@ version = "1.0.80"
|
|||
version = "0.5"
|
||||
|
||||
[dependencies.uniffi_meta]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
|
||||
[dependencies.weedle2]
|
||||
version = "4.0.0"
|
||||
|
|
|
@ -36,13 +36,10 @@ use std::hash::{Hash, Hasher};
|
|||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use super::attributes::{ArgumentAttributes, FunctionAttributes};
|
||||
use super::ffi::{FFIArgument, FFIFunction};
|
||||
use super::literal::{convert_default_value, Literal};
|
||||
use super::types::{Type, TypeIterator};
|
||||
use super::{
|
||||
attributes::{ArgumentAttributes, FunctionAttributes},
|
||||
convert_type,
|
||||
};
|
||||
use super::{APIConverter, ComponentInterface};
|
||||
|
||||
/// Represents a standalone function.
|
||||
|
@ -92,7 +89,7 @@ impl Function {
|
|||
}
|
||||
|
||||
pub fn derive_ffi_func(&mut self, ci_prefix: &str) -> Result<()> {
|
||||
// The name is already set if the function is defined through a proc-macro invocation
|
||||
// The name is already set if the function is defined in a proc-macro-generated JSON file
|
||||
// rather than in UDL. Don't overwrite it in that case.
|
||||
if self.ffi_func.name.is_empty() {
|
||||
self.ffi_func.name = format!("{ci_prefix}_{}", self.name);
|
||||
|
@ -138,6 +135,34 @@ impl From<uniffi_meta::FnMetadata> for Function {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_type(s: &uniffi_meta::Type) -> Type {
|
||||
use uniffi_meta::Type as Ty;
|
||||
|
||||
match s {
|
||||
Ty::U8 => Type::UInt8,
|
||||
Ty::U16 => Type::UInt16,
|
||||
Ty::U32 => Type::UInt32,
|
||||
Ty::U64 => Type::UInt64,
|
||||
Ty::I8 => Type::Int8,
|
||||
Ty::I16 => Type::Int16,
|
||||
Ty::I32 => Type::Int32,
|
||||
Ty::I64 => Type::Int64,
|
||||
Ty::F32 => Type::Float32,
|
||||
Ty::F64 => Type::Float64,
|
||||
Ty::Bool => Type::Boolean,
|
||||
Ty::String => Type::String,
|
||||
Ty::Option { inner_type } => Type::Optional(convert_type(inner_type).into()),
|
||||
Ty::Vec { inner_type } => Type::Sequence(convert_type(inner_type).into()),
|
||||
Ty::HashMap {
|
||||
key_type,
|
||||
value_type,
|
||||
} => Type::Map(
|
||||
convert_type(key_type).into(),
|
||||
convert_type(value_type).into(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Function {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// We don't include the FFIFunc in the hash calculation, because:
|
||||
|
|
|
@ -77,7 +77,6 @@ pub use record::{Field, Record};
|
|||
|
||||
pub mod ffi;
|
||||
pub use ffi::{FFIArgument, FFIFunction, FFIType};
|
||||
use uniffi_meta::MethodMetadata;
|
||||
|
||||
/// The main public interface for this module, representing the complete details of an interface exposed
|
||||
/// by a rust component and the details of consuming it via an extern-C FFI layer.
|
||||
|
@ -516,27 +515,6 @@ impl ComponentInterface {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) fn add_method_definition(&mut self, meta: MethodMetadata) -> Result<()> {
|
||||
let object = match self.objects.iter_mut().find(|o| o.name == meta.self_name) {
|
||||
Some(o) => o,
|
||||
None => {
|
||||
self.objects.push(Object::new(meta.self_name.clone()));
|
||||
self.objects.last_mut().unwrap()
|
||||
}
|
||||
};
|
||||
|
||||
let defn: Method = meta.into();
|
||||
for arg in &defn.arguments {
|
||||
self.types.add_known_type(arg.type_.clone())?;
|
||||
}
|
||||
if let Some(ty) = &defn.return_type {
|
||||
self.types.add_known_type(ty.clone())?;
|
||||
}
|
||||
object.methods.push(defn);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Called by `APIBuilder` impls to add a newly-parsed object definition to the `ComponentInterface`.
|
||||
fn add_object_definition(&mut self, defn: Object) {
|
||||
// Note that there will be no duplicates thanks to the previous type-finding pass.
|
||||
|
@ -807,35 +785,6 @@ impl<U, T: APIConverter<U>> APIConverter<Vec<U>> for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
fn convert_type(s: &uniffi_meta::Type) -> Type {
|
||||
use uniffi_meta::Type as Ty;
|
||||
|
||||
match s {
|
||||
Ty::U8 => Type::UInt8,
|
||||
Ty::U16 => Type::UInt16,
|
||||
Ty::U32 => Type::UInt32,
|
||||
Ty::U64 => Type::UInt64,
|
||||
Ty::I8 => Type::Int8,
|
||||
Ty::I16 => Type::Int16,
|
||||
Ty::I32 => Type::Int32,
|
||||
Ty::I64 => Type::Int64,
|
||||
Ty::F32 => Type::Float32,
|
||||
Ty::F64 => Type::Float64,
|
||||
Ty::Bool => Type::Boolean,
|
||||
Ty::String => Type::String,
|
||||
Ty::Option { inner_type } => Type::Optional(convert_type(inner_type).into()),
|
||||
Ty::Vec { inner_type } => Type::Sequence(convert_type(inner_type).into()),
|
||||
Ty::HashMap {
|
||||
key_type,
|
||||
value_type,
|
||||
} => Type::Map(
|
||||
convert_type(key_type).into(),
|
||||
convert_type(value_type).into(),
|
||||
),
|
||||
Ty::ArcObject { object_name } => Type::Object(object_name.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
|
|
@ -63,13 +63,10 @@ use std::{collections::HashSet, iter};
|
|||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use super::attributes::{ConstructorAttributes, InterfaceAttributes, MethodAttributes};
|
||||
use super::ffi::{FFIArgument, FFIFunction, FFIType};
|
||||
use super::function::Argument;
|
||||
use super::types::{Type, TypeIterator};
|
||||
use super::{
|
||||
attributes::{ConstructorAttributes, InterfaceAttributes, MethodAttributes},
|
||||
convert_type,
|
||||
};
|
||||
use super::{APIConverter, ComponentInterface};
|
||||
|
||||
/// An "object" is an opaque type that can be instantiated and passed around by reference,
|
||||
|
@ -96,7 +93,7 @@ pub struct Object {
|
|||
}
|
||||
|
||||
impl Object {
|
||||
pub(super) fn new(name: String) -> Object {
|
||||
fn new(name: String) -> Object {
|
||||
Object {
|
||||
name,
|
||||
constructors: Default::default(),
|
||||
|
@ -392,12 +389,7 @@ impl Method {
|
|||
}
|
||||
|
||||
pub fn derive_ffi_func(&mut self, ci_prefix: &str, obj_prefix: &str) -> Result<()> {
|
||||
// The name is already set if the function is defined through a proc-macro invocation
|
||||
// rather than in UDL. Don't overwrite it in that case.
|
||||
if self.ffi_func.name.is_empty() {
|
||||
self.ffi_func.name = format!("{ci_prefix}_{obj_prefix}_{}", self.name);
|
||||
}
|
||||
|
||||
self.ffi_func.name = format!("{ci_prefix}_{obj_prefix}_{}", self.name);
|
||||
self.ffi_func.arguments = self.full_arguments().iter().map(Into::into).collect();
|
||||
self.ffi_func.return_type = self.return_type.as_ref().map(Into::into);
|
||||
Ok(())
|
||||
|
@ -413,29 +405,6 @@ impl Method {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<uniffi_meta::MethodMetadata> for Method {
|
||||
fn from(meta: uniffi_meta::MethodMetadata) -> Self {
|
||||
let ffi_name = meta.ffi_symbol_name();
|
||||
|
||||
let return_type = meta.return_type.map(|out| convert_type(&out));
|
||||
let arguments = meta.inputs.into_iter().map(Into::into).collect();
|
||||
|
||||
let ffi_func = FFIFunction {
|
||||
name: ffi_name,
|
||||
..FFIFunction::default()
|
||||
};
|
||||
|
||||
Self {
|
||||
name: meta.name,
|
||||
object_name: meta.self_name,
|
||||
arguments,
|
||||
return_type,
|
||||
ffi_func,
|
||||
attributes: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hash for Method {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
// We don't include the FFIFunc in the hash calculation, because:
|
||||
|
|
|
@ -388,7 +388,7 @@ pub fn run_tests(
|
|||
/// For now, we assume that the UDL file is in `./src/something.udl` relative
|
||||
/// to the crate root. We might consider something more sophisticated in
|
||||
/// future.
|
||||
pub fn guess_crate_root(udl_file: &Utf8Path) -> Result<&Utf8Path> {
|
||||
fn guess_crate_root(udl_file: &Utf8Path) -> Result<&Utf8Path> {
|
||||
let path_guess = udl_file
|
||||
.parent()
|
||||
.context("UDL file has no parent folder!")?
|
||||
|
@ -428,7 +428,7 @@ fn get_out_dir(udl_file: &Utf8Path, out_dir_override: Option<&Utf8Path>) -> Resu
|
|||
Ok(match out_dir_override {
|
||||
Some(s) => {
|
||||
// Create the directory if it doesn't exist yet.
|
||||
fs::create_dir_all(s)?;
|
||||
fs::create_dir_all(&s)?;
|
||||
s.canonicalize_utf8().context("Unable to find out-dir")?
|
||||
}
|
||||
None => udl_file
|
||||
|
@ -537,9 +537,9 @@ enum Commands {
|
|||
#[clap(long, short)]
|
||||
config: Option<Utf8PathBuf>,
|
||||
|
||||
/// Extract proc-macro metadata from a native lib (cdylib or staticlib) for this crate.
|
||||
/// Extract proc-macro metadata from a cdylib for this crate
|
||||
#[clap(long)]
|
||||
lib_file: Option<Utf8PathBuf>,
|
||||
cdylib: Option<Utf8PathBuf>,
|
||||
|
||||
/// Path to the UDL file.
|
||||
udl_file: Utf8PathBuf,
|
||||
|
@ -594,14 +594,14 @@ pub fn run_main() -> Result<()> {
|
|||
out_dir,
|
||||
no_format,
|
||||
config,
|
||||
lib_file,
|
||||
cdylib,
|
||||
udl_file,
|
||||
} => crate::generate_bindings(
|
||||
udl_file,
|
||||
config.as_deref(),
|
||||
language.iter().map(String::as_str).collect(),
|
||||
out_dir.as_deref(),
|
||||
lib_file.as_deref(),
|
||||
cdylib.as_deref(),
|
||||
!no_format,
|
||||
),
|
||||
Commands::Scaffolding {
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::interface::ComponentInterface;
|
||||
use anyhow::anyhow;
|
||||
use uniffi_meta::Metadata;
|
||||
|
||||
/// Add Metadata items to the ComponentInterface
|
||||
|
@ -19,33 +18,10 @@ pub fn add_to_ci(
|
|||
metadata_items: Vec<Metadata>,
|
||||
) -> anyhow::Result<()> {
|
||||
for item in metadata_items {
|
||||
let (item_desc, crate_name) = match &item {
|
||||
Metadata::Func(meta) => (
|
||||
format!("function `{}`", meta.name),
|
||||
meta.module_path.first().unwrap(),
|
||||
),
|
||||
Metadata::Method(meta) => (
|
||||
format!("method `{}.{}`", meta.self_name, meta.name),
|
||||
meta.module_path.first().unwrap(),
|
||||
),
|
||||
};
|
||||
|
||||
let ns = iface.namespace();
|
||||
if crate_name != ns {
|
||||
return Err(anyhow!("Found {item_desc} from crate `{crate_name}`.")
|
||||
.context(format!(
|
||||
"Main crate is expected to be named `{ns}` based on the UDL namespace."
|
||||
))
|
||||
.context("Mixing symbols from multiple crates is not supported yet."));
|
||||
}
|
||||
|
||||
match item {
|
||||
Metadata::Func(meta) => {
|
||||
iface.add_function_definition(meta.into())?;
|
||||
}
|
||||
Metadata::Method(meta) => {
|
||||
iface.add_method_definition(meta)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -157,7 +157,6 @@ impl ExtractedItems {
|
|||
// Already extracted this item
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Use the file data starting from offset, without specifying the end position. We don't
|
||||
// always know the end position, because goblin reports the symbol size as 0 for PE and
|
||||
// MachO files.
|
||||
|
@ -166,7 +165,6 @@ impl ExtractedItems {
|
|||
// just ignore the trailing data.
|
||||
let data = &file_data[offset..];
|
||||
self.items.push(bincode::deserialize::<Metadata>(data)?);
|
||||
self.names.insert(name.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#}
|
||||
#[doc(hidden)]
|
||||
#[no_mangle]
|
||||
#[allow(clippy::let_unit_value)] // Sometimes we generate code that binds `_retval` to `()`.
|
||||
pub extern "C" fn r#{{ func.ffi_func().name() }}(
|
||||
{% call rs::arg_list_ffi_decl(func.ffi_func()) %}
|
||||
) {% call rs::return_signature(func) %} {
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"b4ebe427f0e8554d82ac58d6c5736f096f9efd1aa1dedeec9eff6785de3df6c2","src/lib.rs":"485a0c0ab99077a1d4037f4deec9801e87a248196e7589a002556fb84973528a"},"package":"74b65ae1c0bac70369bb0d9df6fae578b1ca130bf4cb6203e2636e2d6969dba5"}
|
||||
{"files":{"Cargo.toml":"37cbd8dcb462b29e57c9833b8a29c36a950565042d04db6db435c483371e1d35","src/lib.rs":"485a0c0ab99077a1d4037f4deec9801e87a248196e7589a002556fb84973528a"},"package":"8d6c6fedf97b345227270837fcfd8d9a799f202af7fa843298c788fb943b159f"}
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "uniffi_build"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
|
||||
description = "a multi-language bindings generator for rust (build script helpers)"
|
||||
homepage = "https://mozilla.github.io/uniffi-rs"
|
||||
|
@ -32,7 +32,7 @@ version = "1"
|
|||
version = "1.0.8"
|
||||
|
||||
[dependencies.uniffi_bindgen]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
optional = true
|
||||
|
||||
[features]
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"8263d68d6cc42f964c80a2b4defb96f77b0093b8931afbdbba5518509b66c091","src/export.rs":"ce8fff30de7341fed60c035bbeaa4d01aa590dba4964d592777faef208d1326e","src/export/metadata.rs":"b17921bf23191a8e00a579da4c525bdf1876523c79cc8d5af359d9760185fac1","src/export/metadata/convert.rs":"075d6d33605700a4597c099793455ab6e0babf94487be9aba0c2182c8677f8e0","src/export/metadata/function.rs":"11833cabd37e7671c0a01944bec73b8892a15df814bbe4c26fdae57aad89a2ba","src/export/metadata/impl_.rs":"ecfdaa132f05dd946414281e52165ef19c90c0bfd76ec651d4ec86837bd41d1c","src/export/scaffolding.rs":"66939405063e56fc983126f249e2d7ddc3257cb045a738abd0cf813a4aafc59c","src/lib.rs":"f37d2ede0b3893bdf9a74c1e5ddf00e5d6adc2269b52821e8c183177b0e30976","src/util.rs":"3278a098a6fe1f7f950ba706e242e49fae05cec8eb3d956dcec49770d6e764ab"},"package":"5efddfb993c5b394a75042c0d144665388af2ad3db628401ab8f4fb6f6d07e54"}
|
||||
{"files":{"Cargo.toml":"6fabeb7aaec0073c72c41a753f37154fd5ee067b75e219f505b828366a177949","src/export.rs":"b5c17b44672a92b6e354c39451448e12c01948f4e428c1289f99da72c1dc0259","src/export/metadata.rs":"12faefe7fa89cb764f1116d7a0d47a3d29c9dd7ec369370afce4f3e906aa4ea6","src/export/metadata/function.rs":"4ca0d3f648dbce7acf71539d48bc5cdb8891d5a5759bda30caa7d99397699207","src/export/scaffolding.rs":"bdffa85b4fac9ae131d28f6df3fe69f9be71071b73be8837c8822c13df0548d6","src/lib.rs":"9678be604c87850907ae8ee84fe7d0840d4586847efee0219e0fac40b196a976","src/util.rs":"3278a098a6fe1f7f950ba706e242e49fae05cec8eb3d956dcec49770d6e764ab"},"package":"090e5a993b51dc02faa0dc135ce94f02f050791bda283a5ae9f40fc9a4389a39"}
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "uniffi_macros"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
authors = ["Firefox Sync Team <sync-team@mozilla.com>"]
|
||||
description = "a multi-language bindings generator for rust (convenience macros)"
|
||||
homepage = "https://mozilla.github.io/uniffi-rs"
|
||||
|
@ -57,10 +57,10 @@ features = ["full"]
|
|||
version = "0.5.9"
|
||||
|
||||
[dependencies.uniffi_build]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
|
||||
[dependencies.uniffi_meta]
|
||||
version = "=0.20.0"
|
||||
version = "=0.19.6"
|
||||
|
||||
[features]
|
||||
builtin-bindgen = ["uniffi_build/builtin-bindgen"]
|
||||
|
|
|
@ -2,149 +2,26 @@
|
|||
* 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 std::collections::BTreeMap;
|
||||
|
||||
use proc_macro2::{Ident, TokenStream};
|
||||
use quote::{format_ident, quote};
|
||||
use uniffi_meta::{checksum, FnMetadata, Metadata, MethodMetadata, Type};
|
||||
use proc_macro2::TokenStream;
|
||||
|
||||
mod metadata;
|
||||
mod scaffolding;
|
||||
|
||||
pub use self::metadata::gen_metadata;
|
||||
use self::scaffolding::{gen_fn_scaffolding, gen_method_scaffolding};
|
||||
use crate::export::metadata::convert::convert_type;
|
||||
use self::metadata::gen_metadata;
|
||||
use self::scaffolding::gen_scaffolding;
|
||||
|
||||
// TODO(jplatte): Ensure no generics, no async, …
|
||||
// TODO(jplatte): Aggregate errors instead of short-circuiting, whereever possible
|
||||
|
||||
pub enum ExportItem {
|
||||
enum ExportItem {
|
||||
Function {
|
||||
sig: Box<syn::Signature>,
|
||||
metadata: FnMetadata,
|
||||
},
|
||||
Impl {
|
||||
self_ident: Ident,
|
||||
methods: Vec<syn::Result<Method>>,
|
||||
item: syn::ItemFn,
|
||||
checksum: u16,
|
||||
meta_static_var: TokenStream,
|
||||
},
|
||||
}
|
||||
|
||||
pub struct Method {
|
||||
item: syn::ImplItemMethod,
|
||||
metadata: MethodMetadata,
|
||||
}
|
||||
|
||||
pub fn expand_export(metadata: ExportItem, mod_path: &[String]) -> TokenStream {
|
||||
match metadata {
|
||||
ExportItem::Function { sig, metadata } => {
|
||||
let checksum = checksum(&metadata);
|
||||
let scaffolding = gen_fn_scaffolding(&sig, mod_path, checksum);
|
||||
let type_assertions = fn_type_assertions(&sig);
|
||||
let meta_static_var = create_metadata_static_var(&sig.ident, metadata.into());
|
||||
|
||||
quote! {
|
||||
#scaffolding
|
||||
#type_assertions
|
||||
#meta_static_var
|
||||
}
|
||||
}
|
||||
ExportItem::Impl {
|
||||
methods,
|
||||
self_ident,
|
||||
} => methods
|
||||
.into_iter()
|
||||
.map(|res| {
|
||||
res.map_or_else(
|
||||
syn::Error::into_compile_error,
|
||||
|Method { item, metadata }| {
|
||||
let checksum = checksum(&metadata);
|
||||
let scaffolding =
|
||||
gen_method_scaffolding(&item.sig, mod_path, checksum, &self_ident);
|
||||
let meta_static_var =
|
||||
create_metadata_static_var(&item.sig.ident, metadata.into());
|
||||
|
||||
quote! {
|
||||
#scaffolding
|
||||
#meta_static_var
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
fn fn_type_assertions(sig: &syn::Signature) -> TokenStream {
|
||||
// Convert uniffi_meta::Type back to a Rust type
|
||||
fn convert_type_back(ty: &Type) -> TokenStream {
|
||||
match &ty {
|
||||
Type::U8 => quote! { ::std::primitive::u8 },
|
||||
Type::U16 => quote! { ::std::primitive::u16 },
|
||||
Type::U32 => quote! { ::std::primitive::u32 },
|
||||
Type::U64 => quote! { ::std::primitive::u64 },
|
||||
Type::I8 => quote! { ::std::primitive::i8 },
|
||||
Type::I16 => quote! { ::std::primitive::i16 },
|
||||
Type::I32 => quote! { ::std::primitive::i32 },
|
||||
Type::I64 => quote! { ::std::primitive::i64 },
|
||||
Type::F32 => quote! { ::std::primitive::f32 },
|
||||
Type::F64 => quote! { ::std::primitive::f64 },
|
||||
Type::Bool => quote! { ::std::primitive::bool },
|
||||
Type::String => quote! { ::std::string::String },
|
||||
Type::Option { inner_type } => {
|
||||
let inner = convert_type_back(inner_type);
|
||||
quote! { ::std::option::Option<#inner> }
|
||||
}
|
||||
Type::Vec { inner_type } => {
|
||||
let inner = convert_type_back(inner_type);
|
||||
quote! { ::std::vec::Vec<#inner> }
|
||||
}
|
||||
Type::HashMap {
|
||||
key_type,
|
||||
value_type,
|
||||
} => {
|
||||
let key = convert_type_back(key_type);
|
||||
let value = convert_type_back(value_type);
|
||||
quote! { ::std::collections::HashMap<#key, #value> }
|
||||
}
|
||||
Type::ArcObject { object_name } => {
|
||||
let object_ident = format_ident!("{object_name}");
|
||||
quote! { ::std::sync::Arc<crate::uniffi_types::#object_ident> }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let input_types = sig.inputs.iter().filter_map(|input| match input {
|
||||
syn::FnArg::Receiver(_) => None,
|
||||
syn::FnArg::Typed(pat_ty) => Some(&pat_ty.ty),
|
||||
});
|
||||
let output_type = match &sig.output {
|
||||
syn::ReturnType::Default => None,
|
||||
syn::ReturnType::Type(_, ty) => Some(ty),
|
||||
};
|
||||
|
||||
let type_assertions: BTreeMap<_, _> = input_types
|
||||
.chain(output_type)
|
||||
.filter_map(|ty| {
|
||||
convert_type(ty).ok().map(|meta_ty| {
|
||||
let expected_ty = convert_type_back(&meta_ty);
|
||||
let assert = quote! {
|
||||
::uniffi::deps::static_assertions::assert_type_eq_all!(#ty, #expected_ty);
|
||||
};
|
||||
(meta_ty, assert)
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
type_assertions.into_values().collect()
|
||||
}
|
||||
|
||||
fn create_metadata_static_var(name: &Ident, val: Metadata) -> TokenStream {
|
||||
let data: Vec<u8> = bincode::serialize(&val).expect("Error serializing metadata item");
|
||||
let count = data.len();
|
||||
let var_name = format_ident!("UNIFFI_META_{}", name);
|
||||
|
||||
quote! {
|
||||
#[no_mangle]
|
||||
pub static #var_name: [u8; #count] = [#(#data),*];
|
||||
}
|
||||
pub fn expand_export(item: syn::Item, mod_path: &[String]) -> syn::Result<TokenStream> {
|
||||
let item = gen_metadata(item, mod_path)?;
|
||||
gen_scaffolding(item, mod_path)
|
||||
}
|
||||
|
|
|
@ -2,20 +2,23 @@
|
|||
* 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 proc_macro2::Span;
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use quote::{format_ident, quote, IdentFragment, ToTokens};
|
||||
use uniffi_meta::{Metadata, Type};
|
||||
|
||||
use super::ExportItem;
|
||||
|
||||
pub(super) mod convert;
|
||||
mod function;
|
||||
mod impl_;
|
||||
|
||||
use self::{function::gen_fn_metadata, impl_::gen_impl_metadata};
|
||||
use self::function::gen_fn_metadata;
|
||||
|
||||
pub fn gen_metadata(item: syn::Item, mod_path: &[String]) -> syn::Result<ExportItem> {
|
||||
pub(super) fn gen_metadata(item: syn::Item, mod_path: &[String]) -> syn::Result<ExportItem> {
|
||||
match item {
|
||||
syn::Item::Fn(item) => gen_fn_metadata(item.sig, mod_path),
|
||||
syn::Item::Impl(item) => gen_impl_metadata(item, mod_path),
|
||||
syn::Item::Fn(item) => gen_fn_metadata(item, mod_path),
|
||||
syn::Item::Impl(_) => Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
"impl blocks are not yet supported",
|
||||
)),
|
||||
// FIXME: Support const / static?
|
||||
_ => Err(syn::Error::new(
|
||||
Span::call_site(),
|
||||
|
@ -24,3 +27,140 @@ pub fn gen_metadata(item: syn::Item, mod_path: &[String]) -> syn::Result<ExportI
|
|||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_type(ty: &syn::Type) -> syn::Result<Type> {
|
||||
let type_path = type_as_type_path(ty)?;
|
||||
|
||||
if type_path.qself.is_some() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"qualified self types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
if type_path.path.segments.len() > 1 {
|
||||
return Err(syn::Error::new_spanned(
|
||||
&type_path,
|
||||
"qualified paths in types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
match &type_path.path.segments.first() {
|
||||
Some(seg) => match &seg.arguments {
|
||||
syn::PathArguments::None => convert_bare_type_name(&seg.ident),
|
||||
syn::PathArguments::AngleBracketed(a) => convert_generic_type(&seg.ident, a),
|
||||
syn::PathArguments::Parenthesized(_) => Err(type_not_supported(type_path)),
|
||||
},
|
||||
None => Err(syn::Error::new_spanned(
|
||||
&type_path,
|
||||
"unreachable: TypePath must have non-empty segments",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type(
|
||||
ident: &Ident,
|
||||
a: &syn::AngleBracketedGenericArguments,
|
||||
) -> syn::Result<Type> {
|
||||
let mut it = a.args.iter();
|
||||
match it.next() {
|
||||
// `u8<>` is a valid way to write `u8` in the type namespace, so why not?
|
||||
None => convert_bare_type_name(ident),
|
||||
Some(arg1) => match it.next() {
|
||||
None => convert_generic_type1(ident, arg1),
|
||||
Some(arg2) => match it.next() {
|
||||
None => convert_generic_type2(ident, arg1, arg2),
|
||||
Some(_) => Err(syn::Error::new_spanned(
|
||||
ident,
|
||||
"types with more than two generics are not currently
|
||||
supported by uniffi::export",
|
||||
)),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_bare_type_name(ident: &Ident) -> syn::Result<Type> {
|
||||
match ident.to_string().as_str() {
|
||||
"u8" => Ok(Type::U8),
|
||||
"u16" => Ok(Type::U16),
|
||||
"u32" => Ok(Type::U32),
|
||||
"u64" => Ok(Type::U64),
|
||||
"i8" => Ok(Type::I8),
|
||||
"i16" => Ok(Type::I16),
|
||||
"i32" => Ok(Type::I32),
|
||||
"i64" => Ok(Type::I64),
|
||||
"f32" => Ok(Type::F32),
|
||||
"f64" => Ok(Type::F64),
|
||||
"bool" => Ok(Type::Bool),
|
||||
"String" => Ok(Type::String),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type1(ident: &Ident, arg: &syn::GenericArgument) -> syn::Result<Type> {
|
||||
let arg = arg_as_type(arg)?;
|
||||
match ident.to_string().as_str() {
|
||||
"Option" => Ok(Type::Option {
|
||||
inner_type: convert_type(arg)?.into(),
|
||||
}),
|
||||
"Vec" => Ok(Type::Vec {
|
||||
inner_type: convert_type(arg)?.into(),
|
||||
}),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type2(
|
||||
ident: &Ident,
|
||||
arg1: &syn::GenericArgument,
|
||||
arg2: &syn::GenericArgument,
|
||||
) -> syn::Result<Type> {
|
||||
let arg1 = arg_as_type(arg1)?;
|
||||
let arg2 = arg_as_type(arg2)?;
|
||||
|
||||
match ident.to_string().as_str() {
|
||||
"HashMap" => Ok(Type::HashMap {
|
||||
key_type: convert_type(arg1)?.into(),
|
||||
value_type: convert_type(arg2)?.into(),
|
||||
}),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
fn type_as_type_path(ty: &syn::Type) -> syn::Result<&syn::TypePath> {
|
||||
match ty {
|
||||
syn::Type::Group(g) => type_as_type_path(&g.elem),
|
||||
syn::Type::Paren(p) => type_as_type_path(&p.elem),
|
||||
syn::Type::Path(p) => Ok(p),
|
||||
_ => Err(type_not_supported(ty)),
|
||||
}
|
||||
}
|
||||
|
||||
fn arg_as_type(arg: &syn::GenericArgument) -> syn::Result<&syn::Type> {
|
||||
match arg {
|
||||
syn::GenericArgument::Type(t) => Ok(t),
|
||||
_ => Err(syn::Error::new_spanned(
|
||||
arg,
|
||||
"non-type generic parameters are not currently supported by uniffi::export",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn type_not_supported(ty: &impl ToTokens) -> syn::Error {
|
||||
syn::Error::new_spanned(
|
||||
&ty,
|
||||
"this type is not currently supported by uniffi::export in this position",
|
||||
)
|
||||
}
|
||||
|
||||
fn create_metadata_static_var(name: impl IdentFragment, val: Metadata) -> TokenStream {
|
||||
let data: Vec<u8> = bincode::serialize(&val).expect("Error serializing metadata item");
|
||||
let count = data.len();
|
||||
let var_name = format_ident!("UNIFFI_META_{}", name);
|
||||
|
||||
quote! {
|
||||
#[no_mangle]
|
||||
pub static #var_name: [u8; #count] = [#(#data),*];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,171 +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/. */
|
||||
|
||||
use proc_macro2::Ident;
|
||||
use quote::ToTokens;
|
||||
use syn::{punctuated::Punctuated, Token};
|
||||
use uniffi_meta::{FnParamMetadata, Type};
|
||||
|
||||
pub(super) fn fn_param_metadata(
|
||||
params: &Punctuated<syn::FnArg, Token![,]>,
|
||||
) -> syn::Result<Vec<FnParamMetadata>> {
|
||||
params
|
||||
.iter()
|
||||
.filter_map(|a| {
|
||||
let _is_method = false;
|
||||
let (name, ty) = match a {
|
||||
syn::FnArg::Receiver(_) => return None,
|
||||
syn::FnArg::Typed(pat_ty) => {
|
||||
let name = match &*pat_ty.pat {
|
||||
syn::Pat::Ident(pat_id) => pat_id.ident.to_string(),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
(name, &pat_ty.ty)
|
||||
}
|
||||
};
|
||||
|
||||
Some(convert_type(ty).map(|ty| FnParamMetadata { name, ty }))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn return_type_metadata(ty: &syn::ReturnType) -> syn::Result<Option<Type>> {
|
||||
Ok(match ty {
|
||||
syn::ReturnType::Default => None,
|
||||
syn::ReturnType::Type(_, ty) => Some(convert_type(ty)?),
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn convert_type(ty: &syn::Type) -> syn::Result<Type> {
|
||||
let type_path = type_as_type_path(ty)?;
|
||||
|
||||
if type_path.qself.is_some() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"qualified self types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
if type_path.path.segments.len() > 1 {
|
||||
return Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"qualified paths in types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
match &type_path.path.segments.first() {
|
||||
Some(seg) => match &seg.arguments {
|
||||
syn::PathArguments::None => convert_bare_type_name(&seg.ident),
|
||||
syn::PathArguments::AngleBracketed(a) => convert_generic_type(&seg.ident, a),
|
||||
syn::PathArguments::Parenthesized(_) => Err(type_not_supported(type_path)),
|
||||
},
|
||||
None => Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"unreachable: TypePath must have non-empty segments",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type(
|
||||
ident: &Ident,
|
||||
a: &syn::AngleBracketedGenericArguments,
|
||||
) -> syn::Result<Type> {
|
||||
let mut it = a.args.iter();
|
||||
match it.next() {
|
||||
// `u8<>` is a valid way to write `u8` in the type namespace, so why not?
|
||||
None => convert_bare_type_name(ident),
|
||||
Some(arg1) => match it.next() {
|
||||
None => convert_generic_type1(ident, arg1),
|
||||
Some(arg2) => match it.next() {
|
||||
None => convert_generic_type2(ident, arg1, arg2),
|
||||
Some(_) => Err(syn::Error::new_spanned(
|
||||
ident,
|
||||
"types with more than two generics are not currently
|
||||
supported by uniffi::export",
|
||||
)),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_bare_type_name(ident: &Ident) -> syn::Result<Type> {
|
||||
match ident.to_string().as_str() {
|
||||
"u8" => Ok(Type::U8),
|
||||
"u16" => Ok(Type::U16),
|
||||
"u32" => Ok(Type::U32),
|
||||
"u64" => Ok(Type::U64),
|
||||
"i8" => Ok(Type::I8),
|
||||
"i16" => Ok(Type::I16),
|
||||
"i32" => Ok(Type::I32),
|
||||
"i64" => Ok(Type::I64),
|
||||
"f32" => Ok(Type::F32),
|
||||
"f64" => Ok(Type::F64),
|
||||
"bool" => Ok(Type::Bool),
|
||||
"String" => Ok(Type::String),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type1(ident: &Ident, arg: &syn::GenericArgument) -> syn::Result<Type> {
|
||||
let arg = arg_as_type(arg)?;
|
||||
match ident.to_string().as_str() {
|
||||
"Arc" => Ok(Type::ArcObject {
|
||||
object_name: type_as_type_path(arg)?
|
||||
.path
|
||||
.get_ident()
|
||||
.ok_or_else(|| type_not_supported(arg))?
|
||||
.to_string(),
|
||||
}),
|
||||
"Option" => Ok(Type::Option {
|
||||
inner_type: convert_type(arg)?.into(),
|
||||
}),
|
||||
"Vec" => Ok(Type::Vec {
|
||||
inner_type: convert_type(arg)?.into(),
|
||||
}),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
fn convert_generic_type2(
|
||||
ident: &Ident,
|
||||
arg1: &syn::GenericArgument,
|
||||
arg2: &syn::GenericArgument,
|
||||
) -> syn::Result<Type> {
|
||||
let arg1 = arg_as_type(arg1)?;
|
||||
let arg2 = arg_as_type(arg2)?;
|
||||
|
||||
match ident.to_string().as_str() {
|
||||
"HashMap" => Ok(Type::HashMap {
|
||||
key_type: convert_type(arg1)?.into(),
|
||||
value_type: convert_type(arg2)?.into(),
|
||||
}),
|
||||
_ => Err(type_not_supported(ident)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn type_as_type_path(ty: &syn::Type) -> syn::Result<&syn::TypePath> {
|
||||
match ty {
|
||||
syn::Type::Group(g) => type_as_type_path(&g.elem),
|
||||
syn::Type::Paren(p) => type_as_type_path(&p.elem),
|
||||
syn::Type::Path(p) => Ok(p),
|
||||
_ => Err(type_not_supported(ty)),
|
||||
}
|
||||
}
|
||||
|
||||
fn arg_as_type(arg: &syn::GenericArgument) -> syn::Result<&syn::Type> {
|
||||
match arg {
|
||||
syn::GenericArgument::Type(t) => Ok(t),
|
||||
_ => Err(syn::Error::new_spanned(
|
||||
arg,
|
||||
"non-type generic parameters are not currently supported by uniffi::export",
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn type_not_supported(ty: &impl ToTokens) -> syn::Error {
|
||||
syn::Error::new_spanned(
|
||||
ty,
|
||||
"this type is not currently supported by uniffi::export in this position",
|
||||
)
|
||||
}
|
|
@ -2,25 +2,54 @@
|
|||
* 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 uniffi_meta::FnMetadata;
|
||||
use uniffi_meta::{checksum, FnMetadata, FnParamMetadata};
|
||||
|
||||
use super::convert::{fn_param_metadata, return_type_metadata};
|
||||
use super::{convert_type, create_metadata_static_var};
|
||||
use crate::export::ExportItem;
|
||||
|
||||
pub(super) fn gen_fn_metadata(sig: syn::Signature, mod_path: &[String]) -> syn::Result<ExportItem> {
|
||||
let metadata = fn_metadata(&sig, mod_path)?;
|
||||
pub(super) fn gen_fn_metadata(item: syn::ItemFn, mod_path: &[String]) -> syn::Result<ExportItem> {
|
||||
let meta = fn_metadata(&item, mod_path)?;
|
||||
|
||||
Ok(ExportItem::Function {
|
||||
sig: Box::new(sig),
|
||||
metadata,
|
||||
checksum: checksum(&meta),
|
||||
meta_static_var: create_metadata_static_var(&item.sig.ident, meta.into()),
|
||||
item,
|
||||
})
|
||||
}
|
||||
|
||||
fn fn_metadata(sig: &syn::Signature, mod_path: &[String]) -> syn::Result<FnMetadata> {
|
||||
fn fn_metadata(f: &syn::ItemFn, mod_path: &[String]) -> syn::Result<FnMetadata> {
|
||||
let return_type = match &f.sig.output {
|
||||
syn::ReturnType::Default => None,
|
||||
syn::ReturnType::Type(_, ty) => Some(convert_type(ty)?),
|
||||
};
|
||||
|
||||
Ok(FnMetadata {
|
||||
module_path: mod_path.to_owned(),
|
||||
name: sig.ident.to_string(),
|
||||
inputs: fn_param_metadata(&sig.inputs)?,
|
||||
return_type: return_type_metadata(&sig.output)?,
|
||||
name: f.sig.ident.to_string(),
|
||||
inputs: f
|
||||
.sig
|
||||
.inputs
|
||||
.iter()
|
||||
.map(|a| fn_param_metadata(a, false))
|
||||
.collect::<syn::Result<_>>()?,
|
||||
return_type,
|
||||
})
|
||||
}
|
||||
|
||||
fn fn_param_metadata(a: &syn::FnArg, _is_method: bool) -> syn::Result<FnParamMetadata> {
|
||||
let (name, ty) = match a {
|
||||
syn::FnArg::Receiver(_) => unimplemented!(),
|
||||
syn::FnArg::Typed(pat_ty) => {
|
||||
let name = match &*pat_ty.pat {
|
||||
syn::Pat::Ident(pat_id) => pat_id.ident.to_string(),
|
||||
_ => unimplemented!(),
|
||||
};
|
||||
(name, &pat_ty.ty)
|
||||
}
|
||||
};
|
||||
|
||||
Ok(FnParamMetadata {
|
||||
name,
|
||||
ty: convert_type(ty)?,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,84 +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/. */
|
||||
|
||||
use uniffi_meta::MethodMetadata;
|
||||
|
||||
use super::convert::{fn_param_metadata, return_type_metadata, type_as_type_path};
|
||||
use crate::export::{ExportItem, Method};
|
||||
|
||||
pub(super) fn gen_impl_metadata(
|
||||
item: syn::ItemImpl,
|
||||
mod_path: &[String],
|
||||
) -> syn::Result<ExportItem> {
|
||||
if !item.generics.params.is_empty() || item.generics.where_clause.is_some() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
&item.generics,
|
||||
"generic impls are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
let type_path = type_as_type_path(&item.self_ty)?;
|
||||
|
||||
if type_path.qself.is_some() {
|
||||
return Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"qualified self types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
|
||||
let self_ident = match type_path.path.get_ident() {
|
||||
Some(id) => id,
|
||||
None => {
|
||||
return Err(syn::Error::new_spanned(
|
||||
type_path,
|
||||
"qualified paths in self-types are not currently supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let methods = item
|
||||
.items
|
||||
.into_iter()
|
||||
.map(|it| gen_method_metadata(it, &self_ident.to_string(), mod_path))
|
||||
.collect();
|
||||
|
||||
Ok(ExportItem::Impl {
|
||||
methods,
|
||||
self_ident: self_ident.to_owned(),
|
||||
})
|
||||
}
|
||||
|
||||
fn gen_method_metadata(
|
||||
it: syn::ImplItem,
|
||||
self_name: &str,
|
||||
mod_path: &[String],
|
||||
) -> syn::Result<Method> {
|
||||
let item = match it {
|
||||
syn::ImplItem::Method(m) => m,
|
||||
_ => {
|
||||
return Err(syn::Error::new_spanned(
|
||||
it,
|
||||
"only methods are supported in impl blocks annotated with uniffi::export",
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
let metadata = method_metadata(self_name, &item, mod_path)?;
|
||||
|
||||
Ok(Method { item, metadata })
|
||||
}
|
||||
|
||||
fn method_metadata(
|
||||
self_name: &str,
|
||||
f: &syn::ImplItemMethod,
|
||||
mod_path: &[String],
|
||||
) -> syn::Result<MethodMetadata> {
|
||||
Ok(MethodMetadata {
|
||||
module_path: mod_path.to_owned(),
|
||||
self_name: self_name.to_owned(),
|
||||
name: f.sig.ident.to_string(),
|
||||
inputs: fn_param_metadata(&f.sig.inputs)?,
|
||||
return_type: return_type_metadata(&f.sig.output)?,
|
||||
})
|
||||
}
|
|
@ -3,175 +3,99 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use proc_macro2::{Ident, Span, TokenStream};
|
||||
use quote::{format_ident, quote, ToTokens};
|
||||
use syn::{FnArg, Pat, ReturnType, Signature};
|
||||
use quote::{format_ident, quote};
|
||||
use syn::{FnArg, ItemFn, Pat, ReturnType};
|
||||
|
||||
pub(super) fn gen_fn_scaffolding(
|
||||
sig: &Signature,
|
||||
use super::ExportItem;
|
||||
|
||||
pub(super) fn gen_scaffolding(item: ExportItem, mod_path: &[String]) -> syn::Result<TokenStream> {
|
||||
match item {
|
||||
ExportItem::Function {
|
||||
item,
|
||||
checksum,
|
||||
meta_static_var,
|
||||
} => {
|
||||
let scaffolding = gen_fn_scaffolding(&item, mod_path, checksum)?;
|
||||
Ok(quote! {
|
||||
#scaffolding
|
||||
#meta_static_var
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gen_fn_scaffolding(
|
||||
item: &ItemFn,
|
||||
mod_path: &[String],
|
||||
checksum: u16,
|
||||
) -> TokenStream {
|
||||
let name = &sig.ident;
|
||||
) -> syn::Result<TokenStream> {
|
||||
let name = &item.sig.ident;
|
||||
let name_s = name.to_string();
|
||||
|
||||
let ffi_ident = Ident::new(
|
||||
let ffi_name = Ident::new(
|
||||
&uniffi_meta::fn_ffi_symbol_name(mod_path, &name_s, checksum),
|
||||
Span::call_site(),
|
||||
);
|
||||
|
||||
const ERROR_MSG: &str =
|
||||
"uniffi::export must be used on the impl block, not its containing fn's";
|
||||
let (params, args): (Vec<_>, Vec<_>) = collect_params(&sig.inputs, ERROR_MSG).unzip();
|
||||
let mut params = Vec::new();
|
||||
let mut args = Vec::new();
|
||||
|
||||
for (i, arg) in item.sig.inputs.iter().enumerate() {
|
||||
match arg {
|
||||
FnArg::Receiver(receiver) => {
|
||||
return Err(syn::Error::new_spanned(
|
||||
receiver,
|
||||
"methods are not yet supported by uniffi::export",
|
||||
));
|
||||
}
|
||||
FnArg::Typed(pat_ty) => {
|
||||
let ty = &pat_ty.ty;
|
||||
let name = format_ident!("arg{i}");
|
||||
|
||||
params.push(quote! { #name: <#ty as ::uniffi::FfiConverter>::FfiType });
|
||||
|
||||
let panic_fmt = match &*pat_ty.pat {
|
||||
Pat::Ident(i) => {
|
||||
format!("Failed to convert arg '{}': {{}}", i.ident)
|
||||
}
|
||||
_ => {
|
||||
format!("Failed to convert arg #{i}: {{}}")
|
||||
}
|
||||
};
|
||||
args.push(quote! {
|
||||
<#ty as ::uniffi::FfiConverter>::try_lift(#name).unwrap_or_else(|err| {
|
||||
::std::panic!(#panic_fmt, err)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let fn_call = quote! {
|
||||
#name(#(#args),*)
|
||||
};
|
||||
|
||||
gen_ffi_function(sig, ffi_ident, ¶ms, fn_call)
|
||||
}
|
||||
|
||||
pub(super) fn gen_method_scaffolding(
|
||||
sig: &syn::Signature,
|
||||
mod_path: &[String],
|
||||
checksum: u16,
|
||||
self_ident: &Ident,
|
||||
) -> TokenStream {
|
||||
let name = &sig.ident;
|
||||
let name_s = name.to_string();
|
||||
|
||||
let ffi_name = format!("impl_{self_ident}_{name_s}");
|
||||
let ffi_ident = Ident::new(
|
||||
&uniffi_meta::fn_ffi_symbol_name(mod_path, &ffi_name, checksum),
|
||||
Span::call_site(),
|
||||
);
|
||||
|
||||
let mut params_args = (Vec::new(), Vec::new());
|
||||
|
||||
const RECEIVER_ERROR: &str = "unreachable: only first parameter can be method receiver";
|
||||
let mut assoc_fn_error = None;
|
||||
let fn_call_prefix = match sig.inputs.first() {
|
||||
Some(arg) if is_receiver(arg) => {
|
||||
let ffi_converter = quote! {
|
||||
<::std::sync::Arc<#self_ident> as ::uniffi::FfiConverter>
|
||||
};
|
||||
|
||||
params_args.0.push(quote! { this: #ffi_converter::FfiType });
|
||||
|
||||
let remaining_args = sig.inputs.iter().skip(1);
|
||||
params_args.extend(collect_params(remaining_args, RECEIVER_ERROR));
|
||||
|
||||
quote! {
|
||||
#ffi_converter::try_lift(this).unwrap_or_else(|err| {
|
||||
::std::panic!("Failed to convert arg 'self': {}", err)
|
||||
}).
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
assoc_fn_error = Some(
|
||||
syn::Error::new_spanned(sig, "associated functions are not currently supported")
|
||||
.into_compile_error(),
|
||||
);
|
||||
params_args.extend(collect_params(&sig.inputs, RECEIVER_ERROR));
|
||||
quote! { #self_ident:: }
|
||||
}
|
||||
};
|
||||
|
||||
let (params, args) = params_args;
|
||||
|
||||
let fn_call = quote! {
|
||||
#assoc_fn_error
|
||||
#fn_call_prefix #name(#(#args),*)
|
||||
};
|
||||
|
||||
gen_ffi_function(sig, ffi_ident, ¶ms, fn_call)
|
||||
}
|
||||
|
||||
fn is_receiver(fn_arg: &FnArg) -> bool {
|
||||
match fn_arg {
|
||||
FnArg::Receiver(_) => true,
|
||||
FnArg::Typed(pat_ty) => matches!(&*pat_ty.pat, Pat::Ident(i) if i.ident == "self"),
|
||||
}
|
||||
}
|
||||
|
||||
fn collect_params<'a>(
|
||||
inputs: impl IntoIterator<Item = &'a FnArg> + 'a,
|
||||
receiver_error_msg: &'static str,
|
||||
) -> impl Iterator<Item = (TokenStream, TokenStream)> + 'a {
|
||||
fn receiver_error(
|
||||
receiver: impl ToTokens,
|
||||
receiver_error_msg: &str,
|
||||
) -> (TokenStream, TokenStream) {
|
||||
let param = quote! { &self };
|
||||
let arg = syn::Error::new_spanned(receiver, receiver_error_msg).into_compile_error();
|
||||
(param, arg)
|
||||
}
|
||||
|
||||
inputs.into_iter().enumerate().map(|(i, arg)| {
|
||||
let (ty, name) = match arg {
|
||||
FnArg::Receiver(r) => {
|
||||
return receiver_error(r, receiver_error_msg);
|
||||
}
|
||||
FnArg::Typed(pat_ty) => {
|
||||
let name = match &*pat_ty.pat {
|
||||
Pat::Ident(i) if i.ident == "self" => {
|
||||
return receiver_error(i, receiver_error_msg);
|
||||
}
|
||||
Pat::Ident(i) => Some(i.ident.to_string()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
(&pat_ty.ty, name)
|
||||
}
|
||||
};
|
||||
|
||||
let arg_n = format_ident!("arg{i}");
|
||||
let param = quote! { #arg_n: <#ty as ::uniffi::FfiConverter>::FfiType };
|
||||
|
||||
let panic_fmt = match name {
|
||||
Some(name) => format!("Failed to convert arg '{name}': {{}}"),
|
||||
None => format!("Failed to convert arg #{i}: {{}}"),
|
||||
};
|
||||
let arg = quote! {
|
||||
<#ty as ::uniffi::FfiConverter>::try_lift(#arg_n).unwrap_or_else(|err| {
|
||||
::std::panic!(#panic_fmt, err)
|
||||
})
|
||||
};
|
||||
|
||||
(param, arg)
|
||||
})
|
||||
}
|
||||
|
||||
fn gen_ffi_function(
|
||||
sig: &syn::Signature,
|
||||
ffi_ident: Ident,
|
||||
params: &[TokenStream],
|
||||
rust_fn_call: TokenStream,
|
||||
) -> TokenStream {
|
||||
let name = &sig.ident;
|
||||
let name_s = name.to_string();
|
||||
|
||||
// FIXME(jplatte): Use an extra trait implemented for `T: FfiConverter` as
|
||||
// well as `()` so no different codegen is needed?
|
||||
let (output, return_expr);
|
||||
match &sig.output {
|
||||
match &item.sig.output {
|
||||
ReturnType::Default => {
|
||||
output = None;
|
||||
return_expr = rust_fn_call;
|
||||
return_expr = fn_call;
|
||||
}
|
||||
ReturnType::Type(_, ty) => {
|
||||
output = Some(quote! {
|
||||
-> <#ty as ::uniffi::FfiConverter>::FfiType
|
||||
});
|
||||
return_expr = quote! {
|
||||
<#ty as ::uniffi::FfiConverter>::lower(#rust_fn_call)
|
||||
<#ty as ::uniffi::FfiConverter>::lower(#fn_call)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
quote! {
|
||||
Ok(quote! {
|
||||
#[doc(hidden)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn #ffi_ident(
|
||||
pub extern "C" fn #ffi_name(
|
||||
#(#params,)*
|
||||
call_status: &mut ::uniffi::RustCallStatus,
|
||||
) #output {
|
||||
|
@ -180,5 +104,5 @@ fn gen_ffi_function(
|
|||
#return_expr
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -28,8 +28,7 @@ pub fn export(
|
|||
let gen_output = || {
|
||||
let mod_path = util::mod_path()?;
|
||||
let item = syn::parse(input)?;
|
||||
let metadata = export::gen_metadata(item, &mod_path)?;
|
||||
Ok(expand_export(metadata, &mod_path))
|
||||
expand_export(item, &mod_path)
|
||||
};
|
||||
let output = gen_output().unwrap_or_else(syn::Error::into_compile_error);
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"ec0a05f6721f0ece7dff220b2080ffa83179c6715f2476aecee83736fc37d63a","src/lib.rs":"a178a5ee798d2b4d98d597de42aa182900f850f611d534e2f16e6f03b9385e92"},"package":"fe1767e693cbd11fc22c37a4033d82eb9d891c3862e45329b4a891c1d8395df5"}
|
||||
{"files":{"Cargo.toml":"7325f41f20eae641f84338520e31efb47c35bf8c5509fb024d00d09455fe0d87","src/lib.rs":"923e1119ef7d654aa794f62287b66dfb14c84c7b06f8a496d5e4ebce7fdb5d1b"},"package":"10d099cea0c721294ec11ae6c39d661c96d13d8994247ffadaf1576b065e38e6"}
|
|
@ -12,7 +12,7 @@
|
|||
[package]
|
||||
edition = "2021"
|
||||
name = "uniffi_meta"
|
||||
version = "0.20.0"
|
||||
version = "0.19.6"
|
||||
description = "uniffi_meta"
|
||||
homepage = "https://mozilla.github.io/uniffi-rs"
|
||||
keywords = [
|
||||
|
|
|
@ -23,22 +23,6 @@ impl FnMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, Deserialize, Serialize)]
|
||||
pub struct MethodMetadata {
|
||||
pub module_path: Vec<String>,
|
||||
pub self_name: String,
|
||||
pub name: String,
|
||||
pub inputs: Vec<FnParamMetadata>,
|
||||
pub return_type: Option<Type>,
|
||||
}
|
||||
|
||||
impl MethodMetadata {
|
||||
pub fn ffi_symbol_name(&self) -> String {
|
||||
let full_name = format!("impl_{}_{}", self.self_name, self.name);
|
||||
fn_ffi_symbol_name(&self.module_path, &full_name, checksum(self))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Hash, Deserialize, Serialize)]
|
||||
pub struct FnParamMetadata {
|
||||
pub name: String,
|
||||
|
@ -46,7 +30,7 @@ pub struct FnParamMetadata {
|
|||
pub ty: Type,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
|
||||
#[derive(Clone, Debug, Hash, Deserialize, Serialize)]
|
||||
pub enum Type {
|
||||
U8,
|
||||
U16,
|
||||
|
@ -70,9 +54,6 @@ pub enum Type {
|
|||
key_type: Box<Type>,
|
||||
value_type: Box<Type>,
|
||||
},
|
||||
ArcObject {
|
||||
object_name: String,
|
||||
},
|
||||
}
|
||||
|
||||
/// Returns the last 16 bits of the value's hash as computed with [`DefaultHasher`].
|
||||
|
@ -94,17 +75,10 @@ pub fn fn_ffi_symbol_name(mod_path: &[String], name: &str, checksum: u16) -> Str
|
|||
#[derive(Clone, Debug, Hash, Deserialize, Serialize)]
|
||||
pub enum Metadata {
|
||||
Func(FnMetadata),
|
||||
Method(MethodMetadata),
|
||||
}
|
||||
|
||||
impl From<FnMetadata> for Metadata {
|
||||
fn from(value: FnMetadata) -> Metadata {
|
||||
Self::Func(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MethodMetadata> for Metadata {
|
||||
fn from(m: MethodMetadata) -> Self {
|
||||
Self::Method(m)
|
||||
Metadata::Func(value)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -744,11 +744,7 @@ impl BitsRequest {
|
|||
cancel_with_reason_nsIRequest => CancelWithReason(status: nsresult, _reason: *const nsACString)
|
||||
);
|
||||
#[allow(non_snake_case)]
|
||||
fn cancel_with_reason_nsIRequest(
|
||||
&self,
|
||||
status: nsresult,
|
||||
_reason: *const nsACString,
|
||||
) -> Result<(), BitsTaskError> {
|
||||
fn cancel_with_reason_nsIRequest(&self, status: nsresult, _reason: *const nsACString) -> Result<(), BitsTaskError> {
|
||||
self.cancel(status, None)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ edition = "2018"
|
|||
license = "MPL-2.0"
|
||||
|
||||
[dependencies]
|
||||
glean = "51.4.0"
|
||||
glean = "51.2.0"
|
||||
log = "0.4"
|
||||
nserror = { path = "../../../xpcom/rust/nserror" }
|
||||
nsstring = { path = "../../../xpcom/rust/nsstring" }
|
||||
|
|
|
@ -8,7 +8,7 @@ publish = false
|
|||
[dependencies]
|
||||
bincode = "1.0"
|
||||
chrono = "0.4.10"
|
||||
glean = "51.4.0"
|
||||
glean = "51.2.0"
|
||||
inherent = "1.0.0"
|
||||
log = "0.4"
|
||||
nsstring = { path = "../../../../xpcom/rust/nsstring", optional = true }
|
||||
|
|
|
@ -13,7 +13,7 @@ askama = { version = "0.11", default-features = false, features = ["config"] }
|
|||
clap = { version = "3.1", features = ["std", "derive"] }
|
||||
extend = "1.1"
|
||||
heck = "0.4"
|
||||
uniffi_bindgen = "0.20"
|
||||
uniffi_bindgen = "0.19"
|
||||
serde = "1"
|
||||
toml = "0.5"
|
||||
camino = "1.0.8"
|
||||
|
|
|
@ -14,9 +14,9 @@ name = "uniffi_custom_types"
|
|||
anyhow = "1"
|
||||
bytes = "1.0"
|
||||
serde_json = "1"
|
||||
uniffi_macros = "0.20"
|
||||
uniffi = "0.20"
|
||||
uniffi_macros = "0.19"
|
||||
uniffi = "0.19"
|
||||
url = "2.1"
|
||||
|
||||
[build-dependencies]
|
||||
uniffi_build = "0.20"
|
||||
uniffi_build = "0.19"
|
||||
|
|
Загрузка…
Ссылка в новой задаче