Skip to content
Open
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
453 changes: 453 additions & 0 deletions src/cmds/gcc/gcc_cmd.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/cmds/gcc/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod gcc_cmd;
1 change: 1 addition & 0 deletions src/cmds/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub mod cloud;
pub mod dotnet;
pub mod gcc;
pub mod git;
pub mod go;
pub mod js;
Expand Down
9 changes: 5 additions & 4 deletions src/core/toml_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,7 @@ const RUST_HANDLED_COMMANDS: &[&str] = &[
"proxy",
"verify",
"learn",
"gcc",
];

fn compile_filter(name: String, def: TomlFilterDef) -> Result<CompiledFilter, String> {
Expand Down Expand Up @@ -1612,8 +1613,8 @@ match_command = "^make\\b"
let filters = make_filters(BUILTIN_TOML);
assert_eq!(
filters.len(),
58,
"Expected exactly 58 built-in filters, got {}. \
57,
"Expected exactly 57 built-in filters, got {}. \
Update this count when adding/removing filters in src/filters/.",
filters.len()
);
Expand Down Expand Up @@ -1673,8 +1674,8 @@ expected = "output line 1\noutput line 2"
// All 58 existing filters still present + 1 new = 59
assert_eq!(
filters.len(),
59,
"Expected 59 filters after concat (58 built-in + 1 new)"
58,
"Expected 58 filters after concat (58 built-in + 1 new)"
);

// New filter is discoverable
Expand Down
38 changes: 38 additions & 0 deletions src/discover/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ pub const PATTERNS: &[&str] = &[
r"^(?:bundle\s+exec\s+)?(?:bin/)?(?:rake|rails)\s+test",
r"^(?:bundle\s+exec\s+)?rspec(?:\s|$)",
r"^(?:bundle\s+exec\s+)?rubocop(?:\s|$)",
// C/C++ compilers (one pattern per binary so rtk_cmd can encode the name)
r"^gcc(\s|$)",
r"^g\+\+(\s|$)",
r"^clang(\s|$)",
r"^clang\+\+(\s|$)",
// AWS CLI
r"^aws\s+",
// PostgreSQL
Expand Down Expand Up @@ -378,6 +383,39 @@ pub const RULES: &[RtkRule] = &[
subcmd_savings: &[],
subcmd_status: &[],
},
// C/C++ compilers
RtkRule {
rtk_cmd: "rtk gcc",
rewrite_prefixes: &["gcc"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk g++",
rewrite_prefixes: &["g++"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk clang",
rewrite_prefixes: &["clang"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
RtkRule {
rtk_cmd: "rtk clang++",
rewrite_prefixes: &["clang++"],
category: "Build",
savings_pct: 70.0,
subcmd_savings: &[],
subcmd_status: &[],
},
// AWS CLI
RtkRule {
rtk_cmd: "rtk aws",
Expand Down
49 changes: 0 additions & 49 deletions src/filters/gcc.toml

This file was deleted.

44 changes: 44 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod parser;
// Re-export command modules for routing
use cmds::cloud::{aws_cmd, container, curl_cmd, psql_cmd, wget_cmd};
use cmds::dotnet::{binlog, dotnet_cmd, dotnet_format_report, dotnet_trx};
use cmds::gcc::gcc_cmd;
use cmds::git::{diff_cmd, gh_cmd, git, gt_cmd};
use cmds::go::{go_cmd, golangci_cmd};
use cmds::js::{
Expand Down Expand Up @@ -654,6 +655,32 @@ enum Commands {
args: Vec<String>,
},

/// gcc compiler with grouped error output (60-80% token savings)
Gcc {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},

/// g++ compiler with grouped error output (60-80% token savings)
#[command(name = "g++")]
Gxx {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},

/// clang compiler with grouped error output (60-80% token savings)
Clang {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},

/// clang++ compiler with grouped error output (60-80% token savings)
#[command(name = "clang++")]
Clangxx {
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,
},

/// Show hook rewrite audit metrics (requires RTK_HOOK_AUDIT=1)
#[command(name = "hook-audit")]
HookAudit {
Expand Down Expand Up @@ -2049,6 +2076,19 @@ fn main() -> Result<()> {
golangci_cmd::run(&args, cli.verbose)?;
}

Commands::Gcc { args } => {
gcc_cmd::run("gcc", &args, cli.verbose)?;
}
Commands::Gxx { args } => {
gcc_cmd::run("g++", &args, cli.verbose)?;
}
Commands::Clang { args } => {
gcc_cmd::run("clang", &args, cli.verbose)?;
}
Commands::Clangxx { args } => {
gcc_cmd::run("clang++", &args, cli.verbose)?;
}

Commands::HookAudit { since } => {
hooks::hook_audit_cmd::run(since, cli.verbose)?;
}
Expand Down Expand Up @@ -2268,6 +2308,10 @@ fn is_operational_command(cmd: &Commands) -> bool {
| Commands::Go { .. }
| Commands::GolangciLint { .. }
| Commands::Gt { .. }
| Commands::Gcc { .. }
| Commands::Gxx { .. }
| Commands::Clang { .. }
| Commands::Clangxx { .. }
)
}

Expand Down
Empty file.
43 changes: 43 additions & 0 deletions tests/fixtures/gcc/build_errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
In file included from src/main.c:3:
src/utils.h:12:5: warning: implicit declaration of function 'strlcpy' [-Wimplicit-function-declaration]
12 | strlcpy(dst, src, size);
| ^~~~~~~
src/utils.h:12:5: note: include '<string.h>' or provide a declaration of 'strlcpy'
src/main.c: In function 'main':
src/main.c:25:9: error: 'x' undeclared (first use in this function)
25 | x = 42;
| ^
src/main.c:25:9: note: each undeclared identifier is reported only once for each function it appears in
src/main.c:31:12: error: expected ';' before '}' token
31 | return 0
| ^
| ;
31 | }
| ~
src/main.c:45:22: warning: unused variable 'buf' [-Wunused-variable]
45 | char buf[256];
| ^~~~
src/parser.c: In function 'parse_line':
src/parser.c:88:5: error: implicit declaration of function 'my_strdup' [-Wimplicit-function-declaration]
88 | return my_strdup(line);
| ^~~~~~
src/parser.c:88:12: warning: returning 'int' from a function with return type 'char *' makes pointer from integer without a cast [-Wint-conversion]
88 | return my_strdup(line);
| ^~~~~~~~~
src/parser.c:102:20: error: incompatible types when assigning to type 'int' from type 'char *'
102 | token->value = strdup(buf);
| ^~~~~
src/lexer.c: In function 'tokenize':
src/lexer.c:55:18: error: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
55 | size_t len = strlen(count);
| ^~~~~ ~~~~~
| |
| int *
src/lexer.c:55:18: note: expected 'const char *' but argument is of type 'int *'
src/lexer.c:72:12: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'int' [-Wformat=]
72 | printf("%s\n", value);
| ~^ ~~~~~
| | |
| char * int
| %d
make: *** [Makefile:10: build] Error 1
7 changes: 7 additions & 0 deletions tests/fixtures/gcc/build_success.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
src/utils.c: In function 'init_buffer':
src/utils.c:14:5: warning: ignoring return value of 'fgets' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | fgets(buf, sizeof(buf), stdin);
| ^~~~~~
src/main.c:88:32: warning: comparison between pointer and integer [-Wpointer-compare]
88 | if (result != NULL && result != 0) {
| ^~