From 6e78e5c27ea2f34da3b2024e1a9fe144388c1e3c Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 22 Jan 2022 17:16:38 -0800 Subject: [PATCH 1/2] Allow other Cargo commands (like check and clippy) This makes it easier to switch between check/clippy and build. Otherwise, unless you use the same exact RUSTFLAGS and parameters, Cargo will rebuild everything (throwing away the build cache). --- src/main.rs | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index e2d2f69..825ccd3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,17 +69,22 @@ fn main() { let args: Vec = args.collect(); let args: Vec<&str> = args.iter().map(String::as_str).collect(); - let must_link = match command.as_deref() { - Some("build") => false, - Some("link") => true, - _ => { + let (command, must_link) = match command.as_deref() { + Some("link") => ("link", true), + Some(command) => (command, false), + None => { print_usage(&mut io::stderr()); process::exit(2) } }; - eprintln!("Building ELF"); - build_elf(&args); + eprintln!("Running Cargo"); + build_elf(command, &args); + + if !["build", "link"].contains(&command) { + // We only do more work if it's a build or build + 3dslink operation + return; + } eprintln!("Getting metadata"); let app_conf = get_metadata(&args, &optimization_level); @@ -116,11 +121,13 @@ fn print_usage(f: &mut impl std::io::Write) { Usage: {invocation} build [--release] [CARGO_OPTS...] {invocation} link [--release] [CARGO_OPTS...] + {invocation} [CARGO_OPTS...] {invocation} -h | --help Commands: - build build a 3dsx executable. - link build a 3dsx executable and send it to a device with 3dslink. + build build a 3dsx executable. + link build a 3dsx executable and send it to a device with 3dslink. + execute some other Cargo command with 3ds options configured (ex. check or clippy). Options: -h --help Show this screen. @@ -168,12 +175,12 @@ fn check_rust_version() { } } -fn build_elf(args: &[&str]) { +fn build_elf(command: &str, args: &[&str]) { let rustflags = env::var("RUSTFLAGS").unwrap_or_default() + &format!(" -L{}/libctru/lib -lctru", env::var("DEVKITPRO").unwrap()); let mut process = Command::new("cargo") - .arg("build") + .arg(command) .arg("-Z") .arg("build-std") .arg("--target") From cf3717470d5262c229ac897d07d435c84ba76b60 Mon Sep 17 00:00:00 2001 From: AzureMarker Date: Sat, 22 Jan 2022 17:20:29 -0800 Subject: [PATCH 2/2] Fix the link command --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 825ccd3..aa361d4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -70,7 +70,7 @@ fn main() { let args: Vec<&str> = args.iter().map(String::as_str).collect(); let (command, must_link) = match command.as_deref() { - Some("link") => ("link", true), + Some("link") => ("build", true), Some(command) => (command, false), None => { print_usage(&mut io::stderr()); @@ -81,7 +81,7 @@ fn main() { eprintln!("Running Cargo"); build_elf(command, &args); - if !["build", "link"].contains(&command) { + if command != "build" && !must_link { // We only do more work if it's a build or build + 3dslink operation return; }