Skip to content

Commit

Permalink
Remove cargo_metadata and make other versions match m-c's.
Browse files Browse the repository at this point in the history
When building in Gecko, `cargo_metadata` panics in a macro. This is
fixed in oli-obk/cargo_metadata#123 (and in Serde upstream), but
pulling `uniffi` in as a path dependency in Gecko, and depending on
`cargo_metadata` as a Git dependency, confuses Cargo. It doesn't
update the vendored versions of Serde or other dependencies, then
fails to build complaining it can't satisfy the newer versions that
`uniffi` requests.

In the interest of getting a demo working, I've just commented out
the dependencies for now, and downgraded the other versions to match
what's already vendored in m-c.
  • Loading branch information
linabutler committed Aug 26, 2020
1 parent 0fa2617 commit adc030b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 60 deletions.
6 changes: 3 additions & 3 deletions uniffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ edition = "2018"
# Re-exported dependencies used in generated Rust scaffolding files.
anyhow = "1"
bytes = "0.5"
ffi-support = "~0.4.2"
ffi-support = "0.4.0"
lazy_static = "1.4"
log = "0.4"
# Regular dependencies
cargo_metadata = "0.11"
paste = "1.0"
# cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata", rev = "64ee6d1d169103ed60ae4de5ddf84da751e7d841" }
paste = "0.1"
uniffi_bindgen = { path = "../uniffi_bindgen", optional = true }

[features]
Expand Down
4 changes: 2 additions & 2 deletions uniffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
use anyhow::{bail, Result};
use bytes::buf::{Buf, BufMut};
use ffi_support::ByteBuffer;
use paste::paste;
use paste::*;
use std::{collections::HashMap, convert::TryFrom, ffi::CString};

// It would be nice if this module was behind a cfg(test) guard, but it
Expand Down Expand Up @@ -160,7 +160,7 @@ macro_rules! impl_via_ffi_for_num_primitive {
($($T:ty,)+) => { impl_via_ffi_for_num_primitive!($($T),+); };
($($T:ty),*) => {
$(
paste! {
paste::item! {
unsafe impl ViaFfi for $T {
type FfiType = Self;

Expand Down
55 changes: 3 additions & 52 deletions uniffi/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
//! the `uniffi_macros` crate.

use anyhow::{bail, Result};
use cargo_metadata::Message;
// use cargo_metadata::Message;
use lazy_static::lazy_static;
use std::{
collections::HashMap,
path::Path,
path::{Path, PathBuf},
process::{Command, Stdio},
sync::Mutex,
};
Expand Down Expand Up @@ -56,56 +56,7 @@ pub fn run_foreign_language_testcase(pkg_dir: &str, idl_file: &str, test_file: &
/// Internally, this function does a bit of caching and concurrency management to avoid rebuilding
/// the component for multiple testcases.
pub fn ensure_compiled_cdylib(pkg_dir: &str) -> Result<String> {
// Have we already compiled this component?
let mut compiled_components = COMPILED_COMPONENTS.lock().unwrap();
if let Some(cdylib_file) = compiled_components.get(pkg_dir) {
return Ok(cdylib_file.to_string());
}
// Nope, looks like we'll have to compile it afresh.
let mut cmd = Command::new("cargo");
cmd.arg("build").arg("--message-format=json").arg("--lib");
cmd.current_dir(pkg_dir);
cmd.stdout(Stdio::piped());
let mut child = cmd.spawn()?;
let output = std::io::BufReader::new(child.stdout.take().unwrap());
// Build the crate, looking for any cdylibs that it might produce.
let cdylibs = Message::parse_stream(output)
.filter_map(|message| match message {
Err(e) => Some(Err(e.into())),
Ok(Message::CompilerArtifact(artifact)) => {
if artifact.target.kind.iter().any(|item| item == "cdylib") {
Some(Ok(artifact))
} else {
None
}
}
_ => None,
})
.collect::<Result<Vec<_>>>()?;
if !child.wait()?.success() {
bail!("Failed to execute `cargo build`");
}
// If we didn't just build exactly one cdylib, we're going to have a bad time.
match cdylibs.len() {
0 => bail!("Crate did not produce any cdylibs, it must not be a uniffi component"),
1 => (),
_ => bail!("Crate produced multiple cdylibs, it must not be a uniffi component"),
}
let cdylib_files: Vec<_> = cdylibs[0]
.filenames
.iter()
.filter(|nm| match nm.extension().unwrap_or_default().to_str() {
Some("dylib") | Some("so") => true,
_ => false,
})
.collect();
if cdylib_files.len() != 1 {
bail!("Failed to build exactly one cdylib file, it must not be a uniffi component");
}
let cdylib_file = cdylib_files[0].to_string_lossy().into_owned();
// Cache the result for subsequent tests.
compiled_components.insert(pkg_dir.to_string(), cdylib_file.clone());
Ok(cdylib_file)
unimplemented!()
}

/// Execute the `uniffi-bindgen test` command.
Expand Down
2 changes: 1 addition & 1 deletion uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ name = "uniffi-bindgen"
path = "src/main.rs"

[dependencies]
cargo_metadata = "0.11"
# cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata", rev = "64ee6d1d169103ed60ae4de5ddf84da751e7d841" }
weedle = "0.11"
anyhow = "1"
askama = "0.10"
Expand Down
4 changes: 3 additions & 1 deletion uniffi_bindgen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub fn generate_component_scaffolding<P: AsRef<Path>>(
.canonicalize()
.map_err(|e| anyhow!("Failed to find idl file: {:?}", e))?;
let component = parse_idl(&idl_file)?;
ensure_versions_compatibility(&idl_file, manifest_path_override)?;
// ensure_versions_compatibility(&idl_file, manifest_path_override)?;
let mut filename = Path::new(&idl_file)
.file_stem()
.ok_or_else(|| anyhow!("not a file"))?
Expand All @@ -141,6 +141,7 @@ pub fn generate_component_scaffolding<P: AsRef<Path>>(
Ok(())
}

/*
// If the crate for which we are generating bindings for depends on
// a `uniffi` runtime version that doesn't agree with our own version,
// the developer of that said crate will be in a world of pain.
Expand Down Expand Up @@ -184,6 +185,7 @@ fn ensure_versions_compatibility(
}
Ok(())
}
*/

// Generate the bindings in the target languages that call the scaffolding
// Rust code.
Expand Down
2 changes: 1 addition & 1 deletion uniffi_build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MPL-2.0"
edition = "2018"

[dependencies]
cargo_metadata = "0.11"
# cargo_metadata = { git = "https://github.com/oli-obk/cargo_metadata", rev = "64ee6d1d169103ed60ae4de5ddf84da751e7d841" }
anyhow = "1"
uniffi_bindgen = { path = "../uniffi_bindgen", optional = true }

Expand Down

0 comments on commit adc030b

Please sign in to comment.