macOS: Support dSYM generation for cc_binary#25881
macOS: Support dSYM generation for cc_binary#25881benjivos wants to merge 1 commit intobazelbuild:masterfrom
Conversation
keith
left a comment
There was a problem hiding this comment.
i wondered if we should output a directory for this or a flat file, but directory seems preferred. AFAICT the reason that the apple binary logic doesn't do that predates good tree artifact support. but today the apple logic also lipos the dsym binary if you do a multi-arch built, so it has some post processing that this will not too.
I wondered if checking this feature was the right way to do this, and it seems fine, but it would also be equivalent to check the cpp fragment that the feature was based on
Directory is preferred as the .dSYM bundle can contain other resources too (like the UUID property list, see https://lldb.llvm.org/use/symbols.html).
Would you prefer this instead (tested here and seems to work too)? |
I'm not sure which of these would be preferred. The latter seems more resilient to me, but the googlers who have to review can weigh in |
|
@allevato could you review this change please? |
|
C++ rules like |
|
@googlewalt could you please review these changes? Thank you! |
| # then a .dSYM file will be built along with the executable. | ||
| dsym_file = None | ||
| if cc_common.is_enabled(feature_configuration = feature_configuration, feature_name = "generate_dsym_file"): | ||
| dsym_file = ctx.actions.declare_directory( |
There was a problem hiding this comment.
I think this needs to be a file. Historically the toolchain calls dsymutil with --flat to generate a flat file, and that still seems to true for apple_support today. I suspect there might be a desire to support dsymutil generating a directory also, but let's not worry about that for this PR.
I missed this discussion before I reviewed. Currently the default behavior of both the internal and OSS toolchains is to output a file, so for consistency it seems this should be a file. Internally we have a bazel flag to control what the toolchain should output, but unfortunately that's internal only. |
I'd prefer that since it's equivalent, shorter, and consistent with the objc linking code, but don't feel strongly. |
I think the problem with this for cc_binary is that rules_apple does post processing https://github.com/bazelbuild/rules_apple/blob/14a8b6c05f71f3186d587c8b05c545a5d40ceae5/apple/internal/partials/debug_symbols.bzl#L172 to generate the |
|
I don't think we can hardwire this code to support a directory. The functionality would be broken internally; it would not work with the apple_support toolchain; and it is inconsistent with the analogous code in objc linking. If we want to support directory, I think it has to be in addition to supporting a file. One solution would be to add an internal flag for this -- I don't love it but at least it would work. For this PR can we implement a file? If we need directory support we can continue discussion outside of it. |
Add .dSYM as additional_linker_outputs and expose a linker variable that can be used by apple_support and rules_swift. Fixes issue bazelbuild#16893. Signed-off-by: Benji Vos <[email protected]>
aeca8ad to
bcd58c5
Compare
|
Thanks for the review, @googlewalt!
I understand the concern. I'm currently working on adding proper support for dSYM bundles in apple_support here. The changes to
I’d prefer to focus on proper support for dSYM bundles in this PR, rather than implementing flat dSYMs. Beyond embedding plists, we also rely on bundles to include Python scripts that LLDB loads automatically (for example https://dmaclach.medium.com/kernel-debugging-on-apple-silicon-ff5aa76c4429 and https://github.com/apple/darwin-xnu/blob/main/tools/lldbmacros/Makefile). These features and usecases don’t work with flat dSYM files. I’d love to discuss how we can move forward with robust support for bundled dSYMs — happy to collaborate on that! |
|
@googlewalt any thoughts on this? What is your suggestion to move forward? |
|
I see. I need to make some changes so that this is compatible to our toolchain internally, but your proposal looks reasonable. |
|
@iancha1992 would you be able to merge this PR? Thank you! |
|
I'm getting it merged; might take a day or two to find someone to review it. |
Add .dSYM as additional_linker_outputs and expose a linker variable that can be used by apple_support and rules_swift. Fixes issue bazelbuild#16893. Closes bazelbuild#25881. PiperOrigin-RevId: 754100310 Change-Id: I76016785b80540443383ab4be0a10655b41ce138
Add support for generating a .dSYM file if this is requested using `--apple_generate_dsym`. This change contains the following patches: * Add `DSYM_HINT` flags to be picked up by `wrapped_clang` to generate .dSYM bundles on request. * In `wrapped_clang.cc` make sure the linked binary is stripped after generating the .dSYM bundle first to make the .dSYM bundle contain useful information. Adopts [changes](bazelbuild/bazel#25881) in bazel to support .dSYM files (as part of fixing bazelbuild/bazel#16893).
This was discussed in #25881 where we believed it was equivalent. This isn't equivalent if the toolchain does not support dSYM generations but --apple_generate_dsym is still passed (as is possible on Linux). In this case we let feature configuration handle this instead, as this feature is requested when --apple_generate_dsym is passed. In that case because of this mismatch this directory will be created "successfully" but it will always be empty (this would be a failure if it wasn't a tree artifact)
This was discussed in bazelbuild/bazel#25881 where we believed it was equivalent. This isn't equivalent if the toolchain does not support dSYM generations but --apple_generate_dsym is still passed (as is possible on Linux). In this case we let feature configuration handle this instead, as this feature is requested when --apple_generate_dsym is passed. In that case because of this mismatch this directory will be created "successfully" but it will always be empty (this would be a failure if it wasn't a tree artifact) Closes #26925. PiperOrigin-RevId: 848240203 Change-Id: I7de21ba82fda794ffecb2ad86d2010e46732316f
This was discussed in #25881 where we believed it was equivalent. This isn't equivalent if the toolchain does not support dSYM generations but --apple_generate_dsym is still passed (as is possible on Linux). In this case we let feature configuration handle this instead, as this feature is requested when --apple_generate_dsym is passed. In that case because of this mismatch this directory will be created "successfully" but it will always be empty (this would be a failure if it wasn't a tree artifact) Closes #26925. PiperOrigin-RevId: 848240203 Change-Id: I604bc97e44c195142b12222b73d7442a1115ccd1
This was discussed in bazelbuild#25881 where we believed it was equivalent. This isn't equivalent if the toolchain does not support dSYM generations but --apple_generate_dsym is still passed (as is possible on Linux). In this case we let feature configuration handle this instead, as this feature is requested when --apple_generate_dsym is passed. In that case because of this mismatch this directory will be created "successfully" but it will always be empty (this would be a failure if it wasn't a tree artifact) Closes bazelbuild#26925. PiperOrigin-RevId: 848240203 Change-Id: I604bc97e44c195142b12222b73d7442a1115ccd1
Add .dSYM as additional_linker_outputs and expose a linker variable that can be used by apple_support and rules_swift.
Fixes issue #16893.