#build-time #timestamp #build #string #time #compile

macro no-std build_timestamp

Simple proc-macro to generate a build timestamp string as a const

1 unstable release

Uses old Rust 2015

0.1.0 Sep 8, 2018

#68 in #build-time

Download history 50/week @ 2024-11-19 8/week @ 2024-11-26 10/week @ 2024-12-03 24/week @ 2024-12-10 7/week @ 2024-12-17 16/week @ 2025-01-07 23/week @ 2025-01-14 14/week @ 2025-01-21 15/week @ 2025-01-28 35/week @ 2025-02-04 53/week @ 2025-02-11 25/week @ 2025-02-18 54/week @ 2025-02-25 116/week @ 2025-03-04

253 downloads per month

MIT/Apache

7KB

Build Timestamp String Generator

build_timestamp is a simple proc-macro for Rust to generate a const string with a build timestamp (in UTC), formatted with strftime syntax.

Note: using this crate makes your build non-deterministic!

Note: using this crate requires nightly Rust

Example

// Rust2018 macro import
use build_timestamp::build_time;

// generates a `const BUILD_TIME: &str`
build_time!("%A %Y-%m-%d / %H:%M:%S");

fn main() {
    println!("This is {}, built on: {}",
        env!("CARGO_PKG_NAME"), BUILD_TIME);
}

Running this example will print something that looks like:

This is my_crate, built on: Saturday 2018-09-08 / 11:35:43

TODO

Features that I'd like this crate to support in the future:

  • proper error handling (currently just uses unwrap() to panic)
  • ability to specify the name for the generated const
  • non-UTC timezones

If you would like to implement any of this, I welcome patches.

Dependencies

~3MB
~63K SLoC