Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OUT_DIR returns incorrect directory #9023

Closed
violetastcs opened this issue Dec 28, 2020 · 2 comments
Closed

OUT_DIR returns incorrect directory #9023

violetastcs opened this issue Dec 28, 2020 · 2 comments
Labels
C-bug Category: bug

Comments

@violetastcs
Copy link

Problem

I have a build-rs that contains the following:

use std::fs::copy;
use std::io;

fn main() -> io::Result<()> {
	println!("cargo:rerun-if-changed=res/*");

	let out_dir = std::env::var("OUT_DIR").unwrap();
	
	for x in std::fs::read_dir("res/")?
		.filter_map(Result::ok)
		.filter(|item| item.file_type().unwrap().is_file())
		.map(|item| (item.path(), format!("{}/res/{}", out_dir, item.file_name()
			.to_string_lossy()
			.to_owned()
		)))
		.map(|(from, to)| {
			println!("from: {:?}, to: {}", from, to);
			copy(from, to)
		}) 
	{
		x?;
	}

	Ok(())
}

Which should copy every file in the folder res into $OUT_DIR/res. However, when I try and build my project, I get an error:

error: failed to run custom build command for `gfx v0.1.0 (/home/violet/projects/gfx)`

Caused by:
  process didn't exit successfully: `/home/violet/projects/gfx/target/debug/build/gfx-1385f1dbcfa44ce1/build-script-build` (exit code: 1)
  --- stdout
  cargo:rerun-if-changed=res/*
  from: "res/cube-diffuse.jpg", to: /home/violet/projects/gfx/target/debug/build/gfx-52f2df593a0e8de1/out/res/cube-diffuse.jpg

which appears to show that what is contained in OUT_DIR is incorrect.

Notes
I'm running Void Linux, and I'm using rustc version 1.51.0-nightly and cargo version 1.50.0-nightly.

@violetastcs violetastcs added the C-bug Category: bug label Dec 28, 2020
@ehuss
Copy link
Contributor

ehuss commented Dec 28, 2020

fs::copy does not create intermediate directories. I don't see anything creating the res directory in OUT_DIR.

Also, FYI, rerun-if-changed does not support * globbing. A recent change (#8973) allows it to be a directory, which should be in the next beta.

@violetastcs
Copy link
Author

fs::copy does not create intermediate directories. I don't see anything creating the res directory in OUT_DIR.

Also, FYI, rerun-if-changed does not support * globbing. A recent change (#8973) allows it to be a directory, which should be in the next beta.

ah thank you for the help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants