Skip to content

feat: add Rust (rust2cpg) frontend support#25

Merged
Lekssays merged 1 commit into
mainfrom
feat/rust-frontend-support
Jul 15, 2026
Merged

feat: add Rust (rust2cpg) frontend support#25
Lekssays merged 1 commit into
mainfrom
feat/rust-frontend-support

Conversation

@Lekssays

Copy link
Copy Markdown
Owner

Summary

Joern 4.0.581 ships rust2cpg. This wires Rust into codebadger's language registry and satisfies the two frontend-specific runtime requirements needed for a real (non-empty) Rust CPG. Verified end-to-end: rust2cpg on a minimal crate produces a CPG with the expected user methods (add, greet, main).

Registry wiring (src/defaults.py, src/utils/validators.py, config.example.yaml)

  • SUPPORTED_LANGUAGES += rust (both the defaults.py and validators.py copies, and config.example.yaml)
  • LANGUAGE_COMMANDS: rust/opt/joern/joern-cli/rust2cpg
  • FRONTEND_CAPABILITIES: rust2cpg{exclude_regex} (its --help exposes only --exclude/--exclude-regex)
  • LANGUAGE_EXTENSIONS / SCOPE_SOURCE_EXTENSIONS: rustrs
  • Snippet language-inference signals for Rust (fn, let mut, macros, use std::, impl, #[...], ::)

Image changes (Dockerfile)

Both were required to get a non-empty CPG, and both are verified in the rebuilt image:

  1. Base image eclipse-temurin:21-jdk-jammy:21-jdk-noble. rust2cpg's native astgen (rust_ast_gen-linux) is linked against GLIBC_2.39; jammy (Ubuntu 22.04) ships glibc 2.35, so it fails with version `GLIBC_2.39' not found and silently yields an empty CPG. noble (24.04) ships glibc 2.39. glibc is backward-compatible, so every other frontend's native astgen keeps working.
  2. Install the Rust toolchain (rustup, minimal profile → rustc + cargo). rust2cpg's astgen loads the crate by shelling out to cargo/rustc and errors (Are cargo and rustc on your PATH?) without them. docker exec inherits the image ENV PATH, so the frontend finds the toolchain at build time.

Notable decision: Rust is omitted from languages_with_exclusions

Exactly like Go already is. rust2cpg matches --exclude-regex against cargo-resolved paths, and the default exclusion_patterns were observed to collapse a Rust CPG to 0 methods. Rust stays in supported_languages and builds fine — just without exclusion filtering.

ABAP (abap2cpg) — evaluated, left out

abap2cpg is the other frontend new to 4.0.581. Its native abapgen expects a specific serialized ABAP format and rejected ordinary hand-written ABAP (No ABAP files were parsed), so support couldn't be verified. Happy to add it in a follow-up given real ABAP sources to test against.

Verification

  • New image: glibc 2.39, cargo 1.97.0, rustc 1.97.0, JOERN_VERSION=4.0.581.
  • rust2cpg on a demo crate (loaded into Joern) → <global>, add, greet, main.
  • tests/test_validators.py (123) and tests/test_cpg_generator.py + tests/test_build_scoping.py (29) pass. (The unrelated pre-existing RichHandler collection errors in other test modules are an environment/rich-version issue, not from this change.)

Note: config.yaml (gitignored runtime config) was updated locally the same way; only tracked files are in this PR.

🤖 Generated with Claude Code

Joern 4.0.581 ships rust2cpg. Wire Rust into codebadger's language
registry: SUPPORTED_LANGUAGES, LANGUAGE_COMMANDS (-> rust2cpg),
FRONTEND_CAPABILITIES ({exclude_regex}), LANGUAGE_EXTENSIONS /
SCOPE_SOURCE_EXTENSIONS (.rs), the validators mirror + snippet-inference
signals, and config.example.yaml's supported_languages.

Two frontend-specific requirements had to be met for a real (non-empty)
Rust CPG, both verified end-to-end (methods add/greet/main recovered):

* Base image jammy (22.04, glibc 2.35) -> noble (24.04, glibc 2.39).
  rust2cpg's native astgen (rust_ast_gen-linux) is linked against
  GLIBC_2.39 and fails on jammy ("version `GLIBC_2.39' not found"),
  silently yielding an empty CPG. glibc is backward-compatible, so every
  other frontend's native astgen keeps working on noble.

* Install the Rust toolchain (rustup, minimal profile). rust2cpg's astgen
  loads the crate by shelling out to cargo/rustc and errors without them.

Rust is deliberately OMITTED from LANGUAGES_WITH_EXCLUSIONS (same as go):
rust2cpg matches --exclude-regex against cargo-resolved paths, and the
default exclusion_patterns were observed to collapse a Rust CPG to 0
methods. Rust still builds — just without exclusions.

ABAP (abap2cpg, also new in 4.0.581) was evaluated and left out: its
native abapgen expects a specific serialized ABAP format and rejected
ordinary hand-written ABAP, so support could not be verified.

Also update test_invalid_language to use "cobol" now that "rust" is valid.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Lekssays
Lekssays merged commit 2e28509 into main Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant