@@ -2368,29 +2368,42 @@ impl Build {
2368
2368
let mut parts = target. split ( '-' ) ;
2369
2369
if let Some ( arch) = parts. next ( ) {
2370
2370
let arch = & arch[ 5 ..] ;
2371
+
2372
+ // Assume that "rv{arch}" is a valid RISC-V ISA string.
2373
+ // The compiler would error out otherwise, and we fix
2374
+ // that later.
2375
+ cmd. args . push ( format ! ( "-march=rv{arch}" ) . into ( ) ) ;
2376
+
2377
+ // Detect single-letter extensions from `arch`, assuming
2378
+ // no version numbers and canonical order
2379
+ let single_letter = arch
2380
+ . split ( [ '_' , 'z' , 's' ] )
2381
+ . next ( )
2382
+ // The arch string starts with 32 or 64
2383
+ . expect ( "arch string cannot be empty" ) ;
2384
+
2385
+ let riscv_implements = |ext| single_letter. contains ( ext) ;
2386
+
2387
+ // Detect ABI to select based on de facto standard
2388
+
2389
+ let float_abi = if riscv_implements ( "g" ) || riscv_implements ( "d" ) {
2390
+ // Implements "d" (double-float), use double-float ABI
2391
+ "d"
2392
+ } else if riscv_implements ( "f" ) {
2393
+ // Implements "f" (single-float), use single-float ABI
2394
+ "f"
2395
+ } else {
2396
+ // No floating support, use soft-float ABI
2397
+ ""
2398
+ } ;
2399
+
2371
2400
if arch. starts_with ( "64" ) {
2372
- if target. contains ( "linux" )
2373
- | target. contains ( "freebsd" )
2374
- | target. contains ( "netbsd" )
2375
- | target. contains ( "linux" )
2376
- {
2377
- cmd. args . push ( ( "-march=rv64gc" ) . into ( ) ) ;
2378
- cmd. args . push ( "-mabi=lp64d" . into ( ) ) ;
2379
- } else {
2380
- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
2381
- cmd. args . push ( "-mabi=lp64" . into ( ) ) ;
2382
- }
2383
- } else if arch. starts_with ( "32" ) {
2384
- if target. contains ( "linux" ) {
2385
- cmd. args . push ( ( "-march=rv32gc" ) . into ( ) ) ;
2386
- cmd. args . push ( "-mabi=ilp32d" . into ( ) ) ;
2387
- } else {
2388
- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
2389
- cmd. args . push ( "-mabi=ilp32" . into ( ) ) ;
2390
- }
2401
+ cmd. args . push ( format ! ( "-mabi=lp64{float_abi}" ) . into ( ) ) ;
2391
2402
} else {
2392
- cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
2403
+ cmd. args . push ( format ! ( "-mabi=ilp32{float_abi}" ) . into ( ) ) ;
2393
2404
}
2405
+
2406
+ cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
2394
2407
}
2395
2408
}
2396
2409
}
0 commit comments