Compiling LuaJIT for iOS Simulator - ios

Does anyone know the correct flags to pass to make in order to cross compile LuaJIT for the iOS Simulator? I managed to get it running on a device, but I am having trouble building for the simulator, I can't find a working example anywhere on the webs.
Thanks!!
Inside LuaJIT checkout (I'm using v2.1 branch):
IXCODE=`xcode-select -p`
ISDK=$IXCODE/Platforms/iPhoneSimulator.platform/Developer
ISDKVER=iPhoneSimulator8.1.sdk
ISDKP=/usr/bin/
ISDKF="-arch i386 -isysroot $ISDK/SDKs/$ISDKVER"
make clean
make HOST_CFLAGS="-arch i386" HOST_LDFLAGS="-arch i386" TARGET=x86 CROSS=$ISDKP TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS
This is the error message I am getting:
ld: building for MacOSX, but linking against dylib built for iOS Simulator file '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator8.1.sdk/usr/lib/libSystem.dylib' for architecture i386
Building for armv7 works:
IXCODE=`xcode-select -p`
ISDK=$IXCODE/Platforms/iPhoneOS.platform/Developer
ISDKVER=iPhoneOS8.1.sdk
ISDKP=/usr/bin/
ISDKF="-arch armv7 -isysroot $ISDK/SDKs/$ISDKVER"
make clean
make HOST_CC="gcc -m32 -arch i386" CROSS=$ISDKP TARGET_FLAGS="$ISDKF" TARGET_SYS=iOS

add -mios-simulator-version-min=8.1 to your TARGET_FLAGS
ISDKF="-arch i386 -isysroot $ISDK/SDKs/$ISDKVER"
should be
ISDKF="-arch i386 -mios-simulator-version-min=8.1 -isysroot $ISDK/SDKs/$ISDKVER"
you may also have to set the
BUILDMODE="static"
and you may need to set ios-simulator-version-min to match the simulator sdk version. 8.2 is for Xcode 6.2.

Related

Creating iOS universal framework with Xcode 9

I am creating universal framework for iOS. I am trying to create one through lipo and it does create a universal one
I check the architecture with lipo after creation it returns me correct:
Architectures in the fat file: i386 x86_64 armv7 arm64
I run the application on phone and simulator that works fine as well.. But when I try to export the .ipa from xcarchive I get the following error:
Failed to verify bitcode in Myframework.framework/Myframework:\nerror: Platform iPhoneSimulator is not supported\n\n
Also I can the bitcode symbols in my universal framework running
otool -l /Path/To/Framework | grep __LLVM
segname __LLVM
segname __LLVM
If I choose only iphoneos framework that works fine
You need to strip i386 and x86_64 from the framework before exporting the archive.
e.g.
$ lipo -remove i386 ./path/to/binary_name -o ./path/to/binary_name
$ lipo -remove x86_64 ./path/to/binary_name -o ./path/to/binary_name
You need to do this, since i386 and x86_64 are not supported for export -- "Platform iPhoneSimulator is not supported"

Bitcode and dylib

I am trying to compile a C library to use it in my iOS project, and I want to embed bitcode.
I can successfully build static libraries targeting each arch. And those static library do contain bitcode (checked using otool), but the dynamic library doesn't contain bitcode. Why? Is bitcode not supported in dylib?
The library I am trying to build is xz. Here is the script
build_iOS()
{
ARCH=$1
if [ $ARCH == "i386" ] || [ $ARCH == "x86_64" ];
then
SDKROOT="$(xcodebuild -version -sdk iphonesimulator | grep -E '^Path' | sed 's/Path: //')"
else
SDKROOT="$(xcodebuild -version -sdk iphoneos | grep -E '^Path' | sed 's/Path: //')"
fi
export CC="$(xcrun -sdk iphoneos -find clang)"
export CFLAGS="-fembed-bitcode -isysroot $SDKROOT -arch ${ARCH} -miphoneos-version-min=9.0"
export LDFLAGS="-arch ${ARCH} -isysroot $SDKROOT"
if [ $ARCH == "i386" ] || [ $ARCH == "x86_64" ];
then
./configure --prefix=$XZPATH/build/iOS/$ARCH --host=i686-apple-darwin11 --disable-static --enable-shared
else
./configure --prefix=$XZPATH/build/iOS/$ARCH --host=arm-apple-darwin --disable-static --enable-shared
fi
make && make install && make clean
}
build_iOS i386
build_iOS x86_64
build_iOS armv7
build_iOS armv7s
build_iOS arm64
Thanks!
It looks like I cannot add bitcode to dylibs. I tried building several dylibs, then use otool -l path_to_dylib | grep bitcode to test if they contain any bitcode, all got nothing.
More evidence:
in Xcode(7.3.1), macOS (previously called OS X) targets don't have enable bitcode option in build settings
in the bitcode section of App Thinning, Apple didn't mentioned bitcode on macOS. Plus, App Thinning is only available on iOS, watchOS and tvOS.
I currently don't know why macOS apps don't have enable bitcode option in build setting. Maybe it's because Mac App store is not the only way for distributing mac apps? And people might copy one mac app from one mac app to another using USB sticks?
I was not able to verify bitcode in my bitcode enabled dynamic library via cmd line tools (otool, file or clang). Also comparing the diff between bitcode and non-bitcode build showed no difference, except the filesize.
Interestingly when using the dynamic library withouth bitcode enabled in an actual app and archiving xcode will fail to archive when I use the non-bitcode build:
ld: bitcode bundle could not be generated because '...' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture armv7
When building the dylib with bitcode enabled the filesize increases a lot and also xcode does not fail on archiving a sample project with bitcode enabled. So I am pretty sure that bitcode must be included in the dynamic lib, although we haven't found a way to verify that via cmd line tools yet...

How can I cross-compile GCC to produce libgfortran for iOS devices (arm, armv7)?

I need to compile Fortran-77 subroutines to be accessible on iOS. I am using GCC with the DragonEgg plugin, so I can use gfortran with the LLVM backend. I followed this answer but I am stuck when it comes to build libgfortran for armv7, armv7s and arm64.
Can I build libgfortran alone or is it always necessary to compile the GCC suite completely?
What is the correct way of producing this library for a different target? Is it possible to use GCC for this step or do I need LLVM for the arm*-targets?
Building GCC with arm-targets using GCC I get these errors:
./configure --prefix=/tmp/out --host=arm-apple-darwin --enable-languages=fortran
make
…
make[2]: arm-apple-darwin-ar: No such file or directory
make[2]: *** [libiberty.a] Error 1
make[1]: *** [all-libiberty] Error 2
Building GCC with arm-targets using LLVM I have problems with configure:
export CC="$(xcrun -sdk iphoneos -find clang)"
export CPP="$CC -E"
export CFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=9.2"
export AR=$(xcrun -sdk iphoneos -find ar)
export RANLIB=$(xcrun -sdk iphoneos -find ranlib)
export CPPFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path) -miphoneos-version-min=9.2"
export LDFLAGS="-arch armv7 -arch armv7s -arch arm64 -isysroot $(xcrun --sdk iphoneos --show-sdk-path)"
./configure --prefix=/tmp/out --enable-languages=fortran --host=arm-apple-darwin --disable-shared
…
checking how to run the C preprocessor... /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E
configure: error: in `/Users/timo/temp/gcc-4.8.5-build/fixincludes':
configure: error: C preprocessor "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -E" fails sanity check
See `config.log' for more details.
make[1]: *** [configure-fixincludes] Error 1
The configure script states that
configure: WARNING: If you wanted to set the --build type, don't use --host.
If a cross compiler is detected then cross compile mode will be used.
What is meant by If a cross compiler is detected? How do I define the target platform correctly?
LLVM uses -arch armv7 etc. as target definition. What is nedded when using GCC?
You are trying to build cross-gcc libraries without cross binutils. Here is a good manual for building cross-gcc for arm, you can follow it.
What is meant by If a cross compiler is detected? How do I define the
target platform correctly?
When configuring you should also set --target=arm-apple-darwin. (In my own experience I did not set --host at all)
make[2]: arm-apple-darwin-ar: No such file or directory
Before building arm cross-compiler target libraries you should build binutils for this target.
Can't say anything about llvm.
So just try to make all steps in the link above.

