Being open source has many advantages. One of it is that you can take the source code and port it to new platforms. And that is what I did last week for GDC: I ported both Cocos2d-x v4.0-alpha0 and v3.4 to MIPS Creator CI20.
The porting process was very straight forward:
- I compiled the cocos2d-x 3rd party dependencies for Android MIPS
- Then I manually copied the binaries + headers to the cocos2d-x/external folder
- I compiled cocos2d-x Cpp-test for Android MIPS
- The only thing that I did was to add “APP_API := mips” in Application.mk
And that’s it.
The issues that I found are:
- You must use GCC 4.8 as the NDK Toolchain. GCC 4.9 crashes immediately, and Clang crashes on some tests. I’m not sure why.
- It uses Lua instead of LuaJIT, since LuaJIT is not supported on MIPS
Detailed steps to port Cocos2d-x to CI20:
a) Set NDK_TOOLCHAIN_VERSION to 4.8
The NDK_TOOLCHAIN_VERSION environment variable must be set to 4.8. eg:
$ export NDK_TOOLCHAIN_VERSION=4.8
b) Clone the Cocos2d-x 3rd party dependencies
Clone the the v4 branch of Cocos2d-x-3rd-party-src repo from gihtub:
$ git clone https://github.com/cocos2d/cocos2d-x-3rd-party-libs-src
$ cd cocos2d-x-3rd-party-src
$ git checkout v4
c) Compile all the 3rd party dependencies for Android MIPS
$ cd build
$ ./build.sh -p=android --arch=mips
That will compile all the Android libraries. You can compile them one by one in case you need it. eg:
$ cd build
$ ./build.sh -p=android --arch=mips --libs=png
d) Copy the generated libraries to the Cocos2d-x “external” folder
$ cp -R android/ ~/path/to/cocos2d-x/external/
e) Configure Cpp-tests for MIPS
$ cd ~/path/to/cocos2d-x/tests/cpp-tests/proj.android/jni
$ vi Application.mk
And add the following line:
APP_ABI := mips
To support multiple platforms you can do:
APP_ABI := mips armeabi
If no APP_ABI is defined, it will only compile for armeabi.
f) Compile Cpp-tests
Go to the Cocos2d-x build directory and build Cpp-tests!
$ cd ~/path/to/Cocos2d-x/build
$ python ./android-build.py -p=20 -n -j8 cpp-tests
On another blog post I’ll describe the steps needed to port Cocos2d-x to CI20 for Linux. The logic is the same, but it is a bit more complex since the default Linux distribution installed on CI20 uses a different toolchain than the cross-compilation toolchain that is available from Mentor Graphics.