@@ -168,9 +168,13 @@ fn only_run_on_file(
168168 // Add compile filter to specify the target corresponding to the given file
169169 cmd. arg ( "-p" ) . arg ( format ! ( "{}:{}" , pkg. name, pkg. version) ) ;
170170
171+ // See https://doc.rust-lang.org/cargo/commands/cargo-check.html#target-selection for possible compile kinds
171172 enum CompileKind {
172173 Lib ,
173174 Bin ,
175+ Example ,
176+ Test ,
177+ Bench ,
174178 ProcMacro ,
175179 }
176180
@@ -181,6 +185,9 @@ fn only_run_on_file(
181185 "lib" | "rlib" | "dylib" | "staticlib" | "cdylib" => CompileKind :: Lib ,
182186 "bin" => CompileKind :: Bin ,
183187 "proc-macro" => CompileKind :: ProcMacro ,
188+ "example" => CompileKind :: Example ,
189+ "test" => CompileKind :: Test ,
190+ "bench" => CompileKind :: Bench ,
184191 _ => unreachable ! ( "unexpected cargo crate type: {kind_str}" ) ,
185192 } ;
186193
@@ -207,10 +214,37 @@ fn only_run_on_file(
207214 cmd. args ( [ "--bin" , & target. name ] ) ;
208215 }
209216 CompileKind :: ProcMacro => { }
217+ CompileKind :: Example => {
218+ cmd. args ( [ "--example" , & target. name ] ) ;
219+ }
220+ CompileKind :: Test => {
221+ cmd. args ( [ "--test" , & target. name ] ) ;
222+ }
223+ CompileKind :: Bench => {
224+ cmd. args ( [ "--bench" , & target. name ] ) ;
225+ }
210226 }
211227
212- cmd. env ( SPECIFIC_CRATE , pkg. name . replace ( '-' , "_" ) ) ;
213- cmd. env ( SPECIFIC_TARGET , kind_str) ;
228+ cmd. env (
229+ SPECIFIC_CRATE ,
230+ match kind {
231+ CompileKind :: Lib => & pkg. name ,
232+ CompileKind :: Bin => & pkg. name ,
233+ CompileKind :: Example => & target. name ,
234+ CompileKind :: Test => & target. name ,
235+ CompileKind :: Bench => & target. name ,
236+ CompileKind :: ProcMacro => & pkg. name ,
237+ }
238+ . replace ( '-' , "_" ) ,
239+ ) ;
240+ cmd. env (
241+ SPECIFIC_TARGET ,
242+ if matches ! ( kind, CompileKind :: Bench | CompileKind :: Example ) {
243+ "bin"
244+ } else {
245+ kind_str
246+ } ,
247+ ) ;
214248
215249 log:: debug!(
216250 "Package: {}, target kind {}, target name {}" ,
0 commit comments