Skip to content

Commit

Permalink
uv: support android libuv standalone build
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Linus Mårtensson authored and bnoordhuis committed May 31, 2013
1 parent ede8318 commit 3fdd2a1
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

Microsoft Windows operating systems since Windows XP SP2. It can be built
Expand Down
20 changes: 20 additions & 0 deletions android-configure
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
'gcc_version%': 'unknown',
'clang%': 0,

'conditions': [
# Workaround for the legacy handling of android in gyp
['android_build == 1', {
'OS': 'android',
}],
],
},

'target_defaults': {
Expand Down Expand Up @@ -148,7 +155,8 @@
[ 'OS=="solaris"', {
'cflags': [ '-pthreads' ],
'ldflags': [ '-pthreads' ],
}, {
}],
[ 'OS not in "android solaris"', {
'cflags': [ '-pthread' ],
'ldflags': [ '-pthread' ],
}],
Expand Down
16 changes: 15 additions & 1 deletion config-unix.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# IN THE SOFTWARE.

E=
CFLAGS += -g -Wall -Wextra -Wno-unused-parameter -std=c89
CFLAGS += -g -Wall -Wextra -Wno-unused-parameter
CPPFLAGS += -I$(SRCDIR)/src
LDFLAGS=-lm

Expand Down Expand Up @@ -104,6 +104,18 @@ OBJS += src/unix/linux-core.o \
src/unix/proctitle.o
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))
HAVE_DTRACE=1
LDFLAGS+=-lkvm
Expand Down Expand Up @@ -132,8 +144,10 @@ endif
ifeq (sunos,$(PLATFORM))
RUNNER_LDFLAGS += -pthreads
else
ifneq (android, $(PLATFORM))
RUNNER_LDFLAGS += -pthread
endif
endif

ifeq ($(HAVE_DTRACE), 1)
DTRACE_HEADER = src/unix/uv-dtrace.h
Expand Down
2 changes: 1 addition & 1 deletion include/uv-private/uv-unix.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

#include <semaphore.h>
#include <pthread.h>
#ifdef ANDROID
#ifdef __ANDROID__
#include "pthread-fixes.h"
#endif
#include <signal.h>
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include <fcntl.h>
#include <time.h>

#ifndef ANDROID
#ifndef __ANDROID__
#define HAVE_IFADDRS_H 1
#endif

Expand Down
6 changes: 3 additions & 3 deletions src/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ int uv_cond_init(uv_cond_t* cond) {
if (pthread_condattr_init(&attr))
return -1;

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


Expand Down

0 comments on commit 3fdd2a1

Please sign in to comment.