Skip to content

Commit

Permalink
auto merge of #8994 : alexcrichton/rust/upgrade-libuv, r=brson
Browse files Browse the repository at this point in the history
This is a reopening of the libuv-upgrade part of #8645. Hopefully this won't
cause random segfaults all over the place. The windows regression in testing
should also be fixed (it shouldn't build the whole compiler twice).

A notable difference from before is that gyp is now a git submodule instead of
always git-cloned at make time. This allows bundling for releases more easily.

Closes #8850
  • Loading branch information
bors committed Sep 6, 2013
2 parents d39cec6 + b4c36c2 commit 28d042e
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 147 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
branch = master
[submodule "src/libuv"]
path = src/libuv
url = https://github.com/brson/libuv.git
url = https://github.com/alexcrichton/libuv.git
branch = master
[submodule "src/gyp"]
path = src/gyp
url = https://git.chromium.org/external/gyp.git
2 changes: 1 addition & 1 deletion mk/dist.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ PKG_ICO = $(S)src/etc/pkg/rust-logo.ico
PKG_EXE = $(PKG_DIR)-install.exe
endif

PKG_GITMODULES := $(S)src/libuv $(S)src/llvm
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp

PKG_FILES := \
$(S)COPYRIGHT \
Expand Down
35 changes: 25 additions & 10 deletions mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -170,36 +170,51 @@ LIBUV_DEPS := $$(wildcard \
$$(S)src/libuv/*/*/*/*)
endif

LIBUV_MAKEFILE_$(1)_$(2) := $$(CFG_BUILD_DIR)$$(RT_BUILD_DIR_$(1)_$(2))/libuv/Makefile
LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
uv_dtrace_header.target.mk uv_dtrace_provider.target.mk

export PYTHONPATH := $(PYTHONPATH):$$(S)src/gyp/pylib

$$(LIBUV_MAKEFILE_$(1)_$(2)):
(cd $(S)src/libuv/ && \
./gyp_uv -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) -D ninja \
-Goutput_dir=$$(@D) --generator-output $$(@D))

# XXX: Shouldn't need platform-specific conditions here
ifdef CFG_WINDOWSY_$(1)
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
OS=mingw \
$$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
AR="$$(AR_$(1))" \
V=$$(VERBOSE)
$$(Q)cp $$(S)src/libuv/libuv.a $$@
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
$$(Q)$$(MAKE) -C $$(@D) \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
CC="$$(CC_$(1))" \
CXX="$$(CXX_$(1))" \
LINK="$$(CXX_$(1))" \
AR="$$(AR_$(1))" \
PLATFORM=android \
BUILDTYPE=Release \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
host=android OS=linux \
builddir="." \
BUILDTYPE=Release \
NO_LOAD="$$(LIBUV_NO_LOAD)" \
V=$$(VERBOSE)
else
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
$$(Q)$$(MAKE) -C $$(@D) \
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
CC="$$(CC_$(1))" \
CXX="$$(CXX_$(1))" \
AR="$$(AR_$(1))" \
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
builddir="." \
BUILDTYPE=Release \
NO_LOAD="$$(LIBUV_NO_LOAD)" \
V=$$(VERBOSE)
endif

Expand Down
1 change: 1 addition & 0 deletions src/gyp
Submodule gyp added at f407f0
2 changes: 1 addition & 1 deletion src/libstd/rt/io/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ mod test {
do run_in_newsched_task {
let mut called = false;
do io_error::cond.trap(|e| {
assert!(e.kind == ConnectionRefused);
assert_eq!(e.kind, ConnectionRefused);
called = true;
}).inside {
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };
Expand Down
5 changes: 2 additions & 3 deletions src/libstd/rt/uv/addrinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use ptr::null;
use rt::uv::uvll;
use rt::uv::uvll::UV_GETADDRINFO;
use rt::uv::{Loop, UvError, NativeHandle};
use rt::uv::status_to_maybe_uv_error_with_loop;
use rt::uv::status_to_maybe_uv_error;
use rt::uv::net::UvAddrInfo;

type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &UvAddrInfo, Option<UvError>);
Expand Down Expand Up @@ -90,8 +90,7 @@ impl GetAddrInfoRequest {
status: c_int,
res: *uvll::addrinfo) {
let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req);
let loop_ = req.get_loop();
let err = status_to_maybe_uv_error_with_loop(loop_.native_handle(), status);
let err = status_to_maybe_uv_error(status);
let addrinfo = UvAddrInfo(res);
let data = req.get_req_data();
(*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/rt/uv/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl AsyncWatcher {

extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
let status = status_to_maybe_uv_error(watcher, status);
let status = status_to_maybe_uv_error(status);
let data = watcher.get_watcher_data();
let cb = data.async_cb.get_ref();
(*cb)(watcher, status);
Expand Down
22 changes: 10 additions & 12 deletions src/libstd/rt/uv/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use prelude::*;
use ptr::null;
use libc::c_void;
use rt::uv::{Request, NativeHandle, Loop, FsCallback, Buf,
status_to_maybe_uv_error_with_loop, UvError};
status_to_maybe_uv_error, UvError};
use rt::uv::uvll;
use rt::uv::uvll::*;
use super::super::io::support::PathLike;
Expand Down Expand Up @@ -62,7 +62,7 @@ impl FsRequest {
pub fn open_sync<P: PathLike>(loop_: &Loop, path: &P, flags: int, mode: int)
-> Result<int, UvError> {
let result = FsRequest::open_common(loop_, path, flags, mode, None);
sync_cleanup(loop_, result)
sync_cleanup(result)
}

fn unlink_common<P: PathLike>(loop_: &Loop, path: &P, cb: Option<FsCallback>) -> int {
Expand All @@ -83,11 +83,11 @@ impl FsRequest {
}
pub fn unlink<P: PathLike>(loop_: &Loop, path: &P, cb: FsCallback) {
let result = FsRequest::unlink_common(loop_, path, Some(cb));
sync_cleanup(loop_, result);
sync_cleanup(result);
}
pub fn unlink_sync<P: PathLike>(loop_: &Loop, path: &P) -> Result<int, UvError> {
let result = FsRequest::unlink_common(loop_, path, None);
sync_cleanup(loop_, result)
sync_cleanup(result)
}

pub fn install_req_data(&self, cb: Option<FsCallback>) {
Expand Down Expand Up @@ -140,9 +140,9 @@ impl NativeHandle<*uvll::uv_fs_t> for FsRequest {
}
}

fn sync_cleanup(loop_: &Loop, result: int)
fn sync_cleanup(result: int)
-> Result<int, UvError> {
match status_to_maybe_uv_error_with_loop(loop_.native_handle(), result as i32) {
match status_to_maybe_uv_error(result as i32) {
Some(err) => Err(err),
None => Ok(result)
}
Expand Down Expand Up @@ -186,7 +186,7 @@ impl FileDescriptor {
pub fn write_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
-> Result<int, UvError> {
let result = self.write_common(loop_, buf, offset, None);
sync_cleanup(loop_, result)
sync_cleanup(result)
}

fn read_common(&mut self, loop_: &Loop, buf: Buf,
Expand Down Expand Up @@ -214,7 +214,7 @@ impl FileDescriptor {
pub fn read_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
-> Result<int, UvError> {
let result = self.read_common(loop_, buf, offset, None);
sync_cleanup(loop_, result)
sync_cleanup(result)
}

fn close_common(self, loop_: &Loop, cb: Option<FsCallback>) -> int {
Expand All @@ -236,12 +236,11 @@ impl FileDescriptor {
}
pub fn close_sync(self, loop_: &Loop) -> Result<int, UvError> {
let result = self.close_common(loop_, None);
sync_cleanup(loop_, result)
sync_cleanup(result)
}
}
extern fn compl_cb(req: *uv_fs_t) {
let mut req: FsRequest = NativeHandle::from_native_handle(req);
let loop_ = req.get_loop();
// pull the user cb out of the req data
let cb = {
let data = req.get_req_data();
Expand All @@ -252,8 +251,7 @@ extern fn compl_cb(req: *uv_fs_t) {
// in uv_fs_open calls, the result will be the fd in the
// case of success, otherwise it's -1 indicating an error
let result = req.get_result();
let status = status_to_maybe_uv_error_with_loop(
loop_.native_handle(), result);
let status = status_to_maybe_uv_error(result);
// we have a req and status, call the user cb..
// only giving the user a ref to the FsRequest, as we
// have to clean it up, afterwards (and they aren't really
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/rt/uv/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl IdleWatcher {
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
let data = idle_watcher.get_watcher_data();
let cb: &IdleCallback = data.idle_cb.get_ref();
let status = status_to_maybe_uv_error(idle_watcher, status);
let status = status_to_maybe_uv_error(status);
(*cb)(idle_watcher, status);
}
}
Expand All @@ -57,7 +57,7 @@ impl IdleWatcher {
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
let data = idle_watcher.get_watcher_data();
let cb: &IdleCallback = data.idle_cb.get_ref();
let status = status_to_maybe_uv_error(idle_watcher, status);
let status = status_to_maybe_uv_error(status);
(*cb)(idle_watcher, status);
}
}
Expand Down
52 changes: 13 additions & 39 deletions src/libstd/rt/uv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
// XXX: Need to define the error constants like EOF so they can be
// compared to the UvError type

pub struct UvError(uvll::uv_err_t);
pub struct UvError(c_int);

impl UvError {
pub fn name(&self) -> ~str {
unsafe {
let inner = match self { &UvError(ref a) => a };
let inner = match self { &UvError(a) => a };
let name_str = uvll::err_name(inner);
assert!(name_str.is_not_null());
from_c_str(name_str)
Expand All @@ -218,15 +218,15 @@ impl UvError {

pub fn desc(&self) -> ~str {
unsafe {
let inner = match self { &UvError(ref a) => a };
let inner = match self { &UvError(a) => a };
let desc_str = uvll::strerror(inner);
assert!(desc_str.is_not_null());
from_c_str(desc_str)
}
}

pub fn is_eof(&self) -> bool {
self.code == uvll::EOF
**self == uvll::EOF
}
}

Expand All @@ -238,38 +238,30 @@ impl ToStr for UvError {

#[test]
fn error_smoke_test() {
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
let err: UvError = UvError(err);
let err: UvError = UvError(uvll::EOF);
assert_eq!(err.to_str(), ~"EOF: end of file");
}

pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
unsafe {
let loop_ = watcher.event_loop();
UvError(uvll::last_error(loop_.native_handle()))
}
}

pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
unsafe {
// Importing error constants
use rt::uv::uvll::*;
use rt::io::*;

// uv error descriptions are static
let c_desc = uvll::strerror(&*uverr);
let c_desc = uvll::strerror(*uverr);
let desc = str::raw::c_str_to_static_slice(c_desc);

let kind = match uverr.code {
let kind = match *uverr {
UNKNOWN => OtherIoError,
OK => OtherIoError,
EOF => EndOfFile,
EACCES => PermissionDenied,
ECONNREFUSED => ConnectionRefused,
ECONNRESET => ConnectionReset,
EPIPE => BrokenPipe,
_ => {
rtdebug!("uverr.code %u", uverr.code as uint);
err => {
rtdebug!("uverr.code %d", err as int);
// XXX: Need to map remaining uv error types
OtherIoError
}
Expand All @@ -284,30 +276,12 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
}

/// Given a uv handle, convert a callback status to a UvError
pub fn status_to_maybe_uv_error_with_loop(
loop_: *uvll::uv_loop_t,
status: c_int) -> Option<UvError> {
if status != -1 {
pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
{
if status >= 0 {
None
} else {
unsafe {
rtdebug!("loop: %x", loop_ as uint);
let err = uvll::last_error(loop_);
Some(UvError(err))
}
}
}
/// Given a uv handle, convert a callback status to a UvError
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
status: c_int) -> Option<UvError> {
if status != -1 {
None
} else {
unsafe {
rtdebug!("handle: %x", handle.native_handle() as uint);
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
status_to_maybe_uv_error_with_loop(loop_, status)
}
Some(UvError(status))
}
}

Expand Down
Loading

0 comments on commit 28d042e

Please sign in to comment.