uv: support android libuv standalone build

Tested most of my compilation in the previous patch on NodeJS
and extracted the patches from there. This patch ensures libuv
will be capable of building standalone as well, both with gyp
and Makefiles.

Build documentation was added to the README.md file.

Some tests are failing, and I have not heavily investigated
the reasons. The failures are generally on errors, and are
likely related to differences between fully POSIX-compatible
systems and android.
This commit is contained in:
Linus Mårtensson 2013-05-30 19:42:18 +02:00 committed by Ben Noordhuis
parent ede83188f3
commit 3fdd2a1128
7 changed files with 59 additions and 7 deletions

View File

@ -110,6 +110,16 @@ Note for Linux users: compile your project with `-D_GNU_SOURCE` when you
include `uv.h`. GYP builds take care of that automatically. If you use include `uv.h`. GYP builds take care of that automatically. If you use
autotools, add a `AC_GNU_SOURCE` declaration to your `configure.ac`. autotools, add a `AC_GNU_SOURCE` declaration to your `configure.ac`.
To build for android, locate your android NDK path, then run:
source ./android-configure NDK_PATH
make
To build for android with gyp, add "gyp" to the configuration:
source ./android-configure NDK_PATH gyp
make -C out
## Supported Platforms ## Supported Platforms
Microsoft Windows operating systems since Windows XP SP2. It can be built Microsoft Windows operating systems since Windows XP SP2. It can be built

20
android-configure Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
export TOOLCHAIN=$PWD/android-toolchain
mkdir -p $TOOLCHAIN
$1/build/tools/make-standalone-toolchain.sh \
--toolchain=arm-linux-androideabi-4.7 \
--arch=arm \
--install-dir=$TOOLCHAIN \
--platform=android-9
export PATH=$TOOLCHAIN/bin:$PATH
export AR=arm-linux-androideabi-ar
export CC=arm-linux-androideabi-gcc
export CXX=arm-linux-androideabi-g++
export LINK=arm-linux-androideabi-g++
export PLATFORM=android
if [ $2 -a $2 == 'gyp' ]
then
./gyp_uv -Dandroid_build=1 -Dtarget_arch=arm
fi

View File

@ -8,6 +8,13 @@
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way 'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
'gcc_version%': 'unknown', 'gcc_version%': 'unknown',
'clang%': 0, 'clang%': 0,
'conditions': [
# Workaround for the legacy handling of android in gyp
['android_build == 1', {
'OS': 'android',
}],
],
}, },
'target_defaults': { 'target_defaults': {
@ -148,7 +155,8 @@
[ 'OS=="solaris"', { [ 'OS=="solaris"', {
'cflags': [ '-pthreads' ], 'cflags': [ '-pthreads' ],
'ldflags': [ '-pthreads' ], 'ldflags': [ '-pthreads' ],
}, { }],
[ 'OS not in "android solaris"', {
'cflags': [ '-pthread' ], 'cflags': [ '-pthread' ],
'ldflags': [ '-pthread' ], 'ldflags': [ '-pthread' ],
}], }],

View File

@ -19,7 +19,7 @@
# IN THE SOFTWARE. # IN THE SOFTWARE.
E= E=
CFLAGS += -g -Wall -Wextra -Wno-unused-parameter -std=c89 CFLAGS += -g -Wall -Wextra -Wno-unused-parameter
CPPFLAGS += -I$(SRCDIR)/src CPPFLAGS += -I$(SRCDIR)/src
LDFLAGS=-lm LDFLAGS=-lm
@ -104,6 +104,18 @@ OBJS += src/unix/linux-core.o \
src/unix/proctitle.o src/unix/proctitle.o
endif endif
ifeq (android,$(PLATFORM))
CFLAGS += -D_GNU_SOURCE
LDFLAGS+=-ldl -lrt
RUNNER_CFLAGS += -D_GNU_SOURCE
OBJS += src/unix/linux-core.o \
src/unix/linux-inotify.o \
src/unix/linux-syscalls.o \
src/unix/proctitle.o
else
CFLAGS += -std=c89
endif
ifeq (freebsd,$(PLATFORM)) ifeq (freebsd,$(PLATFORM))
HAVE_DTRACE=1 HAVE_DTRACE=1
LDFLAGS+=-lkvm LDFLAGS+=-lkvm
@ -132,8 +144,10 @@ endif
ifeq (sunos,$(PLATFORM)) ifeq (sunos,$(PLATFORM))
RUNNER_LDFLAGS += -pthreads RUNNER_LDFLAGS += -pthreads
else else
ifneq (android, $(PLATFORM))
RUNNER_LDFLAGS += -pthread RUNNER_LDFLAGS += -pthread
endif endif
endif
ifeq ($(HAVE_DTRACE), 1) ifeq ($(HAVE_DTRACE), 1)
DTRACE_HEADER = src/unix/uv-dtrace.h DTRACE_HEADER = src/unix/uv-dtrace.h

View File

@ -37,7 +37,7 @@
#include <semaphore.h> #include <semaphore.h>
#include <pthread.h> #include <pthread.h>
#ifdef ANDROID #ifdef __ANDROID__
#include "pthread-fixes.h" #include "pthread-fixes.h"
#endif #endif
#include <signal.h> #include <signal.h>

View File

@ -36,7 +36,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <time.h> #include <time.h>
#ifndef ANDROID #ifndef __ANDROID__
#define HAVE_IFADDRS_H 1 #define HAVE_IFADDRS_H 1
#endif #endif

View File

@ -281,7 +281,7 @@ int uv_cond_init(uv_cond_t* cond) {
if (pthread_condattr_init(&attr)) if (pthread_condattr_init(&attr))
return -1; return -1;
#if !defined(ANDROID) #if !defined(__ANDROID__)
if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC)) if (pthread_condattr_setclock(&attr, CLOCK_MONOTONIC))
goto error2; goto error2;
#endif #endif
@ -336,7 +336,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
timeout += uv__hrtime(); timeout += uv__hrtime();
ts.tv_sec = timeout / NANOSEC; ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC; ts.tv_nsec = timeout % NANOSEC;
#if defined(ANDROID) #if defined(__ANDROID__)
/* /*
* The bionic pthread implementation doesn't support CLOCK_MONOTONIC, * The bionic pthread implementation doesn't support CLOCK_MONOTONIC,
* but has this alternative function instead. * but has this alternative function instead.
@ -344,7 +344,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
r = pthread_cond_timedwait_monotonic_np(cond, mutex, &ts); r = pthread_cond_timedwait_monotonic_np(cond, mutex, &ts);
#else #else
r = pthread_cond_timedwait(cond, mutex, &ts); r = pthread_cond_timedwait(cond, mutex, &ts);
#endif /* ANDROID */ #endif /* __ANDROID__ */
#endif #endif