{"id":30991681,"url":"https://github.com/frobware/build-rs-example","last_synced_at":"2025-09-12T20:47:32.862Z","repository":{"id":275841018,"uuid":"927361742","full_name":"frobware/build-rs-example","owner":"frobware","description":"Rust example that uses build.rs to provide build version, build date, and build toolchain information.","archived":false,"fork":false,"pushed_at":"2025-03-08T08:11:26.000Z","size":60,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-12T00:38:16.005Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/frobware.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-04T20:38:12.000Z","updated_at":"2025-03-08T08:11:29.000Z","dependencies_parsed_at":"2025-02-04T21:43:56.363Z","dependency_job_id":null,"html_url":"https://github.com/frobware/build-rs-example","commit_stats":null,"previous_names":["frobware/build-rs-example"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/frobware/build-rs-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frobware%2Fbuild-rs-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frobware%2Fbuild-rs-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frobware%2Fbuild-rs-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frobware%2Fbuild-rs-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/frobware","download_url":"https://codeload.github.com/frobware/build-rs-example/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/frobware%2Fbuild-rs-example/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274873613,"owners_count":25365824,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-12T02:00:09.324Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-12T20:47:27.564Z","updated_at":"2025-09-12T20:47:32.854Z","avatar_url":"https://github.com/frobware.png","language":"Shell","readme":"# Rust `build.rs` Example\n\nThis repository demonstrates how to use Rust's `build.rs` system to generate **version information at compile time**. The example extracts version details from **Cargo.toml**, **Git commit hashes**, and **environment variables**, ensuring correct versioning for both **development and distribution builds**.\n\n## How it Works\n\nThe `build.rs` script runs **before compilation** and sets a **single authoritative environment variable**:\n\n- **`BUILD_VERSION`** → Contains all versioning details in a **Rust-like format**:\n  ```\n  \u003cCargo package version\u003e (\u003cGit commit hash\u003e \u003cbuild timestamp\u003e) \u003cRust compiler version\u003e\n  ```\n\nThis version information is embedded into the final binary and displayed when run.\n\n## Versioning Behaviour\nThe output format follows Rust's versioning style (`rustc --version`), structured as:\n\n```\n\u003cversion\u003e (\u003cgit commit\u003e \u003cbuild date\u003e) \u003crustc version\u003e\n```\n\n### Example Outputs\n#### When built inside a Git repository\n\n```sh\n$ cargo run --quiet --bin main1\nmain1 0.0.15-pre (f4a3c814d9-dirty 2025-03-07T19:38:55Z) rustc 1.84.1 (e71f9a9a9 2025-01-27)\n```\n- **Git commit hash included**: `f4a3c814d9`\n- **Dirty flag (`-dirty`)** if uncommitted changes exist\n- **Build timestamp**: `2025-03-07T19:38:55Z`\n- **Rust compiler version**: `rustc 1.84.1 (e71f9a9a9 2025-01-27)`\n\n#### When built from a tarball (i.e., no Git repository present)\n\n```sh\n$ make test\nGot:     'main1 0.0.15-pre (2025-03-07T19:39:13Z) rustc 1.84.1 (e71f9a9a9 2025-01-27)'\nMatched: 'main1 0.0.15-pre'\n\n...\n\nGot:     'main2 0.0.15-pre (2025-03-07T19:39:14Z) rustc 1.84.1 (e71f9a9a9 2025-01-27)'\nMatched: 'main2 0.0.15-pre'\n```\n\n- **Git hash omitted** (not available)\n- **Build timestamp remains**\n- **Rust compiler version remains**\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrobware%2Fbuild-rs-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffrobware%2Fbuild-rs-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffrobware%2Fbuild-rs-example/lists"}