苹果要求老的app需要在6月份后支持64位,新的app从2.1开始就必须支持64bit。由于我们用了luajit,而luajit2.0.x版本只支持32bit。在2.1版本开始支持64bit了,但目前只是alpha版本。
下面的luajit库编译后支持arm64,armv7和模拟器。即一个库支持64bit编译的所有cpu,不需要针对新老iphone做特殊处理。
下载LuaJit
通过GIT下载Luajit代码
git clone http://repo.or.cz/luajit-2.0.git
进入Luajit下载代码目录签出分支v2.1
git checkout v2.1
编译脚本
在luajit-2.0的上一层目录运行
LUAJIT=./luajit-2.1 DEVDIR=`xcode-select -print-path`/Platforms IOSVER=iPhoneOS8.1.sdk SIMVER=iPhoneSimulator.sdk IOSDIR=$DEVDIR/iPhoneOS.platform/Developer SIMDIR=$DEVDIR/iPhoneSimulator.platform/Developer IOSBIN=$DEVDIR/../usr/bin/ SIMBIN=$SIMDIR/usr/bin/ BUILD_DIR=$LUAJIT/build rm -rf $BUILD_DIR mkdir -p $BUILD_DIR rm *.a 1>/dev/null 2>/dev/null echo ================================================= echo ARMV7 Architecture ISDKF="-arch armv7 -isysroot $IOSDIR/SDKs/$IOSVER" make -j -C $LUAJIT HOST_CC="gcc -m32 " CROSS=$IOSBIN TARGET_FLAGS="$ISDKF" TARGET=armv7 TARGET_SYS=iOS clean make -j -C $LUAJIT HOST_CC="gcc -m32 " CROSS=$IOSBIN TARGET_FLAGS="$ISDKF" TARGET=armv7 TARGET_SYS=iOS mv $LUAJIT/src/libluajit.a $BUILD_DIR/libluajitA7.a echo ================================================= echo ARM64 Architecture ISDKF="-arch arm64 -isysroot $IOSDIR/SDKs/$IOSVER" make -j -C $LUAJIT HOST_CC="gcc " CROSS=$IOSBIN TARGET_FLAGS="$ISDKF" TARGET=arm64 TARGET_SYS=iOS clean make -j -C $LUAJIT HOST_CC="gcc " CROSS=$IOSBIN TARGET_FLAGS="$ISDKF" TARGET=arm64 TARGET_SYS=iOS mv $LUAJIT/src/libluajit.a $BUILD_DIR/libluajit64bit.a echo ================================================= echo IOS Simulator Architecture ISDKF="-arch x86_64 -isysroot $SIMDIR/SDKs/$SIMVER -miphoneos-version-min=7.0" make -j -C $LUAJIT HOST_CFLAGS="-arch x86_64" HOST_LDFLAGS="-arch x86_64" TARGET_SYS=iOS TARGET=x86_64 clean make -j -C $LUAJIT HOST_CFLAGS="-arch x86_64" HOST_LDFLAGS="-arch x86_64" TARGET_SYS=iOS TARGET=x86_64 amalg CROSS=$SIMBIN TARGET_FLAGS="$ISDKF" mv $LUAJIT/src/libluajit.a $BUILD_DIR/libluajitx86_64.a libtool -o $BUILD_DIR/libluajit21.a $BUILD_DIR/*.a 2> /dev/null mkdir -p $BUILD_DIR/Headers cp $LUAJIT/src/lua.h $BUILD_DIR/Headers cp $LUAJIT/src/lauxlib.h $BUILD_DIR/Headers cp $LUAJIT/src/lualib.h $BUILD_DIR/Headers cp $LUAJIT/src/luajit.h $BUILD_DIR/Headers cp $LUAJIT/src/lua.hpp $BUILD_DIR/Headers cp $LUAJIT/src/luaconf.h $BUILD_DIR/Headers mv $BUILD_DIR/libluajit21.a ../lib/ios
注意在编译模拟器的库时:
ISDKF="-arch x86_64 -isysroot $SIMDIR/SDKs/$SIMVER -miphoneos-version-min=7.0"
上面红色字体部分,该段主要用于编译模拟器的luajit库。由于xcode5.0后的更改,必须用这种方式指定编译为模拟器库,否则默认编译为macos.本人在这里折腾了很久。
集成
将luajit/build目录下的libluajit21.a链接到工程。
由于iphone5s以上虚拟机需要x86_64支持,luajit为了支持此模式需要在other
linker flags中增加参数
-pagezero_size 10000 -image_base 100000000
可能陷阱
1: 目前luajit 2.1只是alpha版本,有没有大的bug不清楚
2:在arm64平台下的luajit的bytecode与早前的bytecode有区别无法直接在mac下编译后在arm64平台使用。它使用了最新的lj_gc64与lj_fr2。所以直接在macos下编译的lua代码不能在ios上运行。需要上传源代码在ios下编译
时间: 2024-10-07 14:09:44