Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Rust Support viatree-sitter's parser#10489

Unanswered
lpinilla asked this question inQ&A
Sep 20, 2022· 2 comments· 5 replies
Discussion options

Hi all,

I was reading your docs about how you managed to create thesupport for Ruby where you explain that you used the output fromtree-sitter as an extractor.

we built a tool to read node-types.json and spit out a CodeQL database schema

This extraction process is not only straightforward, it’s also completely language-agnostic. That is, the process is entirely mechanical and works for any tree-sitter grammar.

So, is it possible to usetree-sitter's rust parser to build the database? If so, how could I parse thenode-types.json generated by the parser?

You must be logged in to vote

Replies: 2 comments 5 replies

Comment options

Greetings, thanks for getting in touch with this question!tree-sitter did indeed allow us to build the Ruby extractor very quickly. This code is open source and you're welcome to take a look at it here to see how we did this:https://github.com/github/codeql/tree/main/ruby/extractor. There's still a fair bit of plumbing that needs to be written to convert the output fromtree-sitter into TRAP files (which is the format the CodeQL CLI understands how to produce a database from). You could probably reuse a lot of this plumbing to get a basic extractor that turns the syntax of Rust files into a CodeQL database.

Having said that, the TRAP format as well as a number of other aspects of implementing your own extractor aren't particularly well documented, so it would really be quite a challenge to add a new language to CodeQL yourself. Additionally, even once an extractor is working there's still quite a lot of work that needs to be done before the database can be used to produce useful results. For reference, even thoughtree-sitter allowed us to get the extractor part of Ruby support for CodeQL working fairly quickly, writing the libraries and queries to then get meaningful results still required several engineers working full-time for over a year to get to where we are now.

Additionally, Rust is a rather different language from Ruby and presents some more challenges. In particular, it's likely that to properly analyze Rust code we'll need more information than just the AST of the files in the CodeQL database - we'll also need to see information like flags passed torustc invocations which will require plumbing to observe the build process and produce additional information in the TRAP files recording this. This will make the extractor look more like our C++ extractor, which ismuch more complex than the Ruby one (the code for that is closed-source so you'll have to take my word for it) and relies on more internals of CodeQL (in particular, something called the tracer which helps CodeQL observe build processes) that aren't documented externally.

We're hoping to improve the experience of external contributors when developing an extractor at some point in the mid-term future, but unfortunately for now the lack of documentation would make this very tricky, so I would probably caution you against such an endeavour (especially for a fairly complex compiled language like Rust).

You must be logged in to vote
5 replies
@lpinilla
Comment options

Thanks for the super detailed answer! I can see that this is a much more complex that requires the development and maintenance of several people to achieve it.

I hope that in the future this process is much more documented so that it can spark future contributions.

Thank you for your time!

@borolepratik
Comment options

Wondering if there have been any developments pertaining to rust support?

@edoardopirovano
Comment options

I'm no longer working at GitHub, but@aeisenberg might have more information on this.

@aeisenberg
Comment options

This is something we are working on, but I can't give you any timeline (I can't even guarantee that rust support in CodeQL will be released in a product). Please keep reading our changelog posts for when we release rust support in public beta.

@peterclemenko
Comment options

Please do add this, especially so that it can be enabled for things like solana/anchor projects

Comment options

Hey everyone, just wanted to let you know that we shipped support for Rust in CodeQL topublic preview. Give it a go andlet us know how things went for you!

You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
6 participants
@lpinilla@aeisenberg@peterclemenko@borolepratik@edoardopirovano@coadaflorin

[8]ページ先頭

©2009-2025 Movatter.jp