#cargo #cargo-command #cargo-toml #dylibs #dylib #package #cargo-add

bin+lib cargo-add-dynamic

Cargo 添加命令,将依赖项转换为动态库

3 个版本

0.1.2 2022年10月2日
0.1.1 2022年9月10日
0.1.0 2022年9月9日

417Cargo 插件

每月下载 26

MIT 许可证

22KB
452

cargo add-dynamic

Crates.io

此 cargo 命令允许将依赖项包装为动态库。

有关为什么要这样做,请参阅 使用动态库加速 Rust 增量编译

安装

cargo install cargo-add-dynamic

示例

要将新依赖项作为动态库添加到当前项目,例如运行以下命令

cargo add-dynamic polars --features csv-file,lazy,list,describe,rows,fmt,strings,temporal

这将创建一个子包 polars-dynamic,其内容如下。

polars-dynamic/Cargo.toml

[package]
name = "polars-dynamic"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.net.cn/cargo/reference/manifest.html

[dependencies]
polars = { version = "0.23.2", features = ["csv-file", "lazy", "list", "describe", "rows", "fmt", "strings", "temporal"] }

[lib]
crate-type = ["dylib"]

polars-dynamic/src/lib.rs

pub use polars::*;

它还将 polars = { version = "0.1.0", path = "polars-dynamic", package = "polars-dynamic" } 添加到当前包的依赖项中。

用法

add-dynamic 
Cargo command similar to `cargo add` that will add a dependency <DEP> as a dynamic library (dylib)
crate by creating a new sub-package whose only dependency is the specified <DEP> and whose
crate-type is ["dylib"].

USAGE:
    cargo-add-dynamic [OPTIONS] <DEP>

ARGS:
    <DEP>    

OPTIONS:
    -F, --features <FEATURES>...    Space or comma separated list of features to activate
    -h, --help                      Print help information
        --lib-dir <DIR>             Directory for the new sub-package. Defaults to <DEP>-dynamic
    -n, --name <NAME>               Name of the dynamic library, defaults to <DEP>-dynamic
        --no-default-features       Disable the default features
        --offline                   Run without accessing the network
        --optional                  Mark the dependency as optional. The package name will be
                                    exposed as feature of your crate.
    -p, --package <SPEC>            Package to modify
        --path <PATH>               Filesystem path to local crate to add
        --rename <NAME>             Rename the dependency
                                    Example uses:
                                    - Depending on multiple versions of a crate
                                    - Depend on crates with the same name from different registries
    -v, --verbose                   Additional (debug) logging.

依赖项

~9MB
~152K SLoC