Skip to content

Commit ab1dd09

Browse files
committed
rustc: Switch defaults from libgreen to libnative
The compiler will no longer inject libgreen as the default runtime for rust programs, this commit switches it over to libnative by default. Now that libnative has baked for some time, it is ready enough to start getting more serious usage as the default runtime for rustc generated binaries. We've found that there isn't really a correct decision in choosing a 1:1 or M:N runtime as a default for all applications, but it seems that a larger number of programs today would work more reasonable with a native default rather than a green default. With this commit come a number of bugfixes: * The main native task is now named "<main>" * The main native task has the stack bounds set up properly * #[no_uv] was renamed to #[no_start] * The core-run-destroy test was rewritten for both libnative and libgreen and one of the tests was modified to be more robust. * The process-detach test was locked to libgreen because it uses signal handling
1 parent 7b957a8 commit ab1dd09

File tree

15 files changed

+130
-84
lines changed

15 files changed

+130
-84
lines changed

src/compiletest/compiletest.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extern crate test;
1919
extern crate getopts;
2020
#[phase(link, syntax)]
2121
extern crate log;
22+
extern crate green;
23+
extern crate rustuv;
2224

2325
use std::os;
2426
use std::io;
@@ -41,6 +43,9 @@ pub mod runtest;
4143
pub mod common;
4244
pub mod errors;
4345

46+
#[start]
47+
fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, main) }
48+
4449
pub fn main() {
4550
let args = os::args();
4651
let config = parse_config(args.move_iter().collect());

src/driver/driver.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,19 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#[no_uv];
11+
#[no_uv]; // remove this after stage0
12+
#[allow(attribute_usage)]; // remove this after stage0
13+
extern crate native; // remove this after stage0
1214

1315
#[cfg(rustdoc)]
1416
extern crate this = "rustdoc";
1517

1618
#[cfg(rustc)]
1719
extern crate this = "rustc";
1820

19-
extern crate native;
21+
#[cfg(not(stage0))]
22+
fn main() { this::main() }
2023

24+
#[cfg(stage0)]
2125
#[start]
2226
fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, this::main) }

src/libgreen/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub mod stack;
209209
pub mod task;
210210

