[Bug]: Effect of ABSL_FLAGS_STRIP_NAMES on mobile platforms is poorly documented
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- cpp, ios
- Domain
- cli, documentation, mobile-dev
Research direction
Look at absl/flags/config.h to see how ABSL_FLAGS_STRIP_NAMES is defined for mobile platforms. Examine absl/flags/flag.h to understand the ABSL_FLAG_IMPL macro and how it registers flags. The documentation update should clarify that setting ABSL_FLAGS_STRIP_NAMES=0 disables flag registration on iOS/Android, and suggest where to add this note (perhaps in a README or a comment in config.h).
Written by the indexing model from the issue text.
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, 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 is defined to call absl::flags_internal::FlagRegistrar<T, /*do_register=*/false> or absl::flags_internal::FlagRegistrar<T, /*do_register=*/true>.
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
- Dominant language
- C++
- Stars
- 18.1k
- Forks
- 3.2k
- Avg merge
- 12h 35m
- Merged PRs (30d)
- 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from abseil/abseil-cpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
abseil/abseil-cpp#2168 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
abseil/abseil-cpp#2167 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
abseil/abseil-cpp#2153 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abseil/abseil-cpp#2140 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
abseil/abseil-cpp#2027 · 2 reactions ·
All issues in abseil/abseil-cpp
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NVIDIA/cuda-samples#453 ·