bazelbuild / bazelbuild/bazel

Support stripping Swift symbols

Open
#13,122 4 comments 0 reactions 0 assignees View on GitHub
not stale P3 platform: apple team-Rules-CPP type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the problem / feature request:

Support stripping Swift symbols for binaries built for Apple platforms.

### Feature requests: what underlying problem are you trying to solve with this feature?

There's currently no option to allow stripping Swift symbols for binaries built for Apple platforms. Since `xcodebuild`'s ipa exporting supports that (and defaults to `YES`), results in binaries produced by Bazel has a slightly larger size compared to Xcode's.

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

macOS

### What's the output of `bazel info release`?

release 4.0.0

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

From the `strip` man page:

```
-T
The intent of this flag is to remove Swift symbols. It removes the symbols whose names
begin with `_$S' or `_$s' only when it finds an __objc_imageinfo section with and it has
a non-zero swift version. The future the implementation of this flag may change to match the intent.
```

From the `xcodebuild -h` page:

```
Available keys for -exportOptionsPlist:
...
stripSwiftSymbols : Bool

Should symbols be stripped from Swift libraries in your IPA? Defaults to YES.
```

I found two code paths referencing to code stripping but `-T` is not passed, and passing it via `--stripopt` doesn't take effect.

https://github.com/bazelbuild/bazel/blob/25768512a6c30cdc6af3098078ef02375fd5c914/src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java#L1561-L1574

https://github.com/bazelbuild/bazel/blob/ef903e08b270f3fa3c4d36f8122876a892b47087/tools/osx/crosstool/cc_toolchain_config.bzl#L296-L311

Contributor guide

Open the contributing guide

Research direction

Start with the stripping paths in src/main/java/com/google/devtools/build/lib/rules/objc/CompilationSupport.java and tools/osx/crosstool/cc_toolchain_config.bzl, then compare them with macOS strip's -T behavior and the reported --stripopt path. Done means Bazel provides an effective way to strip Swift symbols from binaries built for Apple platforms.

Written by the indexing model from the issue text.

Assessment

Tech stack
macos, swift
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.