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

build.rs method doesn't (properly) work #67

Open
NeuralModder opened this issue Jun 30, 2024 · 1 comment
Open

build.rs method doesn't (properly) work #67

NeuralModder opened this issue Jun 30, 2024 · 1 comment

Comments

@NeuralModder
Copy link

To run the build script, cargo needs to resolve dependencies first, so if the target/patch/{PACKAGE} directory pointed to in the [patch.crates-io] section isn't existing and populated, cargo will fail to do pretty much anything. You can run cargo patch once to get that directory, and any changes to the patches will (presumably) be applied on subsequent builds. But this requires everyone who first clones a repository for a project that uses this to install and run this command, as well as rerun the command any time they cargo clean. Which sucks, and almost defeats the purpose of using the build script.

There is no real way to fix this. The best way to work around it is to use cargo-make in conjunction with this program, adding a task to run rust code before building that invokes cargo_patch::patch().

I'd suggest updating the readme to warn against this issue and recommend the use of cargo-make, or just replace the build.rs method with the cargo-make method.

@NeuralModder
Copy link
Author

Actually, the cargo-xtask pattern, using the run --manifest-path ./xtask/Cargo.toml -- method, may be a better option than cargo-make since it doesn't need any extra installed binaries to work. You could conceivably write your xtask to run different commands for you, after patching your program (maybe forwarding the output to your terminal so you can see it?), though I'm not quite sure what the optimal workflow would look like here.

One downside in comparison to cargo-make is that you need a whole extra subdirectory for the xtask, which also has its own target directory. Kinda clutter-y.

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

No branches or pull requests

1 participant