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

rustc has incomplete version information when compiling from source #86587

Closed
Zapeth opened this issue Jun 23, 2021 · 2 comments · Fixed by #100557
Closed

rustc has incomplete version information when compiling from source #86587

Zapeth opened this issue Jun 23, 2021 · 2 comments · Fixed by #100557

Comments

@Zapeth
Copy link

Zapeth commented Jun 23, 2021

When building from released sources (https://static.rust-lang.org/dist/rustc-<version>-src.tar.xz), the resulting rustc binary is missing detailed version information like commit hash and commit date.

Looking at the source it seems to only rely on git commands/paths to assemble this information (https://github.com/rust-lang/rust/blob/5a7834050f3a0ebcd117b4ddf0bc1e8459594309/src/bootstrap/channel.rs#L26-L36), but it could also be obtained/parsed from rustc-<version>-src/version when compiling from the released source files (and rustc-<version>-src/git-commit-hash if the entire commit hash is required too).

As far as I know this affects all rust releases that are not obtained via rustup (i.e. packaged by distributions or built from scratch).

Sample output of rustc -vV:

rustc 1.51.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-pc-windows-gnu
release: 1.51.0
LLVM version: 11.0.0
@tlyu
Copy link
Contributor

tlyu commented Jun 24, 2021

What build directions did you follow? Have you looked at these sections of config.toml.example?

# The "channel" for the Rust build to produce. The stable/beta channels only
# allow using stable features, whereas the nightly and dev channels allow using
# nightly features
#channel = "dev"
# Flag indicating whether git info will be retrieved from .git automatically.
# Having the git information can cause a lot of rebuilds during development.
# Note: If this attribute is not explicitly set (e.g. if left commented out) it
# will default to true if channel = "dev", but will default to false otherwise.
#ignore-git = if channel == "dev" { true } else { false }

@Zapeth
Copy link
Author

Zapeth commented Jun 24, 2021

I haven't tried to build rust from scratch myself to be honest, but as I said the problem is present in practically every distributed non-rustup build.

So either they are all missing some required configuration or the detailed version information is only included when the source is built from the git repository.

Here are some pkg build files for reference:
MinGW: https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-rust/PKGBUILD
Arch Linux: https://github.com/archlinux/svntogit-packages/blob/packages/rust/trunk/PKGBUILD
Gentoo: https://gitweb.gentoo.org/repo/gentoo.git/tree/dev-lang/rust/rust-1.53.0.ebuild

And again, as far as I can tell the detailed version information is left unassigned if no git information is found. rust_info is used to set the CFG_VER_ environment variables for version hash/date, and it is initalized from the aforelinked GitInfo struct:

let rust_info = channel::GitInfo::new(ignore_git, &src);

which returns None when no git repository information is found, which ultimately results in the unknownstring in the version information:

fn unw(x: Option<&str>) -> &str {
x.unwrap_or("unknown")
}
println!("binary: {}", binary);
println!("commit-hash: {}", unw(util::commit_hash_str()));
println!("commit-date: {}", unw(util::commit_date_str()));

Also, possibly a consequence of this issue: #33286 (I just looked up that issue and totally forgot that I already left a comment there, whoops)

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

Successfully merging a pull request may close this issue.

2 participants