fn search_lib_dir(path: impl AsRef<Path>, cross: &CrossCompileConfig) -> Vec<PathBuf> {
    let mut sysconfig_paths = vec![];
    let version_pat = if let Some(v) = &cross.version {
        format!("python{}", v)
    } else {
        "python3.".into()
    };
    for f in fs::read_dir(path).expect("Path does not exist").into_iter() {
        sysconfig_paths.extend(match &f {
            // Python 3.6 sysconfigdata without platform specifics
            Ok(f) if f.file_name() == "_sysconfigdata.py" => vec![f.path()],
            // Python 3.7+ sysconfigdata with platform specifics
            Ok(f) if starts_with(f, "_sysconfigdata_") && ends_with(f, "py") => vec![f.path()],
            Ok(f) if f.metadata().map_or(false, |metadata| metadata.is_dir()) => {
                let file_name = f.file_name();
                let file_name = file_name.to_string_lossy();
                if file_name.starts_with("build") {
                    search_lib_dir(f.path(), cross)
                } else if file_name.starts_with("lib.") {
                    // check if right target os
                    if !file_name.contains(if cross.os == "android" {
                        "linux"
                    } else {
                        &cross.os
                    }) {
                        continue;
                    }
                    // Check if right arch
                    if !file_name.contains(&cross.arch) {
                        continue;
                    }
                    search_lib_dir(f.path(), cross)
                } else if file_name.starts_with(&version_pat) {
                    search_lib_dir(f.path(), cross)
                } else {
                    continue;
                }
            }
            _ => continue,
        });
    }
    // If we got more than one file, only take those that contain the arch name.
    // For ubuntu 20.04 with host architecture x86_64 and a foreign architecture of armhf
    // this reduces the number of candidates to 1:
    //
    // $ find /usr/lib/python3.8/ -name '_sysconfigdata*.py' -not -lname '*'
    //  /usr/lib/python3.8/_sysconfigdata__x86_64-linux-gnu.py
    //  /usr/lib/python3.8/_sysconfigdata__arm-linux-gnueabihf.py
    if sysconfig_paths.len() > 1 {
        let temp = sysconfig_paths
            .iter()
            .filter(|p| p.to_string_lossy().contains(&cross.arch))
            .cloned()
            .collect::<Vec<PathBuf>>();
        if !temp.is_empty() {
            sysconfig_paths = temp;
        }
    }

    sysconfig_paths
}
/// recursive search for _sysconfigdata, returns all possibilities of sysconfigdata paths
recursive search for _sysconfigdata, returns all possibilities of sysconfigdata paths
recursive search for _sysconfigdata returns all possibilities of sysconfigdata paths
fn search_lib_dir(path: impl AsRef<Path>, cross: &CrossCompileConfig) -> Vec<PathBuf> {
    let mut sysconfig_paths = vec![];
    let version_pat = if let Some(v) = &cross.version {
        format!("python{}", v)
    } else {
        "python3.".into()
    };
    for f in fs::read_dir(path).expect("Path does not exist").into_iter() {
        sysconfig_paths.extend(match &f {
            // Python 3.6 sysconfigdata without platform specifics
            Ok(f) if f.file_name() == "_sysconfigdata.py" => vec![f.path()],
            // Python 3.7+ sysconfigdata with platform specifics
            Ok(f) if starts_with(f, "_sysconfigdata_") && ends_with(f, "py") => vec![f.path()],
            Ok(f) if f.metadata().map_or(false, |metadata| metadata.is_dir()) => {
                let file_name = f.file_name();
                let file_name = file_name.to_string_lossy();
                if file_name.starts_with("build") {
                    search_lib_dir(f.path(), cross)
                } else if file_name.starts_with("lib.") {
                    // check if right target os
                    if !file_name.contains(if cross.os == "android" {
                        "linux"
                    } else {
                        &cross.os
                    }) {
                        continue;
                    }
                    // Check if right arch
                    if !file_name.contains(&cross.arch) {
                        continue;
                    }
                    search_lib_dir(f.path(), cross)
                } else if file_name.starts_with(&version_pat) {
                    search_lib_dir(f.path(), cross)
                } else {
                    continue;
                }
            }
            _ => continue,
        });
    }
    // If we got more than one file, only take those that contain the arch name.
    // For ubuntu 20.04 with host architecture x86_64 and a foreign architecture of armhf
    // this reduces the number of candidates to 1:
    //
    // $ find /usr/lib/python3.8/ -name '_sysconfigdata*.py' -not -lname '*'
    //  /usr/lib/python3.8/_sysconfigdata__x86_64-linux-gnu.py
    //  /usr/lib/python3.8/_sysconfigdata__arm-linux-gnueabihf.py
    if sysconfig_paths.len() > 1 {
        let temp = sysconfig_paths
            .iter()
            .filter(|p| p.to_string_lossy().contains(&cross.arch))
            .cloned()
            .collect::<Vec<PathBuf>>();
        if !temp.is_empty() {
            sysconfig_paths = temp;
        }
    }
    sysconfig_paths
}
fn search_lib_dir ( path : impl AsRef < Path > , cross : & CrossCompileConfig ) -> Vec < PathBuf > { let mut sysconfig_paths = vec ! [ ] ; let version_pat = if let Some ( v ) = & cross . version { format ! ( " " v ) } else { " " . into ( ) } ; for f in fs :: read_dir ( path ) . expect ( " " ) . into_iter ( ) { sysconfig_paths . extend ( match & f { // Python 3.6 sysconfigdata without platform specifics Ok ( f ) if f . file_name ( ) == " " => vec ! [ f path ( ) ] , // Python 3.7+ sysconfigdata with platform specifics Ok ( f ) if starts_with ( f , " " ) && ends_with ( f , " " ) => vec ! [ f path ( ) ] , Ok ( f ) if f . metadata ( ) . map_or ( false , | metadata | metadata . is_dir ( ) ) => { let file_name = f . file_name ( ) ; let file_name = file_name . to_string_lossy ( ) ; if file_name . starts_with ( " " ) { search_lib_dir ( f . path ( ) , cross ) } else if file_name . starts_with ( " " ) { // check if right target os if ! file_name . contains ( if cross . os == " " { " " } else { & cross . os } ) { continue ; } // Check if right arch if ! file_name . contains ( & cross . arch ) { continue ; } search_lib_dir ( f . path ( ) , cross ) } else if file_name . starts_with ( & version_pat ) { search_lib_dir ( f . path ( ) , cross ) } else { continue ; } } _ => continue , } ) ; } // If we got more than one file, only take those that contain the arch name. // For ubuntu 20.04 with host architecture x86_64 and a foreign architecture of armhf // this reduces the number of candidates to 1: // // $ find /usr/lib/python3.8/ -name '_sysconfigdata*.py' -not -lname '*' //  /usr/lib/python3.8/_sysconfigdata__x86_64-linux-gnu.py //  /usr/lib/python3.8/_sysconfigdata__arm-linux-gnueabihf.py if sysconfig_paths . len ( ) > 1 { let temp = sysconfig_paths . iter ( ) . filter ( | p | p . to_string_lossy ( ) . contains ( & cross . arch ) ) . cloned ( ) . collect :: < Vec < PathBuf > > ( ) ; if ! temp . is_empty ( ) { sysconfig_paths = temp ; } } sysconfig_paths }
recursive search for _sysconfigdata, returns all possibilities of sysconfigdata paths
recursive search for _sysconfigdata returns all possibilities of sysconfigdata paths
path
impl AsRef<Path>
cross
&CrossCompileConfig