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

Populate git information when building Cargo from Rust's source tarball #13832

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

pietroalbini
Copy link
Member

What does this PR try to resolve?

Right now Cargo doesn't populate the commit hash or date in its version output when it's built from Rust's plain source tarball (like rustc-1.77.2-src.tar.xz). That's because Cargo's build script only looks for information in the .git directory, which is missing from that tarball.

I opened rust-lang/rust#124553 to have bootstrap inject a git-commit-info file in src/tools/cargo when building the plain source tarball, containing the correct git information. This is the approach also used by the compiler.

This PR updates the build script to read the information from that file if there is no .git and the file is present.

How should we test and review this PR?

To test the PR you need to move the .git directory somewhere else and create a git-commit-info file like this:

25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
25ef9e3d8
2024-04-09

Then clearing the build cache and running cargo run -- -vV should show the git information in the git-commit-info file.

Additional information

This PR can be merged independently from rust-lang/rust#124553

@rustbot
Copy link
Collaborator

rustbot commented Apr 30, 2024

r? @epage

rustbot has assigned @epage.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2024
@weihanglo
Copy link
Member

Looks reasonable. Thank you!

@bors r+

@bors
Copy link
Contributor

bors commented Apr 30, 2024

📌 Commit bd752e9 has been approved by weihanglo

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 30, 2024
@bors
Copy link
Contributor

bors commented Apr 30, 2024

⌛ Testing commit bd752e9 with merge b861629...

@bors
Copy link
Contributor

bors commented Apr 30, 2024

☀️ Test successful - checks-actions
Approved by: weihanglo
Pushing b861629 to master...

@bors bors merged commit b861629 into rust-lang:master Apr 30, 2024
21 checks passed
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Apr 30, 2024
…r-ozkan

Write `git-commit-{sha,info}` for Cargo in source tarballs

Right now Cargo doesn't populate the commit hash or date in its version output when it's built from the plain source tarball. That's because we don't include the git information for it, and Cargo's build script doesn't pick it up.

This PR *partially* solves the problem by storing the git information for Cargo in `src/tools/cargo` in the plain source tarball. We store separate information because even when built in CI Cargo uses its own git information rather than Rust's.

This PR will also require a change in the Cargo repository to consume this information (rust-lang/cargo#13832), but it doesn't have to be blocked on the Cargo PR being merged.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Apr 30, 2024
Rollup merge of rust-lang#124553 - ferrocene:pa-cargo-git-info, r=onur-ozkan

Write `git-commit-{sha,info}` for Cargo in source tarballs

Right now Cargo doesn't populate the commit hash or date in its version output when it's built from the plain source tarball. That's because we don't include the git information for it, and Cargo's build script doesn't pick it up.

This PR *partially* solves the problem by storing the git information for Cargo in `src/tools/cargo` in the plain source tarball. We store separate information because even when built in CI Cargo uses its own git information rather than Rust's.

This PR will also require a change in the Cargo repository to consume this information (rust-lang/cargo#13832), but it doesn't have to be blocked on the Cargo PR being merged.
bors added a commit to rust-lang-ci/rust that referenced this pull request May 1, 2024
Update cargo

15 commits in b60a1555155111e962018007a6d0ef85207db463..6087566b3fa73bfda29702632493e938b12d19e5
2024-04-26 16:37:29 +0000 to 2024-04-30 20:45:20 +0000
- fix(cargo-fix): dont fix into standard library (rust-lang/cargo#13792)
- refactor: Move diagnostic printing to Shell (rust-lang/cargo#13813)
- Populate git information when building Cargo from Rust's source tarball (rust-lang/cargo#13832)
- docs: fix several typos found by `typos-cli` (rust-lang/cargo#13831)
- fix(alias): Aliases without subcommands should not panic (rust-lang/cargo#13819)
- fix(toml): Improve granularity of traces (rust-lang/cargo#13830)
- fix(toml): Warn, rather than fail publish, if a target is excluded (rust-lang/cargo#13713)
- test(cargo-lints): Add a test to ensure cap-lints works (rust-lang/cargo#13829)
- fix(toml)!: Remove support for inheriting badges (rust-lang/cargo#13788)
- chore(ci): Don't check `cargo` against beta channel (rust-lang/cargo#13827)
- Fix target entry in .gitignore (rust-lang/cargo#13817)
- Bump to 0.81.0; update changelog (rust-lang/cargo#13823)
- Add failing test: artifact_dep_target_specified (rust-lang/cargo#13816)
- fix(cargo-lints): Don't always inherit workspace lints (rust-lang/cargo#13812)
- Update SleepTraker returns_in_order unit test (rust-lang/cargo#13811)

r? ghost
@rustbot rustbot added this to the 1.80.0 milestone May 1, 2024
@pietroalbini pietroalbini deleted the pa-source-tarball-git branch May 1, 2024 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-infrastructure Area: infrastructure around the cargo repo, ci, releases, etc. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants