Your build script is incorrect, and Cargo is checking this so that you don’t publish a broken package.
Build scripts may save any output files or intermediate artifacts in the directory specified in the OUT_DIR environment variable. Scripts should not modify any files outside of that directory.
Build scripts must not write to other locations, especiallysrc, because there is no guarantee that the build script won’t be run twice concurrently (from two different Cargo builds having the same dependency), overwriting files, possibly in the middle of rustc trying to read those files. This can cause compilations to crash or misbehave. Cargo ensures that OUT_DIR is either distinct or accessed with file locking sufficient to avoid this problem.[1]
Change your build script so that it writes only to OUT_DIR. To use the generated files, use an include!(concat!(env!("OUT_DIR"), "/bindings.rs")) or #[path = concat!(env!("OUT_DIR"), "/bindings.rs")].
It is also possible that a future version of Cargo or a non-Cargo package manager might make src read-only via file permissions or sandboxing, so writing to src would not work at all. ↩︎
If they are in your repository and in your package, then the build script does not need to generate them and should not be touching them. Pick one or the other strategy, but not both.
For the sake of completeness: There is at least one way to check if cargo publish is running and there is also a way to use a build script to modify the published package at publish time.
(Obvious disclaimer: You shouldn't do this as it's rather hacky, not guaranteed to work, and not guaranteed to continue working in future rust versions)