facebook / buck2

Build system, successor to Buck
https://buck2.build/
Apache License 2.0
3.33k stars 194 forks source link

Allow `None` in `LinkerInfo.linker_flags`. #593

Closed zadlg closed 2 months ago

zadlg commented 2 months ago

Allow None in LinkerInfo.linker_flags.

LinkerInfo.linker_flags field is by default set to None, as well as other flag list fields (e.g. LinkerInfo.archiver_flags).

However, LinkerInfo.linker_flags isn't consistenly used across prelude.

For instance, in cxx/cxx_library.bzl, LinkerInfo.linker_flags is treated as an optional list:

https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_library.bzl#L774

On the other hand, in cxx/cxx_toolchain_types.bzl, LinkerInfo.linker_flags is expected to contain a non-None value:

https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L308

https://github.com/facebook/buck2/blob/1e89af6622344c46543a9e3781a556e058471043/prelude/cxx/cxx_toolchain_types.bzl#L327

This leads to an error when defining a custom CXX toolchain:

Caused by:
    0: Error running analysis for `toolchains//:cxx (prelude//platforms:default#904931f735703749) (prelude//platforms:default#904931f735703749)`
    1: Traceback (most recent call last):
         File <builtin>, in <module>
         * musl-toolchain/define_toolchain.bzl:53, in _define_cxx_toolchain_impl
             ] + cxx_toolchain_infos(
         * prelude/cxx/cxx_toolchain_types.bzl:308, in cxx_toolchain_infos
             "ldflags-shared": _shell_quote(linker_info.linker_flags),
         * prelude/cxx/cxx_toolchain_types.bzl:328, in _shell_quote
             return cmd_args(xs, quote = "shell")
       error: Expected `a value implementing CommandLineArgLike (str, Artifact, RunInfo, etc)`, but got `NoneType`
          --> prelude/cxx/cxx_toolchain_types.bzl:328:12
           |
       328 |     return cmd_args(xs, quote = "shell")
           |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
           |

This commit handles the LinkerInfo.linker_flags consistently across the project.

facebook-github-bot commented 2 months ago

Hi @zadlg!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

facebook-github-bot commented 2 months ago

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

facebook-github-bot commented 2 months ago

@JakobDegen has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.