Skip to content

Commit 5e4e8ec

Browse files
Linus Mårtenssonbnoordhuis
authored andcommitted
build: add android support
Resolves minor discrepancies between android and standard POSIX systems. In addition, some configure parameters were added, and a helper-script for android configuration. Ideally, this script should be merged into the standard configure script. To build for android, source the android-configure script with an NDK path: source ./android-configure ~/android-ndk-r8d This will create an android standalone toolchain and export the necessary environment parameters. After that, build as normal: make -j8 After the build, you should now have android-compatible NodeJS binaries.
1 parent ffcd8b9 commit 5e4e8ec

File tree

6 files changed

+57
-17
lines changed

6 files changed

+57
-17
lines changed

android-configure

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
export TOOLCHAIN=$PWD/android-toolchain
4+
mkdir -p $TOOLCHAIN
5+
$1/build/tools/make-standalone-toolchain.sh \
6+
--toolchain=arm-linux-androideabi-4.7 \
7+
--arch=arm \
8+
--install-dir=$TOOLCHAIN \
9+
--platform=android-9
10+
export PATH=$TOOLCHAIN/bin:$PATH
11+
export AR=arm-linux-androideabi-ar
12+
export CC=arm-linux-androideabi-gcc
13+
export CXX=arm-linux-androideabi-g++
14+
export LINK=arm-linux-androideabi-g++
15+
16+
./configure \
17+
--without-snapshot \
18+
--dest-cpu=arm \
19+
--dest-os=android

