import re


def determine_clrjit_compiler_version(clrjit_path):
    """ Obtain the version of the compiler that was used to compile the clrjit at the specified path.

    Returns:
        A string extract from the binary or "unknown" if the string could not be found.
        See 'jitBuildString' in buildstring.cpp in the JIT to see where this is defined.
    """

    with open(clrjit_path, "rb") as fh:
        contents = fh.read()

    match = re.search(b'RyuJIT built by ([^\0]*)? targeting ([^\0]*)-([^\0]*)\0', contents)
    if match is None:
        return "unknown"

    return match.group(1).decode("ascii")