Callix-Tools/callix
GitHub: Callix-Tools/callix
一款 Rust 实现的多语言代码分析工具,将多种编程语言解析为共享的图 IR,内置类型检查器,无需安装语言服务器即可生成调用图与跨语言依赖关系。
Stars: 2 | Forks: 0
callix
使用 Rust 进行多语言代码分析。将 Python、TypeScript、Go、Rust、PHP、C、C++ 和 YAML 解析为共享的图 IR —— 内部链接了类型检查器,因此无需安装任何语言服务器。
[](https://pypi.org/project/callix/)
[](https://pypi.org/project/callix/)
[](LICENSE)
[](https://github.com/Callix-Tools/callix/actions)
[文档](https://callix-tools.github.io/callix/) · [代码库](https://github.com/Callix-Tools/callix) · [议题](https://github.com/Callix-Tools/callix/issues)
```
Repository → Language Adapter → Graph (IR) → your code
```
节点和有向关系,具有类型且确定:函数、类、模块、它们之间的调用,以及一个服务与另一个服务交汇的 HTTP 或 gRPC 边界。
## 为什么需要它
代码分析通常需要你自己来组装它——安装一个语言服务器,将其放在 `PATH` 中,配置传输方式,并保持版本同步。callix 则将分析引擎直接链接到了模块中:
| 语言 | 符号解析 | 额外设置 |
|---|---|---|
| Python | [ty](https://github.com/astral-sh/ty),作为库链接 | 无 |
| TypeScript | [typescript-go](https://github.com/microsoft/typescript-go),作为 Go c-archive 链接 | 无 |
| Go | `go/packages` + `go/types`,同一个 c-archive | 需要 Go 工具链 |
| Rust | `rust-analyzer scip` 索引,原生解码 | 需要 `rust-analyzer` 和 Cargo |
| PHP | 从源码构建的符号表 | 无 |
| C / C++ | 基于解析后源码的符号表 | 无 |
| YAML | 无 —— 它不声明任何符号 | 无 |
Python 和 TypeScript 除了 wheel 之外不需要任何东西——检查器及其标准库 stub 都包含在其中。Go 和 Rust 使用项目已有的工具链,因为作为*源代码*提供的标准库无法冻结到 wheel 中。PHP 和 C 系列没有值得链接的检查器,也没有值得调用的广泛安装的索引器——每个精确的 C/C++ 选项都需要 `compile_commands.json`,而几乎没有代码库会提供它——因此 callix 从源码构建符号表并报告 `degraded`,坦诚地表明它只是一个符号表而不是类型检查器。
## 安装
```
pip install callix
```
要求 Python ≥ 3.10。提供适用于 Linux glibc 和 musl (x86_64, aarch64) 以及 macOS (arm64, x86_64) 的 wheel;
[不支持 Windows](https://callix-tools.github.io/callix/docs/getting-started/installation)。
## 用法
```
from callix import NodeKind, PythonAdapter
graph = PythonAdapter().analyze("path/to/project")
print(len(graph.nodes), len(graph.relations))
for node in graph.nodes_by_kind(NodeKind.FUNCTION):
print(node.qualified_name, graph.callers(node.id))
graph.to_json(indent=2) # serialization
old.diff(new) # structural diff
```
同样的调用方式也适用于其他所有语言——`TypeScriptAdapter`、`GoAdapter`、`RustAdapter`、`PhpAdapter`、`CAdapter`、`CppAdapter`、`YamlAdapter`——并且每个适配器都会发现各自的项目根目录,因此无需配置即可支持 monorepo。
默认开启符号解析。设置 `resolve=False` 可获得结构图;`graph.metadata["resolver_status"]` 始终会说明结果的完整程度。
声明了 `@app.get("/users/{id}")` 的 Python 服务器与调用 `fetch("/users/1")` 的 TypeScript 客户端会产生**相同**的边界节点,因此合并它们的图就能将这两个服务链接起来。详情请参阅[跨语言分析](https://callix-tools.github.io/callix/docs/guides/cross-language)。
## 文档
- [安装](https://callix-tools.github.io/callix/docs/getting-started/installation) · [快速开始](https://callix-tools.github.io/callix/docs/getting-started/quick-start) · [核心概念](https://callix-tools.github.io/callix/docs/getting-started/concepts)
- [适配器](https://callix-tools.github.io/callix/docs/adapters/overview)和[解析器工作原理](https://callix-tools.github.io/callix/docs/adapters/resolvers)
- [图模型](https://callix-tools.github.io/callix/docs/graph-model/nodes) · [API 参考](https://callix-tools.github.io/callix/docs/api-reference/callix)
- [从 graphlens 迁移](https://callix-tools.github.io/callix/docs/project/migrating-from-graphlens)
## 基准测试
_最后运行:**2026-07-30 12:01 UTC** · callix `main` · 运行环境 `Linux x86_64` · 单次冷运行,仅供参考。_
| 项目 | 语言 | 提交 | LOC | 文件数 | 节点数 | 关系数 | 耗时 | 峰值 RSS | KLOC/s | 解析器 | 已解析 |
|---|---|---|--:|--:|--:|--:|--:|--:|--:|:--|--:|
| [apache/superset](https://github.com/apache/superset) | python | `c83fb2b` | 399 519 | 1 886 | 181 320 | 370 764 | 19.4s | 1,026 MB | 20.6 | ok | 281 667 中的 85% (11s) |
| [colinhacks/zod](https://github.com/colinhacks/zod) | typescript | `1fb56a5` | 74 194 | 404 | 15 332 | 27 334 | 2.5s | 419 MB | 30.2 | ok | 17 067 中的 89% (1s) |
| [gin-gonic/gin](https://github.com/gin-gonic/gin) | go | `73726dc` | 23 374 | 97 | 13 109 | 19 424 | 6.1s | 948 MB | 3.8 | ok | 13 916 中的 100% (1s) |
| [casdoor/casdoor](https://github.com/casdoor/casdoor) | go | `696bcf0` | 86 898 | 458 | 33 324 | 58 107 | 35.7s | 4,240 MB | 2.4 | ok | 36 633 中的 100% (10s) |
| [gohugoio/hugo](https://github.com/gohugoio/hugo) | go | `4d22555` | 224 821 | 897 | 75 036 | 130 508 | 22.0s | 4,559 MB | 10.2 | ok | 87 043 中的 98% (6s) |
| [BurntSushi/ripgrep](https://github.com/BurntSushi/ripgrep) | rust | `4649aa9` | 50 275 | 98 | 7 787 | 22 852 | 12.8s | 1,077 MB | 3.9 | ok | 16 156 中的 99% (0s) |
| [tokio-rs/axum](https://github.com/tokio-rs/axum) | rust | `c59208c` | 43 653 | 296 | 10 627 | 21 118 | 69.0s | 3,123 MB | 0.6 | ok | 12 625 中的 87% (0s) |
| [astral-sh/ruff](https://github.com/astral-sh/ruff) | rust | `6686f63` | 687 409 | 1 870 | 102 595 | 330 597 | 176.0s | 6,007 MB | 3.9 | ok | 216 936 中的 100% (2s) |
| [laravel/framework](https://github.com/laravel/framework) | php | `92a7072` | 540 800 | 3 016 | 83 164 | 291 129 | 17.8s | 376 MB | 30.4 | degraded | 283 108 中的 70% (1s) |
| [redis/redis](https://github.com/redis/redis) | c | `5279a8d` | 374 211 | 786 | 156 896 | 200 372 | 7.0s | 294 MB | 53.8 | degraded | 161 477 中的 100% (0s) |
| [google/leveldb](https://github.com/google/leveldb) | cpp | `99b3c03` | 28 280 | 131 | 12 235 | 20 600 | 0.9s | 77 MB | 32.5 | degraded | 14 322 中的 100% (0s) |
| [facebook/rocksdb](https://github.com/facebook/rocksdb) | cpp | `3b44608` | 774 485 | 1 342 | 300 996 | 513 211 | 26.9s | 718 MB | 28.8 | degraded | 433 814 中的 100% (0s) |
| [APIs-guru/openapi-directory](https://github.com/APIs-guru/openapi-directory) | yaml | `959d727` | 1 268 530 | 971 | 11 812 | 16 795 | 5.8s | 115 MB | 219.8 | ok | — |
| [argoproj/argo-cd](https://github.com/argoproj/argo-cd) | yaml | `564b949` | 322 262 | 2 201 | 2 220 | 2 246 | 1.4s | 91 MB | 222.5 | ok | — |
| **总计** | | | **4 898 711** | | **1 006 453** | | **403.3s** | | **12.1** | | **1 574 764 中的 91%** |
峰值 RSS 通过 `getrusage.max` 测量(最大的单个进程——无论是我们的进程还是解析器子进程;由于无法读取 cgroup 计数器,因此这不是整个进程树的总和)。KLOC/s = 每秒分析的千行代码数。由 [`benchmarks/run_benchmarks.py`](benchmarks/run_benchmarks.py) 生成。
相较于 [graphlens](https://github.com/Neko1313/graphlens)(即本项目所取代的 Python 实现版本)的加速效果:在 apache/superset 上为 **5.2×**,在 colinhacks/zod 上为 **3.3×**,在 gin-gonic/gin 上为 **2.6×**。详情与方法请参阅[基准测试](https://callix-tools.github.io/callix/docs/project/benchmarks)。
## 版本控制
Semver 涵盖了图契约——节点和关系类型、两个 ID 公式、基于 1 的 spans、节点排序、序列化格式——以及生成并提交到 `.pyi` 中的 Python API。它不涵盖解析器的返回结果:Python 解析器锁定的是 `0.0.x` 版本的 ty,而 Rust 解析器使用的则是机器上安装的任何版本的 `rust-analyzer`。补丁版本可能会更改出现哪些 `CALLS` 边。取而代之作为关注点的是已解析查询的总体比例,该比例会按项目记录在基线中。
完整声明,包括哪些更改需要发布主版本,请参阅:[版本控制](https://callix-tools.github.io/callix/docs/project/versioning)。
## 贡献
有关开发流程、构建限制以及如何发布版本的信息,请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。
## 许可证
MIT
标签:Rust, WebSocket, 中间表示, 云安全监控, 代码分析, 依赖分析, 凭证管理, 可视化界面, 日志审计, 网络流量审计, 调用图, 逆向工具, 通知系统, 静态分析