mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 11:07:44 +00:00
Basic Cargo build
Builds the uutils multicall binary containing all utils (except stdbuf) by default. To only build a subset `cargo --no-default-features --features <utils>` can be used. Whats missing is building the standalone binaries and a mechanism to automatically disable the build of unix only utils on windows.
This commit is contained in:
parent
314a254d1f
commit
9d8abbcb06
75 changed files with 1284 additions and 265 deletions
61
build.rs
Normal file
61
build.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
pub fn main() {
|
||||
let feature_prefix = "CARGO_FEATURE_";
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
|
||||
let mut crates = Vec::new();
|
||||
for (key, val) in env::vars() {
|
||||
if val == "1" && key.starts_with(feature_prefix) {
|
||||
let krate = key[feature_prefix.len()..].to_lowercase();
|
||||
match krate.as_ref() {
|
||||
"default" => continue,
|
||||
"all" => 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" => continue,
|
||||
"true" => continue,
|
||||
_ => cf.write_all(format!("extern crate {krate} as 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();
|
||||
},
|
||||
"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("map
|
||||
}\n".as_bytes()).unwrap();
|
||||
cf.flush().unwrap();
|
||||
mf.flush().unwrap();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue