Skip to content

librustc/driver: expose build information of rustc. #17682

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

Merged
merged 1 commit into from
Oct 3, 2014

Conversation

nodakai
Copy link
Contributor

@nodakai nodakai commented Oct 1, 2014

CFG_RELEASE, CFG_VER_HASH and CFG_VER_DATE were only available
as an output to stdout from the driver::version() function
that had an inconvenient signature.

Also, if one failed to set an env var CFG_COMPILER_HOST_TRIPLE at
compile time, the compilation fails.

Now we can easily check the exact version of rustc running at playpen.

I would appreciate if someone could improve my English in the rustdoc comments!

@@ -51,8 +51,7 @@ pub fn host_triple() -> &'static str {
// Instead of grabbing the host triple (for the current host), we grab (at
// compile time) the target triple that this rustc is built with and
// calling that (at runtime) the host triple.
(option_env!("CFG_COMPILER_HOST_TRIPLE")).
expect("CFG_COMPILER_HOST_TRIPLE")
env!("CFG_COMPILER_HOST_TRIPLE")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this stay as option_env! actually? It's often useful when compiling rustc by hand to not have to define all these environment variables.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alexcrichton I felt too insecure when I saw Option::expect(). I'll use .unwrap_or("unknown-target-triple") instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok to fail at runtime (there's no good default for this), it's just there with an option to make building by hand a little easier.

CFG_RELEASE, CFG_VER_HASH and CFG_VER_DATE were only available as an output
to stdout from the driver::version() function that had an inconvenient
signature.
@nodakai nodakai force-pushed the librustc-handy-version branch from cf521bd to 1dfb23f Compare October 1, 2014 22:59
@nodakai
Copy link
Contributor Author

nodakai commented Oct 1, 2014

@alexcrichton host_triple() was reverted back to the original.

extern crate rustc;
use rustc::driver;

fn main() {
    println!("{}", driver::release_str());
    println!("{}", driver::commit_hash_str());
    println!("{}", driver::commit_date_str());
    println!("{}", driver::driver::host_triple());
}

outputs

Some(0.12.0-dev)
Some(1dfb23f4cf5c8a7224cf9d71a0d0b74f22ad252d)
Some(2014-10-02 02:02:43 +0800)
x86_64-unknown-linux-gnu

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 2, 2014
@bors bors merged commit 1dfb23f into rust-lang:master Oct 3, 2014
@nodakai nodakai deleted the librustc-handy-version branch October 3, 2014 07:39
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 this pull request may close these issues.

3 participants