minimize-rust-ffi-crate-surface
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseMinimize Rust FFI Crate Surface
最小化Rust FFI Crate的对外暴露面
Remove C symbols defined in a Rust FFI crate or file that are either unused or only used in C/C++ unit tests.
移除Rust FFI crate或文件中定义的、未使用或仅在C/C++单元测试中使用的C符号。
Arguments
参数
- : 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
操作步骤
- Use analyze-rust-ffi-crate-surface to enumerate and analyze the usage of all the FFI symbols exposed by the Rust crate or file (e.g. annotated with
extern "C" fnor type definitions).#[unsafe(no_mangle)] - For each unused symbol:
- Delete its Rust definition.
- Run C/C++ unit tests to ensure the symbol was indeed unused (via )
./build.sh RUN_UNIT_TESTS
- For each symbol that is only used in C/C++ unit tests, elaborate a plan to either:
- Refactor the C/C++ unit tests not to use it.
- Remove the C/C++ unit tests (or assertions) that rely on it, since they are prying into the implementation details of the Rust crate.
- Keep the symbol, but mark it as "test only" in the Rust documentation.
- 使用analyze-rust-ffi-crate-surface来枚举并分析Rust crate或文件暴露的所有FFI符号的使用情况(例如带有注解的
#[unsafe(no_mangle)]或类型定义)。extern "C" fn - 对于每个未使用的符号:
- 删除其Rust定义。
- 运行C/C++单元测试以确保该符号确实未被使用(通过)
./build.sh RUN_UNIT_TESTS
- 对于每个仅在C/C++单元测试中使用的符号,制定一个方案,选择以下其中一种处理方式:
- 重构C/C++单元测试,使其不再使用该符号。
- 移除依赖该符号的C/C++单元测试(或断言),因为这些测试窥探了Rust crate的实现细节。
- 保留该符号,但在Rust文档中将其标记为“仅用于测试”。