1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

Refactor and simplify build for utilities.

For coreutils, there are two build artifacts:

  1. multicall executable (each utility is a separate static library)
  2. individual utilities (still separate library with main wrapper)

To avoid namespace collision, each utility crate is defined as
"uu_{CMD}". The end user only sees the original utility name. This
simplifies build.rs.

Also, the thin wrapper for the main() function is no longer contained in
the crate. It has been separated into a dedicated file. This was
necessary to work around Cargo's need for the crate name attribute to
match the name in the respective Cargo.toml.
This commit is contained in:
Joseph Crail 2015-12-07 21:42:08 -05:00
parent d6039c1b22
commit b90d253584
224 changed files with 682 additions and 695 deletions

View file

@ -12,49 +12,43 @@ pub fn main() {
if val == "1" && key.starts_with(feature_prefix) {
let krate = key[feature_prefix.len()..].to_lowercase();
match krate.as_ref() {
"default" | "unix" | "generic" => continue,
_ => {},
"default" | "unix" | "generic" => continue,
_ => {},
}
crates.push(krate.to_string());
}
}
crates.sort();
let mut cf = File::create(Path::new(&out_dir).join("uutils_crates.rs")).unwrap();
let mut mf = File::create(Path::new(&out_dir).join("uutils_map.rs")).unwrap();
mf.write_all("
type UtilityMap = HashMap<&'static str, fn(Vec<String>) -> i32>;
fn util_map() -> UtilityMap {
let mut map: UtilityMap = HashMap::new();\n".as_bytes()).unwrap();
for krate in crates {
match krate.as_ref() {
"false" | "true" => {},
"test" => cf.write_all(format!("extern crate uu{krate};\n", krate=krate).as_bytes()).unwrap(),
_ => cf.write_all(format!("extern crate {krate} as uu{krate};\n", krate=krate).as_bytes()).unwrap(),
}
cf.write_all(format!("extern crate uu_{krate};\n", krate=krate).as_bytes()).unwrap();
match krate.as_ref() {
"hashsum" => {
mf.write_all("map.insert(\"hashsum\", uuhashsum::uumain);
map.insert(\"md5sum\", uuhashsum::uumain);
map.insert(\"sha1sum\", uuhashsum::uumain);
map.insert(\"sha224sum\", uuhashsum::uumain);
map.insert(\"sha256sum\", uuhashsum::uumain);
map.insert(\"sha384sum\", uuhashsum::uumain);
map.insert(\"sha512sum\", uuhashsum::uumain);\n".as_bytes()).unwrap();
mf.write_all("map.insert(\"hashsum\", uu_hashsum::uumain);
map.insert(\"md5sum\", uu_hashsum::uumain);
map.insert(\"sha1sum\", uu_hashsum::uumain);
map.insert(\"sha224sum\", uu_hashsum::uumain);
map.insert(\"sha256sum\", uu_hashsum::uumain);
map.insert(\"sha384sum\", uu_hashsum::uumain);
map.insert(\"sha512sum\", uu_hashsum::uumain);\n".as_bytes()).unwrap();
},
"false" =>
mf.write_all("fn uufalse(_: Vec<String>) -> i32 { 1 }
map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n".as_bytes()).unwrap(),
"true" =>
mf.write_all("fn uutrue(_: Vec<String>) -> i32 { 0 }
map.insert(\"true\", uutrue as fn(Vec<String>) -> i32);\n".as_bytes()).unwrap(),
_ =>
mf.write_all(format!("map.insert(\"{krate}\", uu{krate}::uumain as fn(Vec<String>) -> i32);\n", krate= krate).as_bytes()).unwrap(),
mf.write_all(format!("map.insert(\"{krate}\", uu_{krate}::uumain);\n", krate=krate).as_bytes()).unwrap(),
}
}
mf.write_all("map
}\n".as_bytes()).unwrap();
mf.write_all("map\n}\n".as_bytes()).unwrap();
cf.flush().unwrap();
mf.flush().unwrap();
}