@@ -14,6 +14,11 @@ use std::str::{from_utf8, Utf8Error};
1414extern crate tempfile;
1515use self :: tempfile:: Builder ;
1616
17+ fn set_target_dir ( cmd : & mut Command , path : & Path ) {
18+ cmd. env ( "CARGO_TARGET_DIR" , path) ;
19+ cmd. env ( "CARGO_BUILD_BUILD_DIR" , path) ;
20+ }
21+
1722#[ derive( Debug ) ]
1823/// Possible errors that can occur during `rustc -Zunpretty=expanded`.
1924pub enum Error {
@@ -75,15 +80,15 @@ pub fn expand(
7580 let mut _temp_dir = None ; // drop guard
7681 if use_tempdir {
7782 _temp_dir = Some ( Builder :: new ( ) . prefix ( "cbindgen-expand" ) . tempdir ( ) ?) ;
78- cmd . env ( "CARGO_TARGET_DIR" , _temp_dir. unwrap ( ) . path ( ) ) ;
83+ set_target_dir ( & mut cmd , _temp_dir. unwrap ( ) . path ( ) ) ;
7984 } else if let Ok ( ref path) = env:: var ( "CARGO_EXPAND_TARGET_DIR" ) {
80- cmd . env ( "CARGO_TARGET_DIR" , path) ;
85+ set_target_dir ( & mut cmd , Path :: new ( path) ) ;
8186 } else if let Ok ( ref path) = env:: var ( "OUT_DIR" ) {
8287 // When cbindgen was started programatically from a build.rs file, Cargo is running and
83- // locking the default target directory . In this case we need to use another directory,
84- // else we would end up in a deadlock. If Cargo is running `OUT_DIR` will be set, so we
85- // can use a directory relative to that.
86- cmd . env ( "CARGO_TARGET_DIR" , PathBuf :: from ( path) . join ( "expanded" ) ) ;
88+ // locking the default target and build directories . In this case we need to use another
89+ // directory, else we would end up in a deadlock. If Cargo is running `OUT_DIR` will be
90+ // set, so we can use a directory relative to that.
91+ set_target_dir ( & mut cmd , & PathBuf :: from ( path) . join ( "expanded" ) ) ;
8792 }
8893
8994 // Set this variable so that we don't call it recursively if we expand a crate that is using
0 commit comments