Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails with SIMULATOR and default parameters #2

Closed
lebdron opened this issue Mar 19, 2018 · 4 comments
Closed

Build fails with SIMULATOR and default parameters #2

lebdron opened this issue Mar 19, 2018 · 4 comments

Comments

@lebdron
Copy link

lebdron commented Mar 19, 2018

Building google protocol buffers with the following command fails:

cmake -DCMAKE_TOOLCHAIN_FILE=./ios-cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DCMAKE_INSTALL_PREFIX=./dependencies -Dprotobuf_BUILD_TESTS=OFF -H./protobuf/cmake -B./protobuf/.build

The following error occurs:

[ 40%] Linking CXX executable js_embed
/usr/local/Cellar/cmake/3.10.2/bin/cmake -E cmake_link_script CMakeFiles/js_embed.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++  -mios-simulator-version-min=8.0 -fembed-bitcode-marker -fvisibility=hidden -fvisibility-inlines-hidden -fobjc-abi-version=2 -fobjc-arc  -g -arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator11.2.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/js_embed.dir/protobuf/src/google/protobuf/compiler/js/embed.cc.o  -o js_embed
ld: warning: -headerpad_max_install_names is ignored when used with -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES)
ld: '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a(arclite.o)' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphonesimulator.a' for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [js_embed] Error 1
make[1]: *** [CMakeFiles/js_embed.dir/all] Error 2
make: *** [all] Error 2

It seems that ARC and bitcode are incompatible with SIMULATOR build:

for file in $(ls /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc); do echo $file; otool -l $file| grep __LLVM | uniq;done

libarclite_appletvos.a
   segname __LLVM
libarclite_appletvsimulator.a
libarclite_iphoneos.a
   segname __LLVM
libarclite_iphonesimulator.a
libarclite_macosx.a
libarclite_watchos.a
   segname __LLVM
libarclite_watchsimulator.a
   segname __LLVM
@leetal
Copy link
Owner

leetal commented Mar 19, 2018

Hmm.. I'll have to verify this at work tomorrow. But it seems some of the flags are being overridden somehow by the CMakeLists.txt in the protobuf project. Is it the standard google protobuf repo you are trying to build with the toolchain?

@lebdron
Copy link
Author

lebdron commented Mar 20, 2018

Yes, standard repo (not the latest master though), but the build process is somewhat not trivial, because build requires some binaries on host system:

git clone https://github.com/google/protobuf
(cd ./protobuf ; git checkout 80a37e0782d2d702d52234b62dd4b9ec74fd2c95)
cmake -DCMAKE_BUILD_TYPE=Debug -Dprotobuf_BUILD_TESTS=OFF -H./protobuf/cmake -B./protobuf/host_build # build for host to get js_embed
VERBOSE=1 cmake --build ./protobuf/host_build
sed -i .bak "s~COMMAND js_embed~COMMAND $(pwd)/protobuf/host_build/js_embed~" ./protobuf/cmake/libprotoc.cmake
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$(pwd)/ios-cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DCMAKE_INSTALL_PREFIX=./dependencies -Dprotobuf_BUILD_TESTS=OFF -H./protobuf/cmake -B./protobuf/.build
VERBOSE=1 cmake --build ./protobuf/.build --target install

@leetal
Copy link
Owner

leetal commented Mar 28, 2018

So, i have now checked the situation, and it all seems very reasonable for Apple not to include bitcode in ARClite for simulator builds. Bitcode is only used by Apple for recompiling the binary blobs for newer SDKs and such. And since simulator slices are removed (more like prohibited by Apple) in AppStore-builds, there is little to no reason for them to supply bitcode in ARClite for simulator builds.

After digging through the protobuf code, my recommendation to you is to simply build libprotobuf without ARC, by supplying -DENABLE_ARC=0.

So, the correct commands would look like:

git clone https://github.com/google/protobuf
(cd ./protobuf ; git checkout 80a37e0782d2d702d52234b62dd4b9ec74fd2c95)
cmake -DCMAKE_BUILD_TYPE=Debug -Dprotobuf_BUILD_TESTS=OFF -H./protobuf/cmake -B./protobuf/host_build # build for host to get js_embed
VERBOSE=1 cmake --build ./protobuf/host_build
sed -i .bak "s~COMMAND js_embed~COMMAND $(pwd)/protobuf/host_build/js_embed~" ./protobuf/cmake/libprotoc.cmake
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=$(pwd)/ios-cmake/ios.toolchain.cmake -DIOS_PLATFORM=SIMULATOR -DENABLE_ARC=0 -DCMAKE_INSTALL_PREFIX=./dependencies -Dprotobuf_BUILD_TESTS=OFF -H./protobuf/cmake -B./protobuf/.build
VERBOSE=1 cmake --build ./protobuf/.build --target install

The resulting files under .dependencies will contain the LLVM slices required.

This way, you would be able to build with bitcode (but with ARC disabled for libprotobuf, since it seems that there is no need for it), even for the simulator (to ease one´s life a little). :)

@leetal
Copy link
Owner

leetal commented Mar 28, 2018

I will close this issue, since it is more a problem with documentation of the protobuf library, than an error with this toolchain.

@leetal leetal closed this as completed Mar 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants