Skip to content

rustc has incomplete version information when compiling from source #86587

Closed
@Zapeth

Description

@Zapeth

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

Activity

tlyu

tlyu commented on Jun 24, 2021

@tlyu
Contributor

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

Zapeth commented on Jun 24, 2021

@Zapeth
Author

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)

added a commit that references this issue on Oct 2, 2022

Auto merge of rust-lang#100557 - dawnofmidnight:tarball-commit-info, …

de692f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @tlyu@Zapeth

      Issue actions

        rustc has incomplete version information when compiling from source · Issue #86587 · rust-lang/rust