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

Conversation

alexcrichton
Copy link
Member

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.

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 #37406

@rust-highfive
Copy link
Collaborator

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned eddyb Nov 3, 2016
@alexcrichton
Copy link
Member Author

I tested bootstrapping this with this commit: alexcrichton/libc@5699631. With that I was able to produce static/dynamic MSVC and musl binaries with the flip of this switch, so it's at least confirmed to work there!

@retep998
Copy link
Member

retep998 commented Nov 3, 2016

If possible, it would be really nice to have options for the debug versions of the CRT, msvcrtd.lib and libcmtd.lib.

@bors
Copy link
Contributor

bors commented Nov 6, 2016

☔ The latest upstream changes (presumably #37597) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Nov 9, 2016

☔ The latest upstream changes (presumably #37670) made this pull request unmergeable. Please resolve the merge conflicts.

alexcrichton added a commit to alexcrichton/libc that referenced this pull request Nov 10, 2016
In preparation for rust-lang/rust#37545 this is adding the appropriate
directives to libc to get included.
bors added a commit to rust-lang/libc that referenced this pull request Nov 10, 2016
Use `#[link(cfg(..))]` in preparation for libstd

In preparation for rust-lang/rust#37545 this is adding the appropriate
directives to libc to get included.
@alexcrichton
Copy link
Member Author

Ok, I've updated this and now that beta has been released I went ahead and included the update to liblibc.

@bors
Copy link
Contributor

bors commented Nov 10, 2016

☔ The latest upstream changes (presumably #37463) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Nov 10, 2016

☔ The latest upstream changes (presumably #37542) made this pull request unmergeable. Please resolve the merge conflicts.

@brson
Copy link
Contributor

brson commented Nov 10, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Nov 10, 2016

📌 Commit aede832 has been approved by brson

@brson
Copy link
Contributor

brson commented Nov 11, 2016

@bors r-

Seems like we should feature-gate the crt-static target feature so it can't be mentioned on the command line yet.

@alexcrichton alexcrichton force-pushed the crt-static branch 2 times, most recently from 21d77be to 791763b Compare November 11, 2016 17:06
@alexcrichton
Copy link
Member Author

@bors: r=brson

Hooked up -C target-feature=+crt-static to -Z unstable-options

@bors
Copy link
Contributor

bors commented Nov 11, 2016

📌 Commit 791763b has been approved by brson

eddyb added a commit to eddyb/rust that referenced this pull request Nov 11, 2016
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
@bors
Copy link
Contributor

bors commented Nov 15, 2016

📌 Commit 957d3e9 has been approved by brson

@bors
Copy link
Contributor

bors commented Nov 15, 2016

⌛ Testing commit 957d3e9 with merge a4add40...

bors added a commit that referenced this pull request Nov 15, 2016
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 #37406
@bors
Copy link
Contributor

bors commented Nov 15, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

@alexcrichton
Copy link
Member Author

@bors: r=brson

@bors
Copy link
Contributor

bors commented Nov 15, 2016

📌 Commit 9a9189c has been approved by brson

@bors
Copy link
Contributor

bors commented Nov 15, 2016

⌛ Testing commit 9a9189c with merge fdb5fa1...

@bors
Copy link
Contributor

bors commented Nov 15, 2016

💔 Test failed - auto-win-gnu-32-opt-rustbuild

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
Copy link
Member Author

@bors: r=brson

@bors
Copy link
Contributor

bors commented Nov 16, 2016

📌 Commit 06242ff has been approved by brson

@bors
Copy link
Contributor

bors commented Nov 16, 2016

⌛ Testing commit 06242ff with merge 9d4b6fa...

bors added a commit that referenced this pull request Nov 16, 2016
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 #37406
@bors bors merged commit 06242ff into rust-lang:master Nov 16, 2016
dstcruz added a commit to dstcruz/chocolatey-mypackages that referenced this pull request Nov 18, 2016
This dependency requirement should go away once rust-lang/rust#37545
is implemented.

I'm creating version 0.2.9.1, which points to upstream 0.2.9 as a
package only version to get this dependency in.
urschrei added a commit to urschrei/lonlat_bng that referenced this pull request Nov 20, 2016
-gnu is somewhat broken using cdylib: rust-lang/rust#37530
But we should be able to statically link msvcrt: rust-lang/rust#37545
@alexcrichton alexcrichton deleted the crt-static branch December 19, 2016 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants