@@ -3,30 +3,36 @@ use std::path::PathBuf;
33#[ derive( Debug , Copy , Clone , PartialEq , PartialOrd ) ]
44pub enum Platform {
55 Win64 ,
6- Win32 ,
76 Linux ,
7+ LinuxMusl ,
88}
99
1010impl Platform {
1111 pub fn current ( ) -> Self {
12- if cfg ! ( target_os = "windows" ) && cfg ! ( target_pointer_width = "32" ) {
13- return Self :: Win32 ;
14- }
1512 if cfg ! ( target_os = "windows" ) && cfg ! ( target_pointer_width = "64" ) {
1613 return Self :: Win64 ;
1714 }
18- if cfg ! ( target_os = "linux" ) && cfg ! ( target_pointer_width = "64" ) {
15+ if cfg ! ( target_os = "linux" )
16+ && cfg ! ( target_pointer_width = "64" )
17+ && !cfg ! ( target_env = "musl" )
18+ {
1919 return Self :: Linux ;
2020 }
21+ if cfg ! ( target_os = "linux" )
22+ && cfg ! ( target_pointer_width = "64" )
23+ && cfg ! ( target_env = "musl" )
24+ {
25+ return Self :: LinuxMusl ;
26+ }
2127
2228 unimplemented ! ( "Current platform is not supported" )
2329 }
2430
2531 pub fn to_string ( & self ) -> & ' static str {
2632 match self {
2733 Self :: Win64 => "win-x64" ,
28- Self :: Win32 => "win-x32" ,
2934 Self :: Linux => "linux" ,
35+ Self :: LinuxMusl => "linux-musl" ,
3036 }
3137 }
3238}
@@ -43,40 +49,42 @@ impl PlatformLocation {
4349
4450 pub fn lib_filename < T : AsRef < str > > ( & self , libname : T ) -> String {
4551 match self . platform {
46- Platform :: Win64 | Platform :: Win32 => format ! ( "{}.dll.lib" , libname. as_ref( ) ) ,
52+ Platform :: Win64 => format ! ( "{}.dll.lib" , libname. as_ref( ) ) ,
4753 Platform :: Linux => format ! ( "lib{}.so" , libname. as_ref( ) ) ,
54+ Platform :: LinuxMusl => format ! ( "lib{}.a" , libname. as_ref( ) ) ,
4855 }
4956 }
5057
5158 pub fn bin_filename < T : AsRef < str > > ( & self , libname : T ) -> String {
5259 match self . platform {
53- Platform :: Win64 | Platform :: Win32 => format ! ( "{}.dll" , libname. as_ref( ) ) ,
60+ Platform :: Win64 => format ! ( "{}.dll" , libname. as_ref( ) ) ,
5461 Platform :: Linux => format ! ( "lib{}.so" , libname. as_ref( ) ) ,
62+ Platform :: LinuxMusl => format ! ( "lib{}.a" , libname. as_ref( ) ) ,
5563 }
5664 }
5765}
5866
5967#[ derive( Clone ) ]
6068pub struct PlatformLocations {
6169 pub win64 : Option < PathBuf > ,
62- pub win32 : Option < PathBuf > ,
6370 pub linux : Option < PathBuf > ,
71+ pub linux_musl : Option < PathBuf > ,
6472}
6573
6674impl PlatformLocations {
6775 pub fn new ( ) -> Self {
6876 PlatformLocations {
6977 win64 : None ,
70- win32 : None ,
7178 linux : None ,
79+ linux_musl : None ,
7280 }
7381 }
7482
7583 pub fn add ( & mut self , platform : Platform , location : PathBuf ) {
7684 match platform {
7785 Platform :: Win64 => self . win64 = Some ( location) ,
78- Platform :: Win32 => self . win32 = Some ( location) ,
7986 Platform :: Linux => self . linux = Some ( location) ,
87+ Platform :: LinuxMusl => self . linux_musl = Some ( location) ,
8088 }
8189 }
8290
@@ -85,17 +93,21 @@ impl PlatformLocations {
8593 if let Some ( loc) = & self . win64 {
8694 vec. push ( PlatformLocation :: new ( Platform :: Win64 , loc. clone ( ) ) )
8795 }
88- if let Some ( loc) = & self . win32 {
89- vec. push ( PlatformLocation :: new ( Platform :: Win32 , loc. clone ( ) ) )
90- }
9196 if let Some ( loc) = & self . linux {
9297 vec. push ( PlatformLocation :: new ( Platform :: Linux , loc. clone ( ) ) )
9398 }
99+ if let Some ( loc) = & self . linux_musl {
100+ vec. push ( PlatformLocation :: new ( Platform :: LinuxMusl , loc. clone ( ) ) )
101+ }
94102 vec. into_iter ( )
95103 }
96104
97105 pub fn is_empty ( & self ) -> bool {
98- self . win64 . is_none ( ) && self . win32 . is_none ( ) && self . linux . is_none ( )
106+ self . win64 . is_none ( ) && self . linux . is_none ( ) && self . linux_musl . is_none ( )
107+ }
108+
109+ pub fn has_dynamic_lib ( & self ) -> bool {
110+ self . win64 . is_some ( ) || self . linux . is_some ( )
99111 }
100112}
101113
0 commit comments