4
4
*--------------------------------------------------------------------------------------------*/
5
5
use std:: cmp:: Ordering ;
6
6
7
- use super :: command:: capture_command;
8
7
use crate :: constants:: QUALITYLESS_SERVER_NAME ;
9
8
use crate :: update_service:: Platform ;
10
9
use lazy_static:: lazy_static;
@@ -20,8 +19,10 @@ lazy_static! {
20
19
static ref GENERIC_VERSION_RE : Regex = Regex :: new( r"^([0-9]+)\.([0-9]+)$" ) . unwrap( ) ;
21
20
static ref LIBSTD_CXX_VERSION_RE : BinRegex =
22
21
BinRegex :: new( r"GLIBCXX_([0-9]+)\.([0-9]+)(?:\.([0-9]+))?" ) . unwrap( ) ;
23
- static ref MIN_CXX_VERSION : SimpleSemver = SimpleSemver :: new( 3 , 4 , 19 ) ;
24
- static ref MIN_LDD_VERSION : SimpleSemver = SimpleSemver :: new( 2 , 17 , 0 ) ;
22
+ static ref MIN_CXX_VERSION : SimpleSemver = SimpleSemver :: new( 3 , 4 , 25 ) ;
23
+ static ref MIN_LEGACY_CXX_VERSION : SimpleSemver = SimpleSemver :: new( 3 , 4 , 19 ) ;
24
+ static ref MIN_LDD_VERSION : SimpleSemver = SimpleSemver :: new( 2 , 28 , 0 ) ;
25
+ static ref MIN_LEGACY_LDD_VERSION : SimpleSemver = SimpleSemver :: new( 2 , 17 , 0 ) ;
25
26
}
26
27
27
28
const NIXOS_TEST_PATH : & str = "/etc/NIXOS" ;
@@ -63,18 +64,30 @@ impl PreReqChecker {
63
64
} else {
64
65
println ! ( "!!! WARNING: Skipping server pre-requisite check !!!" ) ;
65
66
println ! ( "!!! Server stability is not guaranteed. Proceed at your own risk. !!!" ) ;
66
- ( Ok ( ( ) ) , Ok ( ( ) ) )
67
+ ( Ok ( false ) , Ok ( false ) )
67
68
} ;
68
69
69
- if ( gnu_a. is_ok ( ) && gnu_b. is_ok ( ) ) || is_nixos {
70
- return Ok ( if cfg ! ( target_arch = "x86_64" ) {
71
- Platform :: LinuxX64
72
- } else if cfg ! ( target_arch = "arm" ) {
73
- Platform :: LinuxARM32
74
- } else {
75
- Platform :: LinuxARM64
76
- } ) ;
77
- }
70
+ match ( & gnu_a, & gnu_b, is_nixos) {
71
+ ( Ok ( false ) , Ok ( false ) , _) | ( _, _, true ) => {
72
+ return Ok ( if cfg ! ( target_arch = "x86_64" ) {
73
+ Platform :: LinuxX64
74
+ } else if cfg ! ( target_arch = "arm" ) {
75
+ Platform :: LinuxARM32
76
+ } else {
77
+ Platform :: LinuxARM64
78
+ } ) ;
79
+ }
80
+ ( Ok ( _) , Ok ( _) , _) => {
81
+ return Ok ( if cfg ! ( target_arch = "x86_64" ) {
82
+ Platform :: LinuxX64Legacy
83
+ } else if cfg ! ( target_arch = "arm" ) {
84
+ Platform :: LinuxARM32Legacy
85
+ } else {
86
+ Platform :: LinuxARM64Legacy
87
+ } ) ;
88
+ }
89
+ _ => { }
90
+ } ;
78
91
79
92
if or_musl. is_ok ( ) {
80
93
return Ok ( if cfg ! ( target_arch = "x86_64" ) {
@@ -126,8 +139,9 @@ async fn check_musl_interpreter() -> Result<(), String> {
126
139
Ok ( ( ) )
127
140
}
128
141
129
- #[ allow( dead_code) ]
130
- async fn check_glibc_version ( ) -> Result < ( ) , String > {
142
+ /// Checks the glibc version, returns "true" if the legacy server is required.
143
+ #[ cfg( target_os = "linux" ) ]
144
+ async fn check_glibc_version ( ) -> Result < bool , String > {
131
145
#[ cfg( target_env = "gnu" ) ]
132
146
let version = {
133
147
let v = unsafe { libc:: gnu_get_libc_version ( ) } ;
@@ -137,15 +151,17 @@ async fn check_glibc_version() -> Result<(), String> {
137
151
} ;
138
152
#[ cfg( not( target_env = "gnu" ) ) ]
139
153
let version = {
140
- capture_command ( "ldd" , [ "--version" ] )
154
+ super :: command :: capture_command ( "ldd" , [ "--version" ] )
141
155
. await
142
156
. ok ( )
143
157
. and_then ( |o| extract_ldd_version ( & o. stdout ) )
144
158
} ;
145
159
146
160
if let Some ( v) = version {
147
161
return if v >= * MIN_LDD_VERSION {
148
- Ok ( ( ) )
162
+ Ok ( false )
163
+ } else if v >= * MIN_LEGACY_LDD_VERSION {
164
+ Ok ( true )
149
165
} else {
150
166
Err ( format ! (
151
167
"find GLIBC >= {} (but found {} instead) for GNU environments" ,
@@ -154,7 +170,7 @@ async fn check_glibc_version() -> Result<(), String> {
154
170
} ;
155
171
}
156
172
157
- Ok ( ( ) )
173
+ Ok ( false )
158
174
}
159
175
160
176
/// Check for nixos to avoid mandating glibc versions. See:
@@ -180,8 +196,9 @@ pub async fn skip_requirements_check() -> bool {
180
196
false
181
197
}
182
198
183
- #[ allow( dead_code) ]
184
- async fn check_glibcxx_version ( ) -> Result < ( ) , String > {
199
+ /// Checks the glibc++ version, returns "true" if the legacy server is required.
200
+ #[ cfg( target_os = "linux" ) ]
201
+ async fn check_glibcxx_version ( ) -> Result < bool , String > {
185
202
let mut libstdc_path: Option < String > = None ;
186
203
187
204
#[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
@@ -193,7 +210,7 @@ async fn check_glibcxx_version() -> Result<(), String> {
193
210
if fs:: metadata ( DEFAULT_LIB_PATH ) . await . is_ok ( ) {
194
211
libstdc_path = Some ( DEFAULT_LIB_PATH . to_owned ( ) ) ;
195
212
} else if fs:: metadata ( LDCONFIG_PATH ) . await . is_ok ( ) {
196
- libstdc_path = capture_command ( LDCONFIG_PATH , [ "-p" ] )
213
+ libstdc_path = super :: command :: capture_command ( LDCONFIG_PATH , [ "-p" ] )
197
214
. await
198
215
. ok ( )
199
216
. and_then ( |o| extract_libstd_from_ldconfig ( & o. stdout ) ) ;
@@ -211,30 +228,35 @@ async fn check_glibcxx_version() -> Result<(), String> {
211
228
}
212
229
}
213
230
214
- #[ allow ( dead_code ) ]
215
- fn check_for_sufficient_glibcxx_versions ( contents : Vec < u8 > ) -> Result < ( ) , String > {
216
- let all_versions : Vec < SimpleSemver > = LIBSTD_CXX_VERSION_RE
231
+ #[ cfg ( target_os = "linux" ) ]
232
+ fn check_for_sufficient_glibcxx_versions ( contents : Vec < u8 > ) -> Result < bool , String > {
233
+ let max_version = LIBSTD_CXX_VERSION_RE
217
234
. captures_iter ( & contents)
218
235
. map ( |m| SimpleSemver {
219
236
major : m. get ( 1 ) . map_or ( 0 , |s| u32_from_bytes ( s. as_bytes ( ) ) ) ,
220
237
minor : m. get ( 2 ) . map_or ( 0 , |s| u32_from_bytes ( s. as_bytes ( ) ) ) ,
221
238
patch : m. get ( 3 ) . map_or ( 0 , |s| u32_from_bytes ( s. as_bytes ( ) ) ) ,
222
239
} )
223
- . collect ( ) ;
240
+ . max ( ) ;
224
241
225
- if !all_versions. iter ( ) . any ( |v| & * MIN_CXX_VERSION >= v) {
226
- return Err ( format ! (
227
- "find GLIBCXX >= {} (but found {} instead) for GNU environments" ,
228
- * MIN_CXX_VERSION ,
229
- all_versions
230
- . iter( )
231
- . map( String :: from)
232
- . collect:: <Vec <String >>( )
233
- . join( ", " )
234
- ) ) ;
242
+ if let Some ( max_version) = & max_version {
243
+ if max_version >= & * MIN_CXX_VERSION {
244
+ return Ok ( false ) ;
245
+ }
246
+
247
+ if max_version >= & * MIN_LEGACY_CXX_VERSION {
248
+ return Ok ( true ) ;
249
+ }
235
250
}
236
251
237
- Ok ( ( ) )
252
+ Err ( format ! (
253
+ "find GLIBCXX >= {} (but found {} instead) for GNU environments" ,
254
+ * MIN_CXX_VERSION ,
255
+ max_version
256
+ . as_ref( )
257
+ . map( String :: from)
258
+ . unwrap_or( "none" . to_string( ) )
259
+ ) )
238
260
}
239
261
240
262
#[ allow( dead_code) ]
@@ -255,6 +277,7 @@ fn extract_generic_version(output: &str) -> Option<SimpleSemver> {
255
277
} )
256
278
}
257
279
280
+ #[ allow( dead_code) ]
258
281
fn extract_libstd_from_ldconfig ( output : & [ u8 ] ) -> Option < String > {
259
282
String :: from_utf8_lossy ( output)
260
283
. lines ( )
@@ -326,12 +349,12 @@ mod tests {
326
349
#[ test]
327
350
fn test_extract_libstd_from_ldconfig ( ) {
328
351
let actual = "
329
- libstoken.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstoken.so.1
330
- libstemmer.so.0d (libc6,x86-64) => /lib/x86_64-linux-gnu/libstemmer.so.0d
331
- libstdc++.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstdc++.so.6
332
- libstartup-notification-1.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstartup-notification-1.so.0
333
- libssl3.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libssl3.so
334
- ". to_owned ( ) . into_bytes ( ) ;
352
+ libstoken.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstoken.so.1
353
+ libstemmer.so.0d (libc6,x86-64) => /lib/x86_64-linux-gnu/libstemmer.so.0d
354
+ libstdc++.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstdc++.so.6
355
+ libstartup-notification-1.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libstartup-notification-1.so.0
356
+ libssl3.so (libc6,x86-64) => /lib/x86_64-linux-gnu/libssl3.so
357
+ ". to_owned ( ) . into_bytes ( ) ;
335
358
336
359
assert_eq ! (
337
360
extract_libstd_from_ldconfig( & actual) ,
@@ -358,10 +381,10 @@ mod tests {
358
381
#[ test]
359
382
fn check_for_sufficient_glibcxx_versions ( ) {
360
383
let actual = "ldd (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31
361
- Copyright (C) 2020 Free Software Foundation, Inc.
362
- This is free software; see the source for copying conditions. There is NO
363
- warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
364
- Written by Roland McGrath and Ulrich Drepper."
384
+ Copyright (C) 2020 Free Software Foundation, Inc.
385
+ This is free software; see the source for copying conditions. There is NO
386
+ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
387
+ Written by Roland McGrath and Ulrich Drepper."
365
388
. to_owned ( )
366
389
. into_bytes ( ) ;
367
390
0 commit comments