rules_apple icon indicating copy to clipboard operation
rules_apple copied to clipboard

Linking error with apple_xcframework depending on each other

Open gferon opened this issue 2 years ago • 2 comments

When using a apple_xcframework target in the deps of another, I get a linking error. I've seen the work from e6a22d7017813bc1825b3e5fbeb525311f4d9cf8 and thought this would fix my issue.

My workaround is currently to have a genrule unzip the xcframework archive, and use apple_dynamic_xcframework_import on the resulting files, so I'm sure there's a way to have apple_xcframework output the proper providers right away.

I'm up for implementing it myself but I'd need a bit of assistance.

gferon avatar Feb 24 '23 14:02 gferon

xcframeworks are not mean to be deps of other xcframeworks since they're only meant for distribution. instead you should make whatever dependencies from the first xcframework are depended on by the second part of your normal deps, and then use avoid_deps to exclude whatever shouldn't be bundled with it. You can see a real world example over here https://github.com/tensorflow/tensorflow/pull/56789/

keith avatar Feb 25 '23 00:02 keith

Thanks for the insight, it looks like avoid_deps is only supported for apple_static_xcframework but not for apple_xcframework.

Right now, what works for us is to have something like:

apple_xcframework(
  name = 'a'
)

genrule(
  name = 'a-unzip',
  deps = [
    ":a",
  ],
  cmd = "unzip -d $(@D) $(location :kenlm-xcframework)",
)

apple_dynamic_xcframework_import(
  name = 'a.xcframework',
  xcframework_imports = [":a-unzip"]
)

apple_xcframework(
  name = 'b',
  deps = [
    ":a"
  ]
)

This is the only way I could figure out to get a B.xcframework with resulting binaries that both have @rpath/A.framework/A and do not include the symbols of A, and I'm sure there's a more elegant way of doing this. As far as I understand, the linker options need to have a path to load the framework with -Fbazel-out/ios-arm64-min15.0-applebin_ios-ios_arm64-fastbuild-ST-f294c57c5bf2/bin/A.xcframework/[platform] and -framework A for this to happen.

gferon avatar Feb 27 '23 09:02 gferon