def _safe_int(s):
    """Returns the integer value of `s` when interpreted as base 10, or `None` if it is invalid.

    This function is needed because `int()` fails the build when passed a string that isn't a valid
    integer, with no way to recover (https://github.com/bazelbuild/bazel/issues/5940).

    Args:
        s: The string to be converted to an integer.

    Returns:
        The integer value of `s`, or `None` if was not a valid base 10 integer.
    """
    for i in range(len(s)):
        if s[i] < "0" or s[i] > "9":
            return None
    return int(s)