Bazel adds "-g" in opt compilation mode when using NDK
Description of the bug:
Seen at src/main/java/com/google/devtools/build/lib/bazel/rules/android/ndkcrosstools/r19/ArmCrosstools.java:91
When building my library using NDK with opt mode, bazel always adds the flag "-g" into the command line arguments. This causes some problems for me because I don't want any debugging information to appear inside my library.
Which category does this issue belong to?
No response
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
No response
Which operating system are you running Bazel on?
No response
What is the output of bazel info release?
No response
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?
No response
Any other information, logs, or outputs that you want to share?
No response
For releases where you don't want debug info you should pass --compilation_mode=opt to bazel
Hi @xiaobao520123, could you please try above and issue still persist, please help us how to reproduce this with all information i.e. bazel version, OS versions etc.
Hi @xiaobao520123, could you please try above and issue still persist, please help us how to reproduce this with all information i.e. bazel version, OS versions etc.
well I try to use -c opt -compilation_mode=opt at the same time but it seems like it still adds "-g"
external/androidndk/ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang '-D__ANDROID_API__=21' -isystemexternal/androidndk/ndk/sysroot/usr/include/arm-linux-androideabi -target armv7-none-linux-androideabi '-march=armv7-a' '-mfloat-abi=softfp' '-mfpu=vfpv3-d16' -gcc-toolchain external/androidndk/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64 -fpic -no-canonical-prefixes -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -funwind-tables -fstack-protector-strong -fno-addrsig '-Werror=return-type' '-Werror=int-to-pointer-cast' '-Werror=pointer-to-int-cast' '-Werror=implicit-function-declaration' -mthumb -Os -g -DNDEBUG -MD -MF ......
Bazelisk version: development Build label: 6.4.0 Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar Build time: Thu Oct 19 17:08:20 2023 (1697735300) Build timestamp: 1697735300 Build timestamp as int: 1697735300
My bazel version is bazel 6.4.0 and the NDK I use is android-ndk-r21e Working on macOS 14.1
Ah right, because it wants to give you debug info in case you need it for crash reports. You can either strip the final binary (maybe --strip=always works?) or you can pass --copt=-gnone to negate the -g
Ah right, because it wants to give you debug info in case you need it for crash reports. You can either strip the final binary (maybe
--strip=alwaysworks?) or you can pass--copt=-gnoneto negate the-g
yeah I've used the latter way you suggest, and it works. But I think when building in opt mode, debug info should not be included by default.
I think the crash reporting case is why it is, probably better to knowingly have to strip than to forget to enable -g when you need it and not be able to symbolicate production crashes
Native android_ndk_repository has been removed from bazel 8, but it looks like this is still set in the Starlark version: https://github.com/bazelbuild/rules_android_ndk/blob/cb776db8e671084669f141d2003e1b61c1a7d21b/ndk_cc_toolchain_config.bzl#L665
so I'll move this issue there