Skip to content

Commit 7f445c0

Browse files
author
bors-servo
authored
Auto merge of #158 - asajeffrey:configure-ndk, r=asajeffrey
Configure the Android NDK This patch adds configuration for the Android NDK directory layout. It's used when building for the Magic Leap, which uses a very similar, but not quite identical, NDK. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/mozjs/158) <!-- Reviewable:end -->
2 parents 61a10fb + 66add25 commit 7f445c0

File tree

7 files changed

+165
-19
lines changed

7 files changed

+165
-19
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "mozjs_sys"
33
description = "System crate for the Mozilla SpiderMonkey JavaScript engine."
44
repository = "https://github.com/servo/mozjs/"
5-
version = "0.61.1"
5+
version = "0.61.2"
66
authors = ["Mozilla"]
77
links = "mozjs"
88
build = "build.rs"

build.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ fn build_jsapi_bindings() {
197197

198198
if let Ok(flags) = env::var("CXXFLAGS") {
199199
for flag in flags.split_whitespace() {
200-
if !flag.starts_with("--sysroot") {
201-
builder = builder.clang_arg(flag);
202-
}
200+
builder = builder.clang_arg(flag);
203201
}
204202
}
205203

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/mozjs/mozglue/build/BionicGlue.cpp b/mozjs/mozglue/build/BionicGlue.cpp
2+
index b9b882166..710d01f2e 100644
3+
--- a/mozjs/mozglue/build/BionicGlue.cpp
4+
+++ b/mozjs/mozglue/build/BionicGlue.cpp
5+
@@ -17,7 +17,7 @@
6+
7+
#define NS_EXPORT __attribute__ ((visibility("default")))
8+
9+
-#if ANDROID_VERSION < 17 || defined(MOZ_WIDGET_ANDROID)
10+
+#if __ANDROID_API__ < 17 || defined(MOZ_WIDGET_ANDROID)
11+
/* Android doesn't have pthread_atfork(), so we need to use our own. */
12+
struct AtForkFuncs {
13+
void (*prepare)(void);
14+
@@ -64,7 +64,7 @@ private:
15+
static std::vector<AtForkFuncs, SpecialAllocator<AtForkFuncs> > atfork;
16+
#endif
17+
18+
-#if ANDROID_VERSION < 17 || defined(MOZ_WIDGET_ANDROID)
19+
+#if __ANDROID_API__ < 17 || defined(MOZ_WIDGET_ANDROID)
20+
extern "C" NS_EXPORT int
21+
pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
22+
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
diff --git a/mozjs/build/moz.configure/android-ndk.configure b/mozjs/build/moz.configure/android-ndk.configure
2+
index 5193332f3..21f7e2767 100644
3+
--- a/mozjs/build/moz.configure/android-ndk.configure
4+
+++ b/mozjs/build/moz.configure/android-ndk.configure
5+
@@ -8,6 +8,15 @@
6+
js_option('--with-android-ndk', nargs=1,
7+
help='location where the Android NDK can be found')
8+
9+
+js_option('--with-android-ndk-version', nargs=1,
10+
+ help='android NDK version')
11+
+
12+
+js_option('--with-android-platform', nargs=1,
13+
+ help='location of the Android platform')
14+
+
15+
+js_option('--with-android-clang', nargs=1,
16+
+ help='location of the Android clang compiler')
17+
+
18+
js_option('--with-android-toolchain', nargs=1,
19+
help='location of the Android toolchain')
20+
21+
@@ -66,13 +75,17 @@ set_config('ANDROID_NDK', ndk)
22+
add_old_configure_assignment('android_ndk', ndk)
23+
24+
25+
-@depends(ndk)
26+
+@depends('--with-android-ndk-version', ndk)
27+
@checking('for android ndk version')
28+
@imports(_from='__builtin__', _import='open')
29+
-def ndk_version(ndk):
30+
+def ndk_version(value, ndk):
31+
if not ndk:
32+
# Building 'js/src' for non-Android.
33+
return
34+
+
35+
+ if value:
36+
+ return value[0]
37+
+
38+
with open(os.path.join(ndk, 'source.properties'), 'r') as f:
39+
for line in f:
40+
if not line.startswith('Pkg.Revision'):
41+
@@ -112,13 +125,16 @@ def ndk_minor_version(ndk_version):
42+
set_config('ANDROID_NDK_MINOR_VERSION', ndk_minor_version)
43+
44+
45+
-@depends(target, android_version, ndk, '--help')
46+
+@depends('--with-android-platform', target, android_version, ndk, '--help')
47+
@checking('for android platform directory')
48+
@imports(_from='os.path', _import='isdir')
49+
-def android_platform(target, android_version, ndk, _):
50+
+def android_platform(value, target, android_version, ndk, _):
51+
if target.os != 'Android':
52+
return
53+
54+
+ if value:
55+
+ return value[0]
56+
+
57+
if 'mips' in target.cpu:
58+
target_dir_name = 'mips'
59+
elif 'aarch64' == target.cpu:
60+
@@ -257,7 +273,7 @@ option(env='STLPORT_CPPFLAGS',
61+
@imports(_from='os.path', _import='isdir')
62+
def stlport_cppflags(value, ndk, _):
63+
if value and len(value):
64+
- return value.split()
65+
+ return value[0].split()
66+
if not ndk:
67+
return
68+
69+
@@ -339,13 +355,16 @@ def bindgen_cflags_defaults(toolchain_flags, toolchain, toolchain_prefix, _):
70+
os.path.join(gcc_include, 'include-fixed'))
71+
72+
73+
-@depends(host, ndk)
74+
+@depends('--with-android-clang', host, ndk)
75+
@imports(_from='os.path', _import='exists')
76+
@imports(_from='os.path', _import='isdir')
77+
-def android_clang_compiler(host, ndk):
78+
+def android_clang_compiler(value, host, ndk):
79+
if not ndk:
80+
return
81+
82+
+ if value:
83+
+ return value[0]
84+
+
85+
llvm_path = '%s/toolchains/llvm/prebuilt/%s-%s/bin' % (ndk,
86+
host.kernel.lower(),
87+
host.cpu)

makefile.cargo

+26-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,27 @@ ifneq ($(HOST),$(TARGET))
2222
endif
2323

2424
ifeq (android,$(findstring android,$(TARGET)))
25-
CONFIGURE_FLAGS += \
26-
--with-android-ndk=$(ANDROID_NDK) \
27-
--with-android-toolchain=$(ANDROID_TOOLCHAIN) \
28-
--with-android-version=$(NDK_ANDROID_VERSION) \
29-
$(NULL)
25+
ifneq (,$(STLPORT_CPPFLAGS))
26+
CONFIGURE_FLAGS += STLPORT_CPPFLAGS="$(STLPORT_CPPFLAGS)"
27+
endif
28+
ifneq (,$(ANDROID_NDK))
29+
CONFIGURE_FLAGS += --with-android-ndk=$(ANDROID_NDK)
30+
endif
31+
ifneq (,$(ANDROID_NDK_VERSION))
32+
CONFIGURE_FLAGS += --with-android-ndk-version=$(ANDROID_NDK_VERSION)
33+
endif
34+
ifneq (,$(ANDROID_VERSION))
35+
CONFIGURE_FLAGS += --with-android-version=$(ANDROID_VERSION)
36+
endif
37+
ifneq (,$(ANDROID_PLATFORM_DIR))
38+
CONFIGURE_FLAGS += --with-android-platform=$(ANDROID_PLATFORM_DIR)
39+
endif
40+
ifneq (,$(ANDROID_TOOLCHAIN_DIR))
41+
CONFIGURE_FLAGS += --with-android-toolchain=$(ANDROID_TOOLCHAIN_DIR)
42+
endif
43+
ifneq (,$(ANDROID_CLANG))
44+
CONFIGURE_FLAGS += --with-android-clang=$(ANDROID_CLANG)
45+
endif
3046
endif
3147

3248
CC ?= $(TARGET)-gcc
@@ -143,6 +159,10 @@ maybe-configure:
143159
if [[ $(JSSRC)/configure -nt $(OUT_DIR)/config.status ]] ; then \
144160
cd $(OUT_DIR) && \
145161
PYTHON="$(PYTHON)" MOZ_TOOLS="$(MOZ_TOOLS)" \
146-
CC="$(CC)" CPP="$(CPP)" CXX="$(CXX)" AR="$(AR)" \
162+
CC="$(CC)" CFLAGS="$(CFLAGS)" \
163+
CPP="$(CPP)" CPPFLAGS="$(CPPFLAGS)" \
164+
CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
165+
AS="$(AS)" AR="$(AR)" \
166+
STLPORT_LIBS="$(STLPORT_LIBS)" \
147167
$(JSSRC)/configure $(strip $(CONFIGURE_FLAGS)) || (cat config.log && exit 1) ; \
148168
fi

mozjs/build/moz.configure/android-ndk.configure

+26-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
js_option('--with-android-ndk', nargs=1,
99
help='location where the Android NDK can be found')
1010

11+
js_option('--with-android-ndk-version', nargs=1,
12+
help='android NDK version')
13+
14+
js_option('--with-android-platform', nargs=1,
15+
help='location of the Android platform')
16+
17+
js_option('--with-android-clang', nargs=1,
18+
help='location of the Android clang compiler')
19+
1120
js_option('--with-android-toolchain', nargs=1,
1221
help='location of the Android toolchain')
1322

@@ -66,13 +75,17 @@ set_config('ANDROID_NDK', ndk)
6675
add_old_configure_assignment('android_ndk', ndk)
6776

6877

69-
@depends(ndk)
78+
@depends('--with-android-ndk-version', ndk)
7079
@checking('for android ndk version')
7180
@imports(_from='__builtin__', _import='open')
72-
def ndk_version(ndk):
81+
def ndk_version(value, ndk):
7382
if not ndk:
7483
# Building 'js/src' for non-Android.
7584
return
85+
86+
if value:
87+
return value[0]
88+
7689
with open(os.path.join(ndk, 'source.properties'), 'r') as f:
7790
for line in f:
7891
if not line.startswith('Pkg.Revision'):
@@ -112,13 +125,16 @@ def ndk_minor_version(ndk_version):
112125
set_config('ANDROID_NDK_MINOR_VERSION', ndk_minor_version)
113126

114127

115-
@depends(target, android_version, ndk, '--help')
128+
@depends('--with-android-platform', target, android_version, ndk, '--help')
116129
@checking('for android platform directory')
117130
@imports(_from='os.path', _import='isdir')
118-
def android_platform(target, android_version, ndk, _):
131+
def android_platform(value, target, android_version, ndk, _):
119132
if target.os != 'Android':
120133
return
121134

135+
if value:
136+
return value[0]
137+
122138
if 'mips' in target.cpu:
123139
target_dir_name = 'mips'
124140
elif 'aarch64' == target.cpu:
@@ -257,7 +273,7 @@ option(env='STLPORT_CPPFLAGS',
257273
@imports(_from='os.path', _import='isdir')
258274
def stlport_cppflags(value, ndk, _):
259275
if value and len(value):
260-
return value.split()
276+
return value[0].split()
261277
if not ndk:
262278
return
263279

@@ -339,13 +355,16 @@ def bindgen_cflags_defaults(toolchain_flags, toolchain, toolchain_prefix, _):
339355
os.path.join(gcc_include, 'include-fixed'))
340356

341357

342-
@depends(host, ndk)
358+
@depends('--with-android-clang', host, ndk)
343359
@imports(_from='os.path', _import='exists')
344360
@imports(_from='os.path', _import='isdir')
345-
def android_clang_compiler(host, ndk):
361+
def android_clang_compiler(value, host, ndk):
346362
if not ndk:
347363
return
348364

365+
if value:
366+
return value[0]
367+
349368
llvm_path = '%s/toolchains/llvm/prebuilt/%s-%s/bin' % (ndk,
350369
host.kernel.lower(),
351370
host.cpu)

mozjs/mozglue/build/BionicGlue.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
#define NS_EXPORT __attribute__ ((visibility("default")))
1919

20-
#if ANDROID_VERSION < 17 || defined(MOZ_WIDGET_ANDROID)
20+
#if __ANDROID_API__ < 17 || defined(MOZ_WIDGET_ANDROID)
2121
/* Android doesn't have pthread_atfork(), so we need to use our own. */
2222
struct AtForkFuncs {
2323
void (*prepare)(void);
@@ -64,7 +64,7 @@ struct SpecialAllocator: public std::allocator<T>
6464
static std::vector<AtForkFuncs, SpecialAllocator<AtForkFuncs> > atfork;
6565
#endif
6666

67-
#if ANDROID_VERSION < 17 || defined(MOZ_WIDGET_ANDROID)
67+
#if __ANDROID_API__ < 17 || defined(MOZ_WIDGET_ANDROID)
6868
extern "C" NS_EXPORT int
6969
pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
7070
{

0 commit comments

Comments
 (0)