Skip to content

Commit 99913c5

Browse files
committed
Auto merge of #38401 - redox-os:redox_cross, r=brson
Redox Cross Compilation 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](https://gist.github.com/jackpot51/6680ad973986e84d69c79854249f2b7e) Prior discussion of a smaller change is here: #38366
2 parents 82611a0 + 4dcb867 commit 99913c5

39 files changed

+1439
-42
lines changed

mk/cfg/x86_64-unknown-redox.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# rustbuild-only target

src/liballoc_jemalloc/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ fn main() {
3636
// targets, which means we have to build the alloc_jemalloc crate
3737
// for targets like emscripten, even if we don't use it.
3838
if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") ||
39-
target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") {
39+
target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") ||
40+
target.contains("redox") {
4041
println!("cargo:rustc-cfg=dummy_jemalloc");
4142
return;
4243
}

src/liballoc_system/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
issue = "27783")]
2020
#![feature(allocator)]
2121
#![feature(staged_api)]
22-
#![cfg_attr(unix, feature(libc))]
22+
#![cfg_attr(any(unix, target_os = "redox"), feature(libc))]
2323

2424
// The minimum alignment guaranteed by the architecture. This value is used to
2525
// 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 {
7171
imp::usable_size(size, align)
7272
}
7373

74-
#[cfg(unix)]
74+
#[cfg(any(unix, target_os = "redox"))]
7575
mod imp {
7676
extern crate libc;
7777

@@ -87,7 +87,7 @@ mod imp {
8787
}
8888
}
8989

90-
#[cfg(target_os = "android")]
90+
#[cfg(any(target_os = "android", target_os = "redox"))]
9191
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
9292
// On android we currently target API level 9 which unfortunately
9393
// doesn't have the `posix_memalign` API used below. Instead we use
@@ -109,7 +109,7 @@ mod imp {
109109
libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8
110110
}
111111

112-
#[cfg(not(target_os = "android"))]
112+
#[cfg(not(any(target_os = "android", target_os = "redox")))]
113113
unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 {
114114
let mut out = ptr::null_mut();
115115
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);

src/libcompiler_builtins/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ fn main() {
242242
"atomic_thread_fence.c"]);
243243
}
244244

245-
if !target.contains("windows") {
245+
if !target.contains("redox") && !target.contains("windows") {
246246
sources.extend(&["emutls.c"]);
247247
}
248248

src/librustc/session/config.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -945,26 +945,20 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
945945
let vendor = &sess.target.target.target_vendor;
946946
let max_atomic_width = sess.target.target.max_atomic_width();
947947

948-
let fam = if let Some(ref fam) = sess.target.target.options.target_family {
949-
Symbol::intern(fam)
950-
} else if sess.target.target.options.is_like_windows {
951-
Symbol::intern("windows")
952-
} else {
953-
Symbol::intern("unix")
954-
};
955-
956948
let mut ret = HashSet::new();
957949
// Target bindings.
958950
ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os))));
959-
ret.insert((Symbol::intern("target_family"), Some(fam)));
951+
if let Some(ref fam) = sess.target.target.options.target_family {
952+
ret.insert((Symbol::intern("target_family"), Some(Symbol::intern(fam))));
953+
if fam == "windows" || fam == "unix" {
954+
ret.insert((Symbol::intern(fam), None));
955+
}
956+
}
960957
ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch))));
961958
ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end))));
962959
ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz))));
963960
ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env))));
964961
ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor))));
965-
if fam == "windows" || fam == "unix" {
966-
ret.insert((fam, None));
967-
}
968962
if sess.target.target.options.has_elf_tls {
969963
ret.insert((Symbol::intern("target_thread_local"), None));
970964
}

src/librustc_back/target/apple_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub fn opts() -> TargetOptions {
3737
function_sections: false,
3838
dynamic_linking: true,
3939
executables: true,
40+
target_family: Some("unix".to_string()),
4041
is_like_osx: true,
4142
has_rpath: true,
4243
dll_prefix: "lib".to_string(),

src/librustc_back/target/bitrig_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions {
1515
TargetOptions {
1616
dynamic_linking: true,
1717
executables: true,
18+
target_family: Some("unix".to_string()),
1819
linker_is_gnu: true,
1920
has_rpath: true,
2021
position_independent_executables: true,

src/librustc_back/target/dragonfly_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions {
1515
TargetOptions {
1616
dynamic_linking: true,
1717
executables: true,
18+
target_family: Some("unix".to_string()),
1819
linker_is_gnu: true,
1920
has_rpath: true,
2021
pre_link_args: vec![

src/librustc_back/target/freebsd_base.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions {
1515
TargetOptions {
1616
dynamic_linking: true,
1717
executables: true,
18+
target_family: Some("unix".to_string()),
1819
linker_is_gnu: true,
1920
has_rpath: true,
2021
pre_link_args: vec![

0 commit comments

Comments
 (0)