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