[Bug]: Effect of ABSL_FLAGS_STRIP_NAMES on mobile platforms is poorly documented
- Langage dominant
- C++
- Étoiles
- 18.1k
- Forks
- 3.2k
- Merge moyen
- 20 h 36 min
- PR mergées (30 j)
- 1
Description
### Describe the issue
I am porting command line C++ code to use on iOS. Setting aside the issue of actually passing command line arguments to an iOS app (it is possible and fully supported), calling `absl::ParseCommandLine(argc, argv)` on stack variables seems to fail mysteriously. Even within the same translation unit, `ABSL_FLAG` definitions are ignored and not present in the `.o`.
I thought this was an issue with my toolchain configuration (linker stripping, etc). But it turns out, it is due to [ABSL_FLAGS_STRIP_NAMES being set to 0 on "mobile" targets](https://github.com/abseil/abseil-cpp/blob/3f242f22e5a21185821678afc697cd71b8a77ef2/absl/flags/config.h#L19), where "mobile" is defined to be Android, iPhone, and "embedded Apple devices".
While explicitly setting `ABSL_FLAGS_STRIP_NAMES=0` fixes the issue, the name `ABSL_FLAGS_STRIP_NAMES` is confusing as its effect is to disable flag registration altogether: [ABSL_FLAG_IMPL](https://github.com/abseil/abseil-cpp/blob/3f242f22e5a21185821678afc697cd71b8a77ef2/absl/flags/flag.h#L206) is defined to call `absl::flags_internal::FlagRegistrar` or `absl::flags_internal::FlagRegistrar`.
I am not advocating that we change the name - that's extremely disruptive.
But maybe we should better document it somewhere as this behavior is surprising (albeit rare - I don't know how many Abseil users actually want to pass flags to iOS apps. My team for one would like to do this as it conveniently lets us pass things like `--stderrthreshold 0`.
### Steps to reproduce the problem
Write a C++ library that looks like:
```
ABSL_FLAG(int, value1, 0, "value1");
ABSL_FLAG(double, value2, 0.0, "value2");
void parse() {
int argc = 4;
char* argv[4] = {
"app",
"--value1=6",
"--value2",
"7.6",
};
absl::ParseCommandLine(argc, argv);
}
```
and call `parse()` from the iOS app. It will mysteriously complain:
```
ERROR: Unknown command line flag 'value1'
ERROR: Unknown command line flag 'value2'
```
Building with `ABSL_FLAGS_STRIP_NAMES=0` fixes the issue.
### What version of Abseil are you using?
20240722.0
### What operating system and version are you using?
iOS 18.0
### What compiler and version are you using?
Xcode 16.0
```
$ clang -v
Apple clang version 16.0.0 (clang-1600.0.26.3)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Applications/Xcode_16.0.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
```
### What build system are you using?
bazel 7.1.0
### Additional context
_No response_
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.