@@ -11,14 +11,15 @@ use crate::build::CApiConfig;
11
11
/// It uses internally `rustc` to validate the string.
12
12
#[ derive( Clone , Debug ) ]
13
13
pub struct Target {
14
+ pub is_target_overridden : bool ,
14
15
pub arch : String ,
15
16
// pub vendor: String,
16
17
pub os : String ,
17
18
pub env : String ,
18
19
}
19
20
20
21
impl Target {
21
- pub fn new < T : AsRef < std:: ffi:: OsStr > > ( target : T ) -> Result < Self , anyhow:: Error > {
22
+ pub fn new < T : AsRef < std:: ffi:: OsStr > > ( target : T , is_target_overridden : bool ) -> Result < Self , anyhow:: Error > {
22
23
let rustc = std:: env:: var ( "RUSTC" ) . unwrap_or_else ( |_| "rustc" . into ( ) ) ;
23
24
let mut cmd = std:: process:: Command :: new ( rustc) ;
24
25
@@ -45,6 +46,7 @@ impl Target {
45
46
// vendor: match_re(vendor_re, s),
46
47
os : match_re ( os_re, s) ,
47
48
env : match_re ( env_re, s) ,
49
+ is_target_overridden,
48
50
} )
49
51
} else {
50
52
Err ( anyhow ! ( "Cannot run {:?}" , cmd) )
@@ -134,32 +136,35 @@ impl Target {
134
136
}
135
137
136
138
pub fn default_libdir ( & self ) -> PathBuf {
137
- if self . is_debianlike ( ) {
138
- let pc = std:: process:: Command :: new ( "dpkg-architecture" )
139
- . arg ( "-qDEB_HOST_MULTIARCH" )
140
- . output ( ) ;
141
- match pc {
142
- std:: io:: Result :: Ok ( v) => {
143
- if v. status . success ( ) {
144
- let archpath = String :: from_utf8_lossy ( & v. stdout ) ;
145
- return format ! ( "lib/{archpath}" ) . into ( ) ;
139
+ if self . is_target_overridden {
140
+ if self . is_debianlike ( ) {
141
+ let pc = std:: process:: Command :: new ( "dpkg-architecture" )
142
+ . arg ( "-qDEB_HOST_MULTIARCH" )
143
+ . output ( ) ;
144
+ match pc {
145
+ std:: io:: Result :: Ok ( v) => {
146
+ if v. status . success ( ) {
147
+ let archpath = String :: from_utf8_lossy ( & v. stdout ) ;
148
+ return format ! ( "lib/{archpath}" ) . into ( ) ;
149
+ }
146
150
}
151
+ std:: io:: Result :: Err ( _) => { }
147
152
}
148
- std:: io:: Result :: Err ( _) => { }
149
153
}
150
- }
151
154
152
- if self . is_freebsd ( ) {
153
- return "lib" . into ( ) ;
154
- }
155
- if consts:: ARCH . eq_ignore_ascii_case ( & self . arch )
156
- && consts:: OS . eq_ignore_ascii_case ( & self . os )
157
- {
158
- let usr_lib64 = PathBuf :: from ( "/usr/lib64" ) ;
159
- if usr_lib64. exists ( ) && !usr_lib64. is_symlink ( ) {
160
- return "lib64" . into ( ) ;
155
+ if self . is_freebsd ( ) {
156
+ return "lib" . into ( ) ;
157
+ }
158
+ if consts:: ARCH . eq_ignore_ascii_case ( & self . arch )
159
+ && consts:: OS . eq_ignore_ascii_case ( & self . os )
160
+ {
161
+ let usr_lib64 = PathBuf :: from ( "/usr/lib64" ) ;
162
+ if usr_lib64. exists ( ) && !usr_lib64. is_symlink ( ) {
163
+ return "lib64" . into ( ) ;
164
+ }
161
165
}
162
166
}
167
+
163
168
"lib" . into ( )
164
169
}
165
170
0 commit comments