Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upRedox Cross Compilation #38401
Conversation
jackpot51
added some commits
Dec 13, 2016
rust-highfive
assigned
sfackler
Dec 15, 2016
This comment has been minimized.
This comment has been minimized.
|
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
jackpot51
reviewed
Dec 16, 2016
|
Hopefully these comments will help you navigate the changes. |
| @@ -0,0 +1 @@ | |||
| # rustbuild-only target | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
The old build system is complicated to use, so there is no support for using it.
| @@ -36,7 +36,8 @@ fn main() { | |||
| // targets, which means we have to build the alloc_jemalloc crate | |||
| // for targets like emscripten, even if we don't use it. | |||
| if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") || | |||
| target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") { | |||
| target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") || | |||
| target.contains("redox") { | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
We do not support jemalloc, so we will build with the dummy.
| @@ -71,7 +72,49 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { | |||
| imp::usable_size(size, align) | |||
| } | |||
|
|
|||
| #[cfg(unix)] | |||
| #[cfg(target_os = "redox")] | |||
| mod imp { | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
Just so we have a stub for potentially using a libc allocator, we implement alloc_system similarly to how the unix implementation works. If desired, these two imp blocks could be combined.
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 20, 2016
Member
You're the one defining the abi of the system allocator, so this is largely up to you. If you follow unix's malloc/free conventions then I'd recommend unifying with the above block for Unix. That handles bits and pieces such as alignment for more-aligned types (e.g. simd types).
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 20, 2016
Author
Contributor
I will probably change this to be different from Unix so that it defines externs that ralloc will fulfill.
| use MIN_ALIGN; | ||
|
|
||
| pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { | ||
| libc::malloc(size as libc::size_t) as *mut u8 |
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
memalign is not used like in the unix implementation, perhaps this is a problem
This comment has been minimized.
This comment has been minimized.
alexcrichton
Dec 20, 2016
Member
Yes I this is one case where I think you'll want to align with the implementation above. This really ends up just needing an allocator interface which supports alignment as an argument, and that's what memalign is targeted at.
This comment has been minimized.
This comment has been minimized.
| @@ -19,6 +19,7 @@ | |||
| issue = "27783")] | |||
| #![feature(allocator)] | |||
| #![feature(staged_api)] | |||
| #![cfg_attr(target_os = "redox", feature(libc))] | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
Note that ralloc is used as the default allocator in librust_back. What we have done here is to ensure that liballoc_system builds, as it is a required dependency of libstd. We never link to it, however.
| @@ -0,0 +1,232 @@ | |||
| use core::{mem, slice}; | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
This is the definition of a Redox scheme. It could probably be removed.
| @@ -0,0 +1,72 @@ | |||
| use super::error::{Error, Result}; | |||
This comment has been minimized.
This comment has been minimized.
| @@ -0,0 +1,72 @@ | |||
| use super::error::{Error, Result}; | |||
This comment has been minimized.
This comment has been minimized.
| @@ -914,6 +914,11 @@ fn use_color(opts: &TestOpts) -> bool { | |||
| } | |||
| } | |||
|
|
|||
| #[cfg(target_os = "redox")] | |||
| fn stdout_isatty() -> bool { | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
Redox needs to support isatty. We return false as a safe alternative
| @@ -1103,6 +1108,12 @@ fn get_concurrency() -> usize { | |||
| } | |||
| } | |||
|
|
|||
| #[cfg(target_os = "redox")] | |||
| fn num_cpus() -> usize { | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 16, 2016
Author
Contributor
Redox needs to provide a way to get the number of CPUs. We return 1 as a safe alternative
jackpot51
added some commits
Dec 20, 2016
jackpot51
referenced this pull request
Dec 21, 2016
Merged
Add memalign to Redox (for use in allocator) #478
bors
added a commit
to rust-lang/libc
that referenced
this pull request
Dec 21, 2016
jackpot51
added some commits
Dec 21, 2016
jackpot51
reviewed
Dec 22, 2016
| @@ -19,7 +19,7 @@ | |||
| issue = "27783")] | |||
| #![feature(allocator)] | |||
| #![feature(staged_api)] | |||
| #![cfg_attr(unix, feature(libc))] | |||
| #![cfg_attr(any(unix, target_os = "redox"), feature(libc))] | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
Author
Contributor
For alloc_system, we simply reuse the unix setup to allow a libc implementation of an allocator
jackpot51
reviewed
Dec 22, 2016
| @@ -87,7 +87,7 @@ mod imp { | |||
| } | |||
| } | |||
|
|
|||
| #[cfg(target_os = "android")] | |||
| #[cfg(any(target_os = "android", target_os = "redox"))] | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
•
Author
Contributor
Newlib does not contain posix_memalign, so we use memalign
jackpot51
reviewed
Dec 22, 2016
| linker_is_gnu: true, | ||
| no_default_libraries: true, | ||
| lib_allocation_crate: "alloc_system".to_string(), | ||
| exe_allocation_crate: "alloc_system".to_string(), |
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
Author
Contributor
We use alloc_system as the default allocator. I personally would like to use ralloc
jackpot51
reviewed
Dec 22, 2016
| #[no_mangle] | ||
| #[naked] | ||
| #[cfg(target_arch = "x86")] | ||
| pub unsafe fn _start() { |
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
Author
Contributor
Hygiene error! In order to generate executables, we have to have a naked _start function at the libstd root.
jackpot51
reviewed
Dec 22, 2016
| #[naked] | ||
| #[cfg(target_arch = "x86_64")] | ||
| pub unsafe fn _start() { | ||
| asm!("mov rdi, rsp |
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
Author
Contributor
Hygiene error! In order to generate executables, we have to have a naked _start function at the libstd root.
jackpot51
added some commits
Dec 22, 2016
This comment has been minimized.
This comment has been minimized.
RobertWHurst
commented
Dec 22, 2016
|
Can't wait for this to land 👌🏻 |
jackpot51
reviewed
Dec 22, 2016
| // Static link | ||
| "-static".to_string() | ||
| ], | ||
| late_link_args: vec![ |
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 22, 2016
Author
Contributor
We late link libc and libm so that they can be provided when binaries are linked, rather than using the compiler defaults.
This comment has been minimized.
This comment has been minimized.
|
This looks great to me. The only thing that bothers me here is |
jackpot51
added some commits
Dec 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Ok @brson - Please see c59bb49. A minor mistake was fixed in 4dcb867. I changed all of the Unix platforms to I changed librustc/session/config.rs to accept target_family only from the target configuration, to insert it as |
jackpot51
reviewed
Dec 23, 2016
| @@ -943,26 +943,20 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { | |||
| let vendor = &sess.target.target.target_vendor; | |||
| let max_atomic_width = sess.target.target.max_atomic_width(); | |||
|
|
|||
| let fam = if let Some(ref fam) = sess.target.target.options.target_family { | |||
| Symbol::intern(fam) | |||
| } else if sess.target.target.options.is_like_windows { | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 23, 2016
Author
Contributor
Since the windows platforms now correctly define target_family, this is no longer necessary.
jackpot51
reviewed
Dec 23, 2016
| @@ -38,7 +38,7 @@ pub fn opts() -> TargetOptions { | |||
| relocation_model: "static".to_string(), | |||
| disable_redzone: true, | |||
| eliminate_frame_pointer: false, | |||
| target_family: Some("redox".to_string()), | |||
| target_family: None, | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
jackpot51
reviewed
Dec 23, 2016
| @@ -24,6 +24,7 @@ pub fn opts() -> TargetOptions { | |||
| staticlib_prefix: "".to_string(), | |||
| staticlib_suffix: ".lib".to_string(), | |||
| no_default_libraries: true, | |||
| target_family: Some("windows".to_string()), | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
reviewed
Dec 23, 2016
| @@ -37,6 +37,7 @@ pub fn opts() -> TargetOptions { | |||
| function_sections: false, | |||
| dynamic_linking: true, | |||
| executables: true, | |||
| target_family: Some("unix".to_string()), | |||
This comment has been minimized.
This comment has been minimized.
jackpot51
Dec 23, 2016
•
Author
Contributor
Everything that isn't windows, is set to unix. That includes Linux, OS X, iOS, DragonflyBSD, NetBSD, OpenBSD, FreeBSD, Bitrig, Solaris, Fuchsia, and Haiku
brson
added
the
relnotes
label
Dec 23, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors r+ I'm very happy with how this is turning out so far. I wish there wasn't so much cfg sprawl in non-std crates, but that's something we can figure out in the future. Tagging with relnotes not only for the redox support, but also the breaking change to target_family. |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Dec 23, 2016
This comment has been minimized.
This comment has been minimized.
bors
merged commit 4dcb867
into
rust-lang:master
Dec 23, 2016
japaric
referenced this pull request
Dec 23, 2016
Closed
When target_family is None, rustc sets it to unix. #38187
This comment has been minimized.
This comment has been minimized.
|
Thanks @brson |
jackpot51 commentedDec 15, 2016
•
edited
I will admit - there are things here that I wish I did not have to do. This completes the ability to create a cross compiler from the rust repository for
x86_64-unknown-redox. I will document this PR with inline comments explaining some things.View this gist to see how a cross compiler is built
Prior discussion of a smaller change is here: #38366