Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

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

Open

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

Activity

  1. added
    C-bug
    A-linkage
    on Apr 28, 2020
  2. petrochenkov commented on Apr 28, 2020

    @petrochenkov
    ContributorAuthor

    -Bstatic -lmylib won't just prefer the static version (e.g. libmylib.a), it will require it.

    If #39998 is accepted as the way to go by default when crt-static is enabled (on non-Windows platforms), then we can just use -Bstatic.

  3. added
    T-compiler
    on Apr 28, 2020
  4. smaeul commented on May 2, 2020

    @smaeul
    Contributor

    This was discussed at length in #55566, where I was told that NativeUnknown means dynamic, and changing the semantics of #[link] was unacceptable.

  5. petrochenkov commented on May 10, 2020

    @petrochenkov
    ContributorAuthor

    Some history in links: #71586 (comment)

  6. petrochenkov commented on May 10, 2020

    @petrochenkov
    ContributorAuthor

    @smaeul
    I do not agree with what alexcrichton said #55566, it's mostly a "it mostly works, so don't touch it because you may break something" position motivated by lack of resources and people ready to take responsibilities for this work on the Rust side.

    We can at least make an experiment (possibly using crater, possibly landing this on nightly and reverting) and verify what actually breaks in practice.

  7. self-assigned this
    on Jun 6, 2020
  8. nagisa commented on Mar 8, 2021

    @nagisa
    Member

    I fear crater will likely have a pretty poor coverage as far as linkage is concerned as its environment won't generally have anything but the most common libraries installed on the system (and the "native" libraries built in build.rs are already almost universally statically linked).

  9. polarathene commented on Mar 2, 2024

    @polarathene

    Was this not resolved with #111698 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-linkageC-bugT-compiler

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions