feat: add Rust (rust2cpg) frontend support#25
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Joern
4.0.581shipsrust2cpg. 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:rust2cpgon 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 thedefaults.pyandvalidators.pycopies, andconfig.example.yaml)LANGUAGE_COMMANDS:rust→/opt/joern/joern-cli/rust2cpgFRONTEND_CAPABILITIES:rust2cpg→{exclude_regex}(its--helpexposes only--exclude/--exclude-regex)LANGUAGE_EXTENSIONS/SCOPE_SOURCE_EXTENSIONS:rust→rsfn,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:
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 withversion `GLIBC_2.39' not foundand 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.rustup, minimal profile →rustc+cargo).rust2cpg's astgen loads the crate by shelling out tocargo/rustcand errors (Are cargo and rustc on your PATH?) without them.docker execinherits the imageENV PATH, so the frontend finds the toolchain at build time.Notable decision: Rust is omitted from
languages_with_exclusionsExactly like Go already is.
rust2cpgmatches--exclude-regexagainst cargo-resolved paths, and the defaultexclusion_patternswere observed to collapse a Rust CPG to 0 methods. Rust stays insupported_languagesand builds fine — just without exclusion filtering.ABAP (
abap2cpg) — evaluated, left outabap2cpgis the other frontend new to4.0.581. Its nativeabapgenexpects 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
glibc 2.39,cargo 1.97.0,rustc 1.97.0,JOERN_VERSION=4.0.581.rust2cpgon a demo crate (loaded into Joern) →<global>, add, greet, main.tests/test_validators.py(123) andtests/test_cpg_generator.py+tests/test_build_scoping.py(29) pass. (The unrelated pre-existingRichHandlercollection errors in other test modules are an environment/rich-version issue, not from this change.)🤖 Generated with Claude Code