-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Redox Cross Compilation #38401
Redox Cross Compilation #38401
Changes from 24 commits
341d2d1
c7aa284
a621d12
d2707aa
ece703a
f86e014
3e7543a
773a0a2
07e313d
6d7c2ec
57bc1a9
86f85c1
01157e6
e55596f
65eecf8
fd4bc88
7697c72
2ca1f0b
bf50acb
e909e43
92c8e0f
7d3ae87
e7b006d
1eb6c44
2ddd117
474eb62
c59bb49
4dcb867
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# rustbuild-only target | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not support jemalloc, so we will build with the dummy. |
||
println!("cargo:rustc-cfg=dummy_jemalloc"); | ||
return; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For |
||
|
||
// The minimum alignment guaranteed by the architecture. This value is used to | ||
// add fast paths for low alignment values. In practice, the alignment is a | ||
|
@@ -71,7 +71,7 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { | |
imp::usable_size(size, align) | ||
} | ||
|
||
#[cfg(unix)] | ||
#[cfg(any(unix, target_os = "redox"))] | ||
mod imp { | ||
extern crate libc; | ||
|
||
|
@@ -87,7 +87,7 @@ mod imp { | |
} | ||
} | ||
|
||
#[cfg(target_os = "android")] | ||
#[cfg(any(target_os = "android", target_os = "redox"))] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Newlib does not contain |
||
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { | ||
// On android we currently target API level 9 which unfortunately | ||
// doesn't have the `posix_memalign` API used below. Instead we use | ||
|
@@ -109,7 +109,7 @@ mod imp { | |
libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8 | ||
} | ||
|
||
#[cfg(not(target_os = "android"))] | ||
#[cfg(not(any(target_os = "android", target_os = "redox")))] | ||
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { | ||
let mut out = ptr::null_mut(); | ||
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,6 +69,7 @@ mod windows_base; | |
mod windows_msvc_base; | ||
mod thumb_base; | ||
mod fuchsia_base; | ||
mod redox_base; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We must add a new OS base for Redox |
||
|
||
pub type TargetResult = Result<Target, String>; | ||
|
||
|
@@ -184,6 +185,8 @@ supported_targets! { | |
("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia), | ||
("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia), | ||
|
||
("x86_64-unknown-redox", x86_64_unknown_redox), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We support a single architecture for Redox, |
||
|
||
("i386-apple-ios", i386_apple_ios), | ||
("x86_64-apple-ios", x86_64_apple_ios), | ||
("aarch64-apple-ios", aarch64_apple_ios), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use PanicStrategy; | ||
use target::TargetOptions; | ||
use std::default::Default; | ||
|
||
pub fn opts() -> TargetOptions { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This target is a bit different from others. Redox does not link to a |
||
TargetOptions { | ||
pre_link_args: vec![ | ||
// We want to be able to strip as much executable code as possible | ||
// from the linker command line, and this flag indicates to the | ||
// linker that it can avoid linking in dynamic libraries that don't | ||
// actually satisfy any symbols up to that point (as with many other | ||
// resolutions the linker does). This option only applies to all | ||
// following libraries so we're sure to pass it as one of the first | ||
// arguments. | ||
"-Wl,--as-needed".to_string(), | ||
|
||
// Always enable NX protection when it is available | ||
"-Wl,-z,noexecstack".to_string(), | ||
|
||
// Static link | ||
"-static".to_string() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redox does not support dynamic linking, so all files should be linked statically. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we've recently added support for |
||
], | ||
late_link_args: vec![ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We late link libc and libm so that they can be provided when binaries are linked, rather than using the compiler defaults. |
||
"-lc".to_string(), | ||
"-lm".to_string() | ||
], | ||
executables: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are able to generate executables. This is done rather unhygienically in |
||
relocation_model: "static".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no support for relocation in Redox. |
||
disable_redzone: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Red zones are not currently supported by Redox. This may be enabled in the future after testing. |
||
eliminate_frame_pointer: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not eliminate the frame pointer so that stack frames are easily traversable. |
||
target_family: Some("redox".to_string()), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a controversial change. With the way things are currently handled, setting this to |
||
linker_is_gnu: true, | ||
no_default_libraries: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No default libraries must be linked, as they would come from the host. |
||
lib_allocation_crate: "alloc_system".to_string(), | ||
exe_allocation_crate: "alloc_system".to_string(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use |
||
has_elf_tls: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do support TLS, so we enable it. |
||
panic_strategy: PanicStrategy::Abort, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We do not support unwinding, so we panic using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unwinding is not supported at the moment, so we abort. |
||
.. Default::default() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use target::{Target, TargetResult}; | ||
|
||
pub fn target() -> TargetResult { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These settings are very similar to those in other targets, and are nothing special. |
||
let mut base = super::redox_base::opts(); | ||
base.cpu = "x86-64".to_string(); | ||
base.max_atomic_width = Some(64); | ||
base.pre_link_args.push("-m64".to_string()); | ||
|
||
Ok(Target { | ||
llvm_target: "x86_64-unknown-redox".to_string(), | ||
target_endian: "little".to_string(), | ||
target_pointer_width: "64".to_string(), | ||
data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), | ||
arch: "x86_64".to_string(), | ||
target_os: "redox".to_string(), | ||
target_env: "".to_string(), | ||
target_vendor: "unknown".to_string(), | ||
options: base, | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,7 +26,7 @@ fn main() { | |
let target = env::var("TARGET").expect("TARGET was not set"); | ||
let host = env::var("HOST").expect("HOST was not set"); | ||
if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") && | ||
!target.contains("emscripten") && !target.contains("fuchsia") { | ||
!target.contains("emscripten") && !target.contains("fuchsia") && !target.contains("redox") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We disable the build of |
||
build_libbacktrace(&host, &target); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,11 +10,10 @@ | |
|
||
#![allow(dead_code, missing_docs, bad_style)] | ||
|
||
pub extern crate syscall; | ||
|
||
use io::{self, ErrorKind}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have moved the |
||
|
||
pub mod args; | ||
#[cfg(any(not(cargobuild), feature = "backtrace"))] | ||
pub mod backtrace; | ||
pub mod condvar; | ||
pub mod env; | ||
|
@@ -34,6 +33,7 @@ pub mod rand; | |
pub mod rwlock; | ||
pub mod stack_overflow; | ||
pub mod stdio; | ||
pub mod syscall; | ||
pub mod thread; | ||
pub mod thread_local; | ||
pub mod time; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,10 +20,11 @@ use vec::{IntoIter, Vec}; | |
|
||
use self::dns::{Dns, DnsQuery}; | ||
|
||
pub extern crate libc as netc; | ||
pub use self::tcp::{TcpStream, TcpListener}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We no longer use the |
||
pub use self::udp::UdpSocket; | ||
|
||
pub mod netc; | ||
|
||
mod dns; | ||
mod tcp; | ||
mod udp; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
pub type in_addr_t = u32; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the definitions from |
||
pub type in_port_t = u16; | ||
|
||
pub type socklen_t = u32; | ||
pub type sa_family_t = u16; | ||
|
||
pub const AF_INET: sa_family_t = 1; | ||
pub const AF_INET6: sa_family_t = 2; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct in_addr { | ||
pub s_addr: in_addr_t, | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct in6_addr { | ||
pub s6_addr: [u8; 16], | ||
__align: [u32; 0], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr { | ||
pub sa_family: sa_family_t, | ||
pub sa_data: [u8; 14], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr_in { | ||
pub sin_family: sa_family_t, | ||
pub sin_port: in_port_t, | ||
pub sin_addr: in_addr, | ||
pub sin_zero: [u8; 8], | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct sockaddr_in6 { | ||
pub sin6_family: sa_family_t, | ||
pub sin6_port: in_port_t, | ||
pub sin6_flowinfo: u32, | ||
pub sin6_addr: in6_addr, | ||
pub sin6_scope_id: u32, | ||
} |
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.
The old build system is complicated to use, so there is no support for using it.