2021-03-26 02:22:00 +01:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
|
|
|
|
2021-02-13 04:46:22 +01:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use structopt::clap::Shell;
|
|
|
|
use structopt::StructOpt;
|
|
|
|
|
2021-03-26 02:22:00 +01:00
|
|
|
use std::fs::File;
|
|
|
|
use std::io::Read;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
2021-02-13 04:46:22 +01:00
|
|
|
include!("src/opt/ssh_authorizedkeys.rs");
|
|
|
|
include!("src/opt/cache_invalidate.rs");
|
|
|
|
include!("src/opt/cache_clear.rs");
|
|
|
|
include!("src/opt/unixd_status.rs");
|
|
|
|
|
2021-03-26 02:22:00 +01:00
|
|
|
include!("../profiles/syntax.rs");
|
|
|
|
|
2021-02-13 04:46:22 +01:00
|
|
|
fn main() {
|
|
|
|
let outdir = match env::var_os("OUT_DIR") {
|
|
|
|
None => return,
|
|
|
|
Some(outdir) => outdir,
|
|
|
|
};
|
|
|
|
|
|
|
|
SshAuthorizedOpt::clap().gen_completions(
|
|
|
|
"kanidm_ssh_authorizedkeys",
|
|
|
|
Shell::Bash,
|
|
|
|
outdir.clone(),
|
|
|
|
);
|
|
|
|
SshAuthorizedOpt::clap().gen_completions(
|
|
|
|
"kanidm_ssh_authorizedkeys",
|
|
|
|
Shell::Zsh,
|
|
|
|
outdir.clone(),
|
|
|
|
);
|
|
|
|
|
|
|
|
CacheInvalidateOpt::clap().gen_completions(
|
|
|
|
"kanidm_cache_invalidate",
|
|
|
|
Shell::Bash,
|
|
|
|
outdir.clone(),
|
|
|
|
);
|
|
|
|
CacheInvalidateOpt::clap().gen_completions(
|
|
|
|
"kanidm_cache_invalidate",
|
|
|
|
Shell::Zsh,
|
|
|
|
outdir.clone(),
|
|
|
|
);
|
|
|
|
|
|
|
|
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Bash, outdir.clone());
|
|
|
|
CacheClearOpt::clap().gen_completions("kanidm_cache_clear", Shell::Zsh, outdir.clone());
|
|
|
|
|
|
|
|
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Bash, outdir.clone());
|
|
|
|
UnixdStatusOpt::clap().gen_completions("kanidm_unixd_status", Shell::Zsh, outdir);
|
2021-03-26 02:22:00 +01:00
|
|
|
|
|
|
|
println!("cargo:rerun-if-env-changed=KANIDM_BUILD_PROFILE");
|
|
|
|
let profile = env::var("KANIDM_BUILD_PROFILE").unwrap_or_else(|_| "developer".to_string());
|
|
|
|
|
|
|
|
let profile_path: PathBuf = ["../profiles", format!("{}.toml", profile).as_str()]
|
|
|
|
.iter()
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed={}", profile_path.to_str().unwrap());
|
|
|
|
|
|
|
|
let mut f =
|
|
|
|
File::open(&profile_path).expect(format!("Failed to open {:?}", profile_path).as_str());
|
|
|
|
|
|
|
|
let mut contents = String::new();
|
|
|
|
f.read_to_string(&mut contents)
|
|
|
|
.expect(format!("Failed to read {:?}", profile_path).as_str());
|
|
|
|
|
|
|
|
let profile_cfg: ProfileConfig = toml::from_str(contents.as_str())
|
|
|
|
.expect(format!("Failed to parse {:?}", profile_path).as_str());
|
|
|
|
|
|
|
|
match profile_cfg.cpu_flags {
|
|
|
|
CpuOptLevel::none => {}
|
|
|
|
CpuOptLevel::native => println!("cargo:rustc-env=RUSTFLAGS=-Ctarget-cpu=native"),
|
|
|
|
CpuOptLevel::x86_64_v1 => println!("cargo:rustc-env=RUSTFLAGS=-Ctarget-feature=+cmov,+cx8,+fxsr,+mmx,+sse,+sse2"),
|
|
|
|
CpuOptLevel::x86_64_v3 => println!("cargo:rustc-env=RUSTFLAGS=-Ctarget-feature=+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+cx16,+sahf,+popcnt,+sse3,+sse4.1,+sse4.2,+avx,+avx2,+bmi,+bmi2,+f16c,+fma,+lzcnt,+movbe,+xsave"),
|
|
|
|
}
|
|
|
|
println!("cargo:rustc-env=KANIDM_PROFILE_NAME={}", profile);
|
|
|
|
println!("cargo:rustc-env=KANIDM_CPU_FLAGS={}", profile_cfg.cpu_flags);
|
2021-02-13 04:46:22 +01:00
|
|
|
}
|