Compiling to get armv7s slice

I am compiling libraries in the terminal with the following command to get an armv7 slice:
./configure CC=/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 --host=arm
NOTE: I also change the ldflags, sysroot to provide the relevant path, although I don´t show that here to keep this short.
I have successfully generated code slices for: i686, i386 and armv7 and combined them, but I can´t get an armv7s slice.
What settings do I use for armv7s code slice?
You should specify -arch armv7s in CFLAGS. Below is what I use to build ICU:
INSTALL=`pwd`/..
if [ $# -eq 0 ]
then
$0 armv7 iPhoneOS
$0 armv7s iPhoneOS
$0 i386 iPhoneSimulator
mkdir -p $INSTALL/universal/lib
cd $INSTALL/armv7/lib
for f in *.a
do
echo $f
xcrun -sdk iphoneos lipo -output ../../universal/lib/$f -create -arch armv7 $f -arch armv7s ../../armv7s/lib/$f -arch i386 ../../i386/lib/$f
done
#cd ../..
else
echo $1 $2
ARCH=$1
PLATFORM=$2
TOOLCHAIN=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain
export CC="$TOOLCHAIN/usr/bin/clang"
DEVROOT=/Applications/Xcode.app/Contents/Developer/Platforms/$PLATFORM.platform/Developer
SDK=6.1
SDKROOT=$DEVROOT/SDKs/$PLATFORM$SDK.sdk
export CFLAGS="-arch $ARCH -isysroot $SDKROOT -miphoneos-version-min=5.0 -I/Users/xxx/icu/source/tools/tzcode"
export CXXFLAGS="$CFLAGS"
gnumake distclean
../../icu/source/configure --host=arm-apple-darwin --enable-static --disable-shared --with-cross-build=/Users/xxx/icu-build/mac --prefix=$INSTALL/$ARCH
gnumake
gnumake install
fi
You could do something similar to get what you want.
EDIT: How to call make with clang:
export CFLAGS=-arch armv7s # add more compiler flags as needed here
export CC=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
make
I've combined the crt.1.x.x.0, libarclite, and libclang Xcode of the three current device architectures in order to support armv6, armv7, and armv7s for my iOS app.
Original Stack Overflow post that helped me: https://stackoverflow.com/a/12836808/761902.
Since you are trying to compile a ARM (conventional iOS device) and Intel (OS X computer) architectures into one file, you can try getting the crt, libarclite, and libclang files specified in the original post.
As the ARM files were located under
Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/,
I would expect the equivalent i386 files to be located under
Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/
, I'm not sure what Xcode build platform i686 falls under since I don't recall seeing that before, but if it is a iPhoneSimulator.platform, it would be in the same files as the i386 platform.
You might also want to add i686 and i386 to your build settings. The below are my architecture settings for building for armv6, armv7, and armv7s.
If that doesn't work, you can also build i686, i386, and armv7s separately and merge the built binaries with lipo.

Building FFTW 3.3.3 for iPhone

I want to build FFTW library for iPhone and use this script:
#!/bin/bash
export SDKVER="6.0"
export DEVROOT="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer"
export SDKROOT="$DEVROOT/SDKs/iPhoneOS$SDKVER.sdk"
export CFLAGS="$CPPFLAGS -isysroot $SDKROOT"
export LDFLAGS="$CFLAGS -Wl,-syslibroot $SDKROOT"
export CC=$DEVROOT/usr/bin/arm-apple-darwin10-llvm-gcc-4.2
export LD=$DEVROOT/usr/bin/ld
export PREFIX="$HOME/Desktop/mylib"
./configure --prefix="$PREFIX" --enable-single --host=arm-apple-darwin
make
make install
Then I import libfftw3f.a and fftw3.h in Xcode in my project, link this library in Build Phases.
When I try to compile, Xcode gives me this warning:
ld: warning: ignoring file /Users/Adem/Desktop/mylib/lib/libfftw3f.a, file was built for archive which is not the architecture being linked (armv7s): /Users/Adem/Desktop/mylib/lib/libfftw3f.a
What am I doing wrong?
Try adding -arch armv7 to your CFLAGS (and hence also to your LDFLAGS)

Resources