Skip to content

Make target dir self-ignoring#15060

Open
senekor wants to merge 1 commit intorust-lang:masterfrom
senekor:senekor/vlulryonntrl
Open

Make target dir self-ignoring#15060
senekor wants to merge 1 commit intorust-lang:masterfrom
senekor:senekor/vlulryonntrl

Conversation

@senekor
Copy link
Copy Markdown

@senekor senekor commented Jan 13, 2025

Fixes #15061

How to test:

  • run cargo new, observer that no .gitignore is generated
  • run cargo build, observe that git still ignores the target directory
  • run cargo build with different ways to override the default target directory location:
    • CLI arg (--target-dir)
    • environment variable (CARGO_TARGET_DIR)
    • .cargo/config.toml: build.target-dir

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jan 13, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @epage (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added A-workspaces Area: workspaces Command-new S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 13, 2025
@senekor
Copy link
Copy Markdown
Author

senekor commented Jan 13, 2025

This is currently a proof of concept, meant as a starting point for discussing how to implement it properly.

The easy approach is to just make sure that the gitignore file exists whenever the target directory path is determined.
This leads to some (maybe unacceptable) quirks.
For example, many cargo commands would touch the file system when the user doesn't expect it (even cargo clean --dry-run creates the gitignore file).

@epage
Copy link
Copy Markdown
Contributor

epage commented Jan 13, 2025

Note that #11548 is not labeled with S-accepted which is a prerequisite for being reviewed, see https://doc.crates.io/contrib/process/working-on-cargo.html

@senekor
Copy link
Copy Markdown
Author

senekor commented Jan 13, 2025

makes sense!

@senekor senekor force-pushed the senekor/vlulryonntrl branch from 174d845 to 42a9f08 Compare January 14, 2025 00:40
@senekor
Copy link
Copy Markdown
Author

senekor commented Jan 14, 2025

I removed the part dealing with cargo new. The PR now points to #15061, which reflects the smaller scope. (approval still pending)

@joshtriplett
Copy link
Copy Markdown
Member

I love this idea.

@senekor senekor force-pushed the senekor/vlulryonntrl branch from 42a9f08 to 46ac2e9 Compare April 7, 2026 10:55
@rustbot

This comment has been minimized.

@senekor senekor force-pushed the senekor/vlulryonntrl branch 2 times, most recently from 56eb115 to 896a349 Compare April 7, 2026 11:46
@senekor
Copy link
Copy Markdown
Author

senekor commented Apr 7, 2026

Note that I changed the implementation here. I previously created the .gitignore file every time a workspace's target_dir was queried. This doesn't seem very clean and lead to actual weirdness. For example, cargo clean would always create the target directory and .gitignore file, then delete them again.

After poking around in the cargo code a little more, I discovered create_dir_all_excluded_from_backups_atomic, which seemed like the perfect place to add this functionality. After all, version control can be considered a form of backup. Turns out that function works very similarly already: It creates a "CACHEDIR.TAG" file with a specific content.

So, I simply added my code as an additional step in that function. I hope this should be correct and maintainable.

@senekor senekor force-pushed the senekor/vlulryonntrl branch from 896a349 to ebd1569 Compare April 7, 2026 11:57
@senekor senekor force-pushed the senekor/vlulryonntrl branch from ebd1569 to d5667bd Compare April 7, 2026 13:30
@rustbot

This comment has been minimized.

@senekor senekor force-pushed the senekor/vlulryonntrl branch from d5667bd to f11b336 Compare April 14, 2026 17:24
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 14, 2026

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@senekor senekor force-pushed the senekor/vlulryonntrl branch from f11b336 to b945559 Compare April 14, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-workspaces Area: workspaces Command-new S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make target dir self-ignoring

4 participants