xtask: handle triples better
This commit is contained in:
parent
84ab4e1f03
commit
11512e92ea
14
Cargo.lock
generated
14
Cargo.lock
generated
|
@ -740,6 +740,15 @@ dependencies = [
|
||||||
"target-lexicon",
|
"target-lexicon",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-expr"
|
||||||
|
version = "0.16.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "345c78335be0624ed29012dc10c49102196c6882c12dde65d9f35b02da2aada8"
|
||||||
|
dependencies = [
|
||||||
|
"smallvec",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cfg-if"
|
name = "cfg-if"
|
||||||
version = "0.1.10"
|
version = "0.1.10"
|
||||||
|
@ -4558,7 +4567,7 @@ version = "6.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349"
|
checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-expr",
|
"cfg-expr 0.15.8",
|
||||||
"heck",
|
"heck",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"toml 0.8.15",
|
"toml 0.8.15",
|
||||||
|
@ -4571,7 +4580,7 @@ version = "7.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6c81f13d9a334a6c242465140bd262fae382b752ff2011c4f7419919a9c97922"
|
checksum = "6c81f13d9a334a6c242465140bd262fae382b752ff2011c4f7419919a9c97922"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-expr",
|
"cfg-expr 0.15.8",
|
||||||
"heck",
|
"heck",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
"toml 0.8.15",
|
"toml 0.8.15",
|
||||||
|
@ -5875,6 +5884,7 @@ name = "xtask"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cargo_metadata",
|
"cargo_metadata",
|
||||||
|
"cfg-expr 0.16.0",
|
||||||
"clap",
|
"clap",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
|
|
|
@ -10,6 +10,7 @@ clap = { version = "4.5.15", features = ["derive"] }
|
||||||
strum = { version = "0.26.3", features = ["derive"] }
|
strum = { version = "0.26.3", features = ["derive"] }
|
||||||
xshell = "0.2.6"
|
xshell = "0.2.6"
|
||||||
cargo_metadata = "0.18.1"
|
cargo_metadata = "0.18.1"
|
||||||
|
cfg-expr = "0.16.0"
|
||||||
nih_plug_xtask = { workspace = true }
|
nih_plug_xtask = { workspace = true }
|
||||||
log = { workspace = true }
|
log = { workspace = true }
|
||||||
env_logger = { workspace = true }
|
env_logger = { workspace = true }
|
||||||
|
|
|
@ -31,12 +31,18 @@ pub enum Commands {
|
||||||
#[derive(clap::Args, Debug)]
|
#[derive(clap::Args, Debug)]
|
||||||
#[command(group(clap::ArgGroup::new("platforms").args(["platform","all_platforms"]).required(true)))]
|
#[command(group(clap::ArgGroup::new("platforms").args(["platform","all_platforms"]).required(true)))]
|
||||||
#[command(group(clap::ArgGroup::new("binaries").args(["binary","all_binaries"]).required(true)))]
|
#[command(group(clap::ArgGroup::new("binaries").args(["binary","all_binaries"]).required(true)))]
|
||||||
|
#[command(group(clap::ArgGroup::new("architectures").args(["architecture","all_architectures"]).required(true)))]
|
||||||
pub struct BuildArgs {
|
pub struct BuildArgs {
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub platform: Vec<Platform>,
|
pub platform: Vec<Platform>,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
pub all_platforms: bool,
|
pub all_platforms: bool,
|
||||||
|
|
||||||
|
#[arg(long, short)]
|
||||||
|
pub architecture: Vec<Architecture>,
|
||||||
|
#[arg(long)]
|
||||||
|
pub all_architectures: bool,
|
||||||
|
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub binary: Vec<Binary>,
|
pub binary: Vec<Binary>,
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
|
@ -51,6 +57,8 @@ pub struct RunArgs {
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub platform: Option<Platform>,
|
pub platform: Option<Platform>,
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
|
pub architecture: Option<Architecture>,
|
||||||
|
#[arg(long, short)]
|
||||||
pub binary: Option<Binary>,
|
pub binary: Option<Binary>,
|
||||||
#[arg(long, short)]
|
#[arg(long, short)]
|
||||||
pub renderer: Option<Renderer>,
|
pub renderer: Option<Renderer>,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use std::io::BufRead;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use strum::IntoEnumIterator;
|
use strum::IntoEnumIterator;
|
||||||
use xshell::Shell;
|
use xshell::Shell;
|
||||||
|
@ -10,18 +12,20 @@ mod types;
|
||||||
static METADATA: std::sync::OnceLock<cargo_metadata::Metadata> = std::sync::OnceLock::new();
|
static METADATA: std::sync::OnceLock<cargo_metadata::Metadata> = std::sync::OnceLock::new();
|
||||||
static OUTPUT_DIR: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new();
|
static OUTPUT_DIR: std::sync::OnceLock<std::path::PathBuf> = std::sync::OnceLock::new();
|
||||||
|
|
||||||
fn executable_dir(binary: Binary, platform: Platform, renderer: Renderer) -> String {
|
fn executable_dir(
|
||||||
format!(
|
binary: Binary,
|
||||||
"{}_{}_{}",
|
triple: &cfg_expr::targets::Triple,
|
||||||
binary.name(),
|
renderer: Renderer,
|
||||||
platform.as_target(),
|
) -> String {
|
||||||
renderer.as_feature()
|
format!("{}_{}_{}", binary.name(), triple, renderer.as_feature())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
std::env::set_var("RUST_LOG", "info");
|
std::env::set_var(
|
||||||
|
"RUST_LOG",
|
||||||
|
"cli=info,frontend_common=info,gb_emu_lib=info,xtask=info",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
@ -55,27 +59,28 @@ fn build(args: BuildArgs, debug: bool) -> Result<(), Box<dyn std::error::Error>>
|
||||||
} else {
|
} else {
|
||||||
args.platform
|
args.platform
|
||||||
};
|
};
|
||||||
log::info!("platforms: {platforms:?}");
|
|
||||||
|
let architectures = if args.all_architectures {
|
||||||
|
Architecture::iter().collect()
|
||||||
|
} else {
|
||||||
|
args.architecture
|
||||||
|
};
|
||||||
|
|
||||||
let binaries = if args.all_binaries {
|
let binaries = if args.all_binaries {
|
||||||
Binary::iter().collect()
|
Binary::iter().collect()
|
||||||
} else {
|
} else {
|
||||||
args.binary
|
args.binary
|
||||||
};
|
};
|
||||||
log::info!("binaries: {binaries:?}");
|
|
||||||
|
|
||||||
let renderers = if args.renderer.is_empty() {
|
let renderers = if args.renderer.is_empty() {
|
||||||
vec![Renderer::Wgpu]
|
vec![Renderer::Wgpu]
|
||||||
} else {
|
} else {
|
||||||
args.renderer
|
args.renderer
|
||||||
};
|
};
|
||||||
log::info!("renderers: {renderers:?}");
|
|
||||||
|
|
||||||
for binary in binaries {
|
for binary in binaries {
|
||||||
for platform in &platforms {
|
for renderer in &renderers {
|
||||||
for renderer in &renderers {
|
build_binary(binary, &platforms, &architectures, *renderer, debug)?;
|
||||||
build_binary(binary, *platform, *renderer, debug)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,11 +89,16 @@ fn build(args: BuildArgs, debug: bool) -> Result<(), Box<dyn std::error::Error>>
|
||||||
|
|
||||||
fn run(args: RunArgs, debug: bool) -> Result<(), Box<dyn std::error::Error>> {
|
fn run(args: RunArgs, debug: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let platform = args.platform.unwrap_or(Platform::host_platform());
|
let platform = args.platform.unwrap_or(Platform::host_platform());
|
||||||
|
let architecture = args
|
||||||
|
.architecture
|
||||||
|
.unwrap_or(Architecture::host_architecture());
|
||||||
|
let triple = get_triple(platform, architecture).unwrap().triple;
|
||||||
let binary = args.binary.unwrap_or(Binary::get_default());
|
let binary = args.binary.unwrap_or(Binary::get_default());
|
||||||
let renderer = args.renderer.unwrap_or(Renderer::Wgpu);
|
let renderer = args.renderer.unwrap_or(Renderer::Wgpu);
|
||||||
|
|
||||||
match binary {
|
match binary {
|
||||||
Binary::Gui => run_gui(platform, renderer, debug),
|
Binary::Gui => run_gui(platform, &triple, renderer, debug),
|
||||||
Binary::Cli => run_cli(platform, renderer, debug),
|
Binary::Cli => run_cli(platform, &triple, renderer, debug),
|
||||||
Binary::Vst => {
|
Binary::Vst => {
|
||||||
eprintln!("twinc_emu_vst doesn't support standalone usage!");
|
eprintln!("twinc_emu_vst doesn't support standalone usage!");
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
|
@ -98,26 +108,81 @@ fn run(args: RunArgs, debug: bool) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
fn build_binary(
|
fn build_binary(
|
||||||
binary: Binary,
|
binary: Binary,
|
||||||
platform: Platform,
|
platforms: &[Platform],
|
||||||
|
architectures: &[Architecture],
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let output_dir = OUTPUT_DIR
|
|
||||||
.get()
|
|
||||||
.unwrap()
|
|
||||||
.join(executable_dir(binary, platform, renderer));
|
|
||||||
|
|
||||||
std::fs::create_dir_all(&output_dir)?;
|
|
||||||
match binary {
|
match binary {
|
||||||
Binary::Gui => build_gui(output_dir, platform, renderer, debug),
|
Binary::Gui => {
|
||||||
Binary::Cli => build_cli(output_dir, platform, renderer, debug),
|
for (platform, triple) in platforms_and_triples(platforms, architectures) {
|
||||||
Binary::Vst => build_vst(platform, renderer, debug),
|
let output_dir = OUTPUT_DIR
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.join(executable_dir(binary, &triple, renderer));
|
||||||
|
|
||||||
|
std::fs::create_dir_all(&output_dir)?;
|
||||||
|
build_gui(output_dir, platform, &triple, renderer, debug)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Binary::Cli => {
|
||||||
|
for (platform, triple) in platforms_and_triples(platforms, architectures) {
|
||||||
|
let output_dir = OUTPUT_DIR
|
||||||
|
.get()
|
||||||
|
.unwrap()
|
||||||
|
.join(executable_dir(binary, &triple, renderer));
|
||||||
|
|
||||||
|
std::fs::create_dir_all(&output_dir)?;
|
||||||
|
build_cli(output_dir, platform, &triple, renderer, debug)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Binary::Vst => {
|
||||||
|
log::warn!("TODO: handle vst builds more smarter");
|
||||||
|
for platform in platforms {
|
||||||
|
if *platform == Platform::Mac {
|
||||||
|
build_vst(*platform, None, renderer, debug)?;
|
||||||
|
} else {
|
||||||
|
for triple in platform_triples(platform, architectures) {
|
||||||
|
build_vst(*platform, Some(&triple), renderer, debug)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn platform_triples<'a>(
|
||||||
|
platform: &'a Platform,
|
||||||
|
architectures: &'a [Architecture],
|
||||||
|
) -> impl Iterator<Item = cfg_expr::targets::Triple> + 'a {
|
||||||
|
architectures
|
||||||
|
.iter()
|
||||||
|
.filter_map(|architecture| get_triple(*platform, *architecture).map(|v| v.triple))
|
||||||
|
.filter(|triple| {
|
||||||
|
if is_toolchain_installed(triple) {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
log::warn!("toolchain not installed for {triple} - skipping");
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
fn platforms_and_triples(
|
||||||
|
platforms: &[Platform],
|
||||||
|
architectures: &[Architecture],
|
||||||
|
) -> Vec<(Platform, cfg_expr::targets::Triple)> {
|
||||||
|
platforms
|
||||||
|
.iter()
|
||||||
|
.flat_map(|platform| platform_triples(platform, architectures).map(|v| (*platform, v)))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_gui(
|
fn build_gui(
|
||||||
output_dir: std::path::PathBuf,
|
output_dir: std::path::PathBuf,
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -126,6 +191,7 @@ fn build_gui(
|
||||||
run_build(
|
run_build(
|
||||||
"gui",
|
"gui",
|
||||||
platform,
|
platform,
|
||||||
|
triple,
|
||||||
renderer,
|
renderer,
|
||||||
debug,
|
debug,
|
||||||
Some(["-F", ui].into_iter().map(String::from).collect()),
|
Some(["-F", ui].into_iter().map(String::from).collect()),
|
||||||
|
@ -135,6 +201,7 @@ fn build_gui(
|
||||||
|
|
||||||
fn run_gui(
|
fn run_gui(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -144,6 +211,7 @@ fn run_gui(
|
||||||
"run",
|
"run",
|
||||||
"gui",
|
"gui",
|
||||||
platform,
|
platform,
|
||||||
|
triple,
|
||||||
renderer,
|
renderer,
|
||||||
debug,
|
debug,
|
||||||
Some(["-F", ui].into_iter().map(String::from).collect()),
|
Some(["-F", ui].into_iter().map(String::from).collect()),
|
||||||
|
@ -154,14 +222,16 @@ fn run_gui(
|
||||||
fn build_cli(
|
fn build_cli(
|
||||||
output_dir: std::path::PathBuf,
|
output_dir: std::path::PathBuf,
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
run_build("cli", platform, renderer, debug, None, output_dir)
|
run_build("cli", platform, triple, renderer, debug, None, output_dir)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_cli(
|
fn run_cli(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
@ -171,13 +241,22 @@ fn run_cli(
|
||||||
.position(|arg| arg == "--")
|
.position(|arg| arg == "--")
|
||||||
.map(|extra_args_index| args[extra_args_index..].to_vec());
|
.map(|extra_args_index| args[extra_args_index..].to_vec());
|
||||||
|
|
||||||
let _ = cargo_exec("run", "cli", platform, renderer, debug, additional_flags)?;
|
let _ = cargo_exec(
|
||||||
|
"run",
|
||||||
|
"cli",
|
||||||
|
platform,
|
||||||
|
triple,
|
||||||
|
renderer,
|
||||||
|
debug,
|
||||||
|
additional_flags,
|
||||||
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_build(
|
fn run_build(
|
||||||
package: &str,
|
package: &str,
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
additional_flags: Option<Vec<String>>,
|
additional_flags: Option<Vec<String>>,
|
||||||
|
@ -187,6 +266,7 @@ fn run_build(
|
||||||
"build",
|
"build",
|
||||||
package,
|
package,
|
||||||
platform,
|
platform,
|
||||||
|
triple,
|
||||||
renderer,
|
renderer,
|
||||||
debug,
|
debug,
|
||||||
additional_flags,
|
additional_flags,
|
||||||
|
@ -200,10 +280,26 @@ fn run_build(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static INSTALLED_TRIPLES: std::sync::LazyLock<Vec<String>> = std::sync::LazyLock::new(|| {
|
||||||
|
let sh = Shell::new().expect("failed to open shell");
|
||||||
|
match xshell::cmd!(sh, "rustup target list --installed").output() {
|
||||||
|
Ok(output) => output.stdout.lines().map_while(Result::ok).collect(),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("Error listing installed targets: {e:?}");
|
||||||
|
std::process::exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fn is_toolchain_installed(triple: &cfg_expr::targets::Triple) -> bool {
|
||||||
|
INSTALLED_TRIPLES.contains(&triple.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn cargo_exec(
|
fn cargo_exec(
|
||||||
verb: &str,
|
verb: &str,
|
||||||
package: &str,
|
package: &str,
|
||||||
platform: Platform,
|
_platform: Platform,
|
||||||
|
triple: &cfg_expr::targets::Triple,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
additional_flags: Option<Vec<String>>,
|
additional_flags: Option<Vec<String>>,
|
||||||
|
@ -212,11 +308,11 @@ fn cargo_exec(
|
||||||
Box<dyn std::error::Error>,
|
Box<dyn std::error::Error>,
|
||||||
> {
|
> {
|
||||||
let sh = Shell::new()?;
|
let sh = Shell::new()?;
|
||||||
let target = platform.as_target();
|
|
||||||
let release = if debug { "" } else { "--release" };
|
let release = if debug { "" } else { "--release" };
|
||||||
|
|
||||||
let renderer = renderer.as_feature();
|
let renderer = renderer.as_feature();
|
||||||
let args=format!("{verb} -p {package} --target {target} {release} --no-default-features -F {renderer} --message-format=json");
|
let args=format!("{verb} -q -p {package} --target {triple} {release} --no-default-features -F {renderer} --message-format=json");
|
||||||
let args = args.split_whitespace().map(|s| s.to_string());
|
let args = args.split_whitespace().map(|s| s.to_string());
|
||||||
let args = if let Some(additional_flags) = additional_flags {
|
let args = if let Some(additional_flags) = additional_flags {
|
||||||
args.chain(additional_flags).collect::<Vec<_>>()
|
args.chain(additional_flags).collect::<Vec<_>>()
|
||||||
|
@ -241,13 +337,15 @@ fn as_artifact(message: cargo_metadata::Message) -> Option<cargo_metadata::Artif
|
||||||
|
|
||||||
fn build_vst(
|
fn build_vst(
|
||||||
platform: Platform,
|
platform: Platform,
|
||||||
|
triple: Option<&cfg_expr::targets::Triple>,
|
||||||
renderer: Renderer,
|
renderer: Renderer,
|
||||||
debug: bool,
|
debug: bool,
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
|
let triple_str = triple.map(|t| t.to_string());
|
||||||
let mut args = if platform == Platform::Mac {
|
let mut args = if platform == Platform::Mac {
|
||||||
vec!["bundle-universal"]
|
vec!["bundle-universal"]
|
||||||
} else {
|
} else {
|
||||||
vec!["bundle", "--target", platform.as_target()]
|
vec!["bundle", "--target", triple_str.as_ref().unwrap().as_str()]
|
||||||
};
|
};
|
||||||
if !debug {
|
if !debug {
|
||||||
args.push("--release");
|
args.push("--release");
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
use cfg_expr::expr::TargetMatcher;
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone, Copy, Debug, strum::EnumIter, PartialEq, Eq)]
|
#[derive(clap::ValueEnum, Clone, Copy, Debug, strum::EnumIter, PartialEq, Eq)]
|
||||||
pub enum Platform {
|
pub enum Platform {
|
||||||
Windows,
|
Windows,
|
||||||
|
@ -6,11 +8,11 @@ pub enum Platform {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Platform {
|
impl Platform {
|
||||||
pub fn as_target(&self) -> &str {
|
pub fn as_cargo(&self) -> cfg_expr::targets::Os {
|
||||||
match self {
|
match self {
|
||||||
Platform::Windows => "x86_64-pc-windows-gnu",
|
Platform::Windows => cfg_expr::targets::Os::windows,
|
||||||
Platform::Linux => "x86_64-unknown-linux-gnu",
|
Platform::Linux => cfg_expr::targets::Os::linux,
|
||||||
Platform::Mac => "aarch64-apple-darwin",
|
Platform::Mac => cfg_expr::targets::Os::macos,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +31,49 @@ impl Platform {
|
||||||
} else if cfg!(target_os = "linux") {
|
} else if cfg!(target_os = "linux") {
|
||||||
Self::Linux
|
Self::Linux
|
||||||
} else {
|
} else {
|
||||||
todo!()
|
unimplemented!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_triple(
|
||||||
|
platform: Platform,
|
||||||
|
architecture: Architecture,
|
||||||
|
) -> Option<cfg_expr::targets::TargetInfo> {
|
||||||
|
cfg_expr::targets::ALL_BUILTINS
|
||||||
|
.iter()
|
||||||
|
.find(|b| {
|
||||||
|
b.matches(&cfg_expr::TargetPredicate::Arch(architecture.as_cargo()))
|
||||||
|
&& b.matches(&cfg_expr::TargetPredicate::Os(platform.as_cargo()))
|
||||||
|
})
|
||||||
|
.cloned()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(clap::ValueEnum, Clone, Copy, Debug, strum::EnumIter, PartialEq, Eq)]
|
||||||
|
pub enum Architecture {
|
||||||
|
Aarch64,
|
||||||
|
X86,
|
||||||
|
X86_64,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Architecture {
|
||||||
|
pub fn as_cargo(&self) -> cfg_expr::targets::Arch {
|
||||||
|
match self {
|
||||||
|
Architecture::Aarch64 => cfg_expr::targets::Arch::aarch64,
|
||||||
|
Architecture::X86_64 => cfg_expr::targets::Arch::x86_64,
|
||||||
|
Architecture::X86 => cfg_expr::targets::Arch::x86,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn host_architecture() -> Self {
|
||||||
|
if cfg!(target_arch = "x86_64") {
|
||||||
|
Self::X86_64
|
||||||
|
} else if cfg!(target_arch = "aarch64") {
|
||||||
|
Self::Aarch64
|
||||||
|
} else if cfg!(target_arch = "x86") {
|
||||||
|
Self::X86
|
||||||
|
} else {
|
||||||
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue