bazelbuild / bazelbuild/rules_apple
Swift: missing symbols in `ios_framework` bundle
- Dominant language
- Starlark
- Stars
- 593
- Forks
- 334
- Avg merge
- 16h 48m
- Merged PRs (30d)
- 9
Description
With most of the heavy lifting done by @steeve (see #223), I made a working `ios_framework` rule for building dynamic frameworks that can be dropped into vanilla (non-Bazel) Xcode projects. At runtime, I discovered that certain symbols that _are_ present in the object file created by the `swift_library` rule are missing from the framework binary created by the `ios_framework` rule.
I believe I traced this to the following weird phenomenon: if a Swift source file contains any ObjC classes, all of its symbols make it into the framework binary, even if they're not bridged to ObjC. But if a Swift source file does not contain any ObjC classes, (say, if it only contains protocols, structs, and classes that don't extend `NSObject`), the `apple_binary` compile subcommand is totally stripping out all symbols generated from that source file's corresponding object file. I was able to debug up to this point, but it wasn't obvious to me from the wrapped `clang` command why this would be happening.
I created a simple repro repository [here](https://github.com/stristr/swift-missing-symbols-repro). The `./repro.sh` bash script should print:
```
WillBeIncluded is in object file
WillBeExcluded is in object file
WillBeIncluded is in framework binary
WillBeExcluded is NOT in framework binary
```
Is this a known issue?
Contributor guide
Research direction
Clone the linked swift-missing-symbols-repro repository and run ./repro.sh to confirm the object-file versus framework-binary output. Then trace the ios_framework, swift_library, and apple_binary steps involved in the reproduction; done means the reported symbols are retained in the framework binary.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bash, ios, swift
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100