analyze-rust-ffi-crate-surface

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Analyze 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
extern "C" fn
annotated with
#[unsafe(no_mangle)]
or a type definition). Then determine which parts of the C codebase use these symbols.
编译给定Rust FFI crate或文件中定义的所有C可见符号列表(例如带有
#[unsafe(no_mangle)]
注解的
extern "C" fn
或类型定义)。 然后确定C代码库中的哪些部分使用了这些符号。

Arguments

参数

  • <path>
    : Path to the Rust crate or file.
  • <path 1> <path 2>
    : Multiple Rust crates/files.
If the path doesn't start with
src/
, assume it to be in the
src/redisearch_rs/c_entrypoint
directory. E.g.
numeric_range_tree_ffi
becomes
src/redisearch_rs/numeric_range_tree_ffi
. If the path points to a directory, review the documentation of all Rust files in that directory.
  • <path>
    : Rust crate或文件的路径。
  • <path 1> <path 2>
    : 多个Rust crate/文件。
如果路径不以
src/
开头,则默认其位于
src/redisearch_rs/c_entrypoint
目录下。例如
numeric_range_tree_ffi
会被解析为
src/redisearch_rs/numeric_range_tree_ffi
。 如果路径指向目录,则检查该目录下所有Rust文件的文档。

Instructions

操作步骤

  • Read the relevant Rust source files.
  • Compile a list of all the FFI symbols defined they expose (e.g.
    extern "C" fn
    annotated with
    #[unsafe(no_mangle)]
    or type definitions). You can use the corresponding auto-generated header file in
    src/redisearch_rs/headers
    , if it helps.
  • 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
*_ffi
Rust crate has a corresponding auto-generated header file in
src/redisearch_rs/headers
, created by the
build.rs
script via
cbindgen
. The auto-generated header file includes all the FFI symbols defined by the Rust crate, no matter the sub-module they are defined in.
每个
*_ffi
Rust crate在
src/redisearch_rs/headers
目录下都有一个对应的自动生成头文件,由
build.rs
脚本通过
cbindgen
工具生成。 自动生成的头文件包含了Rust crate定义的所有FFI符号,无论它们定义在哪个子模块中。