@@ -6,7 +6,7 @@ use std::sync::OnceLock;
66use cargo_metadata:: Message ;
77use clap:: { Args , Parser , Subcommand } ;
88
9- use crate :: { build_3dsx, build_smdh, find_cargo , get_metadata, link, print_command, CTRConfig } ;
9+ use crate :: { build_3dsx, build_smdh, cargo , get_metadata, link, print_command, CTRConfig } ;
1010
1111#[ derive( Parser , Debug ) ]
1212#[ command( name = "cargo" , bin_name = "cargo" ) ]
@@ -22,7 +22,7 @@ pub struct Input {
2222 pub cmd : CargoCmd ,
2323
2424 /// Print the exact commands `cargo-3ds` is running. Note that this does not
25- /// set the verbose flag for cargo itself. To set cargo's verbose flag, add
25+ /// set the verbose flag for cargo itself. To set cargo's verbosity flag, add
2626 /// `-- -v` to the end of the command line.
2727 #[ arg( long, short = 'v' , global = true ) ]
2828 pub verbose : bool ,
@@ -165,21 +165,21 @@ impl CargoCmd {
165165
166166 // We can't run 3DS executables on the host, but we want to respect
167167 // the user's "runner" configuration if set.
168- if test. doc {
169- eprintln ! ( "Documentation tests requested, no 3dsx will be built" ) ;
168+ //
169+ // If doctests were requested, `--no-run` will be rejected on the
170+ // command line and must be set with RUSTDOCFLAGS instead:
171+ // https://github.com/rust-lang/rust/issues/87022
172+ if !test. run_args . use_custom_runner ( ) && !test. doc {
173+ cargo_args. push ( "--no-run" . to_string ( ) ) ;
174+ }
170175
171- // https://github.com/rust-lang/cargo/issues/7040
172- cargo_args. append ( & mut vec ! [
173- "--doc" . to_string( ) ,
174- "-Z" . to_string( ) ,
175- "doctest-xcompile" . to_string( ) ,
176- // doctests don't automatically build the `test` crate,
177- // so we manually specify it on the command line
178- "-Z" . to_string( ) ,
179- "build-std=std,test" . to_string( ) ,
176+ if test. doc {
177+ cargo_args. extend ( [
178+ "--doc" . into ( ) ,
179+ // https://github.com/rust-lang/cargo/issues/7040
180+ "-Z" . into ( ) ,
181+ "doctest-xcompile" . into ( ) ,
180182 ] ) ;
181- } else if !test. run_args . is_runner_configured ( ) {
182- cargo_args. push ( "--no-run" . to_string ( ) ) ;
183183 }
184184
185185 cargo_args
@@ -206,7 +206,7 @@ impl CargoCmd {
206206 match self {
207207 CargoCmd :: Build ( _) => "build" ,
208208 CargoCmd :: Run ( run) => {
209- if run. is_runner_configured ( ) {
209+ if run. use_custom_runner ( ) {
210210 "run"
211211 } else {
212212 "build"
@@ -228,23 +228,31 @@ impl CargoCmd {
228228
229229 /// Whether or not this command should build a 3DSX executable file.
230230 pub fn should_build_3dsx ( & self ) -> bool {
231- matches ! (
232- self ,
233- Self :: Build ( _) | Self :: Run ( _) | Self :: Test ( Test { doc: false , .. } )
234- )
231+ match self {
232+ Self :: Build ( _) | CargoCmd :: Run ( _) => true ,
233+ & Self :: Test ( Test { doc, .. } ) => {
234+ if doc {
235+ eprintln ! ( "Documentation tests requested, no 3dsx will be built" ) ;
236+ false
237+ } else {
238+ true
239+ }
240+ }
241+ _ => false ,
242+ }
235243 }
236244
237245 /// Whether or not the resulting executable should be sent to the 3DS with
238246 /// `3dslink`.
239247 pub fn should_link_to_device ( & self ) -> bool {
240248 match self {
241- Self :: Test ( test ) => ! ( test . no_run || test . run_args . is_runner_configured ( ) ) ,
242- Self :: Run ( run) => !run. is_runner_configured ( ) ,
249+ Self :: Test ( Test { no_run : true , .. } ) => false ,
250+ Self :: Run ( run) | Self :: Test ( Test { run_args : run , .. } ) => !run. use_custom_runner ( ) ,
243251 _ => false ,
244252 }
245253 }
246254
247- pub const DEFAULT_MESSAGE_FORMAT : & str = "json-render-diagnostics" ;
255+ pub const DEFAULT_MESSAGE_FORMAT : & ' static str = "json-render-diagnostics" ;
248256
249257 pub fn extract_message_format ( & mut self ) -> Result < Option < String > , String > {
250258 let cargo_args = match self {
@@ -347,7 +355,7 @@ impl RemainingArgs {
347355
348356 if let Some ( split) = args. iter ( ) . position ( |s| s == "--" ) {
349357 let second_half = args. split_off ( split + 1 ) ;
350- // take off the "--" arg we found
358+ // take off the "--" arg we found, we'll add one later if needed
351359 args. pop ( ) ;
352360
353361 ( args, second_half)
@@ -421,7 +429,7 @@ impl Run {
421429 // Run the normal "build" callback
422430 self . build_args . callback ( config) ;
423431
424- if !self . is_runner_configured ( ) {
432+ if !self . use_custom_runner ( ) {
425433 if let Some ( cfg) = config {
426434 eprintln ! ( "Running 3dslink" ) ;
427435 link ( cfg, self , self . build_args . verbose ) ;
@@ -431,45 +439,44 @@ impl Run {
431439
432440 /// Returns whether the cargo environment has `target.armv6k-nintendo-3ds.runner`
433441 /// configured. This will only be checked once during the lifetime of the program,
434- /// and takes into account the usual ways Cargo looks for
442+ /// and takes into account the usual ways Cargo looks for its
435443 /// [configuration](https://doc.rust-lang.org/cargo/reference/config.html):
436444 ///
437445 /// - `.cargo/config.toml`
438446 /// - Environment variables
439447 /// - Command-line `--config` overrides
440- pub fn is_runner_configured ( & self ) -> bool {
448+ pub fn use_custom_runner ( & self ) -> bool {
441449 static HAS_RUNNER : OnceLock < bool > = OnceLock :: new ( ) ;
442450
443- let has_runner = HAS_RUNNER . get_or_init ( || {
444- let mut cmd = find_cargo ( ) ;
445-
446- let config_args = self . config . iter ( ) . map ( |cfg| format ! ( "--config={cfg}" ) ) ;
447-
448- cmd. args ( config_args)
449- . args ( [
450- "config" ,
451- "-Zunstable-options" ,
452- "get" ,
453- "target.armv6k-nintendo-3ds.runner" ,
454- ] )
455- . stdout ( Stdio :: null ( ) )
456- . stderr ( Stdio :: null ( ) ) ;
451+ let & custom_runner_configured = HAS_RUNNER . get_or_init ( || {
452+ let mut cmd = cargo ( & self . config ) ;
453+ cmd. args ( [
454+ // https://github.com/rust-lang/cargo/issues/9301
455+ "-Z" ,
456+ "unstable-options" ,
457+ "config" ,
458+ "get" ,
459+ "target.armv6k-nintendo-3ds.runner" ,
460+ ] )
461+ . stdout ( Stdio :: null ( ) )
462+ . stderr ( Stdio :: null ( ) ) ;
457463
458464 if self . build_args . verbose {
459465 print_command ( & cmd) ;
460466 }
461467
468+ // `cargo config get` exits zero if the config exists, or nonzero otherwise
462469 cmd. status ( ) . map_or ( false , |status| status. success ( ) )
463470 } ) ;
464471
465472 if self . build_args . verbose {
466473 eprintln ! (
467474 "Custom runner is {}configured" ,
468- if * has_runner { "" } else { "not " }
475+ if custom_runner_configured { "" } else { "not " }
469476 ) ;
470477 }
471478
472- * has_runner
479+ custom_runner_configured
473480 }
474481}
475482
@@ -488,13 +495,13 @@ impl Test {
488495 }
489496}
490497
491- const TOML_CHANGES : & str = "ctru-rs = { git = \ " https://github.com/rust3ds/ctru-rs\ " }
498+ const TOML_CHANGES : & str = r# "ctru-rs = { git = "https://github.com/rust3ds/ctru-rs" }
492499
493500[package.metadata.cargo-3ds]
494- romfs_dir = \ " romfs\ "
495- " ;
501+ romfs_dir = "romfs"
502+ "# ;
496503
497- const CUSTOM_MAIN_RS : & str = "use ctru::prelude::*;
504+ const CUSTOM_MAIN_RS : & str = r# "use ctru::prelude::*;
498505
499506fn main() {
500507 ctru::use_panic_handler();
@@ -504,8 +511,8 @@ fn main() {
504511 let gfx = Gfx::new().unwrap();
505512 let _console = Console::new(gfx.top_screen.borrow_mut());
506513
507- println!(\ " Hello, World!\ " );
508- println!(\" \\ x1b[29;16HPress Start to exit\ " );
514+ println!("Hello, World!");
515+ println!("\ x1b[29;16HPress Start to exit");
509516
510517 while apt.main_loop() {
511518 gfx.wait_for_vblank();
@@ -516,7 +523,7 @@ fn main() {
516523 }
517524 }
518525}
519- " ;
526+ "# ;
520527
521528impl New {
522529 /// Callback for `cargo 3ds new`.
0 commit comments