@@ -1958,25 +1958,37 @@ impl Build {
19581958 let mut parts = target. split ( '-' ) ;
19591959 if let Some ( arch) = parts. next ( ) {
19601960 let arch = & arch[ 5 ..] ;
1961- if target. contains ( "linux" ) && arch. starts_with ( "64" ) {
1962- cmd. args . push ( ( "-march=rv64gc" ) . into ( ) ) ;
1963- cmd. args . push ( "-mabi=lp64d" . into ( ) ) ;
1964- } else if target. contains ( "freebsd" ) && arch. starts_with ( "64" ) {
1965- cmd. args . push ( ( "-march=rv64gc" ) . into ( ) ) ;
1966- cmd. args . push ( "-mabi=lp64d" . into ( ) ) ;
1967- } else if target. contains ( "openbsd" ) && arch. starts_with ( "64" ) {
1968- cmd. args . push ( ( "-march=rv64gc" ) . into ( ) ) ;
1969- cmd. args . push ( "-mabi=lp64d" . into ( ) ) ;
1970- } else if target. contains ( "linux" ) && arch. starts_with ( "32" ) {
1971- cmd. args . push ( ( "-march=rv32gc" ) . into ( ) ) ;
1972- cmd. args . push ( "-mabi=ilp32d" . into ( ) ) ;
1973- } else if arch. starts_with ( "64" ) {
1974- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
1975- cmd. args . push ( "-mabi=lp64" . into ( ) ) ;
1961+
1962+ // Assume that "rv{arch}" is a valid RISC-V ISA string.
1963+ // The compiler would error out otherwise, and we fix
1964+ // that later.
1965+ cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
1966+
1967+ // Detect single-letter extensions from `arch`, assuming
1968+ // no version numbers and canonical order
1969+ let riscv_implements = |ext : & str | -> bool {
1970+ let pattern = |c| [ '_' , 'z' , 's' ] . contains ( & c) ;
1971+ let single_letter = arch. split ( pattern) . next ( ) . expect ( "Empty arch string?" ) ;
1972+ single_letter. contains ( ext)
1973+ } ;
1974+
1975+ let float_abi = if riscv_implements ( "g" ) || riscv_implements ( "d" ) {
1976+ // Implements "d" (double-float), use double-float ABI
1977+ "d"
1978+ } else if riscv_implements ( "f" ) {
1979+ // Implements "f" (single-float), use single-float ABI
1980+ "f"
1981+ } else {
1982+ // No floating support, use soft-float ABI
1983+ ""
1984+ } ;
1985+
1986+ if arch. starts_with ( "64" ) {
1987+ cmd. args . push ( ( "-mabi=lp64" . to_owned ( ) + float_abi) . into ( ) ) ;
19761988 } else {
1977- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
1978- cmd. args . push ( "-mabi=ilp32" . into ( ) ) ;
1989+ cmd. args . push ( ( "-mabi=ilp32" . to_owned ( ) + float_abi) . into ( ) ) ;
19791990 }
1991+
19801992 cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
19811993 }
19821994 }
0 commit comments