@@ -247,6 +247,8 @@ mod tool;
247
247
pub use tool:: Tool ;
248
248
use tool:: ToolFamily ;
249
249
250
+ mod target_info;
251
+
250
252
/// A builder for compilation of a native library.
251
253
///
252
254
/// A `Build` is the main type of the `cc` crate and is used to control all the
@@ -312,6 +314,8 @@ enum ErrorKind {
312
314
ToolNotFound ,
313
315
/// One of the function arguments failed validation.
314
316
InvalidArgument ,
317
+ /// Invalid target
318
+ InvalidTarget ,
315
319
#[ cfg( feature = "parallel" ) ]
316
320
/// jobserver helpthread failure
317
321
JobserverHelpThreadError ,
@@ -1900,6 +1904,13 @@ impl Build {
1900
1904
&& !( target. contains ( "android" )
1901
1905
&& android_clang_compiler_uses_target_arg_internally ( & cmd. path ) )
1902
1906
{
1907
+ let ( arch, rest) = target. split_once ( '-' ) . ok_or_else ( || {
1908
+ Error :: new (
1909
+ ErrorKind :: InvalidTarget ,
1910
+ format ! ( "Invalid target `{}`: no `-` in it" , target) ,
1911
+ )
1912
+ } ) ?;
1913
+
1903
1914
if target. contains ( "darwin" ) {
1904
1915
if let Some ( arch) =
1905
1916
map_darwin_target_from_rust_to_compiler_architecture ( target)
@@ -1983,39 +1994,17 @@ impl Build {
1983
1994
format ! ( "--target={}-apple-tvos{}" , arch, deployment_target) . into ( ) ,
1984
1995
) ;
1985
1996
}
1986
- } else if target. starts_with ( "riscv64gc-" ) {
1987
- cmd. args . push (
1988
- format ! ( "--target={}" , target. replace( "riscv64gc" , "riscv64" ) ) . into ( ) ,
1989
- ) ;
1990
- } else if target. starts_with ( "riscv64imac-" ) {
1991
- cmd. args . push (
1992
- format ! ( "--target={}" , target. replace( "riscv64imac" , "riscv64" ) ) . into ( ) ,
1993
- ) ;
1994
- } else if target. starts_with ( "riscv32gc-" ) {
1997
+ } else if let Ok ( index) = target_info:: RISCV_ARCH_MAPPING
1998
+ . binary_search_by_key ( & arch, |( arch, _) | & arch)
1999
+ {
1995
2000
cmd. args . push (
1996
- format ! ( "--target={}" , target. replace( "riscv32gc" , "riscv32" ) ) . into ( ) ,
2001
+ format ! (
2002
+ "--target={}-{}" ,
2003
+ target_info:: RISCV_ARCH_MAPPING [ index] . 1 ,
2004
+ rest
2005
+ )
2006
+ . into ( ) ,
1997
2007
) ;
1998
- } else if target. starts_with ( "riscv32i-" ) {
1999
- cmd. args . push (
2000
- format ! ( "--target={}" , target. replace( "riscv32i" , "riscv32" ) ) . into ( ) ,
2001
- )
2002
- } else if target. starts_with ( "riscv32im-" ) {
2003
- cmd. args . push (
2004
- format ! ( "--target={}" , target. replace( "riscv32im" , "riscv32" ) ) . into ( ) ,
2005
- )
2006
- } else if target. starts_with ( "riscv32imc-" ) {
2007
- cmd. args . push (
2008
- format ! ( "--target={}" , target. replace( "riscv32imc" , "riscv32" ) ) . into ( ) ,
2009
- )
2010
- } else if target. starts_with ( "riscv32imac-" ) {
2011
- cmd. args . push (
2012
- format ! ( "--target={}" , target. replace( "riscv32imac" , "riscv32" ) ) . into ( ) ,
2013
- )
2014
- } else if target. starts_with ( "riscv32imafc-" ) {
2015
- cmd. args . push (
2016
- format ! ( "--target={}" , target. replace( "riscv32imafc" , "riscv32" ) )
2017
- . into ( ) ,
2018
- )
2019
2008
} else if target. contains ( "uefi" ) {
2020
2009
if target. contains ( "x86_64" ) {
2021
2010
cmd. args . push ( "--target=x86_64-unknown-windows-gnu" . into ( ) ) ;
0 commit comments