Skip to content

Commit

Permalink
Testing arm64 on device only
Browse files Browse the repository at this point in the history
  • Loading branch information
vhbit committed Dec 23, 2014
1 parent 453394a commit bcdf16d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 114 deletions.
7 changes: 3 additions & 4 deletions Rust/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
CROSS_IOS_RUST_ROOT=/Users/vhbit/projects/external/rust/build_latest/x86_64-apple-darwin/stage2
RUSTC ?= $(CROSS_IOS_RUST_ROOT)/bin/rustc
RUST_FLAGS=-O
TARGETS=arm-apple-ios i386-apple-ios
RUSTC = /Users/vhbit/projects/auto-rust/build64/x86_64-apple-darwin/stage2/bin/rustc
RUST_FLAGS=-g
TARGETS=aarch64-apple-ios
LIB_NAME=libobjcrust-$(1).a
ARCH_LIBS=$(foreach target,$(TARGETS),$(call LIB_NAME,$(target)))

Expand Down
101 changes: 19 additions & 82 deletions Rust/objcrust.rs
Original file line number Diff line number Diff line change
@@ -1,91 +1,30 @@
#![crate_type = "staticlib"]

extern crate std;
extern crate native;
extern crate libc;
extern crate collections;

use std::collections::hashmap::HashMap;
use libc::c_char;
use std::collections::HashMap;
use std::comm::{channel, Sender};

use std::iter;
use std::rt;
use std::rt::unwind::try;
use std::rt::task::Task;
use std::rt::local::Local;
use std::c_str::CString;
use native::task;

fn ignore_sigpipe() {
use libc;
use libc::funcs::posix01::signal::signal;
unsafe {
assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != -1);
}
}

#[allow(dead_code)]
fn run_proc_in_task(f: || -> ()) {
ignore_sigpipe();

rt::init(0, std::ptr::null());
let mut task = task::new((0, 0));
task.name = Some(std::str::Slice("<extra-task>"));
let t = task.run(|| {
f();
});
drop(t);
}

// Creates a "fake" task which will be presented always
// It is required to have at least one task before
// using std libs as most of them rely on correct
// runtime initialization
#[no_mangle]
pub extern fn register_task(name: *c_char) {
ignore_sigpipe();

rt::init(0, std::ptr::null());
let mut task = task::new((0, 0));
task.name = Some(std::str::Owned(unsafe {CString::new(name, false).as_str().unwrap().to_string()}));

Local::put(task);
}

#[no_mangle]
pub extern fn deregister_task() {
let task: Box<Task> = Local::take();
drop(task);
}
use std::time::Duration;

#[no_mangle]
pub extern fn run_rust_main() {
// Testing hack to get command line arguments into Rust
println!("Args are {}", std::os::args());
let _ = unsafe { try(|| { rust_main() }) };
}

pub static mut db_sender: *Sender<int> = 0 as *Sender<int>;
pub static mut db_sender: *mut Sender<int> = 0 as *mut Sender<int>;

