Skip to content

Conversation

jschear
Copy link
Collaborator

@jschear jschear commented Apr 16, 2025

…ckaging

When alwayslink is True, objc_library can produce an .lo file instead of an .a file.

From the cc_library docs (which I believe also apply to objc_library):

https://bazel.build/reference/be/c-cpp#cc_library

Use cc_library() for C++-compiled libraries. The result is either a .so, .lo, or .a, depending on what is needed.

If you build something with static linking that depends on a cc_library, the output of a depended-on library rule is the .a file. If you specify alwayslink=True, you get the .lo file.

The actual output file name is libfoo.so for the shared library, where foo is the name of the rule. The other kinds of libraries end with .lo and .a, respectively. If you need a specific shared library name, for example, to define a Python module, use a genrule to copy the library to the desired name.

I'm not 100% sure if this is valid (does a .framework bundle with an .lo file as its binary make sense?), and the non-VFS codepath that uses libtool to merge the objc_library and swift_library binary might break. But if no binary is set in the AppleBundleInfo provider, rules_xcodeproj treats apple_framework_packaging targets as unsupported.

@jschear
Copy link
Collaborator Author

jschear commented Apr 17, 2025

It looks like objc symbols don't end up in the merged framework binary without this change:

# With this change:
~/Development/rules_ios js/include_lo_files_from_objc_library * bazel build //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework --config=ios                                      
INFO: Analyzed target //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework up-to-date:
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/MixedSourceFramework
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Modules/MixedSourceFramework.swiftmodule/arm64.swiftmodule
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework-Swift.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/DoubleQuoteNamespacedLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/DoubleQuoteLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/AngleBracketNamespacedLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/LoggerProtocol.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework-umbrella.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Modules/module.modulemap
INFO: Elapsed time: 0.176s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
~/Development/rules_ios js/include_lo_files_from_objc_library * ar t  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/MixedSourceFramework
__.SYMDEF
SwiftLibrary+extension.swift.o
SwiftLogger.swift.o
AngleBracketNamespacedLogger.o
DoubleQuoteLogger.o
DoubleQuoteNamespacedLogger.o
# On main:
~/Development/rules_ios js/include_lo_files_from_objc_library * bazel build //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework --config=ios
INFO: Analyzed target //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework (1 packages loaded, 39 targets configured).
INFO: Found 1 target...
Target //tests/ios/frameworks/mixed-source/only-source:MixedSourceFramework up-to-date:
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/MixedSourceFramework
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Modules/MixedSourceFramework.swiftmodule/arm64.swiftmodule
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework-Swift.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/DoubleQuoteNamespacedLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/DoubleQuoteLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/AngleBracketNamespacedLogger.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/LoggerProtocol.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Headers/MixedSourceFramework-umbrella.h
  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/Modules/module.modulemap
INFO: Elapsed time: 0.431s, Critical Path: 0.24s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed successfully, 2 total actions
~/Development/rules_ios js/include_lo_files_from_objc_library * ar t  bazel-bin/tests/ios/frameworks/mixed-source/only-source/MixedSourceFramework/MixedSourceFramework.framework/MixedSourceFramework
__.SYMDEF
SwiftLibrary+extension.swift.o
SwiftLogger.swift.o

I've never been completely clear on whether or not those framework binaries are actually used, or if the static libraries from objc_library and swift_library are actually used in the final linker invocation for an application.

@jschear jschear enabled auto-merge (squash) April 17, 2025 18:04
@jschear jschear merged commit 9d33c7a into master Apr 17, 2025
12 checks passed
@jschear jschear deleted the js/include_lo_files_from_objc_library branch April 17, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants