Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cxx_python_extension references python_toolchain.extension_linker_flags, but system_python_toolchain does not define it #840

Open
ArjunZ786 opened this issue Jan 12, 2025 · 0 comments

Comments

@ArjunZ786
Copy link

ArjunZ786 commented Jan 12, 2025

Summary

When using the built-in cxx_python_extension rule and the default system_python_toolchain, Buck2 fails during analysis because the rule references a field (extension_linker_flags) that the standard Python toolchain does not define. This leads to a type error (NoneType vs. list) whenever cxx_python_extension tries to read extension_linker_flags.

Steps to reproduce

Create a minimal BUCK2 project with a simple cxx_python_extension target and the default “system” Python toolchain:


cxx_python_extension(
    name = "my_python_extension",
    module_name = "my_python_extension",
    srcs = ["my_extension.cpp"],
    headers = ["my_extension.h"],
    deps = [],
    visibility = ["PUBLIC"],
)

In toolchains//BUCK (or wherever the system python toolchain is declared), define:


system_python_toolchain(
    name = "python",
    # no ex
tension_linker_flags param, just the defaults
)

Run buck2 build //path/to:my_python_extension.
Observed behavior

Buck2 fails with an error similar to:

Value `None` of type `NoneType` does not match the type annotation `list` for argument `extra_link_flags`
--> prelude/python/cxx_python_extension.bzl:XXX
It points to python_toolchain.extension_linker_flags being None when cxx_python_extension tries to assign it to extra_link_flags.

If we try to fix this by passing extension_linker_flags = [] into system_python_toolchain, Buck2 immediately complains:

Found extension_linker_flags extra named parameter(s) for call to system_python_toolchain
indicating that system_python_toolchain does not accept or define that parameter.

Expected behavior

According to Buck2’s documentation, a simple cxx_python_extension target should “just work” out of the box with no special configuration. The rule’s reference to extension_linker_flags should either:

Be optional (and default to an empty list) if not defined in the Python toolchain, or
Be included as a recognized parameter in system_python_toolchain.
Additional context

Buck2 version: (please fill in or “latest stable at time of writing”).
Platform: e.g. Ubuntu 22.04, macOS 13.x, etc.
The mismatch between cxx_python_extension.bzl (which uses python_toolchain.extension_linker_flags) and system_python_toolchain (which does not define that field) breaks the default usage scenario.
Workarounds include creating a custom Python toolchain that defines extension_linker_flags, or patching cxx_python_extension to default to an empty list if the field is None.
Proposed fix

Option A: Update cxx_python_extension to handle None gracefully, e.g.:
extra_link_flags = python_toolchain.extension_linker_flags or []
Option B: Modify system_python_toolchain so it always provides (or allows specifying) extension_linker_flags, defaulting to [].
Option C: Remove or conditionally skip the code that references extension_linker_flags if it’s not set.
Thank you for taking a look at this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant