sapling/configerator/structs/scm/mononoke/tunables/thrift_build.rs
Callum Ryan 65bd8a9bc9 Support thrift_library::rust_include_srcs
Summary:
`rust_include_srcs` is supported on `thrift_library` as a way of including other Rust code in the generated crate, generally used to implement other traits on the generated types.

Adding support for this in autocargo by copying these files into the output dir and making sure their option is specified to the thrift compiler

Reviewed By: ahornby

Differential Revision: D30789835

fbshipit-source-id: 325cb59fdf85324dccfff20a559802c11816769f
2021-09-10 00:12:44 -07:00

49 lines
1.3 KiB
Rust

// @generated by autocargo
use std::env;
use std::fs;
use std::path::Path;
use thrift_compiler::Config;
#[rustfmt::skip]
fn main() {
let out_dir = env::var_os("OUT_DIR").expect("OUT_DIR env not provided");
let out_dir: &Path = out_dir.as_ref();
fs::write(
out_dir.join("cratemap"),
"tunables crate",
).expect("Failed to write cratemap");
let conf = {
let mut conf = Config::from_env().expect("Failed to instantiate thrift_compiler::Config");
let path_from_manifest_to_base: &Path = "../../../../..".as_ref();
let cargo_manifest_dir =
env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not provided");
let cargo_manifest_dir: &Path = cargo_manifest_dir.as_ref();
let base_path = cargo_manifest_dir
.join(path_from_manifest_to_base)
.canonicalize()
.expect("Failed to canonicalize base_path");
conf.base_path(base_path);
let options = "serde";
if !options.is_empty() {
conf.options(options);
}
let include_srcs = vec![
];
conf.include_srcs(include_srcs);
conf
};
conf
.run(&[
"tunables.thrift"
])
.expect("Failed while running thrift compilation");
}