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

tell Cargo about the config.yml dependency for yarp #1300

Merged
merged 1 commit into from
Aug 22, 2023

Conversation

froydnj
Copy link
Contributor

@froydnj froydnj commented Aug 22, 2023

Otherwise we get peculiar build errors because Cargo doesn't think anything has changed.

Copy link
Collaborator

@HParker HParker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great find,

I am not a rust expert, but found the docs here seem to explain what is happening: https://doc.rust-lang.org/cargo/reference/build-scripts.html#build-scripts

@HParker HParker merged commit 810a6eb into ruby:main Aug 22, 2023
45 checks passed
let file = std::fs::File::open(config_path())?;
let path = config_path();
let file = std::fs::File::open(&path)?;
println!("cargo:rerun-if-changed={}", path.display());
Copy link

@lopopolo lopopolo Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.display() escapes invalid UTF-8 bytes. This code will not behave correctly if a path contains a \xFF on Unix systems or an unpaired surrogate on Windows. I previously delivered feedback on both of these crate build scripts that this code should call path.to_str().unwrap() since using println! to emit a directive to cargo like this requires that the path actually be UTF-8.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lopopolo I didn't see that feedback; is it possible that you can point me to it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left several comments of this sort on the initial PRs that introduced the yarp-sys and yarp crates.

Using Path::display to output a Path with println! is a lossy operation because println! requires UTF-8 and Paths on Unix and windows platforms are not required to be UTF-8.

Rather than print out a cargo directive with a lossy conversion which will cause the build to fail in odd ways further down the pipe, prefer to fail fast and require a UTF-8 path at the time it is used as such.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

4 participants