facebook / buck2

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

Make `CxxToolchainInfo.mk_comp_db` optional. #594

Closed zadlg closed 2 months ago

zadlg commented 2 months ago

Make CxxToolchainInfo.mk_comp_db optional.

According to the documentation, constructing a CxxToolchainInfo requires at least C/C++ compiler info along with linker info. It means that CxxToolchainInfo.mk_comp_db should be optional. By the way, its definition is set to default = None.

A None value in CxxToolchainInfo.mk_comp_db leads to an error:

Caused by:
    Traceback (most recent call last):
      File <builtin>, in <module>
      * prelude/rules.bzl:101, in buck2_compatibility_shim
          return impl(ctx)
      * prelude/cxx/cxx.bzl:191, in cxx_library_impl
          output = cxx_library_parameterized(ctx, params)
      * prelude/cxx/cxx_library.bzl:425, in cxx_library_parameterized
          comp_db = create_compilation_database(ctx, compiled_srcs.compile_cmds.src_com...
    error: Operation `[]` not supported for types `NoneType` and `run_info_callable`
      --> prelude/cxx/comp_db.bzl:34:18
       |
    34 |     mk_comp_db = get_cxx_toolchain_info(ctx).mk_comp_db[RunInfo]
       |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
       |

This commit fixes this small bug by allowing None in CxxToolchainInfo.mk_comp_db.

JakobDegen commented 2 months ago

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.

zadlg commented 2 months ago

I'm not sure to understand the failure here: https://github.com/facebook/buck2/actions/runs/8187055765/job/22490706786?pr=594#step:5:3347 but I guess it's unrelated to my PR.