Skip to content

rustc: Add a new crate type, cdylib - #33553

Merged
bors merged 2 commits into
rust-lang:masterfrom
alexcrichton:cdylibs
May 20, 2016
Merged

rustc: Add a new crate type, cdylib#33553
bors merged 2 commits into
rust-lang:masterfrom
alexcrichton:cdylibs

Conversation

@alexcrichton

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Contributor

r? @jroesch

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

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

r? @brson

@rust-highfiverust-highfive assigned brson and unassigned jroeschMay 11, 2016
@brson

Copy link
Copy Markdown
Contributor

@bors r+

@brsonbrson closed this May 13, 2016
@bors

bors commented May 13, 2016

Copy link
Copy Markdown
Collaborator

📌 Commit a3f5d08 has been approved by brson

@brsonbrson reopened this May 13, 2016
@eddybeddyb mentioned this pull request May 13, 2016
Comment threadsrc/librustc_trans/back/linker.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@eddyb

Copy link
Copy Markdown
Contributor

@bors r- Likely responsible for this failure.

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

Indeed! looks quite suspicious

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

@bors: r=brson bfe7a80

@Manishearth

Copy link
Copy Markdown
Member

Travis fails

@bors

bors commented May 14, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit bfe7a80 with merge 2d45326...

@bors

bors commented May 14, 2016

Copy link
Copy Markdown
Collaborator

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

@eddyb

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
MemberAuthor

@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

bors commented May 17, 2016

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented May 17, 2016

Copy link
Copy Markdown
Collaborator

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

bors added a commit that referenced this pull request May 19, 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#1510Closes#33132
@bors

bors commented May 19, 2016

Copy link
Copy Markdown
Collaborator

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

@alexcrichton

Copy link
Copy Markdown
MemberAuthor

@bors: r=brson 0192796

@bors

bors commented May 19, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 0192796 with merge 89347bf...

@bors

bors commented May 19, 2016

Copy link
Copy Markdown
Collaborator

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

alexcrichtonand others added 2 commits May 19, 2016 15:32
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#1510Closesrust-lang#33132
@alexcrichton

Copy link
Copy Markdown
MemberAuthor

@bors: r=brson 0d2c26c

@bors

bors commented May 20, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 0d2c26c with merge d27bdaf...

bors added a commit that referenced this pull request May 20, 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#1510Closes#33132
@bors
bors merged commit 0d2c26c into rust-lang:masterMay 20, 2016
@blussbluss added the relnotes Marks issues that should be documented in the release notes of the next release. label May 21, 2016
@bluss

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown

@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

Copy link
Copy Markdown
MemberAuthor

@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

Copy link
Copy Markdown

@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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotesMarks issues that should be documented in the release notes of the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@alexcrichton@rust-highfive@brson@bors@eddyb@Manishearth@bluss@torkleyy@retep998@jroesch