Lakelezz / audiopus_sys

Rust FFI-binding of Opus.
ISC License
14 stars 21 forks source link

Compilation on aarch64-apple-ios fails. #11

Open kmonkey opened 1 year ago

kmonkey commented 1 year ago

My project uses opus-rs v0.3.0 which references audiopus-sys v0.2.2. When I specified aarch64-apple-ios as the target to build for iOS, the following error was displayed.

(*'-') < cargo build --target aarch64-apple-ios --release                                                                                                                                                                                            [dev]
    Updating crates.io index
   Compiling ring v0.16.20
   Compiling rustls v0.20.6
   Compiling num-complex v0.3.1
   Compiling ordered-float v2.10.0
   Compiling rmp v0.8.11
   Compiling cexpr v0.6.0
   Compiling audiopus_sys v0.2.2
   Compiling serde_derive v1.0.137
   Compiling tokio-macros v1.8.0
   Compiling futures-macro v0.3.21
   Compiling darling_core v0.13.4
   Compiling thiserror-impl v1.0.31
   Compiling num-bigint v0.3.3
   Compiling num-iter v0.1.43
   Compiling async-trait v0.1.56
   Compiling async-stream-impl v0.3.3
   Compiling crypto-common v0.1.3
   Compiling block-buffer v0.10.2
   Compiling hashbrown v0.11.2
   Compiling bindgen v0.59.2
error: failed to run custom build command for `audiopus_sys v0.2.2`

Caused by:
  process didn't exit successfully: `player-rs/target/release/build/audiopus_sys-4e38d88cac7bbdab/build-script-build` (exit status: 101)
  --- stdout
  cargo:info=No feature or environment variable found, linking by default.
  cargo:rerun-if-env-changed=OPUS_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64-apple-ios
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_aarch64_apple_ios
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-ios
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_ios
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-ios
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_ios
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  cargo:info=`pkg_config` could not find `Opus`.
  cargo:info=Opus source path used: "/Users/xxxxxx/.cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus".
  cargo:info=Building Opus via CMake.
  CMAKE_TOOLCHAIN_FILE_aarch64-apple-ios = None
  CMAKE_TOOLCHAIN_FILE_aarch64_apple_ios = None
  TARGET_CMAKE_TOOLCHAIN_FILE = None
  CMAKE_TOOLCHAIN_FILE = None
  CMAKE_GENERATOR_aarch64-apple-ios = None
  CMAKE_GENERATOR_aarch64_apple_ios = None
  TARGET_CMAKE_GENERATOR = None
  CMAKE_GENERATOR = None
  running: "xcrun" "--show-sdk-path" "--sdk" "iphoneos"
  exit status: 0
  running: "xcrun" "--show-sdk-path" "--sdk" "iphoneos"
  exit status: 0
  CMAKE_PREFIX_PATH_aarch64-apple-ios = None
  CMAKE_PREFIX_PATH_aarch64_apple_ios = None
  TARGET_CMAKE_PREFIX_PATH = None
  CMAKE_PREFIX_PATH = None
  CMAKE_aarch64-apple-ios = None
  CMAKE_aarch64_apple_ios = None
  TARGET_CMAKE = None
  CMAKE = None
  running: "cmake" "/Users/xxxxxx/.cargo/registry/src/github.com-1ecc6299db9ec823/audiopus_sys-0.2.2/opus" "-DCMAKE_OSX_SYSROOT=/" "-DCMAKE_OSX_DEPLOYMENT_TARGET=" "-DCMAKE_INSTALL_PREFIX=/Users/xxxxx/Documents/job/git/ios/player-rs/target/aarch64-apple-ios/release/build/audiopus_sys-736f1bafad9309c3/out" "-DCMAKE_C_FLAGS= -fPIC --target=aarch64-apple-ios -arch arm64 -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -fembed-bitcode" "-DCMAKE_C_COMPILER=/usr/bin/clang" "-DCMAKE_CXX_FLAGS= -fPIC --target=aarch64-apple-ios -arch arm64 -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -fembed-bitcode" "-DCMAKE_CXX_COMPILER=/usr/bin/clang++" "-DCMAKE_ASM_FLAGS= -fPIC --target=aarch64-apple-ios -arch arm64 -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -fembed-bitcode" "-DCMAKE_ASM_COMPILER=/usr/bin/clang" "-DCMAKE_BUILD_TYPE=Release"
  -- Opus project version: 0
  -- The C compiler identification is AppleClang 13.1.6.13160021
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - failed
  -- Check for working C compiler: /usr/bin/clang
  -- Check for working C compiler: /usr/bin/clang - broken
  -- Configuring incomplete, errors occurred!
  See also "/Users/xxxx/Documents/job/ios/player-rs/target/aarch64-apple-ios/release/build/audiopus_sys-736f1bafad9309c3/out/build/CMakeFiles/CMakeOutput.log".
  See also "/Users/xxxx/Documents/job/ios/player-rs/target/aarch64-apple-ios/release/build/audiopus_sys-736f1bafad9309c3/out/build/CMakeFiles/CMakeError.log".

  --- stderr
  CMake Warning at cmake/OpusPackageVersion.cmake:61 (message):
    Could not get package version.
  Call Stack (most recent call first):
    CMakeLists.txt:5 (get_package_version)

  CMake Error at /opt/homebrew/Cellar/cmake/3.24.1/share/cmake/Modules/CMakeTestCCompiler.cmake:69 (message):
    The C compiler

      "/usr/bin/clang"

    is not able to compile a simple test program.

    It fails with the following output:

      Change Dir: /Users/xxxx/ios/player-rs/target/aarch64-apple-ios/release/build/audiopus_sys-736f1bafad9309c3/out/build/CMakeFiles/CMakeTmp

      Run Build Command(s):/usr/bin/make -f Makefile cmTC_d8f2e/fast && /Applications/Xcode.app/Contents/Developer/usr/bin/make  -f CMakeFiles/cmTC_d8f2e.dir/build.make CMakeFiles/cmTC_d8f2e.dir/build
      Building C object CMakeFiles/cmTC_d8f2e.dir/testCCompiler.c.o
      /usr/bin/clang   -fPIC --target=aarch64-apple-ios -arch arm64 -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -fembed-bitcode  -arch x86_64 -MD -MT CMakeFiles/cmTC_d8f2e.dir/testCCompiler.c.o -MF CMakeFiles/cmTC_d8f2e.dir/testCCompiler.c.o.d -o CMakeFiles/cmTC_d8f2e.dir/testCCompiler.c.o -c /Users/xxxxx/Documents/job/ios/player-rs/target/aarch64-apple-ios/release/build/audiopus_sys-736f1bafad9309c3/out/build/CMakeFiles/CMakeTmp/testCCompiler.c
      Linking C executable cmTC_d8f2e
      /opt/homebrew/Cellar/cmake/3.24.1/bin/cmake -E cmake_link_script CMakeFiles/cmTC_d8f2e.dir/link.txt --verbose=1
      /usr/bin/clang  -fPIC --target=aarch64-apple-ios -arch arm64 -miphoneos-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk -fembed-bitcode  -arch x86_64 -Wl,-search_paths_first  CMakeFiles/cmTC_d8f2e.dir/testCCompiler.c.o -o cmTC_d8f2e
      ld: warning: ignoring file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk/usr/lib/libSystem.tbd, missing required architecture x86_64 in file /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.5.sdk/usr/lib/libSystem.tbd (4 slices)
      ld: dynamic main executables must link with libSystem.dylib for architecture x86_64
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      make[1]: *** [cmTC_d8f2e] Error 1
      make: *** [cmTC_d8f2e/fast] Error 2

    CMake will not be able to correctly generate this project.
  Call Stack (most recent call first):
    CMakeLists.txt:7 (project)

  thread 'main' panicked at '
  command did not execute successfully, got: exit status: 1

  build script failed, must exit now', /Users/xxxx/.cargo/registry/src/github.com-1ecc6299db9ec823/cmake-0.1.48/src/lib.rs:975:5
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

I don't know if it's the best way, but I was able to compile by setting some environment variables with reference to the link below. https://cmake.org/cmake/help/latest/manual/cmake-toolchains.7.html#cross-compiling-for-ios-tvos-or-watchos

export CMAKE_OSX_ARCHITECTURES="arm64"                                                                                                                                                                                                                         
export CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH="NO"                                                                             
export CMAKE_IOS_INSTALL_COMBINED="YES"

The best way is to just pass the target to cargo and it will compile, any good ideas?

jkelleyrtp commented 1 year ago

Thank you for the exports on iOS. Do you have an idea of what the env vars might be for android?

lgmarchi commented 8 months ago

I am having same problem yet, even after set CMAKE variables. @kmonkey Were you able to build for android as well?