Improve Cargo support

Currently, Cargo always recompiles the project, even if nothing has changed. See the commit message for details.

This PR also adds `target` to `.gitignore`.