@@ -1958,25 +1958,36 @@ impl Build {
1958
1958
let mut parts = target. split ( '-' ) ;
1959
1959
if let Some ( arch) = parts. next ( ) {
1960
1960
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 single_letter = arch. split ( & [ '_' , 'z' , 's' ] ) . next ( ) . unwrap_or ( arch) ;
1971
+ single_letter. contains ( ext)
1972
+ } ;
1973
+
1974
+ let float_abi = if riscv_implements ( "g" ) || riscv_implements ( "d" ) {
1975
+ // Implements "d" (double-float), use double-float ABI
1976
+ "d"
1977
+ } else if riscv_implements ( "f" ) {
1978
+ // Implements "f" (single-float), use single-float ABI
1979
+ "f"
1980
+ } else {
1981
+ // No floating support, use soft-float ABI
1982
+ ""
1983
+ } ;
1984
+
1985
+ if arch. starts_with ( "64" ) {
1986
+ cmd. args . push ( ( "-mabi=lp64" . to_owned ( ) + float_abi) . into ( ) ) ;
1976
1987
} else {
1977
- cmd. args . push ( ( "-march=rv" . to_owned ( ) + arch) . into ( ) ) ;
1978
- cmd. args . push ( "-mabi=ilp32" . into ( ) ) ;
1988
+ cmd. args . push ( ( "-mabi=ilp32" . to_owned ( ) + float_abi) . into ( ) ) ;
1979
1989
}
1990
+
1980
1991
cmd. args . push ( "-mcmodel=medany" . into ( ) ) ;
1981
1992
}
1982
1993
}
0 commit comments