@@ -53,7 +53,7 @@ pub fn find(build: &mut Build) {
5353 if let Some ( cc) = config. and_then ( |c| c. cc . as_ref ( ) ) {
5454 cfg. compiler ( cc) ;
5555 } else {
56- set_compiler ( & mut cfg, "gcc" , target, config, build) ;
56+ set_compiler ( & mut cfg, Language :: C , target, config, build) ;
5757 }
5858
5959 let compiler = cfg. get_compiler ( ) ;
@@ -74,7 +74,7 @@ pub fn find(build: &mut Build) {
7474 if let Some ( cxx) = config. and_then ( |c| c. cxx . as_ref ( ) ) {
7575 cfg. compiler ( cxx) ;
7676 } else {
77- set_compiler ( & mut cfg, "g++" , host, config, build) ;
77+ set_compiler ( & mut cfg, Language :: CPlusPlus , host, config, build) ;
7878 }
7979 let compiler = cfg. get_compiler ( ) ;
8080 build. verbose ( & format ! ( "CXX_{} = {:?}" , host, compiler. path( ) ) ) ;
@@ -83,7 +83,7 @@ pub fn find(build: &mut Build) {
8383}
8484
8585fn set_compiler ( cfg : & mut cc:: Build ,
86- gnu_compiler : & str ,
86+ compiler : Language ,
8787 target : Interned < String > ,
8888 config : Option < & Target > ,
8989 build : & Build ) {
@@ -94,7 +94,7 @@ fn set_compiler(cfg: &mut cc::Build,
9494 t if t. contains ( "android" ) => {
9595 if let Some ( ndk) = config. and_then ( |c| c. ndk . as_ref ( ) ) {
9696 let target = target. replace ( "armv7" , "arm" ) ;
97- let compiler = format ! ( "{}-{}" , target, gnu_compiler ) ;
97+ let compiler = format ! ( "{}-{}" , target, compiler . clang ( ) ) ;
9898 cfg. compiler ( ndk. join ( "bin" ) . join ( compiler) ) ;
9999 }
100100 }
@@ -103,6 +103,7 @@ fn set_compiler(cfg: &mut cc::Build,
103103 // which is a gcc version from ports, if this is the case.
104104 t if t. contains ( "openbsd" ) => {
105105 let c = cfg. get_compiler ( ) ;
106+ let gnu_compiler = compiler. gcc ( ) ;
106107 if !c. path ( ) . ends_with ( gnu_compiler) {
107108 return
108109 }
@@ -145,3 +146,29 @@ fn set_compiler(cfg: &mut cc::Build,
145146 _ => { }
146147 }
147148}
149+
150+ /// The target programming language for a native compiler.
151+ enum Language {
152+ /// The compiler is targeting C.
153+ C ,
154+ /// The compiler is targeting C++.
155+ CPlusPlus ,
156+ }
157+
158+ impl Language {
159+ /// Obtains the name of a compiler in the GCC collection.
160+ fn gcc ( self ) -> & ' static str {
161+ match self {
162+ Language :: C => "gcc" ,
163+ Language :: CPlusPlus => "g++" ,
164+ }
165+ }
166+
167+ /// Obtains the name of a compiler in the clang suite.
168+ fn clang ( self ) -> & ' static str {
169+ match self {
170+ Language :: C => "clang" ,
171+ Language :: CPlusPlus => "clang++" ,
172+ }
173+ }
174+ }
0 commit comments