@@ -688,9 +688,25 @@ impl<'a> Builder<'a> {
688688 //
689689 // FIXME: the guard against msvc shouldn't need to be here
690690 if !target. contains ( "msvc" ) {
691- let cc = self . cc ( target) ;
692- cargo. env ( format ! ( "CC_{}" , target) , cc)
693- . env ( "CC" , cc) ;
691+ let ccache = self . config . ccache . as_ref ( ) ;
692+ let ccacheify = |s : & Path | {
693+ let ccache = match ccache {
694+ Some ( ref s) => s,
695+ None => return s. display ( ) . to_string ( ) ,
696+ } ;
697+ // FIXME: the cc-rs crate only recognizes the literal strings
698+ // `ccache` and `sccache` when doing caching compilations, so we
699+ // mirror that here. It should probably be fixed upstream to
700+ // accept a new env var or otherwise work with custom ccache
701+ // vars.
702+ match & ccache[ ..] {
703+ "ccache" | "sccache" => format ! ( "{} {}" , ccache, s. display( ) ) ,
704+ _ => s. display ( ) . to_string ( ) ,
705+ }
706+ } ;
707+ let cc = ccacheify ( & self . cc ( target) ) ;
708+ cargo. env ( format ! ( "CC_{}" , target) , & cc)
709+ . env ( "CC" , & cc) ;
694710
695711 let cflags = self . cflags ( target) . join ( " " ) ;
696712 cargo. env ( format ! ( "CFLAGS_{}" , target) , cflags. clone ( ) )
@@ -705,8 +721,9 @@ impl<'a> Builder<'a> {
705721 }
706722
707723 if let Ok ( cxx) = self . cxx ( target) {
708- cargo. env ( format ! ( "CXX_{}" , target) , cxx)
709- . env ( "CXX" , cxx)
724+ let cxx = ccacheify ( & cxx) ;
725+ cargo. env ( format ! ( "CXX_{}" , target) , & cxx)
726+ . env ( "CXX" , & cxx)
710727 . env ( format ! ( "CXXFLAGS_{}" , target) , cflags. clone ( ) )
711728 . env ( "CXXFLAGS" , cflags) ;
712729 }
0 commit comments