diff options
author | Brad King <brad.king@kitware.com> | 2017-09-13 18:33:38 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2017-09-17 15:10:18 (GMT) |
commit | 714ce728828c267da9a5c0d9f2e48eb5f88a8336 (patch) | |
tree | 6b7857ad6dddef5f691ebb609c1d43e695e21d58 /Utilities | |
parent | 6a2d967de07a52f0460089999349e31741b402f8 (diff) | |
download | CMake-714ce728828c267da9a5c0d9f2e48eb5f88a8336.zip CMake-714ce728828c267da9a5c0d9f2e48eb5f88a8336.tar.gz CMake-714ce728828c267da9a5c0d9f2e48eb5f88a8336.tar.bz2 |
bootstrap: Make libuv available during bootstrap
On UNIX, build only the parts of libuv we need for the filesystem,
process, and poll abstractions using the POSIX poll() backend. This
avoids many platform-specific conditions. On Windows, build all of
libuv; there are no conditional alternatives anyway.
Diffstat (limited to 'Utilities')
-rw-r--r-- | Utilities/cmlibuv/include/uv-unix.h | 16 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/cmake-bootstrap.c | 139 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/fs.c | 2 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/internal.h | 14 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/pipe.c | 2 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/posix-hrtime.c | 25 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/unix/stream.c | 10 | ||||
-rw-r--r-- | Utilities/cmlibuv/src/uv-common.c | 2 |
8 files changed, 200 insertions, 10 deletions
diff --git a/Utilities/cmlibuv/include/uv-unix.h b/Utilities/cmlibuv/include/uv-unix.h index d775450..ff59bcb 100644 --- a/Utilities/cmlibuv/include/uv-unix.h +++ b/Utilities/cmlibuv/include/uv-unix.h @@ -44,7 +44,9 @@ #include "uv-threadpool.h" -#if defined(__linux__) +#ifdef CMAKE_BOOTSTRAP +# include "uv-posix.h" +#elif defined(__linux__) # include "uv-linux.h" #elif defined (__MVS__) # include "uv-os390.h" @@ -124,6 +126,17 @@ typedef int uv_file; typedef int uv_os_sock_t; typedef int uv_os_fd_t; +#ifdef CMAKE_BOOTSTRAP +#define UV_ONCE_INIT 0 +typedef int uv_once_t; +typedef int uv_thread_t; +typedef int uv_mutex_t; +typedef int uv_rwlock_t; +typedef int uv_sem_t; +typedef int uv_cond_t; +typedef int uv_key_t; +typedef int uv_barrier_t; +#else #define UV_ONCE_INIT PTHREAD_ONCE_INIT typedef pthread_once_t uv_once_t; @@ -134,6 +147,7 @@ typedef UV_PLATFORM_SEM_T uv_sem_t; typedef pthread_cond_t uv_cond_t; typedef pthread_key_t uv_key_t; typedef pthread_barrier_t uv_barrier_t; +#endif /* Platform-specific definitions for uv_spawn support. */ diff --git a/Utilities/cmlibuv/src/unix/cmake-bootstrap.c b/Utilities/cmlibuv/src/unix/cmake-bootstrap.c new file mode 100644 index 0000000..4f32d03 --- /dev/null +++ b/Utilities/cmlibuv/src/unix/cmake-bootstrap.c @@ -0,0 +1,139 @@ +#include "uv.h" +#include "internal.h" + +int uv__tcp_nodelay(int fd, int on) { + errno = EINVAL; + return -1; +} + +int uv__tcp_keepalive(int fd, int on, unsigned int delay) { + errno = EINVAL; + return -1; +} + +int uv_tcp_listen(uv_tcp_t* tcp, int backlog, uv_connection_cb cb) { + return -EINVAL; +} + +int uv_udp_open(uv_udp_t* handle, uv_os_sock_t sock) { + return -EINVAL; +} + +void uv__tcp_close(uv_tcp_t* handle) { +} + +void uv__udp_close(uv_udp_t* handle) { +} + +void uv__udp_finish_close(uv_udp_t* handle) { +} + +void uv__fs_poll_close(uv_fs_poll_t* handle) { +} + +int uv_async_init(uv_loop_t* loop, uv_async_t* handle, uv_async_cb async_cb) { + return 0; +} + +void uv__async_close(uv_async_t* handle) { +} + +int uv__async_fork(uv_loop_t* loop) { + return 0; +} + +void uv__async_stop(uv_loop_t* loop) { +} + +void uv__work_submit(uv_loop_t* loop, struct uv__work* w, + void (*work)(struct uv__work* w), + void (*done)(struct uv__work* w, int status)) { + abort(); +} + +void uv__work_done(uv_async_t* handle) { +} + +int uv__pthread_atfork(void (*prepare)(void), void (*parent)(void), + void (*child)(void)) { + return 0; +} + +int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset) { + return 0; +} + +int uv_mutex_init(uv_mutex_t* mutex) { + return 0; +} + +void uv_mutex_destroy(uv_mutex_t* mutex) { +} + +void uv_mutex_lock(uv_mutex_t* mutex) { +} + +void uv_mutex_unlock(uv_mutex_t* mutex) { +} + +int uv_rwlock_init(uv_rwlock_t* rwlock) { + return 0; +} + +void uv_rwlock_destroy(uv_rwlock_t* rwlock) { +} + +void uv_rwlock_wrlock(uv_rwlock_t* rwlock) { +} + +void uv_rwlock_wrunlock(uv_rwlock_t* rwlock) { +} + +void uv_rwlock_rdlock(uv_rwlock_t* rwlock) { +} + +void uv_rwlock_rdunlock(uv_rwlock_t* rwlock) { +} + +void uv_once(uv_once_t* guard, void (*callback)(void)) { + if (*guard) { + return; + } + *guard = 1; + callback(); +} + +#if defined(__linux__) +int uv__accept4(int fd, struct sockaddr* addr, socklen_t* addrlen, int flags) { + errno = ENOSYS; + return -1; +} + +int uv__dup3(int oldfd, int newfd, int flags) { + errno = ENOSYS; + return -1; +} + +int uv__pipe2(int pipefd[2], int flags) { + errno = ENOSYS; + return -1; +} + +ssize_t uv__preadv(int fd, const struct iovec *iov, int iovcnt, + int64_t offset) { + errno = ENOSYS; + return -1; +} + +ssize_t uv__pwritev(int fd, const struct iovec *iov, int iovcnt, + int64_t offset) { + errno = ENOSYS; + return -1; +} + +int uv__utimesat(int dirfd, const char* path, const struct timespec times[2], + int flags) { + errno = ENOSYS; + return -1; +} +#endif diff --git a/Utilities/cmlibuv/src/unix/fs.c b/Utilities/cmlibuv/src/unix/fs.c index 8a4ba7a..82c91ef 100644 --- a/Utilities/cmlibuv/src/unix/fs.c +++ b/Utilities/cmlibuv/src/unix/fs.c @@ -244,7 +244,7 @@ skip: #endif } -#if defined(__sun) && _XOPEN_SOURCE < 600 +#if defined(__sun) && (_XOPEN_SOURCE < 600 || defined(CMAKE_BOOTSTRAP)) static char* uv__mkdtemp(char *template) { if (!mktemp(template) || mkdir(template, 0700)) diff --git a/Utilities/cmlibuv/src/unix/internal.h b/Utilities/cmlibuv/src/unix/internal.h index 2e3afa6..e9f7908 100644 --- a/Utilities/cmlibuv/src/unix/internal.h +++ b/Utilities/cmlibuv/src/unix/internal.h @@ -59,7 +59,17 @@ # include <AvailabilityMacros.h> #endif -#if defined(__ANDROID__) +#if defined(CMAKE_BOOTSTRAP) +# undef pthread_atfork +# define pthread_atfork(prepare, parent, child) \ + uv__pthread_atfork(prepare, parent, child) +int uv__pthread_atfork(void (*prepare)(void), void (*parent)(void), + void (*child)(void)); +# undef pthread_sigmask +# define pthread_sigmask(how, set, oldset) \ + uv__pthread_sigmask(how, set, oldset) +int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset); +#elif defined(__ANDROID__) int uv__pthread_sigmask(int how, const sigset_t* set, sigset_t* oset); # ifdef pthread_sigmask # undef pthread_sigmask @@ -261,7 +271,7 @@ FILE* uv__open_file(const char* path); int uv__getpwuid_r(uv_passwd_t* pwd); -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) int uv___stream_fd(const uv_stream_t* handle); #define uv__stream_fd(handle) (uv___stream_fd((const uv_stream_t*) (handle))) #else diff --git a/Utilities/cmlibuv/src/unix/pipe.c b/Utilities/cmlibuv/src/unix/pipe.c index 7ba1bf8..e3d436d 100644 --- a/Utilities/cmlibuv/src/unix/pipe.c +++ b/Utilities/cmlibuv/src/unix/pipe.c @@ -136,7 +136,7 @@ int uv_pipe_open(uv_pipe_t* handle, uv_file fd) { if (err) return err; -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) err = uv__stream_try_select((uv_stream_t*) handle, &fd); if (err) return err; diff --git a/Utilities/cmlibuv/src/unix/posix-hrtime.c b/Utilities/cmlibuv/src/unix/posix-hrtime.c index 323dfc2..a264250 100644 --- a/Utilities/cmlibuv/src/unix/posix-hrtime.c +++ b/Utilities/cmlibuv/src/unix/posix-hrtime.c @@ -22,6 +22,29 @@ #include "uv.h" #include "internal.h" +#if defined(__APPLE__) +/* Special case for CMake bootstrap: no clock_gettime on macOS < 10.12 */ + +#ifndef CMAKE_BOOTSTRAP +#error "This code path meant only for use during CMake bootstrap." +#endif + +#include <mach/mach.h> +#include <mach/mach_time.h> + +uint64_t uv__hrtime(uv_clocktype_t type) { + static mach_timebase_info_data_t info; + + if ((ACCESS_ONCE(uint32_t, info.numer) == 0 || + ACCESS_ONCE(uint32_t, info.denom) == 0) && + mach_timebase_info(&info) != KERN_SUCCESS) + abort(); + + return mach_absolute_time() * info.numer / info.denom; +} + +#else + #include <stdint.h> #include <time.h> @@ -33,3 +56,5 @@ uint64_t uv__hrtime(uv_clocktype_t type) { clock_gettime(CLOCK_MONOTONIC, &ts); return (((uint64_t) ts.tv_sec) * NANOSEC + ts.tv_nsec); } + +#endif diff --git a/Utilities/cmlibuv/src/unix/stream.c b/Utilities/cmlibuv/src/unix/stream.c index 7b23d16..3857bc8 100644 --- a/Utilities/cmlibuv/src/unix/stream.c +++ b/Utilities/cmlibuv/src/unix/stream.c @@ -98,7 +98,7 @@ void uv__stream_init(uv_loop_t* loop, loop->emfile_fd = err; } -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) stream->select = NULL; #endif /* defined(__APPLE_) */ @@ -107,7 +107,7 @@ void uv__stream_init(uv_loop_t* loop, static void uv__stream_osx_interrupt_select(uv_stream_t* stream) { -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) /* Notify select() thread about state change */ uv__stream_select_t* s; int r; @@ -131,7 +131,7 @@ static void uv__stream_osx_interrupt_select(uv_stream_t* stream) { } -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) static void uv__stream_osx_select(void* arg) { uv_stream_t* stream; uv__stream_select_t* s; @@ -1598,7 +1598,7 @@ int uv_is_writable(const uv_stream_t* stream) { } -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) int uv___stream_fd(const uv_stream_t* handle) { const uv__stream_select_t* s; @@ -1619,7 +1619,7 @@ void uv__stream_close(uv_stream_t* handle) { unsigned int i; uv__stream_queued_fds_t* queued_fds; -#if defined(__APPLE__) +#if defined(__APPLE__) && !defined(CMAKE_BOOTSTRAP) /* Terminate select loop first */ if (handle->select != NULL) { uv__stream_select_t* s; diff --git a/Utilities/cmlibuv/src/uv-common.c b/Utilities/cmlibuv/src/uv-common.c index bc7d137..fcb910f 100644 --- a/Utilities/cmlibuv/src/uv-common.c +++ b/Utilities/cmlibuv/src/uv-common.c @@ -175,6 +175,7 @@ const char* uv_strerror(int err) { } #undef UV_STRERROR_GEN +#if !defined(CMAKE_BOOTSTRAP) || defined(_WIN32) int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) { memset(addr, 0, sizeof(*addr)); @@ -343,6 +344,7 @@ int uv_udp_recv_stop(uv_udp_t* handle) { return uv__udp_recv_stop(handle); } +#endif void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) { QUEUE queue; |