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;

0 commit comments

Comments
 (0)