Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions crates/cargo-oxide/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
22 changes: 12 additions & 10 deletions crates/cargo-oxide/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
/// Generate NVVM IR (use with libNVVM -gen-lto)
#[arg(long)]
emit_nvvm_ir: bool,
Expand All @@ -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<String>,
/// Use cgdb frontend (better source view, vim keys)
#[arg(long)]
cgdb: bool,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 } => {
Expand All @@ -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<String>, ctx: &commands::Context) -> String {
fn resolve_example_name(name: Option<String>, ctx: &commands::Context, subcommand: &str) -> String {
if let Some(n) = name {
return n;
}
Expand All @@ -238,7 +240,7 @@ fn resolve_example_name(name: Option<String>, ctx: &commands::Context) -> String
}
eprintln!("Error: <EXAMPLE> is required when running inside the cuda-oxide workspace.");
eprintln!();
eprintln!("Usage: cargo oxide run <EXAMPLE>");
eprintln!("Usage: cargo oxide {subcommand} <EXAMPLE>");
eprintln!();
eprintln!("Available examples are in crates/rustc-codegen-cuda/examples/");
std::process::exit(1);
Expand Down
Loading