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

Projects
None yet
6 participants
@alexcrichton
Copy link
Member

alexcrichton commented Nov 3, 2016

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

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 3, 2016

r? @eddyb

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

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 3, 2016

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned eddyb Nov 3, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 3, 2016

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

bors commented Nov 6, 2016

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

@alexcrichton alexcrichton force-pushed the alexcrichton:crt-static branch from 4487091 to 6da63c8 Nov 6, 2016

@bors

This comment has been minimized.

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

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.

bors added a commit to rust-lang/libc that referenced this pull request Nov 10, 2016

Auto merge of #446 - alexcrichton:link-cfg, r=alexcrichton
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 alexcrichton force-pushed the alexcrichton:crt-static branch from 6da63c8 to f5c9fb6 Nov 10, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 10, 2016

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

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 10, 2016

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

@alexcrichton alexcrichton force-pushed the alexcrichton:crt-static branch from f5c9fb6 to 0d329a2 Nov 10, 2016

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 10, 2016

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

@alexcrichton alexcrichton force-pushed the alexcrichton:crt-static branch 2 times, most recently from 51af985 to aede832 Nov 10, 2016

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Nov 10, 2016

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 10, 2016

📌 Commit aede832 has been approved by brson

@brson

This comment has been minimized.

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 alexcrichton:crt-static branch 2 times, most recently from 21d77be to 791763b Nov 11, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 11, 2016

@bors: r=brson

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

@bors

This comment has been minimized.

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

Rollup merge of rust-lang#37545 - alexcrichton:crt-static, r=brson
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

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 15, 2016

@bors: r=brson

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 15, 2016

📌 Commit 957d3e9 has been approved by brson

@bors

This comment has been minimized.

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

Auto merge of #37545 - alexcrichton:crt-static, r=brson
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

This comment has been minimized.

Copy link
Contributor

bors commented Nov 15, 2016

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

@alexcrichton alexcrichton force-pushed the alexcrichton:crt-static branch from 957d3e9 to 9a9189c Nov 15, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 15, 2016

@bors: r=brson

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 15, 2016

📌 Commit 9a9189c has been approved by brson

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 15, 2016

⌛️ Testing commit 9a9189c with merge fdb5fa1...

bors added a commit that referenced this pull request Nov 15, 2016

Auto merge of #37545 - alexcrichton:crt-static, r=brson
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

This comment has been minimized.

Copy link
Contributor

bors commented Nov 15, 2016

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

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

@alexcrichton alexcrichton force-pushed the alexcrichton:crt-static branch from 9a9189c to 06242ff Nov 16, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Nov 16, 2016

@bors: r=brson

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Nov 16, 2016

📌 Commit 06242ff has been approved by brson

@bors

This comment has been minimized.

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

Auto merge of #37545 - alexcrichton:crt-static, r=brson
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

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

dstcruz added a commit to dstcruz/chocolatey-mypackages that referenced this pull request Nov 18, 2016

Added ripgrep dependency on vcredist2015
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

Switch back to dylib
-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 alexcrichton:crt-static branch Dec 19, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.