Skip to content

Commit 61de78b

Browse files
Copilotdata-douser
andcommitted
Add Rust language support: query packs, TypeScript, scripts, docs, CI
Create Rust CodeQL query pack structure with PrintAST, PrintCFG, CallGraphFrom, CallGraphTo, and CallGraphFromTo tool queries. Update all TypeScript source, shell scripts, documentation, skills, and CI/CD configurations to include Rust. Agent-Logs-Url: https://github.com/advanced-security/codeql-development-mcp-server/sessions/1817d842-51f6-4414-8df3-5b40c48bc036 Co-authored-by: data-douser <70299490+data-douser@users.noreply.github.com>
1 parent 866c9e7 commit 61de78b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+461
-9
lines changed

.github/skills/create-codeql-query-development-workshop/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ Include appropriate CodeQL libraries in `codeql-pack.yml`:
398398
- **JavaScript/TypeScript**: `codeql/javascript-all`
399399
- **Python**: `codeql/python-all`
400400
- **Ruby**: `codeql/ruby-all`
401+
- **Rust**: `codeql/rust-all`
401402

402403
### Java-Specific API Notes
403404

.github/skills/validate-ql-mcp-server-tools-queries/SKILL.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ The tools queries are available for all CodeQL-supported languages:
3333
| javascript | `server/ql/javascript/tools/` | `.js` |
3434
| python | `server/ql/python/tools/` | `.py` |
3535
| ruby | `server/ql/ruby/tools/` | `.rb` |
36+
| rust | `server/ql/rust/tools/` | `.rs` |
3637
| swift | `server/ql/swift/tools/` | `.swift` |
3738

3839
## Tools Queries Overview

