rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.58k stars 12.48k forks source link

[MacCatalyst]: Can't determine the platform when creating an xcframework from rust libraries #107630

Open Milerius opened 1 year ago

Milerius commented 1 year ago

Hello I'm using aarch64-apple-ios-macabi and x86_64-apple-ios-macabi as follow in my project:

CARGO_TARGET_DIR=$BUILD_FOLDER cargo +nightly build -Z build-std --target aarch64-apple-ios-macabi --release
CARGO_TARGET_DIR=$BUILD_FOLDER cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi --release
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

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

Was working fine until XCode 14.2 release which now produce:

error: unable to determine the platform for the given binary 'project/build/local/catalyst/libproject_rs.a'; check your deployment version settings

This is the json target spec for MacCatalyst (aarch64):

{
  "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"
}

Every other targets outside of catalyst seems to work

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (f3126500f 2023-02-02)
binary: rustc
commit-hash: f3126500f25114ba4e0ac3e76694dd45a22de56d
commit-date: 2023-02-02
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

Maybe XCode have new requirements that the targets doesn't respect correctly? and therefore xcodebuild can't create an xcframework from any catalyst library?

Simple repro:

rustup update
  rustup toolchain install nightly
  rustup default nightly
  rustup toolchain install nightly-x86_64-apple-darwin
  rustup toolchain install nightly-aarch64-apple-darwin
  rustup component add rust-src --toolchain nightly-aarch64-apple-darwin
  rustup component add rust-src --toolchain nightly-x86_64-apple-darwin
rustup target add aarch64-apple-darwin x86_64-apple-darwin
rustup target add x86_64-apple-ios aarch64-apple-ios-sim aarch64-apple-ios 
cargo build --target aarch64-apple-ios --release
cargo build --target aarch64-apple-ios-sim --release
 cargo build --target x86_64-apple-ios --release
 cargo build --target aarch64-apple-darwin --release
 cargo build --target x86_64-apple-darwin --release
 cargo +nightly build -Z build-std --target aarch64-apple-ios-macabi --release
 cargo +nightly build -Z build-std --target x86_64-apple-ios-macabi --release

lipo build_folder/x86_64-apple-ios/release/lib_name.a build_folder/aarch64-apple-ios-sim/release/libname.a -create -output build_folder/libname.a

 mkdir -p build_folder/darwin_universal
  lipo build_folder/x86_64-apple-darwin/release/libname.a build_folder/aarch64-apple-darwin/release/libname.a -create -output build_folder/darwin_universal/libname.a
  mkdir -p build_folder//catalyst
  lipo build_folder/aarch64-apple-ios-macabi/release/libname.a build_folder/x86_64-apple-ios-macabi/release/libname.a -create -output build_folder/catalyst/libname.a

## Will fail on catalyst with `error: unable to determine the platform for the given binary 'project/build/local/catalyst/libname.a'; check your deployment version settings`  
    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
keith commented 1 year ago

I can't reproduce this, what crate-type was your case? I assume staticlib but I didn't have any luck with that and Xcode 14.2 (it could be fixed in a newer Xcode version too I guess)

PrismaPhonic commented 5 months ago

I'm getting similar errors now when building for the watchos target. Nearly identical xcodebuild command (except that I'm not using lipo at all, and only testing with a single target). Other apple targets work fine for me, and even the watchos-sim works for me, but failing on unable to determine platform. My issue may be unrelated but does seem oddly similar

madsmtm commented 2 weeks ago

I believe that the issue may have been that we previously only passed arm64-apple-ios-macabi as the LLVM target, where we should have been passing arm64-apple-ios13.1-macabi (with 13.1 being the deployment target). That part was fixed in https://github.com/rust-lang/rust/pull/111384, the aarch64-apple-watchos target having the same problem should be fixed by https://github.com/rust-lang/rust/pull/129341.