#[no_mangle]
pub extern fn rust_main() {
/*
let ref mut w = std::io::stdout();
std::rt::backtrace::write(w);
*/

println!("Hello from Rust!");

// Hashmap - testing rand module works
let mut dict = HashMap::new();
dict.insert(3, 4);
dict.insert(4, 6);
dict.insert(3i, 4i);
dict.insert(4i, 6i);

// Using channels
let (tx, rx) = channel();

spawn(proc () {
spawn(move || {
let (sender, receiver) = channel::<int>();

// Testing if global variable will live
Expand All @@ -98,49 +37,47 @@ pub extern fn rust_main() {
tx.send(sender);

println!("In daemon receiver");
std::io::timer::sleep(3000);
std::io::timer::sleep(Duration::seconds(3));

let mut z = 0;
let mut z = 0i;

loop {
let i = receiver.recv();
if i == 0 {
if i == 0i {
break;
} else {
println!("Task got {} [{}]", i, z);
z += 1;
z += 1i;
}
}

println!("Exiting daemon receiver");
});


let _ = rx.recv();

unsafe {
for i in iter::range(1, 10) {
for i in iter::range(1i, 10) {
(*db_sender).send(i);
}
}

let (tx, rx) = channel();
tx.send(200);
spawn(proc() {
tx.send(200i);
spawn(move || {
let t = rx.recv();
println!("Got {} from main thread", t);
fail!()
panic!()
});

// Testing exception handling and reporting
fail!();
}

#[deriving(Copy)]
pub struct Pair {
foo: uint,
bar: uint,
}

#[deriving(Copy)]
pub struct Complex {
real: f64,
img: f64,
Expand Down Expand Up @@ -226,4 +163,4 @@ pub extern fn inc_complex(comp: Complex) -> Complex {
pub extern fn inc_complex_ptr(comp: &mut Complex) {
comp.real += 1.0;
comp.img += 1.0;
}
}
28 changes: 12 additions & 16 deletions iOS/ObjCrust.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
2B7326BD1778B13900BE08F9 /* [email protected] in Resources */ = {isa = PBXBuildFile; fileRef = 2B7326BC1778B13900BE08F9 /* [email protected] */; };
2B7326C51778B13900BE08F9 /* SenTestingKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 2B7326C41778B13900BE08F9 /* SenTestingKit.framework */; };
2B8D5136184B599800A0D6A5 /* TestRust.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B8D5135184B599800A0D6A5 /* TestRust.m */; };
C42EB83518FBEAE6009A9597 /* libobjcrust.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C42EB82518FBE52A009A9597 /* libobjcrust.a */; };
C40AFBD3198925B6009A9597 /* libobjcrust.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C42EB82518FBE52A009A9597 /* libobjcrust.a */; };
C451C36518F858BF009A9597 /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C451C36418F858BF009A9597 /* Security.framework */; };
C4A87DAE19477381009A9597 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C42EB7F818FBDBDB009A9597 /* Foundation.framework */; };
C4C3F87518F4638C009A9597 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 2B7326B21778B13900BE08F9 /* main.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; };
Expand Down Expand Up @@ -104,9 +104,9 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
C40AFBD3198925B6009A9597 /* libobjcrust.a in Frameworks */,
C4A87DAE19477381009A9597 /* Foundation.framework in Frameworks */,
C451C36518F858BF009A9597 /* Security.framework in Frameworks */,
C42EB83518FBEAE6009A9597 /* libobjcrust.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -281,7 +281,7 @@
name = "Unit Tests";
productName = ObjCrustTests;
productReference = 2B7326C31778B13900BE08F9 /* Unit Tests.octest */;
productType = "com.apple.product-type.bundle";
productType = "com.apple.product-type.bundle.ocunit-test";
};
/* End PBXNativeTarget section */

Expand Down Expand Up @@ -369,7 +369,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# this fucking option set to \"legacy\" screwed compilation\nexport COMMAND_MODE=unix2003\n\ncd $PROJECT_DIR/../Rust\n\nmake";
shellScript = "# this fucking option set to \"legacy\" screwed compilation\nexport COMMAND_MODE=unix2003\nexport DYLD_LIBRARY_PATH=/Users/vhbit/projects/auto-rust/build64/:/Users/vhbit/projects/auto-rust/build64/x86_64-apple-darwin/stage1/lib/rustlib/x86_64-apple-darwin/lib/:$DYLD_LIBRARY_PATH\n\ncd $PROJECT_DIR/../Rust\n\nmake";
};
/* End PBXShellScriptBuildPhase section */

Expand Down Expand Up @@ -431,6 +431,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = arm64;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand Down Expand Up @@ -459,13 +460,15 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = arm64;
};
name = Debug;
};
2B7326D41778B13900BE08F9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ARCHS = arm64;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
Expand All @@ -484,20 +487,18 @@
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
ONLY_ACTIVE_ARCH = YES;
OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1";
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
VALIDATE_PRODUCT = YES;
VALID_ARCHS = arm64;
};
name = Release;
};
2B7326D61778B13900BE08F9 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
armv7,
i386,
);
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
Expand All @@ -515,21 +516,17 @@
"$(inherited)",
"$(PROJECT_DIR)/../Rust",
/Users/vhbit/projects/ObjCrust/Rust,
"/Users/vhbit/projects/ObjCrust-arm64/Rust",
);
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
VALID_ARCHS = armv7;
WRAPPER_EXTENSION = app;
};
name = Debug;
};
2B7326D71778B13900BE08F9 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
armv7,
i386,
);
CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES;
CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES;
Expand All @@ -547,10 +544,11 @@
"$(inherited)",
"$(PROJECT_DIR)/../Rust",
/Users/vhbit/projects/ObjCrust/Rust,
"/Users/vhbit/projects/ObjCrust-arm64/Rust",
);
ONLY_ACTIVE_ARCH = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
VALID_ARCHS = armv7;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down Expand Up @@ -589,15 +587,13 @@
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
VALID_ARCHS = armv7;
};
name = Debug;
};
C42EB7EE18FBD66E009A9597 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
PRODUCT_NAME = "$(TARGET_NAME)";
VALID_ARCHS = armv7;
};
name = Release;
};
Expand Down
15 changes: 3 additions & 12 deletions iOS/Sources/main.m
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#import "CRAppDelegate.h"
#import "objcrust.h"
#import <execinfo.h>

extern void run_rust_main();
extern void register_task(const char *);
extern void deregister_task();
extern void rust_main();

int main(int argc, char *argv[]) {
// Enable printing backtraces
// It works correctly in Simulator, but doesn't work yet on the device
setenv("RUST_BACKTRACE", "1", 1);

// Initially registering task which is required
// to get std libs working
register_task("<main>");

// While it is possible to call rust_main directly
// it will crash the whole app as uses fail!()
// run_rust_main just wraps it into unwinder
run_rust_main();
rust_main();

@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass(CRAppDelegate.class));
Expand Down

0 comments on commit bcdf16d

Please sign in to comment.