mirror of
https://github.com/topjohnwu/cxx.git
synced 2025-02-06 16:18:39 +00:00
Support gz compressed AST input
This commit is contained in:
parent
22ad0495af
commit
6a1f7b92fe
@ -15,7 +15,7 @@ categories = ["development-tools::ffi"]
|
||||
proc-macro = true
|
||||
|
||||
[features]
|
||||
experimental = ["clang-ast", "memmap", "serde", "serde_json"]
|
||||
experimental = ["clang-ast", "flate2", "memmap", "serde", "serde_json"]
|
||||
|
||||
[dependencies]
|
||||
proc-macro2 = "1.0"
|
||||
@ -24,6 +24,7 @@ syn = { version = "1.0.70", features = ["full"] }
|
||||
|
||||
# optional dependencies
|
||||
clang-ast = { version = "0.1", optional = true }
|
||||
flate2 = { version = "1.0", optional = true }
|
||||
memmap = { version = "0.7", optional = true }
|
||||
serde = { version = "1.0", optional = true, features = ["derive"] }
|
||||
serde_json = { version = "1.0", optional = true }
|
||||
|
@ -2,6 +2,7 @@ use crate::syntax::attrs::OtherAttrs;
|
||||
use crate::syntax::namespace::Namespace;
|
||||
use crate::syntax::report::Errors;
|
||||
use crate::syntax::{Api, Discriminant, Doc, Enum, EnumRepr, ForeignName, Pair, Variant};
|
||||
use flate2::write::GzDecoder;
|
||||
use memmap::Mmap;
|
||||
use proc_macro2::{Delimiter, Group, Ident, TokenStream};
|
||||
use quote::{format_ident, quote, quote_spanned};
|
||||
@ -9,6 +10,7 @@ use serde::Deserialize;
|
||||
use std::env;
|
||||
use std::fmt::{self, Display};
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use syn::{parse_quote, Path};
|
||||
@ -91,16 +93,25 @@ pub fn load(cx: &mut Errors, apis: &mut [Api]) {
|
||||
}
|
||||
};
|
||||
|
||||
let ast_dump_bytes =
|
||||
match File::open(&ast_dump_path).and_then(|file| unsafe { Mmap::map(&file) }) {
|
||||
Ok(memmap) => memmap,
|
||||
Err(error) => {
|
||||
let msg = format!("failed to read {}: {}", ast_dump_path.display(), error);
|
||||
return cx.error(span, msg);
|
||||
}
|
||||
};
|
||||
let memmap = match File::open(&ast_dump_path).and_then(|file| unsafe { Mmap::map(&file) }) {
|
||||
Ok(memmap) => memmap,
|
||||
Err(error) => {
|
||||
let msg = format!("failed to read {}: {}", ast_dump_path.display(), error);
|
||||
return cx.error(span, msg);
|
||||
}
|
||||
};
|
||||
|
||||
let ref root: Node = match serde_json::from_slice(&ast_dump_bytes) {
|
||||
let is_gzipped = memmap.get(..2) == Some(b"\x1f\x8b");
|
||||
let mut gunzipped;
|
||||
let ast_dump_bytes: &[u8] = if is_gzipped {
|
||||
gunzipped = Vec::new();
|
||||
GzDecoder::new(&mut gunzipped).write_all(&memmap).unwrap();
|
||||
&gunzipped
|
||||
} else {
|
||||
&memmap
|
||||
};
|
||||
|
||||
let ref root: Node = match serde_json::from_slice(ast_dump_bytes) {
|
||||
Ok(root) => root,
|
||||
Err(error) => {
|
||||
let msg = format!("failed to read {}: {}", ast_dump_path.display(), error);
|
||||
|
50
third-party/Cargo.lock
generated
vendored
50
third-party/Cargo.lock
generated
vendored
@ -2,6 +2,12 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "adler"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
|
||||
|
||||
[[package]]
|
||||
name = "ansi_term"
|
||||
version = "0.11.0"
|
||||
@ -22,6 +28,12 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.2.1"
|
||||
@ -37,6 +49,12 @@ dependencies = [
|
||||
"jobserver",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clang-ast"
|
||||
version = "0.1.0"
|
||||
@ -72,6 +90,15 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "81156fece84ab6a9f2afdb109ce3ae577e42b1228441eded99bd77f627953b1a"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cxx"
|
||||
version = "1.0.46"
|
||||
@ -143,6 +170,7 @@ version = "1.0.46"
|
||||
dependencies = [
|
||||
"clang-ast",
|
||||
"cxx",
|
||||
"flate2",
|
||||
"memmap",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
@ -165,6 +193,18 @@ version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb"
|
||||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd3aec53de10fe96d7d8c565eb17f2c687bb5518a2ec453b5b1252964526abe0"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"crc32fast",
|
||||
"libc",
|
||||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
@ -226,6 +266,16 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
|
||||
dependencies = [
|
||||
"adler",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.7.2"
|
||||
|
Loading…
x
Reference in New Issue
Block a user