shaderc icon indicating copy to clipboard operation
shaderc copied to clipboard

How would one compile for iOS?

Open seivan opened this issue 5 years ago • 6 comments

Is it possible to build a lib for iOS as of today? Right now I’m converting glsl to spirv at buildtime since I can only make it work for macOS but it would be nice to be able to run it on a iOS device directly.

seivan avatar Apr 30 '19 22:04 seivan

There currently doesn't appear to be any build rules specific to iOS in the project, but I am not aware of anything that is known to be broken for iOS. There are some tests being run for iOS's version of metal, so I assume it might do something sane on iOS.

The project uses CMake for its build system, so you would probably need to look into how to integrate a CMake based library target into your iOS build system.

zoddicus avatar May 22 '19 18:05 zoddicus

What if I don't want to integrate with the rest of the iOS build system, but just to build a static lib for iOS? I'm a bit lost on where to look to start with that alone.

Edit: Where can I found those tests for running iOS version of metal? That sounds strange since you can't run Metal in a simulator.

seivan avatar May 23 '19 13:05 seivan

There is a cmake toolchain for iOS. I can't guarantee it will work, but it may be enough to get a static library out.

https://github.com/leetal/ios-cmake/blob/master/ios.toolchain.cmake

AWoloszyn avatar May 23 '19 14:05 AWoloszyn

I also need the iOS version of libshader_combined.a for runtime build of glsl. But it failed to build like this.

[ 73%] Building CXX object third_party/spirv-tools/tools/CMakeFiles/spirv-reduce.dir/reduce/reduce.cpp.o
build/src/shaderc/src/shaderc/third_party/spirv-tools/tools/reduce/reduce.cpp:34:18: error: 'system' is unavailable: not available on iOS
  int res = std::system(nullptr);

devmiyax avatar Mar 14 '21 05:03 devmiyax

Right now cmake fails this way:

"cmake" "/Users/lu_zero/.cargo/registry/src/github.com-1ecc6299db9ec823/shaderc-sys-0.6.3/build" "-G" "Ninja" "-DCMAKE_POSITION_INDEPENDENT_CODE=ON" "-DSPIRV_SKIP_EXECUTABLES=ON" "-DSPIRV_WERROR=OFF" "-DSHADERC_SKIP_TESTS=ON" "-DCMAKE_INSTALL_LIBDIR=lib" "-DCMAKE_OSX_SYSROOT=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk" "-DCMAKE_INSTALL_PREFIX=/private/tmp/bevy-demo/target/x86_64-apple-ios/debug/build/shaderc-sys-c1d61c609ca973e3/out" "-DCMAKE_C_FLAGS= -fPIC --target=x86_64-apple-ios -m64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk" "-DCMAKE_C_COMPILER=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "-DCMAKE_CXX_FLAGS= -fPIC --target=x86_64-apple-ios -m64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -fembed-bitcode" "-DCMAKE_CXX_COMPILER=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++" "-DCMAKE_ASM_FLAGS= -fPIC --target=x86_64-apple-ios -m64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk" "-DCMAKE_ASM_COMPILER=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" "-DCMAKE_BUILD_TYPE=Release"
  -- The C compiler identification is AppleClang 13.1.6.13160021
  -- The CXX compiler identification is AppleClang 13.1.6.13160021
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
  -- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang - broken
  -- Configuring incomplete, errors occurred!
  See also "/tmp/bevy-demo/target/x86_64-apple-ios/debug/build/shaderc-sys-c1d61c609ca973e3/out/build/CMakeFiles/CMakeOutput.log".
  See also "/tmp/bevy-demo/target/x86_64-apple-ios/debug/build/shaderc-sys-c1d61c609ca973e3/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  CMake Error at /usr/local/Cellar/cmake/3.21.4/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
    The C compiler

      "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: /tmp/bevy-demo/target/x86_64-apple-ios/debug/build/shaderc-sys-c1d61c609ca973e3/out/build/CMakeFiles/CMakeTmp
      
      Run Build Command(s):/usr/local/bin/ninja cmTC_4b36f && [1/2] Building C object CMakeFiles/cmTC_4b36f.dir/testCCompiler.c.o
      [2/2] Linking C executable cmTC_4b36f
      FAILED: cmTC_4b36f 
      : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -fPIC --target=x86_64-apple-ios -m64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -fembed-bitcode -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk  -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.5.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names  CMakeFiles/cmTC_4b36f.dir/testCCompiler.c.o -o cmTC_4b36f   && :
      ld: warning: -headerpad_max_install_names is ignored when used with -bitcode_bundle (Xcode setting ENABLE_BITCODE=YES)
      ld: building for iOS Simulator, but linking in .tbd file (/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd) built for macOS/Mac Catalyst, file '/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/lib/libSystem.tbd' for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)

lu-zero avatar Aug 25 '22 11:08 lu-zero

for those who are still compiling shaderc for iOS, system function call in spirv-tools need to be replace with popen, apply this patch and then compile

cd third_party/spirv-tools && git apply spirv-tools.patch && cd -

karelrooted avatar Nov 21 '23 14:11 karelrooted