Got the basic and most needed case of Python marker dependencies working!
In this case cryptography uses cffi if the Python implementation isn't PyPy which doesn't support cffi. This is implemented by creating a decide_marker rule named with a shasum of the marker condition string so that markers can be reused, and then the d41b92cd cycle group (which is the implementation of cryptography) depends on cffi only if the marker rule is true at configuration time.
@pip//cryptography/BUILD
alias(
name = "cryptography",
actual = "//private/sccs:d41b92cd",
visibility = ["//visibility:public"],
)
@pip//private/markers/BUILD
decide_marker(
name = "aa6882d8",
marker = "platform_python_implementation != 'PyPy'",
visibility = ["//private:__subpackages__"],
)
@pip//private/sccs/BUILD
# A placeholder library which allows us to select to nothing
py_library(
name = "empty",
srcs = [],
imports = [],
visibility = ["//visibility:private"]
)
# All of the markers under which d41b92cd depends on cffi
selects.config_setting_group(
name = "_maybe_d41b92cd_cffi",
match_any = ["//private/markers:aa6882d8"],
visibility = ["//visibility:private"],
)
# Depend on cffi of any of the d41b92cd markers are active
alias(
name = "_d41b92cd_cffi",
actual = select({
":_maybe_d41b92cd_cffi": "//cffi",
"//conditions:default": ":empty",
}),
visibility = ["//visibility:private"],
)
py_library(
name = "d41b92cd",
deps = [
"@whl_install__pypi__airflow__cryptography//:install",
":_d41b92cd_cffi"
],
visibility = ["//:__subpackages__"],
)
Behold, part of the #Python bullshit I've been working on for the last several months!
I've been slowly working up an implementation of `uv install` under #Bazel... using only Bazel. This is important because it lets Python apps built with Bazel do crossbuilds (eg build on your mac to prod Linux).