stasel / WebRTC

Unofficial distribution of up to date WebRTC framework binaries for iOS and macOS
Other
359 stars 76 forks source link

Error when trying to generate a framework with the build script #29

Closed fndmaioli closed 2 years ago

fndmaioli commented 2 years ago

Hello, i'm trying to generate a framework using your build.sh script but i keep getting the same error and i'm not sure how to solve it. It seems that it manages to execute the gn gen command, but then it fails when trying to build with Ninja. The error message ld64.lld: error: unable to find matching architecture in ../../third_party/llvm-build/Release+Asserts/lib/clang/14.0.0/lib/darwin/libclang_rt.iossim.a is the same one i got when using these commands to build the framework without the script.

This is the message i get:

Done. Made 1187 targets from 244 files in 1276ms
ninja: Entering directory `./out/ios-arm64-simulator'
[3437/3445] SOLINK obj/sdk/arm64/WebRTC obj/sdk/arm64/WebRTC.TOC
FAILED: obj/sdk/arm64/WebRTC obj/sdk/arm64/WebRTC.TOC 
if [ ! -e "obj/sdk/arm64/WebRTC" -o ! -e "obj/sdk/arm64/WebRTC.TOC" ] || ../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "obj/sdk/arm64/WebRTC" | grep -q LC_REEXPORT_DYLIB ; then TOOL_VERSION=1641494109 ../../build/toolchain/apple/linker_driver.py -Wcrl,strippath,../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -all_load -install_name @rpath/WebRTC.framework/WebRTC -Wl,-install_name,@rpath/WebRTC.framework/WebRTC -fuse-ld=lld -Wl,-fatal_warnings -Wl,--icf=all -Wl,--color-diagnostics -target arm64-apple-ios12.0-simulator -no-canonical-prefixes -Werror -Wl,-dead_strip -nostdlib++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -Wl,-ObjC -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,@loader_path/Frameworks -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -o "obj/sdk/arm64/WebRTC" "@obj/sdk/arm64/WebRTC.rsp" && { ../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "obj/sdk/arm64/WebRTC" | grep LC_ID_DYLIB -A 5; ../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm -gPp "obj/sdk/arm64/WebRTC" | cut -f1-2 -d' ' | grep -v U$$; true; } > "obj/sdk/arm64/WebRTC.TOC"; else TOOL_VERSION=1641494109 ../../build/toolchain/apple/linker_driver.py -Wcrl,strippath,../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/strip ../../third_party/llvm-build/Release+Asserts/bin/clang++ -shared -all_load -install_name @rpath/WebRTC.framework/WebRTC -Wl,-install_name,@rpath/WebRTC.framework/WebRTC -fuse-ld=lld -Wl,-fatal_warnings -Wl,--icf=all -Wl,--color-diagnostics -target arm64-apple-ios12.0-simulator -no-canonical-prefixes -Werror -Wl,-dead_strip -nostdlib++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk -Wl,-ObjC -Wl,-rpath,@executable_path/Frameworks -Wl,-rpath,@loader_path/Frameworks -L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator -o "obj/sdk/arm64/WebRTC" "@obj/sdk/arm64/WebRTC.rsp" && { ../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/otool -l "obj/sdk/arm64/WebRTC" | grep LC_ID_DYLIB -A 5; ../../../../../../../../Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/nm -gPp "obj/sdk/arm64/WebRTC" | cut -f1-2 -d' ' | grep -v U$$; true; } > "obj/sdk/arm64/WebRTC.tmp" && if ! cmp -s "obj/sdk/arm64/WebRTC.tmp" "obj/sdk/arm64/WebRTC.TOC"; then mv "obj/sdk/arm64/WebRTC.tmp" "obj/sdk/arm64/WebRTC.TOC" ; fi; fi
ld64.lld: error: unable to find matching architecture in ../../third_party/llvm-build/Release+Asserts/lib/clang/14.0.0/lib/darwin/libclang_rt.iossim.a
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
Traceback (most recent call last):
  File "../../build/toolchain/apple/linker_driver.py", line 291, in <module>
    LinkerDriver(sys.argv).run()
  File "../../build/toolchain/apple/linker_driver.py", line 116, in run
    subprocess.check_call(compiler_driver_args, env=env)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 190, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['../../third_party/llvm-build/Release+Asserts/bin/clang++', '-shared', '-all_load', '-install_name', '@rpath/WebRTC.framework/WebRTC', '-Wl,-install_name,@rpath/WebRTC.framework/WebRTC', '-fuse-ld=lld', '-Wl,-fatal_warnings', '-Wl,--icf=all', '-Wl,--color-diagnostics', '-target', 'arm64-apple-ios12.0-simulator', '-no-canonical-prefixes', '-Werror', '-Wl,-dead_strip', '-nostdlib++', '-isysroot', '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk', '-Wl,-ObjC', '-Wl,-rpath,@executable_path/Frameworks', '-Wl,-rpath,@loader_path/Frameworks', '-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator15.2.sdk/usr/lib/swift', '-L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphonesimulator', '-o', 'obj/sdk/arm64/WebRTC', '@obj/sdk/arm64/WebRTC.rsp']' returned non-zero exit status 1
ninja: build stopped: subcommand failed.
isadon commented 2 years ago

Getting the same thing. I believe this error is due to the architecture being passed in is not compatible with clang14 which ninja is now bundling in src/third-party. Also the gn arg use_xcode_clang is no longer supported. I believe the build script needs to be modified to fix or workaround some of these issues and also to support building with Bitcode enabled which requires removing -mllvm args in src/build/config/compiler/BUILD.gn.

isadon commented 2 years ago

So after some more digging: build M96(the latest WebRTC code used in this repo as of this date) has this code in src/build/config/ios/BUILD.gn:

# TODO(crbug.com/1223481): Temporarily use a different
  # libclang_rt.iossim.a for arm64 simulator builds. This can be
  # removed when an arm64 slice is added to upstream Clang.
  if (false) {
    ldflags += [
      "-lSystem",
      rebase_path("$ios_toolchains_path/usr/lib/clang/13.0.0/" +
                      "lib/darwin/libclang_rt.iossim.a",
                  root_build_dir),
      "-nodefaultlibs",
    ]
  }

That obviously won't ever be executed because the if condition always fails. Why is it false? I don't know, but it shouldn't be false because indeed the error above is being caused because the bundled third_party/llvm-build/Release+Asserts/lib/clang/14.0.0/lib/darwin/libclang_rt.iossim.a doesn't include the arm64 simulator architecture.

You can verify this to be the case by doing file libclang_rt.iossim.a and getting:

libclang_rt.iossim.a: Mach-O universal binary with 2 architectures: [i386:current ar archive random library] [x86_64:current ar archive random library]
libclang_rt.iossim.a (for architecture i386):   current ar archive random library
libclang_rt.iossim.a (for architecture x86_64): current ar archive random library

Notice that an arm64 target is not included in there.

I'm not sure where the if (false) is coming from to be honest but chromium's source code instead has:

 # TODO(crbug.com/1223481): Temporarily use a different
  # libclang_rt.iossim.a for arm64 simulator builds. This can be
  # removed when an arm64 slice is added to upstream Clang.
  if (target_environment == "simulator" && current_cpu == "arm64") {
    assert(xcode_version_int == 1300)
    ldflags += [
      "-lSystem",
      rebase_path("$ios_toolchains_path/usr/lib/clang/13.0.0/" +
                      "lib/darwin/libclang_rt.iossim.a",
                  root_build_dir),
      "-nodefaultlibs",
    ]
  }

This looks correct (apart from the strict xcode version 13.0.0 check) and would make the build work because it would swap out the libclang_rt.iossim.a file from xcode correctly.

Also please note there is corresponding bug report in webrtc here where they are awaiting for apple to properly include the proper architecture in clang 14. Once that is truly done then the if check and its code won't be needed. As of now it is still needed however which goes against the if (false) implying that it isn't. I can't track where that if (false) is coming from in WebRTC's M96 code, once I can find that a bug report can be filed on WebRTC itself.

Some further info: Even if you manually edit src/build/config/ios/BUILD.gn to be like chromium's check so that the build works, running build.sh, runs ninja, which for some odd reason resets src/build/config/ios/BUILD.gn to its original state and wipes out any edits. Only thing I can think of right now is to manually replace third_party/llvm-build/Release+Asserts/lib/clang/14.0.0/lib/darwin/libclang_rt.iossim.a with Xcode's and hopefully the build works.

stasel commented 2 years ago

Update: Compiling M97 - M102 was a mess. M103 can be compiled with no tricks or modifications to the build scripts.