211211
#[lang = "start"]
212-
#[cfg(not(test))]
212+
#[cfg(not(test), stage0)]
213213
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
214214
use std::cast;
215215
start(argc, argv, proc() {

src/libnative/lib.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858

5959
use std::os;
6060
use std::rt;
61+
use std::str;
6162

6263
pub mod io;
6364
pub mod task;
@@ -68,6 +69,16 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 1 << 20;
6869
#[cfg(unix, not(android))]
6970
static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20);
7071

72+
#[lang = "start"]
73+
#[cfg(not(test), not(stage0))]
74+
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
75+
use std::cast;
76+
start(argc, argv, proc() {
77+
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
78+
main();
79+
})
80+
}
81+
7182
/// Executes the given procedure after initializing the runtime with the given
7283
/// argc/argv.
7384
///
@@ -90,7 +101,12 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
90101
rt::init(argc, argv);
91102
let mut exit_code = None;
92103
let mut main = Some(main);
93-
let t = task::new((my_stack_bottom, my_stack_top)).run(|| {
104+
let mut task = task::new((my_stack_bottom, my_stack_top));
105+
task.name = Some(str::Slice("<main>"));
106+
let t = task.run(|| {
107+
unsafe {
108+
rt::stack::record_stack_bounds(my_stack_bottom, my_stack_top);
109+
}
94110
exit_code = Some(run(main.take_unwrap()));
95111
});
96112
drop(t);

src/librustc/front/std_inject.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ fn use_std(krate: &ast::Crate) -> bool {
4646
!attr::contains_name(krate.attrs.as_slice(), "no_std")
4747
}
4848

49-
fn use_uv(krate: &ast::Crate) -> bool {
50-
!attr::contains_name(krate.attrs.as_slice(), "no_uv")
49+
fn use_start(krate: &ast::Crate) -> bool {
50+
!attr::contains_name(krate.attrs.as_slice(), "no_start")
5151
}
5252

5353
fn no_prelude(attrs: &[ast::Attribute]) -> bool {
@@ -87,18 +87,10 @@ impl<'a> fold::Folder for StandardLibraryInjector<'a> {
8787
span: DUMMY_SP
8888
});
8989

90-
if use_uv(&krate) && !self.sess.building_library.get() {
90+
if use_start(&krate) && !self.sess.building_library.get() {
9191
vis.push(ast::ViewItem {
92-
node: ast::ViewItemExternCrate(token::str_to_ident("green"),
93-
with_version("green"),
94-
ast::DUMMY_NODE_ID),
95-
attrs: Vec::new(),
96-
vis: ast::Inherited,
97-
span: DUMMY_SP
98-
});
99-
vis.push(ast::ViewItem {
100-
node: ast::ViewItemExternCrate(token::str_to_ident("rustuv"),
101-
with_version("rustuv"),
92+
node: ast::ViewItemExternCrate(token::str_to_ident("native"),
93+
with_version("native"),
10294
ast::DUMMY_NODE_ID),
10395
attrs: Vec::new(),
10496
vis: ast::Inherited,

src/librustc/middle/lint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ fn check_heap_item(cx: &Context, it: &ast::Item) {
961961
}
962962

963963
static crate_attrs: &'static [&'static str] = &[
964-
"crate_type", "feature", "no_uv", "no_main", "no_std", "crate_id",
964+
"crate_type", "feature", "no_start", "no_main", "no_std", "crate_id",
965965
"desc", "comment", "license", "copyright", // not used in rustc now
966966
];
967967

src/librustuv/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ via `close` and `delete` methods.
4545
#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0
4646

4747
#[cfg(test)] extern crate green;
48+
#[cfg(test)] extern crate realrustuv = "rustuv";
4849

4950
use std::cast;
5051
use std::fmt;
@@ -69,6 +70,16 @@ pub use self::signal::SignalWatcher;
6970
pub use self::timer::TimerWatcher;
7071
pub use self::tty::TtyWatcher;
7172

73+
// Run tests with libgreen instead of libnative.
74+
//
75+
// FIXME: This egregiously hacks around starting the test runner in a different
76+
// threading mode than the default by reaching into the auto-generated
77+
// '__test' module.
78+
#[cfg(test)] #[start]
79+
fn start(argc: int, argv: **u8) -> int {
80+
green::start(argc, argv, __test::main)
81+
}
82+
7283
mod macros;
7384

7485
mod access;

src/libstd/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
#[cfg(stage0)]
8282
pub use vec_ng = vec;
8383

84+
// Run tests with libgreen instead of libnative.
85+
//
86+
// FIXME: This egregiously hacks around starting the test runner in a different
87+
// threading mode than the default by reaching into the auto-generated
88+
// '__test' module.
89+
#[cfg(test)] #[start]
90+
fn start(argc: int, argv: **u8) -> int {
91+
green::start(argc, argv, __test::main)
92+
}
93+
8494
pub mod macros;
8595

8696
mod rtdeps;

src/test/run-fail/native-failure.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// ignore-android (FIXME #11419)
1212
// error-pattern:explicit failure
1313

14-
#[no_uv];
15-
1614
extern crate native;
1715

1816
#[start]

src/test/run-make/bootstrap-from-c-with-green/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#[crate_id="boot#0.1"];
1212
#[crate_type="dylib"];
13-
#[no_uv];
1413

1514
extern crate rustuv;
1615
extern crate green;

src/test/run-make/bootstrap-from-c-with-native/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
#[crate_id="boot#0.1"];
1212
#[crate_type="dylib"];
13-
#[no_uv];
1413

1514
extern crate native;
1615

src/test/run-pass/capturing-logging.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414

1515
#[feature(phase)];
1616

17-
#[no_uv];
18-
extern crate native;
1917
#[phase(syntax, link)]
2018
extern crate log;
19+
extern crate native;
2120

2221
use std::fmt;
2322
use std::io::{ChanReader, ChanWriter};

src/test/run-pass/core-run-destroy.rs

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,50 @@
99
// except according to those terms.
1010

1111
// ignore-fast
12+
// ignore-pretty
1213
// compile-flags:--test
1314

1415
// NB: These tests kill child processes. Valgrind sees these children as leaking
1516
// memory, which makes for some *confusing* logs. That's why these are here
1617
// instead of in std.
1718

18-
use std::io::timer;
19-
use std::libc;
20-
use std::str;
21-
use std::io::process::{Process, ProcessOutput};
19+
#[feature(macro_rules)];
2220

23-
#[test]
24-
fn test_destroy_once() {
21+
extern crate native;
22+
extern crate green;
23+
extern crate rustuv;
24+
25+
macro_rules! iotest (
26+
{ fn $name:ident() $b:block $($a:attr)* } => (
27+
mod $name {
28+
#[allow(unused_imports)];
29+
30+
use std::io::timer;
31+
use std::libc;
32+
use std::str;
33+
use std::io::process::{Process, ProcessOutput};
34+
use native;
35+
use super::*;
36+
37+
fn f() $b
38+
39+
$($a)* #[test] fn green() { f() }
40+
$($a)* #[test] fn native() {
41+
use native;
42+
let (tx, rx) = channel();
43+
native::task::spawn(proc() { tx.send(f()) });
44+
rx.recv();
45+
}
46+
}
47+
)
48+
)
49+
50+
#[cfg(test)] #[start]
51+
fn start(argc: int, argv: **u8) -> int {
52+
green::start(argc, argv, __test::main)
53+
}
54+
55+
iotest!(fn test_destroy_once() {
2556
#[cfg(not(target_os="android"))]
2657
static mut PROG: &'static str = "echo";
2758

@@ -30,10 +61,9 @@ fn test_destroy_once() {
3061

3162
let mut p = unsafe {Process::new(PROG, []).unwrap()};
3263
p.signal_exit().unwrap(); // this shouldn't crash (and nor should the destructor)
33-
}
64+
})
3465

35-
#[test]
36-
fn test_destroy_twice() {
66+
iotest!(fn test_destroy_twice() {
3767
#[cfg(not(target_os="android"))]
3868
static mut PROG: &'static str = "echo";
3969
#[cfg(target_os="android")]
@@ -45,75 +75,54 @@ fn test_destroy_twice() {
4575
};
4676
p.signal_exit().unwrap(); // this shouldnt crash...
4777
p.signal_exit().unwrap(); // ...and nor should this (and nor should the destructor)
48-
}
78+
})
4979

50-
fn test_destroy_actually_kills(force: bool) {
80+
pub fn test_destroy_actually_kills(force: bool) {
81+
use std::io::process::{Process, ProcessOutput, ExitStatus, ExitSignal};
82+
use std::io::timer;
83+
use std::libc;
84+
use std::str;
5185

5286
#[cfg(unix,not(target_os="android"))]
53-
static mut BLOCK_COMMAND: &'static str = "cat";
87+
static BLOCK_COMMAND: &'static str = "cat";
5488

5589
#[cfg(unix,target_os="android")]
56-
static mut BLOCK_COMMAND: &'static str = "/system/bin/cat";
90+
static BLOCK_COMMAND: &'static str = "/system/bin/cat";
5791

5892
#[cfg(windows)]
59-
static mut BLOCK_COMMAND: &'static str = "cmd";
60-
61-
#[cfg(unix,not(target_os="android"))]
62-
fn process_exists(pid: libc::pid_t) -> bool {
63-
let ProcessOutput {output, ..} = Process::output("ps", [~"-p", pid.to_str()])
64-
.unwrap();
65-
str::from_utf8_owned(output).unwrap().contains(pid.to_str())
66-
}
67-
68-
#[cfg(unix,target_os="android")]
69-
fn process_exists(pid: libc::pid_t) -> bool {
70-
let ProcessOutput {output, ..} = Process::output("/system/bin/ps", [pid.to_str()])
71-
.unwrap();
72-
str::from_utf8_owned(output).unwrap().contains(~"root")
73-
}
74-
75-
#[cfg(windows)]
76-
fn process_exists(pid: libc::pid_t) -> bool {
77-
use std::libc::types::os::arch::extra::DWORD;
78-
use std::libc::funcs::extra::kernel32::{CloseHandle, GetExitCodeProcess, OpenProcess};
79-
use std::libc::consts::os::extra::{FALSE, PROCESS_QUERY_INFORMATION, STILL_ACTIVE };
80-
81-
unsafe {
82-
let process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, pid as DWORD);
83-
if process.is_null() {
84-
return false;
85-
}
86-
// process will be non-null if the process is alive, or if it died recently
87-
let mut status = 0;
88-
GetExitCodeProcess(process, &mut status);
89-
CloseHandle(process);
90-
return status == STILL_ACTIVE;
91-
}
92-
}
93+
static BLOCK_COMMAND: &'static str = "cmd";
9394

9495
// this process will stay alive indefinitely trying to read from stdin
95-
let mut p = unsafe {Process::new(BLOCK_COMMAND, []).unwrap()};
96+
let mut p = Process::new(BLOCK_COMMAND, []).unwrap();
9697

97-
assert!(process_exists(p.id()));
98+
assert!(p.signal(0).is_ok());
9899

99100
if force {
100101
p.signal_kill().unwrap();
101102
} else {
102103
p.signal_exit().unwrap();
103104
}
104105

105-
if process_exists(p.id()) {
106-
timer::sleep(500);
107-
assert!(!process_exists(p.id()));
106+
// Don't let this test time out, this should be quick
107+
let (tx, rx1) = channel();
108+
let mut t = timer::Timer::new().unwrap();
109+
let rx2 = t.oneshot(1000);
110+
spawn(proc() {
111+
select! {
112+
() = rx2.recv() => unsafe { libc::exit(1) },
113+
() = rx1.recv() => {}
114+
}
115+
});
116+
match p.wait() {
117+
ExitStatus(..) => fail!("expected a signal"),
118+
ExitSignal(..) => tx.send(()),
108119
}
109120
}
110121

111-
#[test]
112-
fn test_unforced_destroy_actually_kills() {
122+
iotest!(fn test_unforced_destroy_actually_kills() {
113123
test_destroy_actually_kills(false);
114-
}
124+
})
115125

116-
#[test]
117-
fn test_forced_destroy_actually_kills() {
126+
iotest!(fn test_forced_destroy_actually_kills() {
118127
test_destroy_actually_kills(true);
119-
}
128+
})

src/test/run-pass/native-print-no-runtime.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// ignore-fast
1212

13-
#[no_uv];
14-
1513
#[start]
1614
pub fn main(_: int, _: **u8) -> int {
1715
println!("hello");

0 commit comments

Comments
 (0)