Add Rust support: usaco lang, lint, and main.rs problems
Brings in the stashed Rust work, merged onto the current CLI. A problem's language is whichever source it has (main.cpp or main.rs); 'usaco lang' sets the default for new problems (.lang, or $USACO_LANG), and 'new --rust/--cpp' picks per problem. template.rs is a paste-ready Rust template whose stdio() uses <io>.in/.out when present and stdin/stdout otherwise. run/test now feed <io>.in on stdin and capture stdout when the program doesn't write <io>.out itself, so Codeforces-style solutions work too. 'reset <name> rust|cpp' switches a problem's language (template is still an alias), and --debug builds Rust with overflow checks and debug assertions. 'usaco lint' runs clippy through a generated, gitignored Cargo.toml that also gives rust-analyzer a project; done/skip/undo keep it in step. LeetCode imports stay C++. Also: done stages solved/ and solving/ separately, so a problem that was never committed from solving/ still gets its "Solve" commit, and the site lists main.rs ahead of other files like it does main.cpp. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# usaco lint [name...]
|
||||
# Regenerates the cargo manifest rust-analyzer reads, then runs clippy over the
|
||||
# rust solutions. With no arguments it lints every one, plus template.rs; names
|
||||
# select individual problems (unique prefixes work, as everywhere else), and
|
||||
# the literal name "template" selects template.rs.
|
||||
command -v cargo >/dev/null || { echo "Error: cargo not found" >&2; exit 1; }
|
||||
|
||||
count="$(sync_cargo_manifest)"
|
||||
if [[ -z "$count" ]]; then
|
||||
echo "No rust solutions or template.rs yet — nothing to lint."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
targets=()
|
||||
for name in "$@"; do
|
||||
if [[ "$name" == template ]]; then
|
||||
[[ -f "$ROOT/template.rs" ]] || { echo "Error: template.rs not found" >&2; exit 1; }
|
||||
targets+=(--bin template)
|
||||
continue
|
||||
fi
|
||||
dir="$(find_problem "$name")" || exit 1
|
||||
[[ -f "$dir/main.rs" ]] || { echo "Error: $(basename "$dir") is not a rust problem" >&2; exit 1; }
|
||||
rel="${dir#"$ROOT"/}"
|
||||
targets+=(--bin "${rel%/*}-${rel##*/}")
|
||||
done
|
||||
|
||||
if [[ ${#targets[@]} -eq 0 ]]; then
|
||||
what="$count rust solution(s)"
|
||||
[[ -f "$ROOT/template.rs" ]] && what+=" and template.rs"
|
||||
echo "${DIM}Linting $what...${RST}"
|
||||
targets=(--bins)
|
||||
fi
|
||||
|
||||
# Builds live under target/, away from the ./main binaries usaco produces.
|
||||
(cd "$ROOT" && cargo clippy --quiet "${targets[@]}")
|
||||
Reference in New Issue
Block a user