def sphinx_role(record, lang):
    """
    Return the Sphinx role used for a record.

    This is used for the description directive like ".. c:function::", and
    links like ":c:func:`foo`.
    """

    kind = record["kind"]

    if kind in ["class", "function", "namespace", "struct", "union"]:
        return lang + ":" + kind

    if kind == "define":
        return "c:macro"

    if kind == "enum":
        return lang + (":enum-class" if record["strong"] else ":enum")

    if kind == "typedef":
        return lang + ":type"

    if kind == "enumvalue":
        return lang + ":enumerator"

    if kind == "variable":
        return lang + (":member" if "parent" in record else ":var")

    raise RuntimeError("No known role for kind '%s'" % kind)