Skip to content

Commit cdc2a4a

Browse files
authored
Update iOS and Android scripts (GH weidai11#936, PR weidai11#937)
This commit updates Android and iOS to modern SDKs, NDKs and Xcode.
1 parent b7af0a2 commit cdc2a4a

File tree

9 files changed

+578
-692
lines changed

9 files changed

+578
-692
lines changed

.travis.yml

Lines changed: 113 additions & 187 deletions
Large diffs are not rendered by default.

GNUmakefile-cross

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,11 @@ endif
102102
# iOS cross-compile configuration.
103103
# See http://www.cryptopp.com/wiki/iOS_(Command_Line).
104104
ifeq ($(IS_IOS),1)
105-
CXX = clang++
106-
107-
CXXFLAGS += $(IOS_FLAGS) -arch $(IOS_ARCH)
108-
CXXFLAGS += -isysroot "$(IOS_SYSROOT)" -stdlib=libc++
105+
CXXFLAGS += $(IOS_CXXFLAGS) -stdlib=libc++
106+
CXXFLAGS += --sysroot "$(IOS_SYSROOT)"
109107

110108
AR = libtool
111109
ARFLAGS = -static -o
112-
RANLIB = ranlib
113110
endif
114111

115112
###########################################################
@@ -119,14 +116,13 @@ endif
119116
# Android cross-compile configuration.
120117
# See http://www.cryptopp.com/wiki/Android_(Command_Line).
121118
ifeq ($(IS_ANDROID),1)
122-
# CPP, CXX, AR, RANLIB, LD, etc are set in 'setenv-android.sh'
123-
CXXFLAGS += $(AOSP_FLAGS) -stdlib=$(AOSP_RUNTIME) -DANDROID
124-
CXXFLAGS += -D__ANDROID_API__=$(AOSP_API) --sysroot=$(AOSP_SYSROOT)
119+
CXXFLAGS += $(ANDROID_CXXFLAGS) -D__ANDROID_API__=$(ANDROID_API)
120+
CXXFLAGS += --sysroot=$(ANDROID_SYSROOT)
125121
CXXFLAGS += -Wa,--noexecstack
126122

127123
# Source files copied into PWD for Android cpu-features
128124
# setenv-android.sh does the copying. Its a dirty compile.
129-
AOSP_CPU_OBJ = cpu-features.o
125+
ANDROID_CPU_OBJ = cpu-features.o
130126
endif
131127

132128
###########################################################
@@ -195,6 +191,8 @@ else ifeq ($(findstring distclean,$(MAKECMDGOALS)),distclean)
195191
DETECT_FEATURES := 0
196192
else ifeq ($(findstring distclean,$(MAKECMDGOALS)),trim)
197193
DETECT_FEATURES := 0
194+
else ifeq ($(IS_IOS),1)
195+
DETECT_FEATURES := 0
198196
endif
199197

200198
# Strip out -Wall, -Wextra and friends for feature testing. FORTIFY_SOURCE is removed
@@ -708,7 +706,7 @@ lean: static dynamic cryptest.exe
708706

709707
.PHONY: clean
710708
clean:
711-
-$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(AOSP_CPU_OBJ) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
709+
-$(RM) adhoc.cpp.o adhoc.cpp.proto.o $(LIBOBJS) $(ANDROID_CPU_OBJ) rdrand-*.o $(TESTOBJS) $(DLLOBJS) $(LIBIMPORTOBJS) $(TESTIMPORTOBJS) $(DLLTESTOBJS)
712710
@-$(RM) libcryptopp.a libcryptopp.dylib cryptopp.dll libcryptopp.dll.a libcryptopp.import.a
713711
@-$(RM) libcryptopp.so libcryptopp.so$(SOLIB_COMPAT_SUFFIX) libcryptopp.so$(SOLIB_VERSION_SUFFIX)
714712
@-$(RM) cryptest.exe dlltest.exe cryptest.import.exe cryptest.info ct et
@@ -804,24 +802,24 @@ remove uninstall:
804802
@-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
805803
@-$(RM) $(DESTDIR)$(LIBDIR)/libcryptopp.so
806804

807-
libcryptopp.a: $(LIBOBJS) $(AOSP_CPU_OBJ)
808-
$(AR) $(ARFLAGS) $@ $(LIBOBJS) $(AOSP_CPU_OBJ)
805+
libcryptopp.a: $(LIBOBJS) $(ANDROID_CPU_OBJ)
806+
$(AR) $(ARFLAGS) $@ $(LIBOBJS) $(ANDROID_CPU_OBJ)
809807
$(RANLIB) $@
810808

811809
ifeq ($(HAS_SOLIB_VERSION),1)
812810
.PHONY: libcryptopp.so
813811
libcryptopp.so: libcryptopp.so$(SOLIB_VERSION_SUFFIX)
814812
endif
815813

816-
libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(AOSP_CPU_OBJ)
817-
$(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(AOSP_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
814+
libcryptopp.so$(SOLIB_VERSION_SUFFIX): $(LIBOBJS) $(ANDROID_CPU_OBJ)
815+
$(CXX) -shared $(SOLIB_FLAGS) -o $@ $(strip $(CXXFLAGS)) -Wl,--exclude-libs,ALL $(LIBOBJS) $(ANDROID_CPU_OBJ) $(LDFLAGS) $(LDLIBS)
818816
ifeq ($(HAS_SOLIB_VERSION),1)
819817
-$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so
820818
-$(LN) libcryptopp.so$(SOLIB_VERSION_SUFFIX) libcryptopp.so$(SOLIB_COMPAT_SUFFIX)
821819
endif
822820

823-
libcryptopp.dylib: $(LIBOBJS) $(AOSP_CPU_OBJ)
824-
$(CXX) -dynamiclib -o $@ $(strip $(CXXFLAGS)) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS) $(AOSP_CPU_OBJ)
821+
libcryptopp.dylib: $(LIBOBJS)
822+
$(CXX) -dynamiclib -o $@ $(strip $(CXXFLAGS)) -install_name "$@" -current_version "$(LIB_MAJOR).$(LIB_MINOR).$(LIB_PATCH)" -compatibility_version "$(LIB_MAJOR).$(LIB_MINOR)" -headerpad_max_install_names $(LDFLAGS) $(LIBOBJS)
825823

826824
cryptest.exe: $(LINK_LIBRARY) $(TESTOBJS)
827825
$(CXX) -o $@ $(strip $(CXXFLAGS)) $(TESTOBJS) $(LINK_LIBRARY_PATH)$(LINK_LIBRARY) $(LDFLAGS) $(LDLIBS)

TestScripts/cryptest-android.sh

Lines changed: 41 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,18 @@
33
# ====================================================================
44
# Tests Android cross-compiles
55
#
6-
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
7-
# licensed under the Boost Software License 1.0, while the individual files
8-
# in the compilation are all public domain.
9-
#
106
# See http://www.cryptopp.com/wiki/Android_(Command_Line) for more details
117
# ====================================================================
128

13-
# set -x
14-
159
if [ -z "$(command -v ./setenv-android.sh)" ]; then
16-
echo "Failed to locate setenv-android.sh"
17-
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
10+
echo "Failed to locate setenv-android.sh"
11+
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
1812
fi
1913

2014
# Temp directory
2115
if [[ -z "$TMPDIR" ]]; then
22-
TMPDIR="$HOME/tmp"
23-
mkdir -p "$TMPDIR"
16+
TMPDIR="$HOME/tmp"
17+
mkdir -p "$TMPDIR"
2418
fi
2519

2620
MAKE_JOBS=2
@@ -29,67 +23,53 @@ MAKE_JOBS=2
2923
rm -rf "$TMPDIR/build.failed" 2>/dev/null
3024
rm -rf "$TMPDIR/build.log" 2>/dev/null
3125

32-
if [ "$#" -gt 0 ]; then
33-
# Accept platforms on the command line
34-
PLATFORMS=("$@")
35-
elif [ -n "$PLATFORM" ]; then
36-
# Accept platforms in the environment
37-
PLATFORMS=("$PLATFORM")
38-
else
39-
# Use all platforms
40-
PLATFORMS=(armeabi-v7a arm64-v8a x86 x86_64)
41-
fi
42-
43-
# Thank god... one runtime and one compiler
44-
RUNTIMES=(libc++)
26+
PLATFORMS=(armv7a aarch64 x86 x86_64)
4527

4628
for platform in "${PLATFORMS[@]}"
4729
do
48-
for runtime in "${RUNTIMES[@]}"
49-
do
50-
make -f GNUmakefile-cross distclean > /dev/null 2>&1
51-
52-
echo
53-
echo "===================================================================="
54-
echo "Testing for Android support of $platform using $runtime"
55-
56-
# Test if we can set the environment for the platform
57-
if ! ./setenv-android.sh "$platform" "$runtime";
58-
then
59-
echo
60-
echo "There were problems testing $platform with $runtime"
61-
echo "$platform:$runtime ==> FAILURE" >> "$TMPDIR/build.log"
62-
63-
touch "$TMPDIR/build.failed"
64-
continue
65-
fi
66-
67-
echo
68-
echo "Building for $platform using $runtime..."
69-
echo
70-
71-
# run in subshell to not keep any envars
72-
(
73-
source ./setenv-android.sh "$platform" "$runtime" # > /dev/null 2>&1
74-
if make -k -j "$MAKE_JOBS" -f GNUmakefile-cross static dynamic cryptest.exe;
75-
then
76-
echo "$platform:$runtime ==> SUCCESS" >> "$TMPDIR/build.log"
77-
else
78-
echo "$platform:$runtime ==> FAILURE" >> "$TMPDIR/build.log"
79-
touch "$TMPDIR/build.failed"
80-
fi
81-
)
82-
done
30+
make -f GNUmakefile-cross distclean > /dev/null 2>&1
31+
32+
echo
33+
echo "===================================================================="
34+
echo "Testing for Android support of $platform"
35+
36+
# run in subshell to not keep any envars
37+
(
38+
# Test if we can set the environment for the platform
39+
if ! ./setenv-android.sh > /dev/null 2>&1;
40+
then
41+
echo
42+
echo "There were problems testing $platform"
43+
echo "$platform ==> SKIPPED" >> "$TMPDIR/build.log"
44+
45+
continue
46+
fi
47+
)
48+
49+
echo
50+
echo "Building for $platform..."
51+
echo
52+
53+
# run in subshell to not keep any envars
54+
(
55+
source ./setenv-ios.sh
56+
if make -k -j "$MAKE_JOBS" -f GNUmakefile-cross static dynamic cryptest.exe;
57+
then
58+
echo "$platform ==> SUCCESS" >> "$TMPDIR/build.log"
59+
else
60+
echo "$platform ==> FAILURE" >> "$TMPDIR/build.log"
61+
touch "$TMPDIR/build.failed"
62+
fi
63+
)
8364
done
8465

8566
echo ""
86-
echo "===================================================================="
87-
echo "Dumping build results"
67+
echo "====================================================="
8868
cat "$TMPDIR/build.log"
8969

9070
# let the script fail if any of the builds failed
9171
if [ -f "$TMPDIR/build.failed" ]; then
92-
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
72+
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
9373
fi
9474

9575
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 0 || return 0

TestScripts/cryptest-ios.sh

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,18 @@
33
# ====================================================================
44
# Tests iOS cross-compiles
55
#
6-
# Crypto++ Library is copyrighted as a compilation and (as of version 5.6.2)
7-
# licensed under the Boost Software License 1.0, while the individual files
8-
# in the compilation are all public domain.
9-
#
106
# See http://www.cryptopp.com/wiki/iOS_(Command_Line) for more details
117
# ====================================================================
128

139
if [ -z "$(command -v ./setenv-ios.sh)" ]; then
14-
echo "Failed to locate setenv-ios.sh"
15-
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
10+
echo "Failed to locate setenv-ios.sh"
11+
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
1612
fi
1713

1814
# Temp directory
1915
if [[ -z "$TMPDIR" ]]; then
20-
TMPDIR="$HOME/tmp"
21-
mkdir "$TMPDIR"
16+
TMPDIR="$HOME/tmp"
17+
mkdir "$TMPDIR"
2218
fi
2319

2420
MAKE_JOBS=2
@@ -27,58 +23,72 @@ MAKE_JOBS=2
2723
rm -rf "$TMPDIR/build.failed" 2>/dev/null
2824
rm -rf "$TMPDIR/build.log" 2>/dev/null
2925

30-
if [ "$#" -gt 0 ]; then
31-
# Accept platforms on the command line
32-
PLATFORMS=("$@")
33-
elif [ -n "$PLATFORM" ]; then
34-
# Accept platforms in the environment
35-
PLATFORMS=("$PLATFORM")
36-
else
37-
# Use all platforms
38-
PLATFORMS=(iPhoneOS iPhoneSimulator Arm64 WatchOS WatchSimulator AppleTVOS AppleTVSimulator)
39-
fi
26+
# Hack a Bash data structure...
27+
PLATFORMS=()
28+
PLATFORMS+=("iPhoneOS:armv7")
29+
PLATFORMS+=("iPhoneOS:arm64")
30+
PLATFORMS+=("AppleTVOS:arm64")
31+
PLATFORMS+=("WatchOS:armv7")
32+
PLATFORMS+=("WatchOS:arm64")
33+
PLATFORMS+=("iPhoneSimulator:i386")
34+
PLATFORMS+=("iPhoneSimulator:x86_64")
35+
PLATFORMS+=("AppleTVSimulator:x86_64")
36+
PLATFORMS+=("WatchSimulator:i386")
37+
PLATFORMS+=("WatchSimulator:x86_64")
4038

4139
for platform in "${PLATFORMS[@]}"
4240
do
43-
make -f GNUmakefile-cross distclean > /dev/null 2>&1
44-
45-
echo
46-
echo "====================================================="
47-
echo "Testing for iOS support of $platform"
48-
49-
# Test if we can set the environment for the platform
50-
if ! ./setenv-ios.sh "$platform";
51-
then
52-
echo
53-
echo "$platform not supported by Xcode"
54-
echo "$platform ==> FAILURE" >> "$TMPDIR/build.log"
55-
56-
touch "$TMPDIR/build.failed"
57-
continue
58-
fi
59-
60-
echo
61-
echo "Building for $platform..."
62-
echo
63-
64-
# run in subshell to not keep any envars
65-
(
66-
source ./setenv-ios.sh "$platform" > /dev/null 2>&1
67-
if make -k -j "$MAKE_JOBS" -f GNUmakefile-cross static dynamic cryptest.exe;
68-
then
69-
echo "$platform ==> SUCCESS" >> "$TMPDIR/build.log"
70-
else
71-
echo "$platform ==> FAILURE" >> "$TMPDIR/build.log"
72-
touch "$TMPDIR/build.failed"
73-
fi
74-
)
41+
42+
sdk=$(echo "${platform[@]}" | awk -F':' '{print $1}')
43+
cpu=$(echo "${platform[@]}" | awk -F':' '{print $2}')
44+
45+
# setenv-ios.sh reads these two variables for configuration info.
46+
export IOS_SDK="$sdk"
47+
export IOS_CPU="$cpu"
48+
49+
make -f GNUmakefile-cross distclean > /dev/null 2>&1
50+
51+
echo
52+
echo "====================================================="
53+
echo "Testing for iOS support of $platform"
54+
55+
# run in subshell to not keep any envars
56+
(
57+
# Test if we can set the environment for the platform
58+
if ! ./setenv-ios.sh > /dev/null 2>&1;
59+
then
60+
echo
61+
echo "$platform not supported by Xcode"
62+
echo "$platform ==> SKIPPED" >> "$TMPDIR/build.log"
63+
64+
continue
65+
fi
66+
)
67+
68+
echo
69+
echo "Building for $platform..."
70+
echo
71+
72+
# run in subshell to not keep any envars
73+
(
74+
source ./setenv-ios.sh
75+
if make -k -j "$MAKE_JOBS" -f GNUmakefile-cross static dynamic cryptest.exe;
76+
then
77+
echo "$platform ==> SUCCESS" >> "$TMPDIR/build.log"
78+
else
79+
echo "$platform ==> FAILURE" >> "$TMPDIR/build.log"
80+
touch "$TMPDIR/build.failed"
81+
fi
82+
)
7583
done
7684

85+
echo ""
86+
echo "====================================================="
7787
cat "$TMPDIR/build.log"
7888

7989
# let the script fail if any of the builds failed
8090
if [ -f "$TMPDIR/build.failed" ]; then
81-
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
91+
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 1 || return 1
8292
fi
8393

8494
[[ "$0" = "${BASH_SOURCE[0]}" ]] && exit 0 || return 0

0 commit comments

Comments
 (0)