auto merge of #17673 : aturon/rust/remove-uv, r=alexcrichton

This PR begins the process of [runtime removal](https://github.com/rust-lang/rfcs/pull/230) by dismantling the `librustuv` crate and associated event loop.

The result is that, while `libgreen` can still be used for task scheduling purposes, it will no longer be feasible to use green-threaded I/O.

Removing the libuv-based event loop eases the transition away from the runtime system, which will be done incrementally.

In terms of visible API changes, this PR:

* Removes `std::io::signal`, which was never implemented on the native threading model.

* Removes the `iotest!` macro, which was previously used to run I/O tests on both green and native threading models.

* Removes the `green_start!` macro for starting an application with a `librustuv` event loop.

* Removes the `librustuv` crate itself.

It also removes the `libuv` and `gyp` submodules and adjusts the build system and copyright notices accordingly.

If you wish to continue using `librustuv` and green-threaded I/O, consider using [green-rs](https://github.com/alexcrichton/green-rs/), which provides its own I/O stack.
This commit is contained in:
bors 2014-10-01 21:27:19 +00:00
commit a70a0374e2
70 changed files with 652 additions and 7747 deletions

View file

@ -11,7 +11,6 @@
#![no_start]
extern crate green;
extern crate rustuv;
use std::task::spawn;
use std::os;
@ -22,7 +21,7 @@ use std::uint;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
green::start(argc, argv, green::basic::event_loop, main)
}
fn main() {

View file

@ -40,14 +40,9 @@
// no-pretty-expanded
#![feature(phase)]
#[phase(plugin)] extern crate green;
use std::string::String;
use std::fmt;
green_start!(main)
fn print_complements() {
let all = [Blue, Red, Yellow];
for aa in all.iter() {

View file

@ -40,13 +40,8 @@
// no-pretty-expanded FIXME #15189
#![feature(phase)]
#[phase(plugin)] extern crate green;
use std::sync::Arc;
green_start!(main)
//
// Utilities.
//

View file

@ -40,9 +40,7 @@
// no-pretty-expanded FIXME #15189
#![feature(phase)]
#![allow(non_snake_case)]
#[phase(plugin)] extern crate green;
use std::from_str::FromStr;
use std::iter::count;
@ -50,8 +48,6 @@ use std::cmp::min;
use std::os;
use std::sync::{Arc, RWLock};
green_start!(main)
fn A(i: uint, j: uint) -> f64 {
((i + j) * (i + j + 1) / 2 + i + 1) as f64
}

View file

@ -38,10 +38,6 @@
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
// OF THE POSSIBILITY OF SUCH DAMAGE.
#![feature(phase)]
#[phase(plugin)] extern crate green;
green_start!(main)
fn start(n_tasks: int, token: int) {
let (tx, mut rx) = channel();
tx.send(token);

View file

@ -9,16 +9,13 @@
// except according to those terms.
// This is (hopefully) a quick test to get a good idea about spawning
// performance in libgreen. Note that this uses the rustuv event loop rather
// than the basic event loop in order to get a better real world idea about the
// performance of a task spawn.
// performance in libgreen.
extern crate green;
extern crate rustuv;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
green::start(argc, argv, green::basic::event_loop, main)
}
fn main() {

View file

@ -1,12 +0,0 @@
-include ../tools.mk
HOST_LIB_DIR=$(TMPDIR)/../../../stage$(RUST_BUILD_STAGE)/lib
# This overrides the LD_LIBRARY_PATH for RUN
TARGET_RPATH_DIR:=$(TARGET_RPATH_DIR):$(TMPDIR)
all:
$(RUSTC) lib.rs
$(CC) main.c -o $(call RUN_BINFILE,main) $(call RPATH_LINK_SEARCH,$(HOST_LIB_DIR)) -lboot
$(call RUN,main)
$(call REMOVE_DYLIBS,boot)
$(call FAIL,main)

View file

@ -1,24 +0,0 @@
// Copyright 2013 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.
#![crate_name="boot"]
#![crate_type="dylib"]
extern crate rustuv;
extern crate green;
#[no_mangle] // this needs to get called from C
pub extern "C" fn foo(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, proc() {
spawn(proc() {
println!("hello");
});
})
}

View file

@ -1,16 +0,0 @@
// Copyright 2013 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.
// this is the rust entry point that we're going to call.
int foo(int argc, char *argv[]);
int main(int argc, char *argv[]) {
return foo(argc, argv);
}

View file

@ -20,54 +20,21 @@
extern crate libc;
extern crate native;
extern crate green;
extern crate rustuv;
use std::io::{Process, Command};
use std::io::{Process, Command, timer};
use std::time::Duration;
use std::str;
macro_rules! succeed( ($e:expr) => (
match $e { Ok(..) => {}, Err(e) => fail!("failure: {}", e) }
) )
macro_rules! iotest (
{ fn $name:ident() $b:block $($a:attr)* } => (
mod $name {
#![allow(unused_imports)]
use std::io::timer;
use libc;
use std::str;
use std::io::process::Command;
use native;
use super::{sleeper, test_destroy_actually_kills};
fn f() $b
$($a)* #[test] fn green() { f() }
$($a)* #[test] fn native() {
use native;
let (tx, rx) = channel();
native::task::spawn(proc() { tx.send(f()) });
rx.recv();
}
}
)
)
#[cfg(test)] #[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, test_main)
}
iotest!(fn test_destroy_once() {
fn test_destroy_once() {
let mut p = sleeper();
match p.signal_exit() {
Ok(()) => {}
Err(e) => fail!("error: {}", e),
}
})
}
#[cfg(unix)]
pub fn sleeper() -> Process {
@ -81,11 +48,11 @@ pub fn sleeper() -> Process {
Command::new("ping").arg("127.0.0.1").arg("-n").arg("1000").spawn().unwrap()
}
iotest!(fn test_destroy_twice() {
fn test_destroy_twice() {
let mut p = sleeper();
succeed!(p.signal_exit()); // this shouldnt crash...
let _ = p.signal_exit(); // ...and nor should this (and nor should the destructor)
})
}
pub fn test_destroy_actually_kills(force: bool) {
use std::io::process::{Command, ProcessOutput, ExitStatus, ExitSignal};
@ -129,10 +96,10 @@ pub fn test_destroy_actually_kills(force: bool) {
}
}
iotest!(fn test_unforced_destroy_actually_kills() {
fn test_unforced_destroy_actually_kills() {
test_destroy_actually_kills(false);
})
}
iotest!(fn test_forced_destroy_actually_kills() {
fn test_forced_destroy_actually_kills() {
test_destroy_actually_kills(true);
})
}

View file

@ -8,20 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
extern crate native;
extern crate green;
extern crate rustuv;
use std::time::Duration;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}
fn main() {
native::task::spawn(proc() customtask());
std::task::spawn(proc() customtask());
}
fn customtask() {

View file

@ -10,48 +10,25 @@
// ignore-fast
extern crate green;
extern crate rustuv;
extern crate native;
use std::os;
use std::io;
use std::str;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}
fn main() {
let args = os::args();
let args = args.as_slice();
if args.len() > 1 && args[1].as_slice() == "child" {
if args[2].as_slice() == "green" {
child();
} else {
let (tx, rx) = channel();
native::task::spawn(proc() { tx.send(child()); });
rx.recv();
}
child();
} else {
parent("green".to_string());
parent("native".to_string());
let (tx, rx) = channel();
native::task::spawn(proc() {
parent("green".to_string());
parent("native".to_string());
tx.send(());
});
rx.recv();
parent();
}
}
fn parent(flavor: String) {
fn parent() {
let args = os::args();
let args = args.as_slice();
let mut p = io::process::Command::new(args[0].as_slice())
.arg("child").arg(flavor).spawn().unwrap();
.arg("child").spawn().unwrap();
p.stdin.get_mut_ref().write_str("test1\ntest2\ntest3").unwrap();
let out = p.wait_with_output().unwrap();
assert!(out.status.success());

View file

@ -11,22 +11,13 @@
// This test may not always fail, but it can be flaky if the race it used to
// expose is still present.
extern crate green;
extern crate rustuv;
extern crate native;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}
fn helper(rx: Receiver<Sender<()>>) {
for tx in rx.iter() {
let _ = tx.send_opt(());
}
}
fn test() {
fn main() {
let (tx, rx) = channel();
spawn(proc() { helper(rx) });
let (snd, rcv) = channel::<int>();
@ -40,17 +31,3 @@ fn test() {
}
}
}
fn main() {
let (tx, rx) = channel();
spawn(proc() {
tx.send(test());
});
rx.recv();
let (tx, rx) = channel();
native::task::spawn(proc() {
tx.send(test());
});
rx.recv();
}

View file

@ -8,19 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(phase)]
#[phase(plugin, link)]
extern crate green;
extern crate native;
use std::io::process;
use std::io::Command;
use std::io;
use std::os;
green_start!(main)
fn main() {
let args = os::args();
if args.len() > 1 && args.get(1).as_slice() == "child" {
@ -29,12 +22,6 @@ fn main() {
test();
let (tx, rx) = channel();
native::task::spawn(proc() {
tx.send(test());
});
rx.recv();
}
fn child() {
@ -52,4 +39,3 @@ fn test() {
.spawn().unwrap();
assert!(p.wait().unwrap().success());
}

View file

@ -8,18 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(phase)]
extern crate native;
#[phase(plugin)]
extern crate green;
use native::NativeTaskBuilder;
use std::io::{TempDir, Command, fs};
use std::os;
use std::task::TaskBuilder;
green_start!(main)
fn main() {
// If we're the child, make sure we were invoked correctly
let args = os::args();
@ -28,11 +20,6 @@ fn main() {
}
test();
let (tx, rx) = channel();
TaskBuilder::new().native().spawn(proc() {
tx.send(test());
});
rx.recv();
}
fn test() {

View file

@ -8,28 +8,14 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(phase)]
#[phase(plugin)]
extern crate green;
extern crate native;
use native::NativeTaskBuilder;
use std::io::{process, Command};
use std::os;
use std::task::TaskBuilder;
green_start!(main)
fn main() {
let len = os::args().len();
if len == 1 {
test();
let (tx, rx) = channel();
TaskBuilder::new().native().spawn(proc() {
tx.send(test());
});
rx.recv();
} else {
assert_eq!(len, 3);
}

View file

@ -8,8 +8,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-windows
// ignore-android
// ignore-test
// FIXME: this test is being ignored until signals are implemented
// This test ensures that the 'detach' field on processes does the right thing.
// By detaching the child process, they should be put into a separate process
@ -19,19 +20,12 @@
// Note that the first thing we do is put ourselves in our own process group so
// we don't interfere with other running tests.
extern crate green;
extern crate rustuv;
extern crate libc;
use std::io::process;
use std::io::process::Command;
use std::io::signal::{Listener, Interrupt};
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}
fn main() {
unsafe { libc::setsid(); }

View file

@ -13,30 +13,14 @@
// quite quickly and it takes a few seconds for the sockets to get
// recycled.
#![feature(phase)]
#[phase(plugin)]
extern crate green;
extern crate native;
use std::io::{TcpListener, Listener, Acceptor, EndOfFile, TcpStream};
use std::sync::{atomic, Arc};
use std::task::TaskBuilder;
use native::NativeTaskBuilder;
static N: uint = 8;
static M: uint = 20;
green_start!(main)
fn main() {
test();
let (tx, rx) = channel();
TaskBuilder::new().native().spawn(proc() {
tx.send(test());
});
rx.recv();
}
fn test() {
@ -98,4 +82,3 @@ fn test() {
// Everything should have been accepted.
assert_eq!(cnt.load(atomic::SeqCst), N * M);
}

View file

@ -20,51 +20,23 @@
#![allow(experimental)]
#![reexport_test_harness_main = "test_main"]
extern crate native;
extern crate green;
extern crate rustuv;
#![allow(unused_imports)]
#[cfg(test)] #[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, test_main)
}
use std::io::*;
use std::io::net::tcp::*;
use std::io::test::*;
use std::io;
use std::time::Duration;
macro_rules! iotest (
{ fn $name:ident() $b:block $(#[$a:meta])* } => (
mod $name {
#![allow(unused_imports)]
use std::io::*;
use std::io::net::tcp::*;
use std::io::test::*;
use std::io;
use std::time::Duration;
fn f() $b
$(#[$a])* #[test] fn green() { f() }
$(#[$a])* #[test] fn native() {
use native;
let (tx, rx) = channel();
native::task::spawn(proc() { tx.send(f()) });
rx.recv();
}
}
)
)
iotest!(fn eventual_timeout() {
use native;
#[cfg_attr(target_os = "freebsd", ignore)]
fn eventual_timeout() {
let addr = next_test_ip4();
let host = addr.ip.to_string();
let port = addr.port;
// Use a native task to receive connections because it turns out libuv is
// really good at accepting connections and will likely run out of file
// descriptors before timing out.
let (tx1, rx1) = channel();
let (_tx2, rx2) = channel::<()>();
native::task::spawn(proc() {
std::task::spawn(proc() {
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
tx1.send(());
let _ = rx2.recv_opt();
@ -80,30 +52,29 @@ iotest!(fn eventual_timeout() {
}
}
fail!("never timed out!");
} #[cfg_attr(target_os = "freebsd", ignore)])
}
iotest!(fn timeout_success() {
fn timeout_success() {
let addr = next_test_ip4();
let host = addr.ip.to_string();
let port = addr.port;
let _l = TcpListener::bind(host.as_slice(), port).unwrap().listen();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_ok());
})
}
iotest!(fn timeout_error() {
fn timeout_error() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(1000)).is_err());
})
}
iotest!(fn connect_timeout_zero() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(0)).is_err());
})
iotest!(fn connect_timeout_negative() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(-1)).is_err());
})
fn connect_timeout_zero() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(0)).is_err());
}
fn connect_timeout_negative() {
let addr = next_test_ip4();
assert!(TcpStream::connect_timeout(addr, Duration::milliseconds(-1)).is_err());
}

View file

@ -16,8 +16,6 @@
#[phase(plugin, link)]
extern crate log;
extern crate libc;
extern crate green;
extern crate rustuv;
extern crate debug;
use std::io::net::tcp::{TcpListener, TcpStream};
@ -25,11 +23,6 @@ use std::io::{Acceptor, Listener};
use std::task::TaskBuilder;
use std::time::Duration;
#[start]
fn start(argc: int, argv: *const *const u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}
fn main() {
// This test has a chance to time out, try to not let it time out
spawn(proc() {