From e79f6dc259d5e4efb0c6c3eb4484119cab4e29e8 Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 26 Apr 2024 12:08:30 +0200 Subject: [PATCH 1/3] Improve cargo 3ds new and bump shlex --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- src/command.rs | 4 +++- src/lib.rs | 44 ++++++++++++++++++++++++++------------------ src/main.rs | 5 +++-- 5 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 026942f..27e0f7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -291,9 +291,9 @@ dependencies = [ [[package]] name = "shlex" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7cee0529a6d40f580e7a5e6c495c8fbfe21b7b52795ed4bb5e62cdf92bc6380" +checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" [[package]] name = "strsim" diff --git a/Cargo.toml b/Cargo.toml index de30cce..29efea0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,5 +18,5 @@ serde = { version = "1.0.139", features = ["derive"] } tee = "0.1.0" toml = "0.5.6" clap = { version = "4.0.15", features = ["derive", "wrap_help"] } -shlex = "1.1.0" +shlex = "1.3.0" serde_json = "1.0.108" diff --git a/src/command.rs b/src/command.rs index 02f998f..abeeeb5 100644 --- a/src/command.rs +++ b/src/command.rs @@ -555,9 +555,11 @@ impl New { let toml_path = project_path.join("Cargo.toml"); let romfs_path = project_path.join("romfs"); let main_rs_path = project_path.join("src/main.rs"); + let dummy_romfs_path = romfs_path.join("PUT_YOUR_ROMFS_FILES_HERE.txt"); - // Create the "romfs" directory + // Create the "romfs" directory, and place a dummy file within it. fs::create_dir(romfs_path).unwrap(); + fs::File::create(dummy_romfs_path).unwrap(); // Read the contents of `Cargo.toml` to a string let mut buf = String::new(); diff --git a/src/lib.rs b/src/lib.rs index a9254fa..2774115 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,22 +25,25 @@ use crate::graph::UnitGraph; pub fn run_cargo(input: &Input, message_format: Option) -> (ExitStatus, Vec) { let mut command = make_cargo_command(input, &message_format); - let libctru = if should_use_ctru_debuginfo(&command, input.verbose) { - "ctrud" - } else { - "ctru" - }; + // The unit graph is needed only when compiling a program. + if input.cmd.should_compile() { + let libctru = if should_use_ctru_debuginfo(&command, input.verbose) { + "ctrud" + } else { + "ctru" + }; - let rustflags = command - .get_envs() - .find(|(var, _)| var == &OsStr::new("RUSTFLAGS")) - .and_then(|(_, flags)| flags) - .unwrap_or_default() - .to_string_lossy(); + let rustflags = command + .get_envs() + .find(|(var, _)| var == &OsStr::new("RUSTFLAGS")) + .and_then(|(_, flags)| flags) + .unwrap_or_default() + .to_string_lossy(); - let rustflags = format!("{rustflags} -l{libctru}"); + let rustflags = format!("{rustflags} -l{libctru}"); - command.env("RUSTFLAGS", rustflags); + command.env("RUSTFLAGS", rustflags); + } if input.verbose { print_command(&command); @@ -182,10 +185,13 @@ fn print_command(command: &Command) { eprintln!( " {}={} \\", k.to_string_lossy(), - v.map_or_else(String::new, |s| shlex::quote(&s).to_string()) + v.map_or_else(String::new, |s| shlex::try_quote(&s).unwrap().to_string()) ); } - eprintln!(" {}\n", shlex::join(cmd_str.iter().map(String::as_str))); + eprintln!( + " {}\n", + shlex::try_join(cmd_str.iter().map(String::as_str)).unwrap() + ); } /// Finds the sysroot path of the current toolchain @@ -206,11 +212,13 @@ pub fn find_sysroot() -> PathBuf { /// Checks the current rust version and channel. /// Exits if the minimum requirement is not met. -pub fn check_rust_version() { +pub fn check_rust_version(input: &Input) { let rustc_version = rustc_version::version_meta().unwrap(); - if rustc_version.channel > Channel::Nightly { - eprintln!("cargo-3ds requires a nightly rustc version."); + // If the channel isn't nightly, we can't make use the required unstable tools. + // However, `cargo new` doesn't have these requirements. + if rustc_version.channel > Channel::Nightly && input.cmd.should_compile() { + eprintln!("building with cargo-3ds requires a nightly rustc version."); eprintln!( "Please run `rustup override set nightly` to use nightly in the \ current directory, or use `cargo +nightly 3ds` to use it for a \ diff --git a/src/main.rs b/src/main.rs index 022e635..d43bf57 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,11 @@ use cargo_3ds::{check_rust_version, run_cargo}; use clap::Parser; fn main() { - check_rust_version(); - let Cargo::Input(mut input) = Cargo::parse(); + // Depending on the command, we might have different base requirements for the Rust version. + check_rust_version(&input); + let message_format = match input.cmd.extract_message_format() { Ok(fmt) => fmt, Err(msg) => { From 26e464fab29ebe409cbf6b8fc3f8914f52e9814c Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 26 Apr 2024 18:54:34 +0200 Subject: [PATCH 2/3] Bump msrv --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b2f73ab..f2470b6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -43,7 +43,7 @@ jobs: matrix: toolchain: # Oldest supported nightly - - nightly-2023-06-01 + - nightly-2024-02-18 - nightly continue-on-error: ${{ matrix.toolchain == 'nightly' }} From 067520cd2fb4e88f9c16c786b5d97a64776e03de Mon Sep 17 00:00:00 2001 From: Andrea Ciliberti Date: Fri, 26 Apr 2024 19:00:20 +0200 Subject: [PATCH 3/3] typos --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2774115..5b6cb5c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -215,8 +215,8 @@ pub fn find_sysroot() -> PathBuf { pub fn check_rust_version(input: &Input) { let rustc_version = rustc_version::version_meta().unwrap(); - // If the channel isn't nightly, we can't make use the required unstable tools. - // However, `cargo new` doesn't have these requirements. + // If the channel isn't nightly, we can't make use of the required unstable tools. + // However, `cargo 3ds new` doesn't have these requirements. if rustc_version.channel > Channel::Nightly && input.cmd.should_compile() { eprintln!("building with cargo-3ds requires a nightly rustc version."); eprintln!(