common.gypi

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,14 @@
161161
'BUILDING_UV_SHARED=1',
162162
],
163163
}],
164-
[ 'OS=="linux" or OS=="freebsd" or OS=="openbsd" or OS=="solaris"', {
165-
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', '-pthread', ],
164+
[ 'OS in "linux freebsd openbsd solaris"', {
165+
'cflags': [ '-pthread', ],
166+
'ldflags': [ '-pthread' ],
167+
}],
168+
[ 'OS in "linux freebsd openbsd solaris android"', {
169+
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
166170
'cflags_cc': [ '-fno-rtti', '-fno-exceptions' ],
167-
'ldflags': [ '-pthread', '-rdynamic' ],
171+
'ldflags': [ '-rdynamic' ],
168172
'target_conditions': [
169173
['_type=="static_library"', {
170174
'standalone_static_library': 1, # disable thin archive which needs binutils >= 2.19
@@ -187,6 +191,10 @@
187191
}],
188192
],
189193
}],
194+
[ 'OS=="android"', {
195+
'defines': ['_GLIBCXX_USE_C99_MATH'],
196+
'libraries': [ '-llog' ],
197+
}],
190198
['OS=="mac"', {
191199
'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
192200
'xcode_settings': {

configure

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ parser.add_option("--dest-os",
237237
action="store",
238238
dest="dest_os",
239239
help="Operating system to build for. Valid values are: "
240-
"win, mac, solaris, freebsd, openbsd, linux")
240+
"win, mac, solaris, freebsd, openbsd, linux, android")
241241

242242
parser.add_option("--no-ifaddrs",
243243
action="store_true",
@@ -434,6 +434,8 @@ def configure_arm(o):
434434

435435

436436
def configure_node(o):
437+
if options.dest_os == 'android':
438+
o['variables']['OS'] = "android"
437439
o['variables']['v8_enable_gdbjit'] = 1 if options.gdb else 0
438440
o['variables']['v8_no_strict_aliasing'] = 1 # work around compiler bugs
439441
o['variables']['node_prefix'] = os.path.expanduser(options.prefix or '')
@@ -641,6 +643,7 @@ configure_v8(output)
641643
configure_openssl(output)
642644
configure_winsdk(output)
643645

646+
644647
# variables should be a root level element,
645648
# move everything else to target_defaults
646649
variables = output['variables']

doc/api/process.markdown

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,8 @@ The shell that executed node should see the exit code as 1.
213213

214214
## process.getgid()
215215

216-
Note: this function is only available on POSIX platforms (i.e. not Windows)
216+
Note: this function is only available on POSIX platforms (i.e. not Windows,
217+
Android)
217218

218219
Gets the group identity of the process. (See getgid(2).)
219220
This is the numerical group id, not the group name.
@@ -225,7 +226,8 @@ This is the numerical group id, not the group name.
225226

226227
## process.setgid(id)
227228

228-
Note: this function is only available on POSIX platforms (i.e. not Windows)
229+
Note: this function is only available on POSIX platforms (i.e. not Windows,
230+
Android)
229231

230232
Sets the group identity of the process. (See setgid(2).) This accepts either
231233
a numerical ID or a groupname string. If a groupname is specified, this method
@@ -245,7 +247,8 @@ blocks while resolving it to a numerical ID.
245247

246248
## process.getuid()
247249

248-
Note: this function is only available on POSIX platforms (i.e. not Windows)
250+
Note: this function is only available on POSIX platforms (i.e. not Windows,
251+
Android)
249252

250253
Gets the user identity of the process. (See getuid(2).)
251254
This is the numerical userid, not the username.
@@ -257,7 +260,8 @@ This is the numerical userid, not the username.
257260

258261
## process.setuid(id)
259262

260-
Note: this function is only available on POSIX platforms (i.e. not Windows)
263+
Note: this function is only available on POSIX platforms (i.e. not Windows,
264+
Android)
261265

262266
Sets the user identity of the process. (See setuid(2).) This accepts either
263267
a numerical ID or a username string. If a username is specified, this method
@@ -277,15 +281,17 @@ blocks while resolving it to a numerical ID.
277281

278282
## process.getgroups()
279283

280-
Note: this function is only available on POSIX platforms (i.e. not Windows)
284+
Note: this function is only available on POSIX platforms (i.e. not Windows,
285+
Android)
281286

282287
Returns an array with the supplementary group IDs. POSIX leaves it unspecified
283288
if the effective group ID is included but node.js ensures it always is.
284289

285290

286291
## process.setgroups(groups)
287292

288-
Note: this function is only available on POSIX platforms (i.e. not Windows)
293+
Note: this function is only available on POSIX platforms (i.e. not Windows,
294+
Android)
289295

290296
Sets the supplementary group IDs. This is a privileged operation, meaning you
291297
need to be root or have the CAP_SETGID capability.
@@ -295,7 +301,8 @@ The list can contain group IDs, group names or both.
295301

296302
## process.initgroups(user, extra_group)
297303

298-
Note: this function is only available on POSIX platforms (i.e. not Windows)
304+
Note: this function is only available on POSIX platforms (i.e. not Windows,
305+
Android)
299306

300307
Reads /etc/group and initializes the group access list, using all groups of
301308
which the user is a member. This is a privileged operation, meaning you need

src/cares_wrap.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
#include "tree.h"
3232
#include "uv.h"
3333

34-
#if defined(__OpenBSD__) || defined(__MINGW32__) || defined(_MSC_VER)
34+
#if defined(__ANDROID__) || \
35+
defined(__MINGW32__) || \
36+
defined(__OpenBSD__) || \
37+
defined(_MSC_VER)
3538
# include <nameser.h>
3639
#else
3740
# include <arpa/nameser.h>

src/node.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ typedef int mode_t;
6161
#include <sys/types.h>
6262
#include "zlib.h"
6363

64-
#ifdef __POSIX__
64+
#if defined(__POSIX__) && !defined(__ANDROID__)
6565
# include <pwd.h> /* getpwnam() */
6666
# include <grp.h> /* getgrnam() */
6767
#endif
@@ -1374,7 +1374,7 @@ static Handle<Value> Umask(const Arguments& args) {
13741374
}
13751375

13761376

1377-
#ifdef __POSIX__
1377+
#if defined(__POSIX__) && !defined(__ANDROID__)
13781378

13791379
static const uid_t uid_not_found = static_cast<uid_t>(-1);
13801380
static const gid_t gid_not_found = static_cast<gid_t>(-1);
@@ -1650,7 +1650,7 @@ static Handle<Value> InitGroups(const Arguments& args) {
16501650
return Undefined(node_isolate);
16511651
}
16521652

1653-
#endif // __POSIX__
1653+
#endif // __POSIX__ && !defined(__ANDROID__)
16541654

16551655

16561656
v8::Handle<v8::Value> Exit(const v8::Arguments& args) {
@@ -2349,7 +2349,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
23492349

23502350
NODE_SET_METHOD(process, "umask", Umask);
23512351

2352-
#ifdef __POSIX__
2352+
#if defined(__POSIX__) && !defined(__ANDROID__)
23532353
NODE_SET_METHOD(process, "getuid", GetUid);
23542354
NODE_SET_METHOD(process, "setuid", SetUid);
23552355

@@ -2359,7 +2359,7 @@ Handle<Object> SetupProcessObject(int argc, char *argv[]) {
23592359
NODE_SET_METHOD(process, "getgroups", GetGroups);
23602360
NODE_SET_METHOD(process, "setgroups", SetGroups);
23612361
NODE_SET_METHOD(process, "initgroups", InitGroups);
2362-
#endif // __POSIX__
2362+
#endif // __POSIX__ && !defined(__ANDROID__)
23632363

23642364
NODE_SET_METHOD(process, "_kill", Kill);
23652365

0 commit comments

Comments
 (0)