Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Implement #[link(cfg(..))] and crt-static #37545

Merged
merged 1 commit into from
Nov 16, 2016

Commits on Nov 16, 2016

  1. rustc: Implement #[link(cfg(..))] and crt-static

    This commit is an implementation of [RFC 1721] which adds a new target feature
    to the compiler, `crt-static`, which can be used to select how the C runtime for
    a target is linked. Most targets dynamically linke the C runtime by default with
    the notable exception of some of the musl targets.
    
    [RFC 1721]: https://github.com/rust-lang/rfcs/blob/master/text/1721-crt-static.md
    
    This commit first adds the new target-feature, `crt-static`. If enabled, then
    the `cfg(target_feature = "crt-static")` will be available. Targets like musl
    will have this enabled by default. This feature can be controlled through the
    standard target-feature interface, `-C target-feature=+crt-static` or
    `-C target-feature=-crt-static`.
    
    Next this adds an gated and unstable `#[link(cfg(..))]` feature to enable the
    `crt-static` semantics we want with libc. The exact behavior of this attribute
    is a little squishy, but it's intended to be a forever-unstable
    implementation detail of the liblibc crate.
    
    Specifically the `#[link(cfg(..))]` annotation means that the `#[link]`
    directive is only active in a compilation unit if that `cfg` value is satisfied.
    For example when compiling an rlib, these directives are just encoded and
    ignored for dylibs, and all staticlibs are continued to be put into the rlib as
    usual. When placing that rlib into a staticlib, executable, or dylib, however,
    the `cfg` is evaluated *as if it were defined in the final artifact* and the
    library is decided to be linked or not.
    
    Essentially, what'll happen is:
    
    * On MSVC with `-C target-feature=-crt-static`, the `msvcrt.lib` library will be
      linked to.
    * On MSVC with `-C target-feature=+crt-static`, the `libcmt.lib` library will be
      linked to.
    * On musl with `-C target-feature=-crt-static`, the object files in liblibc.rlib
      are removed and `-lc` is passed instead.
    * On musl with `-C target-feature=+crt-static`, the object files in liblibc.rlib
      are used and `-lc` is not passed.
    
    This commit does **not** include an update to the liblibc module to implement
    these changes. I plan to do that just after the 1.14.0 beta release is cut to
    ensure we get ample time to test this feature.
    
    cc rust-lang#37406
    alexcrichton committed Nov 16, 2016
    Configuration menu
    Copy the full SHA
    06242ff View commit details
    Browse the repository at this point in the history