I'm trying to sort something in a Bazel rule using a custom comparator. It looks like Starlark's sorted() only accepts a key, similar to python3. However, python3 has functool's cmp_to_key (
https://www.geeksforgeeks.org/how-does-the-functools-cmp_to_key-function-works-in-python/) which essentially lets you use a comparator. Starlark doesn't allow for python imports, so this feature isn't available. The underlying implementation uses a class, which is also not available in Starlark, so recreating cmp_to_key in a .bzl file isn't an option.
Is there any way to use a custom comparator in Bazel? One option could be to write a simple insertion sort that uses the comparator, but this isn't ideal and I would prefer to use the built in sorted() function if it is possible.