diff --git a/crates/cargo-oxide/src/commands.rs b/crates/cargo-oxide/src/commands.rs index a8ce3841be..3a94cab7c4 100644 --- a/crates/cargo-oxide/src/commands.rs +++ b/crates/cargo-oxide/src/commands.rs @@ -454,7 +454,7 @@ fn run_host_cargo( /// Same as [`codegen_run`] but uses `cargo build --release` instead of /// `cargo run`. Useful for cross-compilation or when the target hardware /// (e.g., Blackwell tensor cores) isn't available on the build machine. -pub fn codegen_build_example( +pub fn codegen_build( ctx: &Context, example: &str, verbose: bool, @@ -541,7 +541,11 @@ pub fn codegen_build_example( /// module, textual LLVM IR, and the final PTX or NVVM IR. After the build, /// generated artifacts are printed to stdout. pub fn codegen_show_pipeline(ctx: &Context, example: &str, emit_nvvm_ir: bool, arch: Option<&str>) { - let example_dir = resolve_example_dir(ctx, example); + let example_dir = if ctx.is_workspace { + resolve_example_dir(ctx, example) + } else { + ctx.workspace_root.clone() + }; clean_generated_files(&example_dir, example); @@ -635,7 +639,11 @@ pub fn codegen_debug(ctx: &Context, example: &str, use_cgdb: bool, use_tui: bool None }; - let example_dir = resolve_example_dir(ctx, example); + let example_dir = if ctx.is_workspace { + resolve_example_dir(ctx, example) + } else { + ctx.workspace_root.clone() + }; println!("Building {} with debug info...", example); diff --git a/crates/cargo-oxide/src/main.rs b/crates/cargo-oxide/src/main.rs index 47dcd91553..229f60f70f 100644 --- a/crates/cargo-oxide/src/main.rs +++ b/crates/cargo-oxide/src/main.rs @@ -91,8 +91,8 @@ enum Commands { }, /// Show the full compilation pipeline (MIR -> PTX/NVVM IR) with verbose output Pipeline { - /// Example name (from crates/rustc-codegen-cuda/examples/) - example: String, + /// Example name (required in workspace, optional for standalone projects) + example: Option, /// Generate NVVM IR (use with libNVVM -gen-lto) #[arg(long)] emit_nvvm_ir: bool, @@ -102,8 +102,8 @@ enum Commands { }, /// Build with debug info and launch cuda-gdb Debug { - /// Example name (from crates/rustc-codegen-cuda/examples/) - example: String, + /// Example name (required in workspace, optional for standalone projects) + example: Option, /// Use cgdb frontend (better source view, vim keys) #[arg(long)] cgdb: bool, @@ -156,7 +156,7 @@ fn main() { verbose, } => { let ctx = commands::resolve_context(); - let example = resolve_example_name(example, &ctx); + let example = resolve_example_name(example, &ctx, "run"); validate_nvvm_ir_arch(&example, emit_nvvm_ir, &arch); commands::codegen_run( &ctx, @@ -176,9 +176,9 @@ fn main() { verbose, } => { let ctx = commands::resolve_context(); - let example = resolve_example_name(example, &ctx); + let example = resolve_example_name(example, &ctx, "build"); validate_nvvm_ir_arch(&example, emit_nvvm_ir, &arch); - commands::codegen_build_example( + commands::codegen_build( &ctx, &example, verbose, @@ -192,12 +192,14 @@ fn main() { emit_nvvm_ir, arch, } => { - validate_nvvm_ir_arch(&example, emit_nvvm_ir, &arch); let ctx = commands::resolve_context(); + let example = resolve_example_name(example, &ctx, "pipeline"); + validate_nvvm_ir_arch(&example, emit_nvvm_ir, &arch); commands::codegen_show_pipeline(&ctx, &example, emit_nvvm_ir, arch.as_deref()); } Commands::Debug { example, cgdb, tui } => { let ctx = commands::resolve_context(); + let example = resolve_example_name(example, &ctx, "debug"); commands::codegen_debug(&ctx, &example, cgdb, tui); } Commands::Fmt { check } => { @@ -223,7 +225,7 @@ fn main() { /// In workspace mode the name is required; in standalone mode it defaults /// to the current directory name (which matches the package name from /// `cargo oxide new`). -fn resolve_example_name(name: Option, ctx: &commands::Context) -> String { +fn resolve_example_name(name: Option, ctx: &commands::Context, subcommand: &str) -> String { if let Some(n) = name { return n; } @@ -238,7 +240,7 @@ fn resolve_example_name(name: Option, ctx: &commands::Context) -> String } eprintln!("Error: is required when running inside the cuda-oxide workspace."); eprintln!(); - eprintln!("Usage: cargo oxide run "); + eprintln!("Usage: cargo oxide {subcommand} "); eprintln!(); eprintln!("Available examples are in crates/rustc-codegen-cuda/examples/"); std::process::exit(1);