Skip to content

Adding new crate-type target increases size of another crate-type target #55942

@tiras-j

Description

@tiras-j

Problem
Adding an additional crate-type listing appears to affect the size of other crate types, specifically moving from crate-type = ["cdylib", "staticlib"] --> crate-type = ["cdylib", "staticlib", "rlib"] appears to increase the size of the "cdylib" output (in this case a Linux .so ELF) by 100% (2MB -> 4MB) which is suspiciously close to the size of the "rlib" output.

The motivation is to provide benchmarking (via criterion) which of course involves depending on the the core crate to build benchmark functions against. This dependency requires a Rust-style output target, not an arbitrary binary that "cdylib" generates. Adding the "rlib" target does in fact allow the benchmarking but the side-effect of the dramatically increased binary size is not viable, and this size increase appears through the standard cargo build --release process itself.

Steps
Hard to provide concise steps - but basically add an "rlib" type target for an existing "cdylib" crate that exports an some FFI? If this is a me problem, I'd love to hear how to fix this!

Notes

Output of cargo version:
cargo 1.30.0 (36d96825d 2018-10-24)

Also - rustc 1.30.0 stable as the toolchain.

Metadata

Metadata

Assignees

No one assigned

    Labels

    I-heavyIssue: Problems and improvements with respect to binary size of generated code.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions