Permalink
Browse files

Support ARM and Android

Conflicts:
	src/libcore/os.rs
	src/librustc/back/link.rs
	src/librustc/driver/driver.rs
	src/librustc/metadata/loader.rs
	src/librustc/middle/trans/base.rs
  • Loading branch information...
1 parent 27e6a0f commit 987f824f233faee4aed39dac92a1b442d42965cc @kyeongwoon kyeongwoon committed with brson Nov 30, 2012
View
@@ -241,7 +241,7 @@ DRIVER_CRATE := $(S)src/driver/driver.rs
######################################################################
# FIXME: x86-ism
-LLVM_COMPONENTS=x86 ipo bitreader bitwriter linker asmparser jit mcjit \
+LLVM_COMPONENTS=x86 arm ipo bitreader bitwriter linker asmparser jit mcjit \
interpreter
define DEF_LLVM_VARS
View
@@ -717,7 +717,7 @@ do
then
msg "configuring LLVM for $t"
- LLVM_TARGETS="--enable-targets=x86,x86_64"
+ LLVM_TARGETS="--enable-targets=x86,x86_64,arm"
LLVM_BUILD="--build=$t"
LLVM_HOST="--host=$t"
LLVM_TARGET="--target=$t"
View
@@ -40,11 +40,13 @@ struct AllocHeader { priv opaque: () }
struct MemoryRegion { priv opaque: () }
#[cfg(target_arch="x86")]
+#[cfg(target_arch="arm")]
struct Registers {
data: [u32 * 16]
}
#[cfg(target_arch="x86")]
+#[cfg(target_arch="arm")]
struct Context {
regs: Registers,
next: *Context,
@@ -70,6 +72,7 @@ struct BoxedRegion {
}
#[cfg(target_arch="x86")]
+#[cfg(target_arch="arm")]
struct Task {
// Public fields
refcount: intptr_t, // 0
View
@@ -198,12 +198,14 @@ pub mod types {
// Standard types that are scalar but vary by OS and arch.
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
pub mod os {
pub mod common {
pub mod posix01 {}
}
#[cfg(target_arch = "x86")]
+ #[cfg(target_arch = "arm")]
pub mod arch {
pub mod c95 {
pub type c_char = i8;
@@ -797,6 +799,7 @@ pub mod consts {
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
pub mod os {
pub mod c95 {
pub const EXIT_FAILURE : int = 1;
@@ -1264,6 +1267,7 @@ pub mod funcs {
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix88 {
@@ -1283,7 +1287,8 @@ pub mod funcs {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
- unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
+ #[cfg(target_os = "android")]
+ unsafe fn fstat(fildes: c_int, buf: *mut stat) -> c_int;
#[cfg(target_os = "macos")]
#[link_name = "fstat64"]
@@ -1294,6 +1299,7 @@ pub mod funcs {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
+ #[cfg(target_os = "android")]
unsafe fn stat(path: *c_char, buf: *mut stat) -> c_int;
#[cfg(target_os = "macos")]
@@ -1382,6 +1388,7 @@ pub mod funcs {
}
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix01 {
@@ -1394,6 +1401,7 @@ pub mod funcs {
pub extern mod stat_ {
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
+ #[cfg(target_os = "android")]
unsafe fn lstat(path: *c_char, buf: *mut stat) -> c_int;
#[cfg(target_os = "macos")]
@@ -1410,6 +1418,7 @@ pub mod funcs {
unsafe fn fsync(fd: c_int) -> c_int;
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
unsafe fn fdatasync(fd: c_int) -> c_int;
unsafe fn setenv(name: *c_char, val: *c_char,
@@ -1442,6 +1451,7 @@ pub mod funcs {
#[cfg(target_os = "win32")]
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
pub mod posix08 {
@@ -1473,6 +1483,7 @@ pub mod funcs {
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
#[cfg(target_os = "win32")]
pub mod bsd44 {
}
@@ -1492,6 +1503,7 @@ pub mod funcs {
}
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
pub mod extra {
}
View
@@ -325,6 +325,7 @@ pub fn fsync_fd(fd: c_int, _level: io::fsync::Level) -> c_int {
}
#[cfg(target_os = "linux")]
+#[cfg(target_os = "android")]
pub fn fsync_fd(fd: c_int, level: io::fsync::Level) -> c_int {
unsafe {
use libc::funcs::posix01::unistd::*;
@@ -449,6 +450,7 @@ pub fn self_exe_path() -> Option<Path> {
}
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
fn load_self() -> Option<~str> {
unsafe {
use libc::funcs::posix01::unistd::readlink;
@@ -876,6 +878,7 @@ pub fn real_args() -> ~[~str] {
}
#[cfg(target_os = "linux")]
+#[cfg(target_os = "android")]
#[cfg(target_os = "freebsd")]
pub fn real_args() -> ~[~str] {
unsafe {
@@ -976,7 +979,6 @@ pub mod consts {
pub const FAMILY: &str = "windows";
}
-
#[cfg(target_os = "macos")]
use os::consts::macos::*;
@@ -986,6 +988,9 @@ pub mod consts {
#[cfg(target_os = "linux")]
use os::consts::linux::*;
+ #[cfg(target_os = "android")]
+ use os::consts::android::*;
+
#[cfg(target_os = "win32")]
use os::consts::win32::*;
@@ -1010,6 +1015,13 @@ pub mod consts {
pub const EXE_SUFFIX: &str = "";
}
+ pub mod android {
+ pub const SYSNAME: &str = "android";
+ pub const DLL_PREFIX: &str = "lib";
+ pub const DLL_SUFFIX: &str = ".so";
+ pub const EXE_SUFFIX: &str = "";
+ }
+
pub mod win32 {
pub const SYSNAME: &str = "win32";
pub const DLL_PREFIX: &str = "";
View
@@ -89,8 +89,10 @@ pub pure fn Path(s: &str) -> Path {
}
#[cfg(target_os = "linux")]
+#[cfg(target_os = "android")]
mod stat {
#[cfg(target_arch = "x86")]
+ #[cfg(target_arch = "arm")]
pub mod arch {
use libc;
View
@@ -405,6 +405,7 @@ pub fn waitpid(pid: pid_t) -> int {
#[cfg(unix)]
fn waitpid_os(pid: pid_t) -> int {
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
fn WIFEXITED(status: i32) -> bool {
(status & 0xffi32) == 0i32
}
@@ -416,6 +417,7 @@ pub fn waitpid(pid: pid_t) -> int {
}
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "android")]
fn WEXITSTATUS(status: i32) -> i32 {
(status >> 8i32) & 0xffi32
}
View
@@ -0,0 +1,85 @@
+// Copyright 2012 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 back::target_strs;
+use driver::session;
+use session::sess_os_to_meta_os;
+use metadata::loader::meta_section_name;
+
+fn get_target_strs(target_os: session::os) -> target_strs::t {
+ return {
+ module_asm: ~"",
+
+ meta_sect_name: meta_section_name(sess_os_to_meta_os(target_os)),
+
+ data_layout: match target_os {
+ session::os_macos => {
+ ~"e-p:32:32:32" +
+ ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
+ ~"-f32:32:32-f64:64:64" +
+ ~"-v64:64:64-v128:64:128" +
+ ~"-a0:0:64-n32"
+ }
+
+ session::os_win32 => {
+ ~"e-p:32:32:32" +
+ ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
+ ~"-f32:32:32-f64:64:64" +
+ ~"-v64:64:64-v128:64:128" +
+ ~"-a0:0:64-n32"
+ }
+
+ session::os_linux => {
+ ~"e-p:32:32:32" +
+ ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
+ ~"-f32:32:32-f64:64:64" +
+ ~"-v64:64:64-v128:64:128" +
+ ~"-a0:0:64-n32"
+ }
+
+ session::os_android => {
+ ~"e-p:32:32:32" +
+ ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
+ ~"-f32:32:32-f64:64:64" +
+ ~"-v64:64:64-v128:64:128" +
+ ~"-a0:0:64-n32"
+ }
+
+ session::os_freebsd => {
+ ~"e-p:32:32:32" +
+ ~"-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64" +
+ ~"-f32:32:32-f64:64:64" +
+ ~"-v64:64:64-v128:64:128" +
+ ~"-a0:0:64-n32"
+ }
+ },
+
+ target_triple: match target_os {
+ session::os_macos => ~"arm-apple-darwin",
+ session::os_win32 => ~"arm-pc-mingw32",
+ session::os_linux => ~"arm-unknown-linux",
+ session::os_android => ~"arm-unknown-android",
+ session::os_freebsd => ~"arm-unknown-freebsd"
+ },
+
+ cc_args: ~[~"-marm"]
+ };
+}
+
+
+//
+// Local Variables:
+// mode: rust
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
+//
View
@@ -30,7 +30,7 @@ use core::cmp;
use core::hash;
use core::io::{Writer, WriterUtil};
use core::libc::{c_int, c_uint, c_char};
-use core::os::consts::{macos, freebsd, linux, win32};
+use core::os::consts::{macos, freebsd, linux, android, win32};
use core::os;
use core::ptr;
use core::run;
@@ -43,7 +43,7 @@ use syntax::ast_map::{path, path_mod, path_name};
use syntax::attr;
use syntax::print::pprust;
-pub enum output_type {
+enum output_type {
output_type_none,
output_type_bitcode,
output_type_assembly,
@@ -712,6 +712,7 @@ fn output_dll_filename(os: session::os, lm: &link_meta) -> ~str {
session::os_win32 => (win32::DLL_PREFIX, win32::DLL_SUFFIX),
session::os_macos => (macos::DLL_PREFIX, macos::DLL_SUFFIX),
session::os_linux => (linux::DLL_PREFIX, linux::DLL_SUFFIX),
+ session::os_android => (android::DLL_PREFIX, android::DLL_SUFFIX),
session::os_freebsd => (freebsd::DLL_PREFIX, freebsd::DLL_SUFFIX),
};
return str::from_slice(dll_prefix) + libname +
@@ -758,7 +759,10 @@ fn link_binary(sess: Session,
// For win32, there is no cc command,
// so we add a condition to make it use gcc.
let cc_prog: ~str =
- if sess.targ_cfg.os == session::os_win32 { ~"gcc" } else { ~"cc" };
+ if sess.targ_cfg.os == session::os_android {
+ ~"arm-linux-androideabi-g++"
+ } else if sess.targ_cfg.os == session::os_win32 { ~"gcc" }
+ else { ~"cc" };
// The invocations of cc share some flags across platforms
let mut cc_args =
@@ -831,6 +835,11 @@ fn link_binary(sess: Session,
// have to be explicit about linking to it. See #2510
cc_args.push(~"-lm");
}
+ else if sess.targ_cfg.os == session::os_android {
+ cc_args.push_all(~[~"-ldl", ~"-llog", ~"-lsupc++",
+ ~"-lgnustl_shared"]);
+ cc_args.push(~"-lm");
+ }
if sess.targ_cfg.os == session::os_freebsd {
cc_args.push_all(~[~"-pthread", ~"-lrt",
@@ -851,7 +860,9 @@ fn link_binary(sess: Session,
}
// Stack growth requires statically linking a __morestack function
+ if sess.targ_cfg.os != session::os_android {
cc_args.push(~"-lmorestack");
+ }
// FIXME (#2397): At some point we want to rpath our guesses as to where
// extern libraries might live, based on the addl_lib_search_paths
@@ -130,7 +130,8 @@ fn get_rpath_relative_to_output(os: session::os,
// Mac doesn't appear to support $ORIGIN
let prefix = match os {
- session::os_linux | session::os_freebsd => "$ORIGIN",
+ session::os_android |session::os_linux | session::os_freebsd
+ => "$ORIGIN",
session::os_macos => "@executable_path",
session::os_win32 => util::unreachable()
};
@@ -331,6 +332,7 @@ mod test {
#[test]
#[cfg(target_os = "linux")]
+ #[cfg(target_os = "andorid")]
fn test_rpath_relative() {
let o = session::os_linux;
let res = get_rpath_relative_to_output(o,
Oops, something went wrong.

0 comments on commit 987f824

Please sign in to comment.