.github/workflows/query-unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
strategy:
4343
fail-fast: false
4444
matrix:
45-
language: ['actions', 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby']
45+
language: ['actions', 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby', 'rust']
4646

4747
steps:
4848
- name: Query Unit Tests - ${{ matrix.language }} - Checkout repository

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,6 @@ jobs:
279279
echo "### Published CodeQL Packs" >> $GITHUB_STEP_SUMMARY
280280
echo "| Pack | Version |" >> $GITHUB_STEP_SUMMARY
281281
echo "| ---- | ------- |" >> $GITHUB_STEP_SUMMARY
282-
for lang in actions cpp csharp go java javascript python ruby swift; do
282+
for lang in actions cpp csharp go java javascript python ruby rust swift; do
283283
echo "| \`advanced-security/ql-mcp-${lang}-tools-src\` | ${RELEASE_NAME} |" >> $GITHUB_STEP_SUMMARY
284284
done

docs/public.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ The MCP server includes tool query packs for the following CodeQL languages:
187187
| JavaScript/TypeScript | `javascript` | `advanced-security/ql-mcp-javascript-tools-src` |
188188
| Python | `python` | `advanced-security/ql-mcp-python-tools-src` |
189189
| Ruby | `ruby` | `advanced-security/ql-mcp-ruby-tools-src` |
190+
| Rust | `rust` | `advanced-security/ql-mcp-rust-tools-src` |
190191
| Swift | `swift` | `advanced-security/ql-mcp-swift-tools-src` |
191192

192193
Each pack contains the following tool queries used by the server:

server/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"ql/javascript/tools/src/",
1919
"ql/python/tools/src/",
2020
"ql/ruby/tools/src/",
21+
"ql/rust/tools/src/",
2122
"ql/swift/tools/src/",
2223
"scripts/setup-packs.sh",
2324
"package.json",

server/ql/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Currently supported languages:
3535
- `javascript/` - JavaScript/TypeScript
3636
- `python/` - Python
3737
- `ruby/` - Ruby
38+
- `rust/` - Rust
3839
- `swift/` - Swift
3940

4041
## Testing
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* @name Call Graph From for rust
3+
* @description Displays calls made from a specified function, showing the call graph outbound from the source function.
4+
* @id rust/tools/call-graph-from
5+
* @kind problem
6+
* @problem.severity recommendation
7+
* @tags call-graph
8+
*/
9+
10+
import rust
11+
import ExternalPredicates
12+
13+
/**
14+
* Gets a single source function name from the comma-separated list.
15+
*/
16+
string getSourceFunctionName() {
17+
exists(string s | sourceFunction(s) | result = s.splitAt(",").trim())
18+
}
19+
20+
/**
21+
* Gets the name of the called function.
22+
*/
23+
string getCalleeName(CallExpr call) {
24+
if exists(call.getResolvedTarget().(Function).getName())
25+
then result = call.getResolvedTarget().(Function).getName()
26+
else result = call.toString()
27+
}
28+
29+
from CallExpr call, Function source
30+
where
31+
call.getEnclosingCallable() = source and
32+
source.getName() = getSourceFunctionName()
33+
select call, "Call from `" + source.getName() + "` to `" + getCalleeName(call) + "`"
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/**
2+
* @name Call Graph From To for rust
3+
* @description Displays calls on reachable paths from a source function to a target function, showing transitive call graph connectivity.
4+
* @id rust/tools/call-graph-from-to
5+
* @kind problem
6+
* @problem.severity recommendation
7+
* @tags call-graph
8+
*/
9+
10+
import rust
11+
import ExternalPredicates
12+
13+
/**
14+
* Gets a single source function name from the comma-separated list.
15+
*/
16+
string getSourceFunctionName() {
17+
exists(string s | sourceFunction(s) | result = s.splitAt(",").trim())
18+
}
19+
20+
/**
21+
* Gets a single target function name from the comma-separated list.
22+
*/
23+
string getTargetFunctionName() {
24+
exists(string s | targetFunction(s) | result = s.splitAt(",").trim())
25+
}
26+
27+
/**
28+
* Holds if function `caller` directly calls function `callee` by name.
29+
*/
30+
predicate calls(Function caller_, Function callee_) {
31+
exists(CallExpr c |
32+
c.getEnclosingCallable() = caller_ and
33+
c.getResolvedTarget().(Function).getName() = callee_.getName()
34+
)
35+
}
36+
37+
/**
38+
* Gets the name of the called function.
39+
*/
40+
string getCalleeName(CallExpr call) {
41+
if exists(call.getResolvedTarget().(Function).getName())
42+
then result = call.getResolvedTarget().(Function).getName()
43+
else result = call.toString()
44+
}
45+
46+
from CallExpr call, Function caller
47+
where
48+
call.getEnclosingCallable() = caller and
49+
exists(Function source, Function target |
50+
source.getName() = getSourceFunctionName() and
51+
target.getName() = getTargetFunctionName() and
52+
calls*(source, caller) and
53+
exists(Function callee |
54+
call.getResolvedTarget().(Function).getName() = callee.getName() and
55+
calls*(callee, target)
56+
)
57+
)
58+
select call, "Reachable call from `" + caller.getName() + "` to `" + getCalleeName(call) + "`"
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* @name Call Graph To for rust
3+
* @description Displays calls made to a specified function, showing the call graph inbound to the target function.
4+
* @id rust/tools/call-graph-to
5+
* @kind problem
6+
* @problem.severity recommendation
7+
* @tags call-graph
8+
*/
9+
10+
import rust
11+
import ExternalPredicates
12+
13+
/**
14+
* Gets a single target function name from the comma-separated list.
15+
*/
16+
string getTargetFunctionName() {
17+
exists(string s | targetFunction(s) | result = s.splitAt(",").trim())
18+
}
19+
20+
/**
21+
* Gets the caller name for a call expression.
22+
*/
23+
string getCallerName(CallExpr call) {
24+
if exists(call.getEnclosingCallable().(Function).getName())
25+
then result = call.getEnclosingCallable().(Function).getName()
26+
else result = "Top-level"
27+
}
28+
29+
/**
30+
* Gets the name of the called function.
31+
*/
32+
string getCalleeName(CallExpr call) {
33+
if exists(call.getResolvedTarget().(Function).getName())
34+
then result = call.getResolvedTarget().(Function).getName()
35+
else result = call.toString()
36+
}
37+
38+
from CallExpr call
39+
where call.getResolvedTarget().(Function).getName() = getTargetFunctionName()
40+
select call, "Call to `" + getCalleeName(call) + "` from `" + getCallerName(call) + "`"

0 commit comments

Comments
 (0)