pub fn run_build_script() {
    let base_dir = env::var("CARGO_MANIFEST_DIR").expect("Can't get CARGO_MANIFEST_DIR from env");
    let base_dir = path::Path::new(&base_dir);

    let build_rs = base_dir.join("build.rs");
    let cargo_toml = base_dir.join("Cargo.toml");
    let cargo_build_lock = base_dir.join("Cargo.build.lock");

    let build_dir = BuildDir::new();

    let cargo = env::var("CARGO").expect("Can't get CARGO from env");
    let path = env::var("PATH").expect("Can't get PATH from env");
    let ssh_auth_sock = env::var("SSH_AUTH_SOCK").unwrap_or_default();

    let rustup_home = env::var("RUSTUP_HOME").unwrap_or_default();
    let rustup_toolchain = env::var("RUSTUP_TOOLCHAIN").unwrap_or_default();

    // Build in /tmp to avoid the influence of .cargo/config settings in the
    // build crate's parent, which cargo gives us no way to ignore.
    fs::create_dir(&build_dir.path).expect(&format!(
        "Couldn't create temp build dir at {}",
        build_dir.path.display()
    ));

    // copy in build.rs
    fs::create_dir(build_dir.path.join("src")).expect(&format!(
        "Couldn't create directory {}/src",
        build_dir.path.display()
    ));

    fs::copy(&build_rs, build_dir.path.join("src").join("main.rs")).expect(&format!(
        "Error copying build script {} to {}/src/main.rs",
        build_rs.display(),
        build_dir.path.display()
    ));

    // synthesize Cargo.toml
    let deps_section = read_toml_section(&cargo_toml, "workaround-build-dependencies");

    // Fix any relative paths that were in the Cargo.toml
    let deps_section = qualify_cargo_toml_paths_in_text(&deps_section, &base_dir);
    let cargo_toml_content = format!(
        r#"
[package]
name = "workaround-build-script"
version = "0.1.0"
authors = ["The cargo-5730 crate"]
edition = "2018"

[dependencies]
{}
"#,
        deps_section
    );

    fs::write(build_dir.path.join("Cargo.toml"), cargo_toml_content).expect(&format!(
        "Error writing synthesized Cargo manifest to {}/Cargo.toml",
        build_dir.path.display()
    ));

    // copy in Cargo.build.lock, if we have one
    if cargo_build_lock.exists() {
        fs::copy(&cargo_build_lock, build_dir.path.join("Cargo.lock")).expect(&format!(
            "Error copying build manifest lockfile from {} to {}/Cargo.lock",
            cargo_build_lock.display(),
            build_dir.path.display()
        ));
    }

    compile_build_crate(
        &build_dir,
        &cargo,
        &path,
        &ssh_auth_sock,
        &rustup_home,
        &rustup_toolchain,
        &base_dir,
    );

    // copy back the 'Cargo.lock' file, to speed up subsequent compilations
    fs::copy(build_dir.path.join("Cargo.lock"), &cargo_build_lock).expect(&format!(
        "Error copying out Cargo.lock from {}/Cargo.lock to {}",
        build_dir.path.display(),
        cargo_build_lock.display()
    ));

    // Run the build script with its original source directory as the working
    // dir.
    run_compiled_build_script("workaround-build-script", &base_dir);
}
/// Compile and run build.rs from cwd
/// - use 'workaround-build-dependencies' from Cargo.toml
/// - Build it with the workaround_build configuration
/// - Copy Cargo.lock back here to build.Cargo.lock
Compile and run build.rs from cwd
use 'workaround-build-dependencies' from Cargo.toml
Build it with the workaround_build configuration
Copy Cargo.lock back here to build.Cargo.lock
Compile and run build . rs from cwd use ' workaround - build - dependencies ' from Cargo . toml Build it with the workaround_build configuration Copy Cargo . lock back here to build . Cargo . lock
pub fn run_build_script() {
    let base_dir = env::var("CARGO_MANIFEST_DIR").expect("Can't get CARGO_MANIFEST_DIR from env");
    let base_dir = path::Path::new(&base_dir);
    let build_rs = base_dir.join("build.rs");
    let cargo_toml = base_dir.join("Cargo.toml");
    let cargo_build_lock = base_dir.join("Cargo.build.lock");
    let build_dir = BuildDir::new();
    let cargo = env::var("CARGO").expect("Can't get CARGO from env");
    let path = env::var("PATH").expect("Can't get PATH from env");
    let ssh_auth_sock = env::var("SSH_AUTH_SOCK").unwrap_or_default();
    let rustup_home = env::var("RUSTUP_HOME").unwrap_or_default();
    let rustup_toolchain = env::var("RUSTUP_TOOLCHAIN").unwrap_or_default();
    // Build in /tmp to avoid the influence of .cargo/config settings in the
    // build crate's parent, which cargo gives us no way to ignore.
    fs::create_dir(&build_dir.path).expect(&format!(
        "Couldn't create temp build dir at {}",
        build_dir.path.display()
    ));
    // copy in build.rs
    fs::create_dir(build_dir.path.join("src")).expect(&format!(
        "Couldn't create directory {}/src",
        build_dir.path.display()
    ));
    fs::copy(&build_rs, build_dir.path.join("src").join("main.rs")).expect(&format!(
        "Error copying build script {} to {}/src/main.rs",
        build_rs.display(),
        build_dir.path.display()
    ));
    // synthesize Cargo.toml
    let deps_section = read_toml_section(&cargo_toml, "workaround-build-dependencies");
    // Fix any relative paths that were in the Cargo.toml
    let deps_section = qualify_cargo_toml_paths_in_text(&deps_section, &base_dir);
    let cargo_toml_content = format!(
        r#"
[package]
name = "workaround-build-script"
version = "0.1.0"
authors = ["The cargo-5730 crate"]
edition = "2018"
[dependencies]
{}
"#,
        deps_section
    );
    fs::write(build_dir.path.join("Cargo.toml"), cargo_toml_content).expect(&format!(
        "Error writing synthesized Cargo manifest to {}/Cargo.toml",
        build_dir.path.display()
    ));
    // copy in Cargo.build.lock, if we have one
    if cargo_build_lock.exists() {
        fs::copy(&cargo_build_lock, build_dir.path.join("Cargo.lock")).expect(&format!(
            "Error copying build manifest lockfile from {} to {}/Cargo.lock",
            cargo_build_lock.display(),
            build_dir.path.display()
        ));
    }
    compile_build_crate(
        &build_dir,
        &cargo,
        &path,
        &ssh_auth_sock,
        &rustup_home,
        &rustup_toolchain,
        &base_dir,
    );
    // copy back the 'Cargo.lock' file, to speed up subsequent compilations
    fs::copy(build_dir.path.join("Cargo.lock"), &cargo_build_lock).expect(&format!(
        "Error copying out Cargo.lock from {}/Cargo.lock to {}",
        build_dir.path.display(),
        cargo_build_lock.display()
    ));
    // Run the build script with its original source directory as the working
    // dir.
    run_compiled_build_script("workaround-build-script", &base_dir);
}
pub fn run_build_script ( ) { let base_dir = env :: var ( " " ) . expect ( " " ) ; let base_dir = path :: Path :: new ( & base_dir ) ; let build_rs = base_dir . join ( " " ) ; let cargo_toml = base_dir . join ( " " ) ; let cargo_build_lock = base_dir . join ( " " ) ; let build_dir = BuildDir :: new ( ) ; let cargo = env :: var ( " " ) . expect ( " " ) ; let path = env :: var ( " " ) . expect ( " " ) ; let ssh_auth_sock = env :: var ( " " ) . unwrap_or_default ( ) ; let rustup_home = env :: var ( " " ) . unwrap_or_default ( ) ; let rustup_toolchain = env :: var ( " " ) . unwrap_or_default ( ) ; // Build in /tmp to avoid the influence of .cargo/config settings in the // build crate's parent, which cargo gives us no way to ignore. fs :: create_dir ( & build_dir . path ) . expect ( & format ! ( " " build_dir path display ( ) ) ) ; // copy in build.rs fs :: create_dir ( build_dir . path . join ( " " ) ) . expect ( & format ! ( " " build_dir path display ( ) ) ) ; fs :: copy ( & build_rs , build_dir . path . join ( " " ) . join ( " " ) ) . expect ( & format ! ( " " build_rs display ( ) build_dir path display ( ) ) ) ; // synthesize Cargo.toml let deps_section = read_toml_section ( & cargo_toml , " " ) ; // Fix any relative paths that were in the Cargo.toml let deps_section = qualify_cargo_toml_paths_in_text ( & deps_section , & base_dir ) ; let cargo_toml_content = format ! ( r#"
[package]
name = "workaround-build-script"
version = "0.1.0"
authors = ["The cargo-5730 crate"]
edition = "2018"

[dependencies]
{}
"# deps_section ) ; fs :: write ( build_dir . path . join ( " " ) , cargo_toml_content ) . expect ( & format ! ( " " build_dir path display ( ) ) ) ; // copy in Cargo.build.lock, if we have one if cargo_build_lock . exists ( ) { fs :: copy ( & cargo_build_lock , build_dir . path . join ( " " ) ) . expect ( & format ! ( " " cargo_build_lock display ( ) build_dir path display ( ) ) ) ; } compile_build_crate ( & build_dir , & cargo , & path , & ssh_auth_sock , & rustup_home , & rustup_toolchain , & base_dir , ) ; // copy back the 'Cargo.lock' file, to speed up subsequent compilations fs :: copy ( build_dir . path . join ( " " ) , & cargo_build_lock ) . expect ( & format ! ( " " build_dir path display ( ) cargo_build_lock display ( ) ) ) ; // Run the build script with its original source directory as the working // dir. run_compiled_build_script ( " " , & base_dir ) ; }
Compile and run build.rs from cwd
 use 'workaround-build-dependencies' from Cargo.toml
 Build it with the workaround_build configuration
 Copy Cargo.lock back here to build.Cargo.lock
Compile and run build . rs from cwd use ' workaround - build - dependencies ' from Cargo . toml Build it with the workaround_build configuration Copy Cargo . lock back here to build . Cargo . lock