analyze-rust-ffi-crate-surface
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAnalyze Rust FFI Crate Surface
分析Rust FFI Crate的对外符号
Compile a list of all C-visible symbols defined in a given Rust FFI crate or file (e.g. an annotated with or a type definition).
Then determine which parts of the C codebase use these symbols.
extern "C" fn#[unsafe(no_mangle)]编译给定Rust FFI crate或文件中定义的所有C可见符号列表(例如带有注解的或类型定义)。
然后确定C代码库中的哪些部分使用了这些符号。
#[unsafe(no_mangle)]extern "C" fnArguments
参数
- : Path to the Rust crate or file.
<path> - : Multiple Rust crates/files.
<path 1> <path 2>
If the path doesn't start with , assume it to be in the directory. E.g. becomes .
If the path points to a directory, review the documentation of all Rust files in that directory.
src/src/redisearch_rs/c_entrypointnumeric_range_tree_ffisrc/redisearch_rs/numeric_range_tree_ffi- : Rust crate或文件的路径。
<path> - : 多个Rust crate/文件。
<path 1> <path 2>
如果路径不以开头,则默认其位于目录下。例如会被解析为。
如果路径指向目录,则检查该目录下所有Rust文件的文档。
src/src/redisearch_rs/c_entrypointnumeric_range_tree_ffisrc/redisearch_rs/numeric_range_tree_ffiInstructions
操作步骤
- Read the relevant Rust source files.
- Compile a list of all the FFI symbols defined they expose (e.g. annotated with
extern "C" fnor type definitions). You can use the corresponding auto-generated header file in#[unsafe(no_mangle)], if it helps.src/redisearch_rs/headers - For each symbol, determine which modules in the C codebase use it:
- For functions, look for calls to the function in the C codebase.
- For types, check out if they are used as function arguments, field types, or in type casts.
Emit a report that lists, for each symbol, the following information:
- The symbol name.
- The module(s) in the C codebase that use it.
- The type(s) of the symbol (function, type, etc.).
- If it's only used in C/C++ unit tests (i.e. under `tests/)
- 读取相关的Rust源文件。
- 编译它们暴露的所有FFI符号列表(例如带有注解的
#[unsafe(no_mangle)]或类型定义)。 如果有帮助,你可以使用extern "C" fn中对应的自动生成头文件。src/redisearch_rs/headers - 针对每个符号,确定C代码库中的哪些模块使用了它:
- 对于函数,查找C代码库中对该函数的调用。
- 对于类型,检查它们是否被用作函数参数、字段类型或在类型转换中使用。
生成一份报告,为每个符号列出以下信息:
- 符号名称。
- C代码库中使用该符号的模块。
- 符号的类型(函数、类型等)。
- 它是否仅在C/C++单元测试中使用(即位于目录下)
tests/
Auto-generated header files
自动生成的头文件
Each Rust crate has a corresponding auto-generated header file in , created by the script via .
The auto-generated header file includes all the FFI symbols defined by the Rust crate, no matter the sub-module they are defined in.
*_ffisrc/redisearch_rs/headersbuild.rscbindgen每个 Rust crate在目录下都有一个对应的自动生成头文件,由脚本通过工具生成。
自动生成的头文件包含了Rust crate定义的所有FFI符号,无论它们定义在哪个子模块中。
*_ffisrc/redisearch_rs/headersbuild.rscbindgen