我想从我不维护的 Rust 项目生成一个静态库。该项目允许构建 Cargo.toml 指定的动态库 \xe2\x80\x94 crate-type = ["cdylib"]。
修改文件中的板条箱类型是可行的,但如果可能的话,我想将未修改的原始项目作为 git 子模块保留在我的项目中。
\n是否有任何标志可以传递给cargo build命令来覆盖此设置?
你不能覆盖它,但你可以补充它。使用cargo rustc并直接传递--crate-type=staticlib给编译器:
% cargo build
Compiling example v0.1.0 (/private/tmp/example)
Finished dev [unoptimized + debuginfo] target(s) in 0.31s
% find target -name '*.a'
% cargo rustc -- --crate-type=staticlib
Compiling example v0.1.0 (/private/tmp/example)
Finished dev [unoptimized + debuginfo] target(s) in 0.29s
% find target -name '*.a'
target/debug/deps/libexample.a
Run Code Online (Sandbox Code Playgroud)