Move rust's uv implementation to its own crate
There are a few reasons that this is a desirable move to take: 1. Proof of concept that a third party event loop is possible 2. Clear separation of responsibility between rt::io and the uv-backend 3. Enforce in the future that the event loop is "pluggable" and replacable Here's a quick summary of the points of this pull request which make this possible: * Two new lang items were introduced: event_loop, and event_loop_factory. The idea of a "factory" is to define a function which can be called with no arguments and will return the new event loop as a trait object. This factory is emitted to the crate map when building an executable. The factory doesn't have to exist, and when it doesn't then an empty slot is in the crate map and a basic event loop with no I/O support is provided to the runtime. * When building an executable, then the rustuv crate will be linked by default (providing a default implementation of the event loop) via a similar method to injecting a dependency on libstd. This is currently the only location where the rustuv crate is ever linked. * There is a new #[no_uv] attribute (implied by #[no_std]) which denies implicitly linking to rustuv by default Closes #5019
This commit is contained in:
parent
5dd1583c57
commit
201cab84e8
34 changed files with 7104 additions and 160 deletions
|
@ -35,6 +35,10 @@ fn use_std(crate: &ast::Crate) -> bool {
|
|||
!attr::contains_name(crate.attrs, "no_std")
|
||||
}
|
||||
|
||||
fn use_uv(crate: &ast::Crate) -> bool {
|
||||
!attr::contains_name(crate.attrs, "no_uv")
|
||||
}
|
||||
|
||||
fn no_prelude(attrs: &[ast::Attribute]) -> bool {
|
||||
attr::contains_name(attrs, "no_implicit_prelude")
|
||||
}
|
||||
|
@ -53,19 +57,30 @@ struct StandardLibraryInjector {
|
|||
impl fold::ast_fold for StandardLibraryInjector {
|
||||
fn fold_crate(&self, crate: ast::Crate) -> ast::Crate {
|
||||
let version = STD_VERSION.to_managed();
|
||||
let vi1 = ast::view_item {
|
||||
let vers_item = attr::mk_name_value_item_str(@"vers", version);
|
||||
let mut vis = ~[ast::view_item {
|
||||
node: ast::view_item_extern_mod(self.sess.ident_of("std"),
|
||||
None,
|
||||
~[],
|
||||
~[vers_item.clone()],
|
||||
ast::DUMMY_NODE_ID),
|
||||
attrs: ~[
|
||||
attr::mk_attr(attr::mk_name_value_item_str(@"vers", version))
|
||||
],
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: dummy_sp()
|
||||
};
|
||||
}];
|
||||
|
||||
let vis = vec::append(~[vi1], crate.module.view_items);
|
||||
if use_uv(&crate) && !*self.sess.building_library {
|
||||
vis.push(ast::view_item {
|
||||
node: ast::view_item_extern_mod(self.sess.ident_of("rustuv"),
|
||||
None,
|
||||
~[vers_item],
|
||||
ast::DUMMY_NODE_ID),
|
||||
attrs: ~[],
|
||||
vis: ast::private,
|
||||
span: dummy_sp()
|
||||
});
|
||||
}
|
||||
|
||||
vis.push_all(crate.module.view_items);
|
||||
let mut new_module = ast::_mod {
|
||||
view_items: vis,
|
||||
..crate.module.clone()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue