|
1 | 1 | // @generated by autocargo |
| 2 | + |
2 | 3 | use std::env; |
3 | 4 | use std::fs; |
4 | 5 | use std::path::Path; |
5 | | - |
6 | 6 | use thrift_compiler::Config; |
7 | 7 | use thrift_compiler::GenContext; |
8 | | - |
| 8 | +const CRATEMAP: &str = "\ |
| 9 | +fb303_core crate //fb303/thrift:fb303_core-rust |
| 10 | +"; |
9 | 11 | #[rustfmt::skip] |
10 | 12 | fn main() { |
11 | | - // Rerun if this gets rewritten. |
12 | 13 | println!("cargo:rerun-if-changed=thrift_build.rs"); |
13 | | - |
14 | 14 | let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR env not provided"); |
15 | | - let out_dir: &Path = out_dir.as_ref(); |
16 | | - fs::write( |
17 | | - out_dir.join("cratemap"), |
18 | | - "fb303_core crate //fb303/thrift:fb303_core-rust", |
19 | | - ).expect("Failed to write cratemap"); |
20 | | - |
21 | | - let conf = { |
22 | | - let mut conf = Config::from_env(GenContext::Services).expect("Failed to instantiate thrift_compiler::Config"); |
23 | | - |
24 | | - let path_from_manifest_to_base: &Path = "../../..".as_ref(); |
25 | | - let cargo_manifest_dir = |
26 | | - env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not provided"); |
27 | | - let cargo_manifest_dir: &Path = cargo_manifest_dir.as_ref(); |
28 | | - let base_path = cargo_manifest_dir |
29 | | - .join(path_from_manifest_to_base) |
30 | | - .canonicalize() |
31 | | - .expect("Failed to canonicalize base_path"); |
32 | | - // TODO: replace canonicalize() with std::path::absolute() when |
33 | | - // https://github.com/rust-lang/rust/pull/91673 is available (~Rust 1.60) |
34 | | - // and remove this block. |
35 | | - #[cfg(windows)] |
36 | | - let base_path = Path::new( |
37 | | - base_path |
38 | | - .as_path() |
39 | | - .to_string_lossy() |
40 | | - .trim_start_matches(r"\\?\"), |
41 | | - ) |
42 | | - .to_path_buf(); |
43 | | - |
44 | | - conf.base_path(base_path); |
45 | | - |
46 | | - conf.types_crate("fb303_core__types"); |
47 | | - conf.clients_crate("fb303_core__clients"); |
48 | | - conf.services_crate("fb303_core__services"); |
49 | | - |
50 | | - let options = "deprecated_default_enum_min_i32,serde"; |
51 | | - if !options.is_empty() { |
52 | | - conf.options(options); |
53 | | - } |
54 | | - |
55 | | - let types_include_srcs = vec![ |
56 | | - |
57 | | - ]; |
58 | | - conf.types_include_srcs(types_include_srcs); |
59 | | - |
60 | | - conf |
61 | | - }; |
62 | | - |
63 | | - let srcs: &[&str] = &[ |
64 | | - "../fb303_core.thrift" |
65 | | - ]; |
| 15 | + let cratemap_path = Path::new(&out_dir).join("cratemap"); |
| 16 | + fs::write(cratemap_path, CRATEMAP).expect("Failed to write cratemap"); |
| 17 | + let mut conf = Config::from_env(GenContext::Services) |
| 18 | + .expect("Failed to instantiate thrift_compiler::Config"); |
| 19 | + let cargo_manifest_dir = env::var_os("CARGO_MANIFEST_DIR") |
| 20 | + .expect("CARGO_MANIFEST_DIR not provided"); |
| 21 | + let mut base_path = Path::new(&cargo_manifest_dir) |
| 22 | + .join("../../..") |
| 23 | + .canonicalize() |
| 24 | + .expect("Failed to canonicalize base_path"); |
| 25 | + if cfg!(windows) { |
| 26 | + base_path = base_path.to_string_lossy().trim_start_matches(r"\\?\").into(); |
| 27 | + } |
| 28 | + conf.base_path(base_path); |
| 29 | + conf.types_crate("fb303_core__types"); |
| 30 | + conf.clients_crate("fb303_core__clients"); |
| 31 | + conf.services_crate("fb303_core__services"); |
| 32 | + conf.options("deprecated_default_enum_min_i32,serde"); |
| 33 | + let srcs = &["../fb303_core.thrift"]; |
66 | 34 | conf.run(srcs).expect("Failed while running thrift compilation"); |
67 | 35 | } |
0 commit comments