Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linking with XCFrameworks doesn't work #106120

Open
MatrixDev opened this issue Dec 24, 2022 · 0 comments
Open

Linking with XCFrameworks doesn't work #106120

MatrixDev opened this issue Dec 24, 2022 · 0 comments
Labels
C-bug Category: This is a bug. O-ios Operating system: iOS

Comments

@MatrixDev
Copy link

MatrixDev commented Dec 24, 2022

I tried this code:

// build.rs
println!("cargo:rustc-link-search=framework=../../Frameworks/MacOS/Banuba/bnb-0.37.1/iOS/");
println!("cargo:rustc-link-lib=framework=BNBEffectPlayerC");

Folder structure (with frameworks):

- Frameworks/MacOS/Banuba/bnb-0.37.1/iOS
  - BNBEffectPlayerC.xcframework
    - ios-arm64
      - BNBEffectPlayerC.framework
    - ios-arm64_x86_64-simulator
      - BNBEffectPlayerC.framework
    - Info.plist

Expected behavior

I expected for the program to successfully link with BNBEffectPlayerC library and automatically select correct 'sub-framework' based on the build target. Something like this:

  • aarch64-apple-ios => ios-arm64
  • aarch64-apple-ios-sim => ios-arm64_x86_64-simulator
  • x86_64-apple-ios => ios-arm64_x86_64-simulator

Actual behavior

Instead, linking fails with following error:

cargo build --release --target aarch64-apple-ios
   Compiling banuba v0.1.0 (/Users/oleksandr/banuba-rs)
error: linking with `cc` failed: exit status: 1
  = note: "cc" "-Wl, {tons and tons of arguments}
  = note: ld: framework not found BNBEffectPlayerC
          clang: error: linker command failed with exit code 1 (use -v to see invocation)

Workaround

Following workaround is ugly and to properly implement it we should parse Info.plist to select correct framework but it will require much more effort:

// build.rs
let is_simulator = env::var("TARGET").unwrap() == "aarch64-apple-ios-sim" || target == "x86_64-apple-ios";
let framework_folder = match is_simulator {
    true => "ios-arm64_x86_64-simulator",
    false => "ios-arm64",
};
println!("cargo:rustc-link-search=framework=../../Frameworks/MacOS/Banuba/bnb-0.37.1/iOS/BNBEffectPlayerC.xcframework/{}", framework_folder);
println!("cargo:rustc-link-lib=framework=BNBEffectPlayerC");

Proposed solution

Maybe it whould be better to add one more linking variant, something like xcframework?

// build.rs
println!("cargo:rustc-link-search=xcframework=../../Frameworks/MacOS/Banuba/bnb-0.37.1/iOS/");
println!("cargo:rustc-link-lib=xcframework=BNBEffectPlayerC");

Meta

rustc --version --verbose:

rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: aarch64-apple-darwin
release: 1.66.0
LLVM version: 15.0.2
@MatrixDev MatrixDev added the C-bug Category: This is a bug. label Dec 24, 2022
@workingjubilee workingjubilee added the O-ios Operating system: iOS label Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-ios Operating system: iOS
Projects
None yet
Development

No branches or pull requests

2 participants