@@ -84,7 +84,7 @@ pub fn find(build: &mut Build) {
8484 if let Some ( cc) = config. and_then ( |c| c. cc . as_ref ( ) ) {
8585 cfg. compiler ( cc) ;
8686 } else {
87- set_compiler ( & mut cfg, "gcc" , target, config, build) ;
87+ set_compiler ( & mut cfg, Language :: C , target, config, build) ;
8888 }
8989
9090 let compiler = cfg. get_compiler ( ) ;
@@ -112,7 +112,7 @@ pub fn find(build: &mut Build) {
112112 if let Some ( cxx) = config. and_then ( |c| c. cxx . as_ref ( ) ) {
113113 cfg. compiler ( cxx) ;
114114 } else {
115- set_compiler ( & mut cfg, "g++" , host, config, build) ;
115+ set_compiler ( & mut cfg, Language :: CPlusPlus , host, config, build) ;
116116 }
117117 let compiler = cfg. get_compiler ( ) ;
118118 build. verbose ( & format ! ( "CXX_{} = {:?}" , host, compiler. path( ) ) ) ;
@@ -121,7 +121,7 @@ pub fn find(build: &mut Build) {
121121}
122122
123123fn set_compiler ( cfg : & mut cc:: Build ,
124- gnu_compiler : & str ,
124+ compiler : Language ,
125125 target : Interned < String > ,
126126 config : Option < & Target > ,
127127 build : & Build ) {
@@ -132,7 +132,7 @@ fn set_compiler(cfg: &mut cc::Build,
132132 t if t. contains ( "android" ) => {
133133 if let Some ( ndk) = config. and_then ( |c| c. ndk . as_ref ( ) ) {
134134 let target = target. replace ( "armv7" , "arm" ) ;
135- let compiler = format ! ( "{}-{}" , target, gnu_compiler ) ;
135+ let compiler = format ! ( "{}-{}" , target, compiler . clang ( ) ) ;
136136 cfg. compiler ( ndk. join ( "bin" ) . join ( compiler) ) ;
137137 }
138138 }
@@ -141,6 +141,7 @@ fn set_compiler(cfg: &mut cc::Build,
141141 // which is a gcc version from ports, if this is the case.
142142 t if t. contains ( "openbsd" ) => {
143143 let c = cfg. get_compiler ( ) ;
144+ let gnu_compiler = compiler. gcc ( ) ;
144145 if !c. path ( ) . ends_with ( gnu_compiler) {
145146 return
146147 }
@@ -183,3 +184,29 @@ fn set_compiler(cfg: &mut cc::Build,
183184 _ => { }
184185 }
185186}
187+
188+ /// The target programming language for a native compiler.
189+ enum Language {
190+ /// The compiler is targeting C.
191+ C ,
192+ /// The compiler is targeting C++.
193+ CPlusPlus ,
194+ }
195+
196+ impl Language {
197+ /// Obtains the name of a compiler in the GCC collection.
198+ fn gcc ( self ) -> & ' static str {
199+ match self {
200+ Language :: C => "gcc" ,
201+ Language :: CPlusPlus => "g++" ,
202+ }
203+ }
204+
205+ /// Obtains the name of a compiler in the clang suite.
206+ fn clang ( self ) -> & ' static str {
207+ match self {
208+ Language :: C => "clang" ,
209+ Language :: CPlusPlus => "clang++" ,
210+ }
211+ }
212+ }
0 commit comments