Skip to content

rustc should prefer statically linking native dependencies with unspecified kind if crt-static is enabled #71647

Open
@petrochenkov

Description

@petrochenkov

The main goal of +crt-static (at least on non-Windows targets) is to produce self-contained statically linked executables.

With this goal in mind rustc switches linking of 1) Rust crates and 2) libc to static if possible. (The libc part is done in the libraries through lazy cfgs though.)
However, for native dependencies with unspecified kind rustc will still prefer the dynamic version of the library if both are available.

Unfortunately, doing this is not entirely trivial because -Bstatic -lmylib won't just prefer the static version (e.g. libmylib.a), it will require it.
So we need to check for the existence of libmylib.a first (in which directories exactly?) and then pass -l:libmylib.a instead of -lmylib if it exists.

cc #71586 #39998

Metadata

Metadata

Assignees

Labels

A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions