bazel-ios / rules_ios

Bazel rules for building iOS applications and frameworks
Apache License 2.0
276 stars 85 forks source link

Add force load libs to CcInfo linking context in Bazel 7 #811

Closed karim-alweheshy closed 4 months ago

karim-alweheshy commented 9 months ago

Issue

When we build an executable e.g.

bazelisk build //rules/test_host_app:iOS-14.0-AppHost

We get a linker error e.g.

ld: Undefined symbols:
  _main, referenced from:
      <initial-undefines>

Disgnostic

The linker args/flags file, e.g. iOS-14.0-AppHost_bin-2.params file, is missing the -force_load of the forced linked libs in the executable e.g.

-force_load
bazel-out/ios-sim_arm64-min14.0-applebin_ios-ios_sim_arm64-dbg-ST-261a193f71fb/bin/rules/test_host_app/libiOS-14.0-AppHost_objc.a

Resource

Following guide from here Overall effort here Example migrations for rules_apple here

Migration plan

  1. Move everything behind a bazel7 flag //rules:migrates_cc_info_linking_info
  2. A custom ObjC rule that generates ObjcProvider with linking info needs to generate a CcInfo with the same linking info.
  3. A custom ObjC rule that generates one of the providers used by avoid_deps needs to be modified to propagate an appropriate CcInfo.
karim-alweheshy commented 8 months ago

After fixing the force_load issue we have another issue with

clang++: warning: using sysroot for 'iPhoneSimulator' but targeting 'MacOSX' [-Wincompatible-sysroot]

for all the linking on non MaxOSX targets

This will be addressed separately in another PR This should just move us one step closer to bazel 7

karim-alweheshy commented 8 months ago

Shows different errors now in bazel 7 builds https://github.com/bazel-ios/rules_ios/pull/816

karim-alweheshy commented 8 months ago

A step for bazel7 migration https://github.com/bazel-ios/rules_ios/issues/795

luispadron commented 4 months ago

Merged in #850