-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Rollup of 21 pull requests #27206
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
Closed
+906
−80
Closed
Rollup of 21 pull requests #27206
Changes from all commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
fc16c3e
Improve the expected constant integer error message
jawline 3a009cb
Merge branch 'master' of https://github.com/mmjack/rust
jawline f395b2b
Make the message slightly clearer
jawline 8c5ffd3
Reduce line length
jawline 02dd732
Self.sess -> txc.sess
jawline 4872463
Remove 'valid' from error
jawline affbc72
Modified to add 'found' to error message instead
jawline b684826
add test for #20162
apasel422 871ccfb
Add a test for #26468
dotdash 9bb6545
add test for #14229
apasel422 4c73dbd
add test for #19404
apasel422 31a62d3
s/has gained/has not gained/g
pfalabella a7e5c63
add test for #10436
apasel422 3ae7b72
Fix wording nit for E0253
AlisdairO 27fc0f2
Document iterators in std::io
steveklabnik 686d326
Add diagnostics for E0172, fix inline error message for E0139
AlisdairO 7e7ec6b
Document structures in std::io::utils
steveklabnik 9e18326
Update docs for take and broadcast
steveklabnik a29c834
Add travis config to TRPL: release channels
steveklabnik eb39df0
Improve documentation for std::io::BufWriter
steveklabnik 0eb7303
Add E0403 error explanation
GuillaumeGomez cd385cb
Add E0405 error explanation
GuillaumeGomez bc79f20
Add E0404 error explanation
GuillaumeGomez 9581154
Add E0407 error explanation
GuillaumeGomez c13295b
Add E0428 error explanation
GuillaumeGomez d2aee95
Expand documentation for IntoInnerError
steveklabnik 94b8f28
Improve documentation for std::io::LineWriter
steveklabnik 2e919b4
Add E0433 error explanation
GuillaumeGomez e6c058e
Rename 'link-args' to 'advanced-linking', add intro
aidanhs e5c1884
Note possiblities of empty extern blocks (based on #12575)
aidanhs e6d8434
add test for #14382
apasel422 a5c7b96
Add info about usage of 'unsafe' keyword in bindings to foreign inter…
48870d4
rust -> Rust
cf1e078
Klabnik nit-picks ;)
ticki 7af865b
Static linking
aidanhs 692a2d5
musl static linking not glibc
aidanhs 231438a
Additional notes to link-args
aidanhs 18f115c
update compile-fail test for #21174 to account for #27127
apasel422 e4402d9
Rollup merge of #26778 - jawline:master, r=pnkfelix
steveklabnik 70eb2a1
Rollup merge of #27084 - GuillaumeGomez:patch-2, r=brson
steveklabnik 30b8684
Rollup merge of #27127 - AlisdairO:diagnostics172, r=Manishearth
steveklabnik 3b41959
Rollup merge of #27131 - apasel422:issue-20162, r=arielb1
steveklabnik 837e8a9
Rollup merge of #27140 - dotdash:test-26468, r=luqmana
steveklabnik d8a9faa
Rollup merge of #27146 - apasel422:issue-14229, r=alexcrichton
steveklabnik 57edbf1
Rollup merge of #27147 - apasel422:issue-19404, r=alexcrichton
steveklabnik 7061db6
Rollup merge of #27151 - pfalabella:patch-2, r=steveklabnik
steveklabnik b76a0ec
Rollup merge of #27154 - apasel422:issue-10436, r=Gankro
steveklabnik 3af02c1
Rollup merge of #27155 - steveklabnik:doc_std_io_buf_writer, r=alexcr…
steveklabnik 268470d
Rollup merge of #27156 - AlisdairO:diagnostics253, r=Manishearth
steveklabnik def1dd1
Rollup merge of #27157 - steveklabnik:doc_std_io_iterators, r=alexcri…
steveklabnik 542b7d1
Rollup merge of #27158 - apasel422:issue-14382, r=alexcrichton
steveklabnik eb1826e
Rollup merge of #27164 - steveklabnik:doc_io_utils, r=alexcrichton
steveklabnik bc27905
Rollup merge of #27166 - steveklabnik:doc_std_io_linewriter, r=alexcr…
steveklabnik 26626e9
Rollup merge of #27167 - steveklabnik:doc_std_io_take, r=alexcrichton
steveklabnik 6f7d9a5
Rollup merge of #27170 - steveklabnik:doc_std_io_intoinnererror, r=al…
steveklabnik 8cf4f46
Rollup merge of #27175 - steveklabnik:channels_plus_travis, r=alexcri…
steveklabnik 93543ca
Rollup merge of #27193 - aidanhs:aphs-advanced-linking-doc, r=alexcri…
steveklabnik 93018bb
Rollup merge of #27201 - Ticki:master, r=steveklabnik
steveklabnik 263c2ae
Rollup merge of #27202 - apasel422:issue-21174, r=alexcrichton
steveklabnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
% Advanced Linking | ||
|
||
The common cases of linking with Rust have been covered earlier in this book, | ||
but supporting the range of linking possibilities made available by other | ||
languages is important for Rust to achieve seamless interaction with native | ||
libraries. | ||
|
||
# Link args | ||
|
||
There is one other way to tell `rustc` how to customize linking, and that is via | ||
the `link_args` attribute. This attribute is applied to `extern` blocks and | ||
specifies raw flags which need to get passed to the linker when producing an | ||
artifact. An example usage would be: | ||
|
||
``` no_run | ||
#![feature(link_args)] | ||
|
||
#[link_args = "-foo -bar -baz"] | ||
extern {} | ||
# fn main() {} | ||
``` | ||
|
||
Note that this feature is currently hidden behind the `feature(link_args)` gate | ||
because this is not a sanctioned way of performing linking. Right now `rustc` | ||
shells out to the system linker (`gcc` on most systems, `link.exe` on MSVC), | ||
so it makes sense to provide extra command line | ||
arguments, but this will not always be the case. In the future `rustc` may use | ||
LLVM directly to link native libraries, in which case `link_args` will have no | ||
meaning. You can achieve the same effect as the `link-args` attribute with the | ||
`-C link-args` argument to `rustc`. | ||
|
||
It is highly recommended to *not* use this attribute, and rather use the more | ||
formal `#[link(...)]` attribute on `extern` blocks instead. | ||
|
||
# Static linking | ||
|
||
Static linking refers to the process of creating output that contain all | ||
required libraries and so don't need libraries installed on every system where | ||
you want to use your compiled project. Pure-Rust dependencies are statically | ||
linked by default so you can use created binaries and libraries without | ||
installing the Rust everywhere. By contrast, native libraries | ||
(e.g. `libc` and `libm`) usually dynamically linked, but it is possible to | ||
change this and statically link them as well. | ||
|
||
Linking is a very platform dependent topic — on some platforms, static linking | ||
may not be possible at all! This section assumes some basic familiarity with | ||
linking on your platform of choice. | ||
|
||
## Linux | ||
|
||
By default, all Rust programs on Linux will link to the system `libc` along with | ||
a number of other libraries. Let's look at an example on a 64-bit Linux machine | ||
with GCC and `glibc` (by far the most common `libc` on Linux): | ||
|
||
``` text | ||
$ cat example.rs | ||
fn main() {} | ||
$ rustc example.rs | ||
$ ldd example | ||
linux-vdso.so.1 => (0x00007ffd565fd000) | ||
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fa81889c000) | ||
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fa81867e000) | ||
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fa818475000) | ||
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fa81825f000) | ||
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fa817e9a000) | ||
/lib64/ld-linux-x86-64.so.2 (0x00007fa818cf9000) | ||
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fa817b93000) | ||
``` | ||
|
||
Dynamic linking on Linux can be undesirable if you wish to use new library | ||
features on old systems or target systems which do not have the required | ||
dependencies for your program to run. | ||
|
||
Static linking is supported via an alternative `libc`, `musl` - this must be | ||
enabled at Rust compile-time with some prerequisites available. You can compile | ||
your own version of Rust with `musl` enabled and install it into a custom | ||
directory with the instructions below: | ||
|
||
``` | ||
$ mkdir musldist | ||
$ PREFIX=$(pwd)/musldist | ||
$ | ||
$ # Build musl | ||
$ wget http://www.musl-libc.org/releases/musl-1.1.10.tar.gz | ||
[...] | ||
$ tar xf musl-1.1.10.tar.gz | ||
$ cd musl-1.1.10/ | ||
musl-1.1.10 $ ./configure --disable-shared --prefix=$PREFIX | ||
[...] | ||
musl-1.1.10 $ make | ||
[...] | ||
musl-1.1.10 $ make install | ||
[...] | ||
musl-1.1.10 $ cd .. | ||
$ du -h musldist/lib/libc.a | ||
2.2M musldist/lib/libc.a | ||
$ | ||
$ # Build libunwind.a | ||
$ wget http://llvm.org/releases/3.6.1/llvm-3.6.1.src.tar.xz | ||
$ tar xf llvm-3.6.1.src.tar.xz | ||
$ cd llvm-3.6.1.src/projects/ | ||
llvm-3.6.1.src/projects $ svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk/ libcxxabi | ||
llvm-3.6.1.src/projects $ svn co http://llvm.org/svn/llvm-project/libunwind/trunk/ libunwind | ||
llvm-3.6.1.src/projects $ sed -i 's#^\(include_directories\).*$#\0\n\1(../libcxxabi/include)#' libunwind/CMakeLists.txt | ||
llvm-3.6.1.src/projects $ mkdir libunwind/build | ||
llvm-3.6.1.src/projects $ cd libunwind/build | ||
llvm-3.6.1.src/projects/libunwind/build $ cmake -DLLVM_PATH=../../.. -DLIBUNWIND_ENABLE_SHARED=0 .. | ||
llvm-3.6.1.src/projects/libunwind/build $ make | ||
llvm-3.6.1.src/projects/libunwind/build $ cp lib/libunwind.a $PREFIX/lib/ | ||
llvm-3.6.1.src/projects/libunwind/build $ cd cd ../../../../ | ||
$ du -h musldist/lib/libunwind.a | ||
164K musldist/lib/libunwind.a | ||
$ | ||
$ # Build musl-enabled rust | ||
$ git clone https://github.com/rust-lang/rust.git muslrust | ||
$ cd muslrust | ||
muslrust $ ./configure --target=x86_64-unknown-linux-musl --musl-root=$PREFIX --prefix=$PREFIX | ||
muslrust $ make | ||
muslrust $ make install | ||
muslrust $ cd .. | ||
$ du -h musldist/bin/rustc | ||
12K musldist/bin/rustc | ||
``` | ||
|
||
You now have a build of a `musl`-enabled Rust! Because we've installed it to a | ||
custom prefix we need to make sure our system can the binaries and appropriate | ||
libraries when we try and run it: | ||
|
||
``` | ||
$ export PATH=$PREFIX/bin:$PATH | ||
$ export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH | ||
``` | ||
|
||
Let's try it out! | ||
|
||
``` | ||
$ echo 'fn main() { println!("hi!"); panic!("failed"); }' > example.rs | ||
$ rustc --target=x86_64-unknown-linux-musl example.rs | ||
$ ldd example | ||
not a dynamic executable | ||
$ ./example | ||
hi! | ||
thread '<main>' panicked at 'failed', example.rs:1 | ||
``` | ||
|
||
Success! This binary can be copied to almost any Linux machine with the same | ||
machine architecture and run without issues. | ||
|
||
`cargo build` also permits the `--target` option so you should be able to build | ||
your crates as normal. However, you may need to recompile your native libraries | ||
against `musl` before they can be linked against. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this Rust is trying to compile this code block.