选择与Cargo共享或静态库

Geo*_*ard 5 shared-libraries rust rust-cargo

我试图修改Racer以发出共享库而不是rlib.

为此,我添加了货物清单crate-type = ["dylib"][lib]部分,然后跑了cargo build --lib.这很好用,并且libracer.so被发射了.

不幸的是,现在我无法构建Racer二进制文件,这取决于库的静态版本.跑步cargo build抱怨:

   Compiling racer v1.0.0 (file:///home/georgev/dotfiles/vim/bundle/racer)
error: cannot satisfy dependencies so `std` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `core` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `collections` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rustc_unicode` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `alloc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `libc` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: cannot satisfy dependencies so `rand` only shows up once
help: having upstream crates all available in one format will likely make this go away
error: aborting due to 7 previous errors
Could not compile `racer`.
Run Code Online (Sandbox Code Playgroud)

我更改了crate-typeto ["dylib", "bin"],这使得编译成功.但是,cargo build --lib不会再发出共享库(只有一个rlib).

如何指定我想构建哪种类型的库,同时仍然允许静态构建所述库以包含在可执行文件中?

Geo*_*ard 7

bin不是有效值crate-type.有效值为rlib,lib,staticlib,和dylib.将包类型更改为

crate-type = ["dylib", "rlib"]
Run Code Online (Sandbox Code Playgroud)

会导致你所追求的行为.

仅发出rlib的原因["dylib", "bin"]是因为当前存在导致无效值的Cargo错误crate-type仅产生rlib.我提交了拉取请求以解决问题.