Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Use rlibc crate #113

Merged
merged 1 commit into from
Jul 20, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ compile_rust :hamcrest_crate, {
do_not_collect_rust_deps: true,
}

# cross-compiled librlibc
compile_rust :rlibc_crate, {
source: 'thirdparty/librlibc/lib.rs'.in_root,
produce: 'thirdparty/librlibc/lib.rs'.in_root.as_rlib.in_build,
out_dir: true,
recompile_on: :triple,
}

# cross-compiled libcore
compile_rust :core_crate, {
source: 'thirdparty/libcore/lib.rs'.in_root,
Expand All @@ -29,7 +37,7 @@ compile_rust :core_crate, {
# zinc crate
compile_rust :zinc_crate, {
source: 'main.rs'.in_source,
deps: :core_crate,
deps: [:core_crate, :rlibc_crate],
produce: 'main.rs'.in_source.as_rlib.in_build,
out_dir: true,
recompile_on: [:triple, :platform],
Expand All @@ -38,6 +46,7 @@ compile_rust :zinc_crate, {
# zinc runtime support lib
compile_rust :zinc_support, {
source: 'lib/support.rs'.in_source,
deps: [:rlibc_crate],
produce: 'support.o'.in_intermediate,
llvm_pass: :inline,
lto: false,
Expand Down
45 changes: 0 additions & 45 deletions src/lib/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,51 +17,6 @@
#![crate_type="rlib"]
#![feature(asm, intrinsics)]

extern "rust-intrinsic" {
pub fn offset<T>(dst: *const T, offset: int) -> *const T;
}

#[allow(non_camel_case_types)]
pub type c_int = i32;

#[no_mangle]
#[no_split_stack]
#[inline(never)]
pub fn memcpy(dest: *mut u8, src: *const u8, n: int) {
unsafe {
let mut i = 0;
while i < n {
*(offset(dest as *const u8, i) as *mut u8) = *(offset(src, i));
i += 1;
}
}
}

#[no_mangle]
#[no_split_stack]
pub extern "C" fn __aeabi_memcpy(dest: *mut u8, src: *const u8, n: int) {
memcpy(dest, src, n);
}

#[no_mangle]
#[no_split_stack]
#[inline(never)]
pub fn memset(s: *mut u8, c: c_int, n: int) {
unsafe {
let mut i = 0;
while i < n {
*(offset(s as *const u8, i) as *mut u8) = c as u8;
i += 1;
}
}
}

#[no_mangle]
#[no_split_stack]
pub extern "C" fn __aeabi_memset(s: *mut u8, n: int, c: c_int) {
memset(s, c, n);
}

#[cfg(test)]
#[no_split_stack]
#[no_mangle]
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ STM32F403/407).
*/

extern crate core;
extern crate rlibc;

#[cfg(test)] #[phase(plugin,link)] extern crate std;
#[cfg(test)] extern crate native;
Expand Down
4 changes: 4 additions & 0 deletions support/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ def provide_stdlibs
sh "git clone --single-branch --depth 1 https://github.com/mozilla/rust #{t.name}"
end.invoke

Rake::FileTask.define_task 'thirdparty/librlibc/lib.rs'.in_root do |t|
sh "ln -s rust/src/librlibc thirdparty/librlibc"
end.invoke

Rake::FileTask.define_task 'thirdparty/libcore/lib.rs'.in_root do |t|
sh "ln -s rust/src/libcore thirdparty/libcore"
end.invoke
Expand Down