Skip to content

objc_library cannot use @import syntax for dependencies due to lack of automatic module map propagation #2690

@bc-lee

Description

@bc-lee

Problem Description:

When building pure Objective-C code using Bazel's objc_library rule, it is currently difficult or impossible to reliably use the modern @import module syntax for dependencies. While Objective-C supports both the traditional #import/#include and the @import syntax, the latter requires a module map file (module.modulemap) for the dependency to be generated and correctly passed to the compiler.

Details:

  1. The @import syntax depends on the compiler having access to a module map for the imported library. This mechanism is fundamental to how modules work in Clang and is used for both Objective-C and Swift.
  2. Rules within bazelbuild/rules_swift, such as swift_library and mixed_language_library, have established mechanisms for generating and propagating module maps of their dependencies. This is crucial for enabling interoperability between Swift and Objective-C code within modules.
  3. However, the standard objc_library rule does not appear to automatically generate or propagate module maps for its pure Objective-C dependencies in a way that consistently enables the use of @import syntax from within dependent objc_library targets. While there is an enable_modules attribute on objc_library, it seems insufficient on its own to handle the full dependency graph correctly for @import between objc_library targets.
  4. In contrast, other build systems (like Swift Package Manager) handle the generation and use of module maps for Objective-C dependencies more automatically, allowing for smoother adoption of the @import syntax.

Desired Enhancement:

It would be beneficial if objc_library could automatically generate and manage module maps for their dependencies. This automatic propagation of module information should enable reliable use of the @import syntax throughout a pure Objective-C dependency graph defined by objc_library rules, similar to how it functions for mixed-language targets or in other build environments.
antly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions