Cargo command to work with Nintendo 3DS project binaries.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8 KiB

use cargo_3ds::commands::{Cargo, CargoCommand};
use cargo_3ds::{build_3dsx, build_elf, build_smdh, check_rust_version, get_metadata, link};
use clap::Parser;
use std::process;
3 years ago
fn main() {
check_rust_version();
let Cargo::Input(mut input) = Cargo::parse();
let should_link = input.cmd == CargoCommand::Build
|| (input.cmd == CargoCommand::Test
&& if input.cargo_opts.contains(&"--no-run".to_string()) {
false
} else {
input.cargo_opts.push("--no-run".to_string());
true
});
let message_format = if let Some(pos) = input
.cargo_opts
.iter()
.position(|s| s.starts_with("--message-format"))
{
let arg = input.cargo_opts.remove(pos);
let format = if let Some((_, format)) = arg.split_once('=') {
format.to_string()
} else {
input.cargo_opts.remove(pos)
};
if !format.starts_with("json") {
eprintln!("error: non-JSON `message-format` is not supported");
process::exit(1);
} else {
format
}
} else {
"json-render-diagnostics".to_string()
};
let (status, messages) = build_elf(input.cmd, &message_format, &input.cargo_opts);
3 years ago
if !status.success() {
process::exit(status.code().unwrap_or(1));
3 years ago
}
if !input.cmd.should_build_3dsx() {
return;
3 years ago
}
println!("Getting metadata");
let app_conf = get_metadata(&messages);
3 years ago
println!("Building smdh:{}", app_conf.path_smdh().display());
build_smdh(&app_conf);
3 years ago
println!("Building 3dsx: {}", app_conf.path_3dsx().display());
build_3dsx(&app_conf);
3 years ago
if should_link {
println!("Running 3dslink");
link(&app_conf);
3 years ago
}
}