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: Add a new crate type, cdylib #33553

Merged
merged 2 commits into from May 20, 2016

Conversation

Projects
None yet
10 participants
@alexcrichton
Copy link
Member

alexcrichton commented May 11, 2016

This commit is an implementation of RFC 1510 which adds a new crate type,
cdylib, to the compiler. This new crate type differs from the existing dylib
crate type in a few key ways:

  • No metadata is present in the final artifact
  • Symbol visibility rules are the same as executables, that is only reachable
    extern functions are visible symbols
  • LTO is allowed
  • All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the Linker::export_symbols function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" cdylib is 7.2K while the same dylib is 2.4MB,
which is some nice size savings!

Closes #33132

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented May 11, 2016

r? @jroesch

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

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 11, 2016

r? @brson

@rust-highfive rust-highfive assigned brson and unassigned jroesch May 11, 2016

@brson

This comment has been minimized.

Copy link
Contributor

brson commented May 13, 2016

@bors r+

@brson brson closed this May 13, 2016

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 13, 2016

📌 Commit a3f5d08 has been approved by brson

@brson brson reopened this May 13, 2016

eddyb added a commit to eddyb/rust that referenced this pull request May 13, 2016

Rollup merge of rust-lang#33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes rust-lang#33132

@eddyb eddyb referenced this pull request May 13, 2016

Closed

Rollup of 29 pull requests #33610

bors added a commit that referenced this pull request May 13, 2016

let res = (|| -> io::Result<()> {
let mut f = BufWriter::new(File::create(&path)?);
for sym in exported_symbols(sess, trans, crate_type) {
writeln!(f, " {}", sym)?;

This comment has been minimized.

@eddyb

eddyb May 13, 2016

Member

This doesn't seem to be enough for iOS, see failure.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented May 13, 2016

@bors r- Likely responsible for this failure.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 13, 2016

Indeed! looks quite suspicious

@alexcrichton alexcrichton force-pushed the alexcrichton:cdylibs branch from a3f5d08 to bfe7a80 May 13, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 13, 2016

@bors: r=brson bfe7a80

bors added a commit that referenced this pull request May 13, 2016

bors added a commit that referenced this pull request May 13, 2016

@Manishearth

This comment has been minimized.

Copy link
Member

Manishearth commented May 14, 2016

Travis fails

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 14, 2016

⌛️ Testing commit bfe7a80 with merge 2d45326...

bors added a commit that referenced this pull request May 14, 2016

Auto merge of #33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 14, 2016

💔 Test failed - auto-mac-64-opt-rustbuild

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented May 14, 2016

I'm working on rebasing this over #33602 because otherwise I'd need windows to investigate my metadata problem.
Could be delayed for a few days by my flight, so if you don't hear anything from me, feel free to merge this.

@alexcrichton alexcrichton force-pushed the alexcrichton:cdylibs branch from bfe7a80 to 557aae0 May 17, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 17, 2016

@bors: r=brson 557aae0

@eddyb I've applied your patch to retain the metadata symbol for dylibs, let's see how far it gets...

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 17, 2016

⌛️ Testing commit 557aae0 with merge 3ad8865...

bors added a commit that referenced this pull request May 17, 2016

Auto merge of #33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 17, 2016

💔 Test failed - auto-linux-64-opt-rustbuild

@alexcrichton alexcrichton force-pushed the alexcrichton:cdylibs branch from 557aae0 to e3517db May 17, 2016

bors added a commit that referenced this pull request May 19, 2016

Auto merge of #33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 19, 2016

💔 Test failed - auto-linux-musl-64-opt

@alexcrichton alexcrichton force-pushed the alexcrichton:cdylibs branch from 698ba68 to 0192796 May 19, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 19, 2016

@bors: r=brson 0192796

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 19, 2016

⌛️ Testing commit 0192796 with merge 89347bf...

bors added a commit that referenced this pull request May 19, 2016

Auto merge of #33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 19, 2016

💔 Test failed - auto-mac-64-nopt-t

alexcrichton and others added some commits May 10, 2016

rustc: Add a new crate type, cdylib
This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132

@alexcrichton alexcrichton force-pushed the alexcrichton:cdylibs branch from 0192796 to 0d2c26c May 19, 2016

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented May 19, 2016

@bors: r=brson 0d2c26c

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 20, 2016

⌛️ Testing commit 0d2c26c with merge d27bdaf...

bors added a commit that referenced this pull request May 20, 2016

Auto merge of #33553 - alexcrichton:cdylibs, r=brson
rustc: Add a new crate type, cdylib

This commit is an implementation of [RFC 1510] which adds a new crate type,
`cdylib`, to the compiler. This new crate type differs from the existing `dylib`
crate type in a few key ways:

* No metadata is present in the final artifact
* Symbol visibility rules are the same as executables, that is only reachable
  `extern` functions are visible symbols
* LTO is allowed
* All libraries are always linked statically

This commit is relatively simple by just plubming the compiler with another
crate type which takes different branches here and there. The only major change
is an implementation of the `Linker::export_symbols` function on Unix which now
actually does something. This helps restrict the public symbols from a cdylib on
Unix.

With this PR a "hello world" `cdylib` is 7.2K while the same `dylib` is 2.4MB,
which is some nice size savings!

[RFC 1510]: rust-lang/rfcs#1510

Closes #33132

@bors bors merged commit 0d2c26c into rust-lang:master May 20, 2016

2 checks passed

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

@bluss bluss added the relnotes label May 21, 2016

@bluss

This comment has been minimized.

Copy link
Contributor

bluss commented May 21, 2016

This is kind of immediately a new feature on the stable release where this is included, isn't it? If I'm wrong, then the relnote tag can be removed again.

@torkleyy

This comment has been minimized.

Copy link

torkleyy commented Apr 9, 2017

@alexcrichton How can I compile a crate as cdylib without modifying Cargo.toml? I thought it would be cargo rustc -- --crate-type cdylib, but the crate-type option is just ignored.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Apr 10, 2017

@torkleyy unfortunately that's not possible right now (short of generating a new Cargo.toml. Would you like to open a new issue at rust-lang/cargo?

@torkleyy

This comment has been minimized.

Copy link

torkleyy commented Apr 10, 2017

@alexcrichton Thanks for your reply!

Would you like to open a new issue at rust-lang/cargo?

Sure, I'll do that.

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.