Skip to content

Commit 28d042e

Browse files
committed
auto merge of #8994 : alexcrichton/rust/upgrade-libuv, r=brson
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
2 parents d39cec6 + b4c36c2 commit 28d042e

17 files changed

+115
-147
lines changed

.gitmodules

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44
branch = master
55
[submodule "src/libuv"]
66
path = src/libuv
7-
url = https://github.com/brson/libuv.git
7+
url = https://github.com/alexcrichton/libuv.git
88
branch = master
9+
[submodule "src/gyp"]
10+
path = src/gyp
11+
url = https://git.chromium.org/external/gyp.git

mk/dist.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ PKG_ICO = $(S)src/etc/pkg/rust-logo.ico
1212
PKG_EXE = $(PKG_DIR)-install.exe
1313
endif
1414

15-
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm
15+
PKG_GITMODULES := $(S)src/libuv $(S)src/llvm $(S)src/gyp
1616

1717
PKG_FILES := \
1818
$(S)COPYRIGHT \

mk/rt.mk

+25-10
Original file line numberDiff line numberDiff line change
@@ -170,36 +170,51 @@ LIBUV_DEPS := $$(wildcard \
170170
$$(S)src/libuv/*/*/*/*)
171171
endif
172172

173+
LIBUV_MAKEFILE_$(1)_$(2) := $$(CFG_BUILD_DIR)$$(RT_BUILD_DIR_$(1)_$(2))/libuv/Makefile
174+
LIBUV_NO_LOAD = run-benchmarks.target.mk run-tests.target.mk \
175+
uv_dtrace_header.target.mk uv_dtrace_provider.target.mk
176+
177+
export PYTHONPATH := $(PYTHONPATH):$$(S)src/gyp/pylib
178+
179+
$$(LIBUV_MAKEFILE_$(1)_$(2)):
180+
(cd $(S)src/libuv/ && \
181+
./gyp_uv -f make -Dtarget_arch=$$(LIBUV_ARCH_$(1)) -D ninja \
182+
-Goutput_dir=$$(@D) --generator-output $$(@D))
183+
173184
# XXX: Shouldn't need platform-specific conditions here
174185
ifdef CFG_WINDOWSY_$(1)
175186
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
176-
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
177-
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
178-
OS=mingw \
187+
$$(Q)$$(MAKE) -C $$(S)src/libuv -f Makefile.mingw \
188+
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
189+
AR="$$(AR_$(1))" \
179190
V=$$(VERBOSE)
191+
$$(Q)cp $$(S)src/libuv/libuv.a $$@
180192
else ifeq ($(OSTYPE_$(1)), linux-androideabi)
181-
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
182-
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
193+
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
194+
$$(Q)$$(MAKE) -C $$(@D) \
183195
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
184196
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
185197
CC="$$(CC_$(1))" \
186198
CXX="$$(CXX_$(1))" \
187199
LINK="$$(CXX_$(1))" \
188200
AR="$$(AR_$(1))" \
189201
PLATFORM=android \
190-
BUILDTYPE=Release \
191-
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
192202
host=android OS=linux \
203+
builddir="." \
204+
BUILDTYPE=Release \
205+
NO_LOAD="$$(LIBUV_NO_LOAD)" \
193206
V=$$(VERBOSE)
194207
else
195-
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS)
196-
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
208+
$$(LIBUV_LIB_$(1)_$(2)): $$(LIBUV_DEPS) $$(LIBUV_MAKEFILE_$(1)_$(2))
209+
$$(Q)$$(MAKE) -C $$(@D) \
197210
CFLAGS="$$(CFG_GCCISH_CFLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
198211
LDFLAGS="$$(CFG_GCCISH_LINK_FLAGS) $$(LIBUV_FLAGS_$$(HOST_$(1)))" \
199212
CC="$$(CC_$(1))" \
200213
CXX="$$(CXX_$(1))" \
201214
AR="$$(AR_$(1))" \
202-
builddir_name="$$(CFG_BUILD_DIR)/$$(RT_BUILD_DIR_$(1)_$(2))/libuv" \
215+
builddir="." \
216+
BUILDTYPE=Release \
217+
NO_LOAD="$$(LIBUV_NO_LOAD)" \
203218
V=$$(VERBOSE)
204219
endif
205220

src/gyp

Submodule gyp added at f407f09

src/libstd/rt/io/net/tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ mod test {
182182
do run_in_newsched_task {
183183
let mut called = false;
184184
do io_error::cond.trap(|e| {
185-
assert!(e.kind == ConnectionRefused);
185+
assert_eq!(e.kind, ConnectionRefused);
186186
called = true;
187187
}).inside {
188188
let addr = SocketAddr { ip: Ipv4Addr(0, 0, 0, 0), port: 1 };

src/libstd/rt/uv/addrinfo.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use ptr::null;
1717
use rt::uv::uvll;
1818
use rt::uv::uvll::UV_GETADDRINFO;
1919
use rt::uv::{Loop, UvError, NativeHandle};
20-
use rt::uv::status_to_maybe_uv_error_with_loop;
20+
use rt::uv::status_to_maybe_uv_error;
2121
use rt::uv::net::UvAddrInfo;
2222

2323
type GetAddrInfoCallback = ~fn(GetAddrInfoRequest, &UvAddrInfo, Option<UvError>);
@@ -90,8 +90,7 @@ impl GetAddrInfoRequest {
9090
status: c_int,
9191
res: *uvll::addrinfo) {
9292
let mut req: GetAddrInfoRequest = NativeHandle::from_native_handle(req);
93-
let loop_ = req.get_loop();
94-
let err = status_to_maybe_uv_error_with_loop(loop_.native_handle(), status);
93+
let err = status_to_maybe_uv_error(status);
9594
let addrinfo = UvAddrInfo(res);
9695
let data = req.get_req_data();
9796
(*data.getaddrinfo_cb.get_ref())(req, &addrinfo, err);

src/libstd/rt/uv/async.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl AsyncWatcher {
3434

3535
extern fn async_cb(handle: *uvll::uv_async_t, status: c_int) {
3636
let mut watcher: AsyncWatcher = NativeHandle::from_native_handle(handle);
37-
let status = status_to_maybe_uv_error(watcher, status);
37+
let status = status_to_maybe_uv_error(status);
3838
let data = watcher.get_watcher_data();
3939
let cb = data.async_cb.get_ref();
4040
(*cb)(watcher, status);

src/libstd/rt/uv/file.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use prelude::*;
1212
use ptr::null;
1313
use libc::c_void;
1414
use rt::uv::{Request, NativeHandle, Loop, FsCallback, Buf,
15-
status_to_maybe_uv_error_with_loop, UvError};
15+
status_to_maybe_uv_error, UvError};
1616
use rt::uv::uvll;
1717
use rt::uv::uvll::*;
1818
use super::super::io::support::PathLike;
@@ -62,7 +62,7 @@ impl FsRequest {
6262
pub fn open_sync<P: PathLike>(loop_: &Loop, path: &P, flags: int, mode: int)
6363
-> Result<int, UvError> {
6464
let result = FsRequest::open_common(loop_, path, flags, mode, None);
65-
sync_cleanup(loop_, result)
65+
sync_cleanup(result)
6666
}
6767

6868
fn unlink_common<P: PathLike>(loop_: &Loop, path: &P, cb: Option<FsCallback>) -> int {
@@ -83,11 +83,11 @@ impl FsRequest {
8383
}
8484
pub fn unlink<P: PathLike>(loop_: &Loop, path: &P, cb: FsCallback) {
8585
let result = FsRequest::unlink_common(loop_, path, Some(cb));
86-
sync_cleanup(loop_, result);
86+
sync_cleanup(result);
8787
}
8888
pub fn unlink_sync<P: PathLike>(loop_: &Loop, path: &P) -> Result<int, UvError> {
8989
let result = FsRequest::unlink_common(loop_, path, None);
90-
sync_cleanup(loop_, result)
90+
sync_cleanup(result)
9191
}
9292

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

143-
fn sync_cleanup(loop_: &Loop, result: int)
143+
fn sync_cleanup(result: int)
144144
-> Result<int, UvError> {
145-
match status_to_maybe_uv_error_with_loop(loop_.native_handle(), result as i32) {
145+
match status_to_maybe_uv_error(result as i32) {
146146
Some(err) => Err(err),
147147
None => Ok(result)
148148
}
@@ -186,7 +186,7 @@ impl FileDescriptor {
186186
pub fn write_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
187187
-> Result<int, UvError> {
188188
let result = self.write_common(loop_, buf, offset, None);
189-
sync_cleanup(loop_, result)
189+
sync_cleanup(result)
190190
}
191191

192192
fn read_common(&mut self, loop_: &Loop, buf: Buf,
@@ -214,7 +214,7 @@ impl FileDescriptor {
214214
pub fn read_sync(&mut self, loop_: &Loop, buf: Buf, offset: i64)
215215
-> Result<int, UvError> {
216216
let result = self.read_common(loop_, buf, offset, None);
217-
sync_cleanup(loop_, result)
217+
sync_cleanup(result)
218218
}
219219

220220
fn close_common(self, loop_: &Loop, cb: Option<FsCallback>) -> int {
@@ -236,12 +236,11 @@ impl FileDescriptor {
236236
}
237237
pub fn close_sync(self, loop_: &Loop) -> Result<int, UvError> {
238238
let result = self.close_common(loop_, None);
239-
sync_cleanup(loop_, result)
239+
sync_cleanup(result)
240240
}
241241
}
242242
extern fn compl_cb(req: *uv_fs_t) {
243243
let mut req: FsRequest = NativeHandle::from_native_handle(req);
244-
let loop_ = req.get_loop();
245244
// pull the user cb out of the req data
246245
let cb = {
247246
let data = req.get_req_data();
@@ -252,8 +251,7 @@ extern fn compl_cb(req: *uv_fs_t) {
252251
// in uv_fs_open calls, the result will be the fd in the
253252
// case of success, otherwise it's -1 indicating an error
254253
let result = req.get_result();
255-
let status = status_to_maybe_uv_error_with_loop(
256-
loop_.native_handle(), result);
254+
let status = status_to_maybe_uv_error(result);
257255
// we have a req and status, call the user cb..
258256
// only giving the user a ref to the FsRequest, as we
259257
// have to clean it up, afterwards (and they aren't really

src/libstd/rt/uv/idle.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl IdleWatcher {
4343
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
4444
let data = idle_watcher.get_watcher_data();
4545
let cb: &IdleCallback = data.idle_cb.get_ref();
46-
let status = status_to_maybe_uv_error(idle_watcher, status);
46+
let status = status_to_maybe_uv_error(status);
4747
(*cb)(idle_watcher, status);
4848
}
4949
}
@@ -57,7 +57,7 @@ impl IdleWatcher {
5757
let mut idle_watcher: IdleWatcher = NativeHandle::from_native_handle(handle);
5858
let data = idle_watcher.get_watcher_data();
5959
let cb: &IdleCallback = data.idle_cb.get_ref();
60-
let status = status_to_maybe_uv_error(idle_watcher, status);
60+
let status = status_to_maybe_uv_error(status);
6161
(*cb)(idle_watcher, status);
6262
}
6363
}

src/libstd/rt/uv/mod.rs

+13-39
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,12 @@ impl<H, W: Watcher + NativeHandle<*H>> WatcherInterop for W {
204204
// XXX: Need to define the error constants like EOF so they can be
205205
// compared to the UvError type
206206

207-
pub struct UvError(uvll::uv_err_t);
207+
pub struct UvError(c_int);
208208

209209
impl UvError {
210210
pub fn name(&self) -> ~str {
211211
unsafe {
212-
let inner = match self { &UvError(ref a) => a };
212+
let inner = match self { &UvError(a) => a };
213213
let name_str = uvll::err_name(inner);
214214
assert!(name_str.is_not_null());
215215
from_c_str(name_str)
@@ -218,15 +218,15 @@ impl UvError {
218218

219219
pub fn desc(&self) -> ~str {
220220
unsafe {
221-
let inner = match self { &UvError(ref a) => a };
221+
let inner = match self { &UvError(a) => a };
222222
let desc_str = uvll::strerror(inner);
223223
assert!(desc_str.is_not_null());
224224
from_c_str(desc_str)
225225
}
226226
}
227227

228228
pub fn is_eof(&self) -> bool {
229-
self.code == uvll::EOF
229+
**self == uvll::EOF
230230
}
231231
}
232232

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

239239
#[test]
240240
fn error_smoke_test() {
241-
let err = uvll::uv_err_t { code: 1, sys_errno_: 1 };
242-
let err: UvError = UvError(err);
241+
let err: UvError = UvError(uvll::EOF);
243242
assert_eq!(err.to_str(), ~"EOF: end of file");
244243
}
245244
246-
pub fn last_uv_error<H, W: Watcher + NativeHandle<*H>>(watcher: &W) -> UvError {
247-
unsafe {
248-
let loop_ = watcher.event_loop();
249-
UvError(uvll::last_error(loop_.native_handle()))
250-
}
251-
}
252-
253245
pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
254246
unsafe {
255247
// Importing error constants
256248
use rt::uv::uvll::*;
257249
use rt::io::*;
258250
259251
// uv error descriptions are static
260-
let c_desc = uvll::strerror(&*uverr);
252+
let c_desc = uvll::strerror(*uverr);
261253
let desc = str::raw::c_str_to_static_slice(c_desc);
262254
263-
let kind = match uverr.code {
255+
let kind = match *uverr {
264256
UNKNOWN => OtherIoError,
265257
OK => OtherIoError,
266258
EOF => EndOfFile,
267259
EACCES => PermissionDenied,
268260
ECONNREFUSED => ConnectionRefused,
269261
ECONNRESET => ConnectionReset,
270262
EPIPE => BrokenPipe,
271-
_ => {
272-
rtdebug!("uverr.code %u", uverr.code as uint);
263+
err => {
264+
rtdebug!("uverr.code %d", err as int);
273265
// XXX: Need to map remaining uv error types
274266
OtherIoError
275267
}
@@ -284,30 +276,12 @@ pub fn uv_error_to_io_error(uverr: UvError) -> IoError {
284276
}
285277
286278
/// Given a uv handle, convert a callback status to a UvError
287-
pub fn status_to_maybe_uv_error_with_loop(
288-
loop_: *uvll::uv_loop_t,
289-
status: c_int) -> Option<UvError> {
290-
if status != -1 {
279+
pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
280+
{
281+
if status >= 0 {
291282
None
292283
} else {
293-
unsafe {
294-
rtdebug!("loop: %x", loop_ as uint);
295-
let err = uvll::last_error(loop_);
296-
Some(UvError(err))
297-
}
298-
}
299-
}
300-
/// Given a uv handle, convert a callback status to a UvError
301-
pub fn status_to_maybe_uv_error<T, U: Watcher + NativeHandle<*T>>(handle: U,
302-
status: c_int) -> Option<UvError> {
303-
if status != -1 {
304-
None
305-
} else {
306-
unsafe {
307-
rtdebug!("handle: %x", handle.native_handle() as uint);
308-
let loop_ = uvll::get_loop_for_uv_handle(handle.native_handle());
309-
status_to_maybe_uv_error_with_loop(loop_, status)
310-
}
284+
Some(UvError(status))
311285
}
312286
}
313287

0 commit comments

Comments
 (0)