Skip to content

Commit

Permalink
Merge pull request #57 from rust3ds/fix/cargo-new
Browse files Browse the repository at this point in the history
  • Loading branch information
Meziu authored May 3, 2024
2 parents af2d8bf + 067520c commit a5d5c3f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' }}
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 3 additions & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::graph::UnitGraph;
pub fn run_cargo(input: &Input, message_format: Option<String>) -> (ExitStatus, Vec<Message>) {
let mut command = make_cargo_command(input, &message_format);

// 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"
Expand Down Expand Up @@ -184,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
Expand All @@ -208,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 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!(
"Please run `rustup override set nightly` to use nightly in the \
current directory, or use `cargo +nightly 3ds` to use it for a \
Expand Down
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit a5d5c3f

Please sign in to comment.