mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-22 11:53:44 +00:00
Remove rlibc from the distribution
To make progress on #18585 we're paring down the distribution to theoretically "only libstd", and this commit makes progress on this by removing the rlibc crate from the distribution. The crate has now been moved into an external cargo package located in the rust lang organization [1]. This is a breaking change due to this removal, and existing crates depending on `rlibc` should use the Cargo crate instead. [1]: https://github.com/rust-lang/rlibc [breaking-change] cc #18585
This commit is contained in:
parent
8ed288edb2
commit
b39f1dcba0
@ -51,7 +51,7 @@
|
||||
|
||||
TARGET_CRATES := libc std green native flate arena term \
|
||||
serialize sync getopts collections test time rand \
|
||||
log regex graphviz core rbml rlibc alloc rustrt \
|
||||
log regex graphviz core rbml alloc rustrt \
|
||||
unicode
|
||||
HOST_CRATES := syntax rustc rustdoc regex_macros fmt_macros \
|
||||
rustc_llvm rustc_back
|
||||
@ -60,7 +60,6 @@ TOOLS := compiletest rustdoc rustc
|
||||
|
||||
DEPS_core :=
|
||||
DEPS_libc := core
|
||||
DEPS_rlibc := core
|
||||
DEPS_unicode := core
|
||||
DEPS_alloc := core libc native:jemalloc
|
||||
DEPS_rustrt := alloc core libc collections native:rustrt_native
|
||||
@ -104,7 +103,6 @@ TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
|
||||
|
||||
ONLY_RLIB_core := 1
|
||||
ONLY_RLIB_libc := 1
|
||||
ONLY_RLIB_rlibc := 1
|
||||
ONLY_RLIB_alloc := 1
|
||||
ONLY_RLIB_rand := 1
|
||||
ONLY_RLIB_collections := 1
|
||||
|
@ -1,202 +0,0 @@
|
||||
// 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.
|
||||
|
||||
//! A bare-metal library supplying functions rustc may lower code to
|
||||
//!
|
||||
//! This library is not intended for general use, and is superseded by a system
|
||||
//! libc if one is available. In a freestanding context, however, common
|
||||
//! functions such as memset, memcpy, etc are not implemented. This library
|
||||
//! provides an implementation of these functions which are either required by
|
||||
//! libcore or called by rustc implicitly.
|
||||
//!
|
||||
//! This library is never included by default, and must be manually included if
|
||||
//! necessary. It is an error to include this library when also linking with
|
||||
//! the system libc library.
|
||||
|
||||
#![crate_name = "rlibc"]
|
||||
#![experimental]
|
||||
#![license = "MIT/ASL2"]
|
||||
#![crate_type = "rlib"]
|
||||
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
||||
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
||||
html_root_url = "http://doc.rust-lang.org/nightly/")]
|
||||
|
||||
#![feature(import_shadowing, intrinsics, phase)]
|
||||
#![no_std]
|
||||
|
||||
// This library defines the builtin functions, so it would be a shame for
|
||||
// LLVM to optimize these function calls to themselves!
|
||||
#![no_builtins]
|
||||
|
||||
#[phase(plugin, link)] extern crate core;
|
||||
|
||||
#[cfg(test)] extern crate native;
|
||||
#[cfg(test)] extern crate test;
|
||||
|
||||
#[cfg(test)] #[phase(plugin, link)] extern crate std;
|
||||
|
||||
// Require the offset intrinsics for LLVM to properly optimize the
|
||||
// implementations below. If pointer arithmetic is done through integers the
|
||||
// optimizations start to break down.
|
||||
extern "rust-intrinsic" {
|
||||
fn offset<T>(dst: *const T, offset: int) -> *const T;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8,
|
||||
n: uint) -> *mut u8 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
i += 1;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8,
|
||||
n: uint) -> *mut u8 {
|
||||
if src < dest as *const u8 { // copy from end
|
||||
let mut i = n;
|
||||
while i != 0 {
|
||||
i -= 1;
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
}
|
||||
} else { // copy from beginning
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(dest as *const u8, i as int) as *mut u8) =
|
||||
*offset(src, i as int);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: uint) -> *mut u8 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
*(offset(s as *const u8, i as int) as *mut u8) = c as u8;
|
||||
i += 1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 {
|
||||
let mut i = 0;
|
||||
while i < n {
|
||||
let a = *offset(s1, i as int);
|
||||
let b = *offset(s2, i as int);
|
||||
if a != b {
|
||||
return a as i32 - b as i32
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use core::str::StrPrelude;
|
||||
use core::slice::{SlicePrelude};
|
||||
|
||||
use super::{memcmp, memset, memcpy, memmove};
|
||||
|
||||
#[test]
|
||||
fn memcmp_single_byte_pointers() {
|
||||
unsafe {
|
||||
assert_eq!(memcmp(&0xFAu8, &0xFAu8, 1), 0x00);
|
||||
assert!(memcmp(&0xEFu8, &0xFEu8, 1) < 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memcmp_strings() {
|
||||
{
|
||||
let (x, z) = ("Hello!", "Good Bye.");
|
||||
let l = x.len();
|
||||
unsafe {
|
||||
assert_eq!(memcmp(x.as_ptr(), x.as_ptr(), l), 0);
|
||||
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) > 0);
|
||||
assert!(memcmp(z.as_ptr(), x.as_ptr(), l) < 0);
|
||||
}
|
||||
}
|
||||
{
|
||||
let (x, z) = ("hey!", "hey.");
|
||||
let l = x.len();
|
||||
unsafe {
|
||||
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) < 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memset_single_byte_pointers() {
|
||||
let mut x: u8 = 0xFF;
|
||||
unsafe {
|
||||
memset(&mut x, 0xAA, 1);
|
||||
assert_eq!(x, 0xAA);
|
||||
memset(&mut x, 0x00, 1);
|
||||
assert_eq!(x, 0x00);
|
||||
x = 0x01;
|
||||
memset(&mut x, 0x12, 0);
|
||||
assert_eq!(x, 0x01);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memset_array() {
|
||||
let mut buffer = [b'X', .. 100];
|
||||
unsafe {
|
||||
memset(buffer.as_mut_ptr(), b'#' as i32, buffer.len());
|
||||
}
|
||||
for byte in buffer.iter() { assert_eq!(*byte, b'#'); }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memcpy_and_memcmp_arrays() {
|
||||
let (src, mut dst) = ([b'X', .. 100], [b'Y', .. 100]);
|
||||
unsafe {
|
||||
assert!(memcmp(src.as_ptr(), dst.as_ptr(), 100) != 0);
|
||||
let _ = memcpy(dst.as_mut_ptr(), src.as_ptr(), 100);
|
||||
assert_eq!(memcmp(src.as_ptr(), dst.as_ptr(), 100), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn memmove_overlapping() {
|
||||
{
|
||||
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
|
||||
unsafe {
|
||||
memmove(&mut buffer[4], &buffer[0], 6);
|
||||
let mut i = 0;
|
||||
for byte in b"0123012345".iter() {
|
||||
assert_eq!(buffer[i], *byte);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
|
||||
unsafe {
|
||||
memmove(&mut buffer[0], &buffer[4], 6);
|
||||
let mut i = 0;
|
||||
for byte in b"4567896789".iter() {
|
||||
assert_eq!(buffer[i], *byte);
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user