use std::fs::File;
use std::io::Write;
use std::path::{Path, PathBuf};
fn generate_typed_host_arch() {
let mut target = std::env::var("TARGET").expect("Expected TARGET to be set");
let out_dir = PathBuf::from(std::env::var("OUT_DIR").expect("Expected OUT_DIR to be set"));
for libc in ["gnu", "musl", "uclibc"] {
if let Some(start) = target.find(libc) {
target.replace_range(start..start + libc.len(), "*")
}
}
let target = match target.as_str() {
"arm-unknown-linux-*eabi" => "armv7l",
"arm-unknown-linux-*eabihf" => "armv7hl",
_ => target
.split('-')
.next()
.expect("Expected TARGET to include `-`"),
};
let path: PathBuf = [&out_dir, Path::new("host-arch")].into_iter().collect();
File::create(path)
.expect("Expected to be able to open host arch file")
.write_all(target.as_bytes())
.expect("Expected to be able to write host arch file");
let target = ["crate::metadata::Arch::", target]
.into_iter()
.collect::<String>();
let path: PathBuf = [&out_dir, Path::new("host-arch.rs")].into_iter().collect();
File::create(path)
.expect("Expected to be able to open host arch file")
.write_all(target.as_bytes())
.expect("Expected to be able to write host arch file")
}
fn main() {
generate_typed_host_arch();
}