11use crate :: { AllocatorKind , AllocatorLib } ;
22use std:: path:: PathBuf ;
33
4- /// Returns the glob patterns used to find this allocator's shared libraries.
5- fn get_allocator_paths ( lib : & AllocatorKind ) -> & ' static [ & ' static str ] {
6- match lib {
7- AllocatorKind :: Libc => & [
8- // Debian, Ubuntu: Standard Linux multiarch paths
9- "/lib/*-linux-gnu/libc.so.6 " ,
10- "/usr/lib/*-linux-gnu/libc.so.6 " ,
4+ impl AllocatorKind {
5+ /// Build glob patterns for finding this allocator's shared libraries.
6+ fn search_patterns ( & self ) -> Vec < String > {
7+ const LIB_DIRS : & [ & str ] = & [
8+ // Debian, Ubuntu: multiarch paths
9+ "/lib/*-linux-gnu" ,
10+ "/usr/lib/*-linux-gnu" ,
1111 // RHEL, Fedora, CentOS, Arch
12- "/lib*/libc.so.6" ,
13- "/usr/lib*/libc.so.6" ,
14- // NixOS: find all glibc versions in the Nix store
15- "/nix/store/*glibc*/lib/libc.so.6" ,
16- ] ,
17- AllocatorKind :: LibCpp => & [
18- // Standard Linux multiarch paths
19- "/lib/*-linux-gnu/libstdc++.so*" ,
20- "/usr/lib/*-linux-gnu/libstdc++.so*" ,
21- // RHEL, Fedora, CentOS, Arch
22- "/lib*/libstdc++.so*" ,
23- "/usr/lib*/libstdc++.so*" ,
24- // NixOS: find all gcc lib versions in the Nix store
25- "/nix/store/*gcc*/lib/libstdc++.so*" ,
26- ] ,
27- AllocatorKind :: Jemalloc => & [
28- // Debian, Ubuntu: Standard Linux multiarch paths
29- "/lib/*-linux-gnu/libjemalloc.so*" ,
30- "/usr/lib/*-linux-gnu/libjemalloc.so*" ,
31- // RHEL, Fedora, CentOS, Arch
32- "/lib*/libjemalloc.so*" ,
33- "/usr/lib*/libjemalloc.so*" ,
34- "/usr/local/lib*/libjemalloc.so*" ,
35- // NixOS
36- "/nix/store/*jemalloc*/lib/libjemalloc.so*" ,
37- ] ,
38- AllocatorKind :: Mimalloc => & [
39- // Debian, Ubuntu: Standard Linux multiarch paths
40- "/lib/*-linux-gnu/libmimalloc.so*" ,
41- "/usr/lib/*-linux-gnu/libmimalloc.so*" ,
42- // RHEL, Fedora, CentOS, Arch
43- "/lib*/libmimalloc.so*" ,
44- "/usr/lib*/libmimalloc.so*" ,
45- "/usr/local/lib*/libmimalloc.so*" ,
46- // NixOS
47- "/nix/store/*mimalloc*/lib/libmimalloc.so*" ,
48- ] ,
49- AllocatorKind :: Tcmalloc => & [
50- // gperftools tcmalloc variants
51- // Debian, Ubuntu: Standard Linux multiarch paths
52- "/lib/*-linux-gnu/libtcmalloc.so*" ,
53- "/lib/*-linux-gnu/libtcmalloc_minimal.so*" ,
54- "/lib/*-linux-gnu/libtcmalloc_debug.so*" ,
55- "/lib/*-linux-gnu/libtcmalloc_and_profiler.so*" ,
56- "/usr/lib/*-linux-gnu/libtcmalloc.so*" ,
57- "/usr/lib/*-linux-gnu/libtcmalloc_minimal.so*" ,
58- "/usr/lib/*-linux-gnu/libtcmalloc_debug.so*" ,
59- "/usr/lib/*-linux-gnu/libtcmalloc_and_profiler.so*" ,
60- // RHEL, Fedora, CentOS, Arch
61- "/lib*/libtcmalloc*.so*" ,
62- "/usr/lib*/libtcmalloc*.so*" ,
63- "/usr/local/lib*/libtcmalloc*.so*" ,
64- // NixOS
65- "/nix/store/*tcmalloc*/lib/libtcmalloc*.so*" ,
66- "/nix/store/*gperftools*/lib/libtcmalloc*.so*" ,
67- ] ,
12+ "/lib*" ,
13+ "/usr/lib*" ,
14+ // Local installs
15+ "/usr/local/lib*" ,
16+ ] ;
17+
18+ let ( filenames, nix_hints) : ( & [ & str ] , & [ & str ] ) = match self {
19+ AllocatorKind :: Libc => ( & [ "libc.so.6" ] , & [ "glibc" ] ) ,
20+ AllocatorKind :: LibCpp => ( & [ "libstdc++.so*" ] , & [ "gcc" ] ) ,
21+ AllocatorKind :: Jemalloc => ( & [ "libjemalloc.so*" ] , & [ "jemalloc" ] ) ,
22+ AllocatorKind :: Mimalloc => ( & [ "libmimalloc.so*" ] , & [ "mimalloc" ] ) ,
23+ AllocatorKind :: Tcmalloc => ( & [ "libtcmalloc*.so*" ] , & [ "tcmalloc" , "gperftools" ] ) ,
24+ } ;
25+
26+ let mut patterns = Vec :: new ( ) ;
27+
28+ for dir in LIB_DIRS {
29+ for filename in filenames {
30+ patterns. push ( format ! ( "{dir}/{filename}" ) ) ;
31+ }
32+ }
33+
34+ for hint in nix_hints {
35+ for filename in filenames {
36+ patterns. push ( format ! ( "/nix/store/*{hint}*/lib/{filename}" ) ) ;
37+ }
38+ }
39+
40+ patterns
6841 }
6942}
7043
@@ -78,8 +51,8 @@ pub fn find_all() -> anyhow::Result<Vec<AllocatorLib>> {
7851 for kind in AllocatorKind :: all ( ) {
7952 let mut found_any = false ;
8053
81- for pattern in get_allocator_paths ( kind) {
82- let paths = glob:: glob ( pattern)
54+ for pattern in kind. search_patterns ( ) {
55+ let paths = glob:: glob ( & pattern)
8356 . ok ( )
8457 . into_iter ( )
8558 . flatten ( )
0 commit comments