1

So I've build the following fat binary

➜  wallet-core git:(m/rust_fix) ✗ lipo -detailed_info build/local/catalyst/libwallet_core_rs.a
Fat header in: build/local/catalyst/libwallet_core_rs.a
fat_magic 0xcafebabe
nfat_arch 2
architecture x86_64
    cputype CPU_TYPE_X86_64
    cpusubtype CPU_SUBTYPE_X86_64_ALL
    capabilities 0x0
    offset 48
    size 1038808
    align 2^3 (8)
architecture arm64
    cputype CPU_TYPE_ARM64
    cpusubtype CPU_SUBTYPE_ARM64_ALL
    capabilities 0x0
    offset 1038856
    size 2649760
    align 2^3 (8)

Using the tutorial https://nadim.computer/posts/2022-02-11-maccatalyst.html

and use xcodebuild to build a xcframework from different fat libs in order to create a universal framework:

#!/bin/bash

set -e

TARGET_NAME="libwallet_core_rs.a"
TARGET_XCFRAMEWORK_NAME=../swift/WalletCoreRs.xcframework
BUILD_FOLDER=../build/local
CRATE="wallet-core-rs"
HEADER_NAME="WalletCoreRSBindgen.h"

create_xc_framework() {
  rm -rf $TARGET_XCFRAMEWORK_NAME
  xcodebuild -create-xcframework -library $BUILD_FOLDER/$TARGET_NAME -library $BUILD_FOLDER/darwin_universal/$TARGET_NAME -library $BUILD_FOLDER/aarch64-apple-ios/release/$TARGET_NAME -library $BUILD_FOLDER/catalyst/$TARGET_NAME -output $TARGET_XCFRAMEWORK_NAME
}

cd rust

echo "Generating Native targets"
CARGO_TARGET_DIR=$BUILD_FOLDER/ cargo build --release
CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target wasm32-unknown-emscripten --release
if [[ `uname` == "Darwin" ]]; then
  echo "Generating Android targets"
  CARGO_TARGET_DIR=$BUILD_FOLDER/ cargo build --target aarch64-linux-android --release
  CARGO_TARGET_DIR=$BUILD_FOLDER/ cargo build --target armv7-linux-androideabi --release
  CARGO_TARGET_DIR=$BUILD_FOLDER/ cargo build --target x86_64-linux-android --release
  CARGO_TARGET_DIR=$BUILD_FOLDER/ cargo build --target i686-linux-android --release
  echo "Generating iOS targets"
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target aarch64-apple-ios --release
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target aarch64-apple-ios-sim --release
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target x86_64-apple-ios --release
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target aarch64-apple-darwin --release
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo build --target x86_64-apple-darwin --release
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo +nightly build -Z build-std --target aarch64-apple-ios-macabi --release --lib
  CARGO_TARGET_DIR=$BUILD_FOLDER cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi --release --lib
  lipo $BUILD_FOLDER/x86_64-apple-ios/release/$TARGET_NAME $BUILD_FOLDER/aarch64-apple-ios-sim/release/$TARGET_NAME -create -output $BUILD_FOLDER/$TARGET_NAME
  mkdir -p $BUILD_FOLDER/darwin_universal
  lipo $BUILD_FOLDER/x86_64-apple-darwin/release/$TARGET_NAME $BUILD_FOLDER/aarch64-apple-darwin/release/$TARGET_NAME -create -output $BUILD_FOLDER/darwin_universal/$TARGET_NAME
  mkdir -p $BUILD_FOLDER/catalyst
  lipo $BUILD_FOLDER/aarch64-apple-ios-macabi/release/$TARGET_NAME $BUILD_FOLDER/x86_64-apple-ios-macabi/release/$TARGET_NAME -create -output $BUILD_FOLDER/catalyst/$TARGET_NAME

  create_xc_framework
fi
cbindgen --crate $CRATE --output ../src/rust/bindgen/$HEADER_NAME
cd -
cp build/local/release/${TARGET_NAME} build/local/lib/

Everything was working fine until XCode 14.2 start to spit out this spurious error:

error: unable to determine the platform for the given binary '$HOME/Documents/C++/wallet-core/build/local/catalyst/libwallet_core_rs.a'; check your deployment version settings

lipo tells me that the build/local/catalyst/libwallet_core_rs.ais perfectly valid fat binary.

That's what gives rustc spec info about the aarch64 target:

➜  wallet-core git:(m/rust_fix) ✗ rustc -Z unstable-options --target=aarch64-apple-ios-macabi --print target-spec-json | jq

{
  "abi": "macabi",
  "abi-return-struct-as-int": true,
  "arch": "aarch64",
  "archive-format": "darwin",
  "bitcode-llvm-cmdline": "-triple\u0000arm64-apple-ios-macabi\u0000-emit-obj\u0000-disable-llvm-passes\u0000-Os\u0000",
  "cpu": "apple-a12",
  "data-layout": "e-m:o-i64:64-i128:128-n32:64-S128",
  "debuginfo-kind": "dwarf-dsym",
  "default-dwarf-version": 2,
  "dll-suffix": ".dylib",
  "dynamic-linking": true,
  "eh-frame-header": false,
  "emit-debug-gdb-scripts": false,
  "features": "+neon,+fp-armv8,+apple-a12",
  "forces-embed-bitcode": true,
  "frame-pointer": "non-leaf",
  "function-sections": false,
  "has-rpath": true,
  "is-builtin": true,
  "is-like-osx": true,
  "link-env": [
    "ZERO_AR_DATE=1"
  ],
  "link-env-remove": [
    "IPHONEOS_DEPLOYMENT_TARGET"
  ],
  "linker-is-gnu": false,
  "lld-flavor": "darwin",
  "llvm-target": "arm64-apple-ios-macabi",
  "max-atomic-width": 128,
  "os": "ios",
  "pre-link-args": {
    "gcc": [
      "-target",
      "arm64-apple-ios-macabi"
    ],
    "ld": [
      "-arch",
      "arm64",
      "-platform_version",
      "mac-catalyst",
      "7.0",
      "7.0"
    ],
    "ld64.lld": [
      "-arch",
      "arm64",
      "-platform_version",
      "mac-catalyst",
      "7.0",
      "7.0"
    ]
  },
  "split-debuginfo": "packed",
  "supported-split-debuginfo": [
    "packed",
    "unpacked",
    "off"
  ],
  "target-family": [
    "unix"
  ],
  "target-pointer-width": "64",
  "vendor": "apple"
}

Everything outside of catalyst works well, but I wonder how to fix this error if anyone encountered it.

roman Sztergbaum
  • 671
  • 1
  • 5
  • 11
  • I've run into this exact same error message trying to create a universal binary from a few static libraries using lipo and then including it in a framework (nothing to do with rust though). Did you ever find out what the underlying problem was? – asmvolatile Jul 11 '23 at 15:44

0 Answers0