Skip to content

Rustc and XCFramework won't work #79408

Closed

Description

Hi

We are currently trying to build a xcframework, which includes a rust static library as a binary target. When we build the xcframework with xcodebuild -create-xcframework -library target/aarch64-apple-ios/release/libxcframework_test.a -headers test.h -output test.xcframework we get The CodingKeys(stringValue: "SupportedPlatform", intValue: nil) is empty in library -arm64..

To reproduce the failure just build a static lib with a function in it e.g.:

#[no_mangle]
pub unsafe extern "C" fn test() {
}

cargo build --release --target aarch64-apple-ios

Interestingly enough, the binary works when statically linked during the usual build process in XCode (so the code itself seems to be correct).

Further, for the darwin binary (target macos) the xcframework creation process succeeds.

I think with rustc 1.43 the xcframework also worked for the ios platform, but other than that we have no idea what is wrong.

It is though certainly somehow linked to rust, as C/C++ libraries work (e.g. libsodium) with exact the same command/folder-structure.

[EDIT] We found that LC_VERSION_MIN_* is emitted instead of LC_BUILD_VERSION in the load commands of the MachO binary. Apparently this is the newly used command to specify the platform.

As of iOS 12 (and I’m not sure which macOS version), the loader looks for LC_BUILD_VERSION instead of LC_VERSION_MIN*.
1

As a comparison:
XCODE:

Load command 1
cmd LC_BUILD_VERSION
cmdsize 24
platform ios
sdk 14.2
minos 14.2
ntools 0

RUST:

Load command 1
cmd LC_VERSION_MIN_IPHONEOS
cmdsize 16
version 7.0
sdk 13.7

[EDIT 2]
Getting closer found #29664 and made a new target, where I set the llvm-target to the one with the correct version like this:

{
  "abi-return-struct-as-int": true,
  "arch": "aarch64",
  "archive-format": "darwin",
  "bitcode-llvm-cmdline": "-triple\u0000arm64-apple-ios11.0.0\u0000-emit-obj\u0000-disable-llvm-passes\u0000-target-abi\u0000darwinpcs\u0000-Os\u0000",
  "cpu": "apple-a7",
  "data-layout": "e-m:o-i64:64-i128:128-n32:64-S128",
  "dll-suffix": ".dylib",
  "dwarf-version": 2,
  "eh-frame-header": false,
  "eliminate-frame-pointer": false,
  "emit-debug-gdb-scripts": false,
  "executables": true,
  "features": "+neon,+fp-armv8,+apple-a7",
  "forces-embed-bitcode": true,
  "function-sections": false,
  "has-rpath": true,
  "is-builtin": true,
  "is-like-osx": true,
  "link-env": [
    "ZERO_AR_DATE=1"
  ],
  "link-env-remove": [
    "MACOSX_DEPLOYMENT_TARGET"
  ],
  "llvm-target": "arm64-apple-ios9.0",
  "max-atomic-width": 128,
  "os": "ios",
  "target-family": "unix",
  "target-pointer-width": "64",
  "unsupported-abis": [
    "stdcall",
    "fastcall",
    "vectorcall",
    "thiscall",
    "win64",
    "sysv64"
  ],
  "vendor": "apple"
}

Now I can create an xcframework again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-crossArea: Cross compilationA-target-specsArea: Compile-target specificationsC-enhancementCategory: An issue proposing an enhancement or a PR with one.O-iosOperating system: iOS

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions