@@ -2361,29 +2361,41 @@ impl Build {
23612361 let mut parts = target. split ( '-' ) ;
23622362 if let Some ( arch) = parts. next ( ) {
23632363 let arch = & arch[ 5 ..] ;
2364+
2365+ // Assume that "rv{arch}" is a valid RISC-V ISA string.
2366+ // The compiler would error out otherwise, and we fix
2367+ // that later.
2368+ cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
2369+
2370+ // Detect single-letter extensions from `arch`, assuming
2371+ // no version numbers and canonical order
2372+ let single_letter = arch
2373+ . split ( [ '_' , 'z' , 's' ] )
2374+ . next ( )
2375+ . expect ( "Empty arch string?" ) ;
2376+
2377+ let riscv_implements = |ext| single_letter. contains ( ext) ;
2378+
2379+ // Detect ABI to select based on de facto standard
2380+
2381+ let float_abi = if riscv_implements ( "g" ) || riscv_implements ( "d" ) {
2382+ // Implements "d" (double-float), use double-float ABI
2383+ "d"
2384+ } else if riscv_implements ( "f" ) {
2385+ // Implements "f" (single-float), use single-float ABI
2386+ "f"
2387+ } else {
2388+ // No floating support, use soft-float ABI
2389+ ""
2390+ } ;
2391+
23642392 if arch. starts_with ( "64" ) {
2365- if target. contains ( "linux" )
2366- | target. contains ( "freebsd" )
2367- | target. contains ( "netbsd" )
2368- | target. contains ( "linux" )
2369- {
2370- cmd. args . push ( ( "-march=rv64gc" ) . into ( ) ) ;
2371- cmd. args . push ( "-mabi=lp64d" . into ( ) ) ;
2372- } else {
2373- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
2374- cmd. args . push ( "-mabi=lp64" . into ( ) ) ;
2375- }
2376- } else if arch. starts_with ( "32" ) {
2377- if target. contains ( "linux" ) {
2378- cmd. args . push ( ( "-march=rv32gc" ) . into ( ) ) ;
2379- cmd. args . push ( "-mabi=ilp32d" . into ( ) ) ;
2380- } else {
2381- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
2382- cmd. args . push ( "-mabi=ilp32" . into ( ) ) ;
2383- }
2393+ cmd. args . push ( ( "-mabi=lp64" . to_owned ( ) + float_abi) . into ( ) ) ;
23842394 } else {
2385- cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
2395+ cmd. args . push ( ( "-mabi=ilp32" . to_owned ( ) + float_abi ) . into ( ) ) ;
23862396 }
2397+
2398+ cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
23872399 }
23882400 }
23892401 }
0 commit comments