bazelbuild / bazelbuild/bazel

Using `enable_modules` with `module_map` in `objc_library` does not enable Clang modules

Open
#20,703 1 comment 0 reactions 0 assignees View on GitHub
team-Rules-ObjC type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

When defining an `objc_library` with `module_map` set and `enable_modules = True`, [this code](https://github.com/bazelbuild/bazel/blob/18d01e7f6d8a3f5b4b4487e9d61a6d4d0f74f33a/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java#L1280) silently passes on enabling clang modules. This causes build failures in Objective-C libraries that both define a custom module map and use `@import`.

### Which category does this issue belong to?

C++/Objective-C Rules

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

```c
// Foo.m

@import Foundation;
```

---

```python
# BUILD.bazel

objc_library(
name = "Foo",
srcs = ["Foo.m"],
hdrs = ["Foo.h"],
enable_modules = True,
module_map = "module.modulemap"
)
```

This can be fixed by passing `-fmodules` to copts instead:

```python
objc_library(
name = "Foo",
srcs = ["Foo.m"],
hdrs = ["Foo.h"],
copts = ["-fmodules"],
module_map = "module.modulemap"
)
```

### Which operating system are you running Bazel on?

macOS 13.6.3

### What is the output of `bazel info release`?

6.4.0

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

_No response_

### Have you found anything relevant by searching the web?

Related discussion in `rules_apple`: https://github.com/bazelbuild/rules_apple/pull/2351

### Any other information, logs, or outputs that you want to share?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start in src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java at the referenced module-enabling code. Reproduce the minimal objc_library with a custom module_map and @import on macOS, then verify that enabling modules works without requiring -fmodules in copts.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, objective-c
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.