Replace anyhow dependency with a handwritten reporter
diff --git a/BUCK b/BUCK
index a58e0a2..2c60139 100644
--- a/BUCK
+++ b/BUCK
@@ -16,7 +16,6 @@
crate = "cxxbridge",
visibility = ["PUBLIC"],
deps = [
- "//third-party:anyhow",
"//third-party:clap",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
@@ -60,7 +59,6 @@
srcs = glob(["gen/build/src/**"]),
visibility = ["PUBLIC"],
deps = [
- "//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
@@ -74,7 +72,6 @@
srcs = glob(["gen/lib/src/**"]),
visibility = ["PUBLIC"],
deps = [
- "//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
diff --git a/BUILD b/BUILD
index 53bccf7..0248173 100644
--- a/BUILD
+++ b/BUILD
@@ -19,7 +19,6 @@
data = ["gen/cmd/src/gen/include/cxx.h"],
visibility = ["//visibility:public"],
deps = [
- "//third-party:anyhow",
"//third-party:clap",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
@@ -59,7 +58,6 @@
data = ["gen/build/src/gen/include/cxx.h"],
visibility = ["//visibility:public"],
deps = [
- "//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
@@ -74,7 +72,6 @@
data = ["gen/lib/src/gen/include/cxx.h"],
visibility = ["//visibility:public"],
deps = [
- "//third-party:anyhow",
"//third-party:cc",
"//third-party:codespan-reporting",
"//third-party:proc-macro2",
diff --git a/gen/build/Cargo.toml b/gen/build/Cargo.toml
index 3faed78..9858005 100644
--- a/gen/build/Cargo.toml
+++ b/gen/build/Cargo.toml
@@ -10,7 +10,6 @@
categories = ["development-tools::ffi"]
[dependencies]
-anyhow = "1.0"
cc = "1.0.49"
codespan-reporting = "0.9"
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs
index aabac22..840424e 100644
--- a/gen/build/src/lib.rs
+++ b/gen/build/src/lib.rs
@@ -58,8 +58,8 @@
mod syntax;
use crate::error::Result;
+use crate::gen::error::report;
use crate::gen::Opt;
-use anyhow::anyhow;
use std::fs;
use std::io::{self, Write};
use std::iter;
@@ -93,7 +93,7 @@
for path in rust_source_files {
if let Err(err) = try_generate_bridge(&mut build, path.as_ref()) {
- let _ = writeln!(io::stderr(), "\n\ncxxbridge error: {:?}\n\n", anyhow!(err));
+ let _ = writeln!(io::stderr(), "\n\ncxxbridge error: {}\n\n", report(err));
process::exit(1);
}
}
diff --git a/gen/cmd/Cargo.toml b/gen/cmd/Cargo.toml
index fd4d31a..cd74cee 100644
--- a/gen/cmd/Cargo.toml
+++ b/gen/cmd/Cargo.toml
@@ -14,7 +14,6 @@
path = "src/main.rs"
[dependencies]
-anyhow = "1.0"
clap = "2.33"
codespan-reporting = "0.9"
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
diff --git a/gen/lib/Cargo.toml b/gen/lib/Cargo.toml
index eb17487..48a4b72 100644
--- a/gen/lib/Cargo.toml
+++ b/gen/lib/Cargo.toml
@@ -10,7 +10,6 @@
categories = ["development-tools::ffi"]
[dependencies]
-anyhow = "1.0"
cc = "1.0.49"
codespan-reporting = "0.9"
proc-macro2 = { version = "1.0.17", default-features = false, features = ["span-locations"] }
diff --git a/gen/src/error.rs b/gen/src/error.rs
index d8badac..a7ce6e1 100644
--- a/gen/src/error.rs
+++ b/gen/src/error.rs
@@ -1,5 +1,4 @@
use crate::syntax;
-use anyhow::anyhow;
use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream, WriteColor};
@@ -63,11 +62,34 @@
display_syn_error(stderr, path, source, error);
}
}
- _ => eprintln!("cxxbridge: {:?}", anyhow!(error)),
+ _ => {
+ let _ = writeln!(io::stderr(), "cxxbridge: {}", report(error));
+ }
}
process::exit(1);
}
+pub(crate) fn report(error: impl StdError) -> impl Display {
+ struct Report<E>(E);
+
+ impl<E: StdError> Display for Report<E> {
+ fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
+ Display::fmt(&self.0, formatter)?;
+ let mut error: &dyn StdError = &self.0;
+
+ while let Some(cause) = error.source() {
+ formatter.write_str("\n\nCaused by:\n ")?;
+ Display::fmt(cause, formatter)?;
+ error = cause;
+ }
+
+ Ok(())
+ }
+ }
+
+ Report(error)
+}
+
fn sort_syn_errors(error: syn::Error) -> Vec<syn::Error> {
let mut errors: Vec<_> = error.into_iter().collect();
errors.sort_by_key(|e| {
diff --git a/gen/src/mod.rs b/gen/src/mod.rs
index a832280..873ce1d 100644
--- a/gen/src/mod.rs
+++ b/gen/src/mod.rs
@@ -1,7 +1,7 @@
// Functionality that is shared between the cxx_build::bridge entry point and
// the cxxbridge CLI command.
-mod error;
+pub(super) mod error;
mod file;
pub(super) mod include;
pub(super) mod out;
diff --git a/third-party/BUCK b/third-party/BUCK
index 585dafd..95c879a 100644
--- a/third-party/BUCK
+++ b/third-party/BUCK
@@ -1,13 +1,6 @@
# To be generated by Facebook's `reindeer` tool once that is open source.
rust_library(
- name = "anyhow",
- srcs = glob(["vendor/anyhow-1.0.32/src/**"]),
- visibility = ["PUBLIC"],
- features = ["std"],
-)
-
-rust_library(
name = "bitflags",
srcs = glob(["vendor/bitflags-1.2.1/src/**"]),
)
diff --git a/third-party/BUILD b/third-party/BUILD
index 65edf92..081737e 100644
--- a/third-party/BUILD
+++ b/third-party/BUILD
@@ -6,13 +6,6 @@
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
rust_library(
- name = "anyhow",
- srcs = glob(["vendor/anyhow-1.0.32/src/**"]),
- crate_features = ["std"],
- visibility = ["//visibility:public"],
-)
-
-rust_library(
name = "bitflags",
srcs = glob(["vendor/bitflags-1.2.1/src/**"]),
)
diff --git a/third-party/Cargo.lock b/third-party/Cargo.lock
index ae67969..6e7a504 100644
--- a/third-party/Cargo.lock
+++ b/third-party/Cargo.lock
@@ -10,12 +10,6 @@
]
[[package]]
-name = "anyhow"
-version = "1.0.32"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6b602bfe940d21c130f3895acd65221e8a61270debe89d628b9cb4e3ccb8569b"
-
-[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -81,7 +75,6 @@
name = "cxx-build"
version = "0.3.7"
dependencies = [
- "anyhow",
"cc",
"codespan-reporting",
"cxx-gen",
@@ -94,7 +87,6 @@
name = "cxx-gen"
version = "0.0.1"
dependencies = [
- "anyhow",
"cc",
"codespan-reporting",
"proc-macro2",
@@ -115,7 +107,6 @@
name = "cxxbridge-cmd"
version = "0.3.7"
dependencies = [
- "anyhow",
"clap",
"codespan-reporting",
"proc-macro2",