{"id":19741923,"url":"https://github.com/pyo3/pyo3-built","last_synced_at":"2025-10-12T11:49:35.728Z","repository":{"id":34836050,"uuid":"133048229","full_name":"PyO3/pyo3-built","owner":"PyO3","description":"Expose build variables obtained with built as a PyDict","archived":false,"fork":false,"pushed_at":"2025-01-22T11:19:54.000Z","size":47,"stargazers_count":34,"open_issues_count":2,"forks_count":7,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-28T06:06:58.877Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PyO3.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":"2018-05-11T14:11:14.000Z","updated_at":"2025-02-09T19:36:20.000Z","dependencies_parsed_at":"2024-11-12T01:31:01.926Z","dependency_job_id":"6842a2bc-e09c-401a-9159-b5a7a9d1daea","html_url":"https://github.com/PyO3/pyo3-built","commit_stats":null,"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyO3%2Fpyo3-built","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyO3%2Fpyo3-built/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyO3%2Fpyo3-built/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PyO3%2Fpyo3-built/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PyO3","download_url":"https://codeload.github.com/PyO3/pyo3-built/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247135143,"owners_count":20889420,"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","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":"2024-11-12T01:28:27.698Z","updated_at":"2025-10-12T11:49:30.706Z","avatar_url":"https://github.com/PyO3.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `pyo3-built`\n\n*Simple macro to expose metadata obtained with the [`built`](https://crates.io/crates/built)\ncrate as a [`PyDict`](https://pyo3.github.io/pyo3/pyo3/struct.PyDict.html)*\n\n[![Build](https://img.shields.io/github/actions/workflow/status/PyO3/pyo3-built/test.yml?branch=main\u0026maxAge=600\u0026style=flat-square)](https://github.com/PyO3/pyo3-built/actions)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?style=flat-square\u0026maxAge=2678400)](https://choosealicense.com/licenses/apache-2.0/)\n[![Source](https://img.shields.io/badge/source-GitHub-303030.svg?maxAge=2678400\u0026style=flat-square)](https://github.com/PyO3/pyo3-built)\n[![Crate](https://img.shields.io/crates/v/pyo3-built.svg?maxAge=600\u0026style=flat-square)](https://crates.io/crates/pyo3-built)\n[![GitHub issues](https://img.shields.io/github/issues/PyO3/pyo3-built.svg?style=flat-square)](https://github.com/PyO3/pyo3-built/issues)\n\n## Usage\n\nAdd the following to your `Cargo.toml` manifest:\n```toml\n[build-dependencies]\nbuilt = { version = \"0.7\", features = [\"chrono\"] }\n[dependencies]\npyo3-built = \"0.6\"\n```\n\nCreate your `build.rs` as you normally would with `built`, but activate\ndependencies metadata as well:\n```rust,ignore\n//! build.rs\nextern crate built;\n\nfn main() {\n    built::write_built_file().expect(\"Failed to acquire build-time information\");\n}\n```\n\nThen, include the generated file anywhere in a dedicated module in your Python\nextension, and use the `pyo3_built!` macro to generate the `PyDict`:\n```rust,ignore\n//! lib.rs\n#[macro_use]\nextern crate pyo3_built;\nextern crate pyo3;\n\nuse pyo3::prelude::*;\n\n#[allow(dead_code)]\nmod build {\n    include!(concat!(env!(\"OUT_DIR\"), \"/built.rs\"));\n}\n\n/// Module documentation string\n#[modinit(\"mymodule\")]\nfn init(py: Python, m: \u0026PyModule) -\u003e PyResult\u003c()\u003e {\n    // ... //\n    m.add(\"__build__\", pyo3_built!(py, build))?;\n    Ok(())\n}\n```\n\nThat's it ! After compiling your extension module, the `__build__` attribute\nwill contain the following metadata:\n```python\n\u003e\u003e\u003e import mymodule\n\u003e\u003e\u003e mymodule.__build__\n{\n   \"build-time\": datetime.datetime(2018, 5, 11, 16, 43, 28),\n   \"debug\": true,\n   \"dependencies\": {\n      ...\n      \"pyo3\": \"0.6.0\",\n      \"pyo3-built\": \"0.1.0\",\n      \"pyo3cls\": \"0.6.0\",\n      ...\n   },\n   \"features\": [\n      \"PYO3\"\n   ],\n   \"host\": {\n      \"triple\": \"x86_64-unknown-linux-gnu\"\n   },\n   \"opt-level\": \"0\",\n   \"rustc\": \"rustc\",\n   \"rustc-version\": \"rustc 1.27.0-nightly (acd3871ba 2018-05-10)\",\n   \"target\": {\n      \"arch\": \"x86_64\",\n      \"endianness\": \"little\",\n      \"env\": \"gnu\",\n      \"family\": \"unix\",\n      \"os\": \"linux\",\n      \"pointer-width\": \"64\",\n      \"profile\": \"debug\",\n      \"triple\": \"x86_64-unknown-linux-gnu\"\n   }\n}\n```\n\n### Customization\n\nWhen invoking the macro, one can control what will be added\nto the build dictionary by postfixing the list of the parameters we want in the dictionary.\nSee the following example:\n```rust,ignore\nm.add(\"__build__\", pyo3_built!(py, build, \"time\", \"git\", \"target\"))?;\n```\n\nThe following parameters are available, mirroring built categories:\n\n- `\"build\"`\n- `\"time\"` (requires the `chrono` feature of `built`)\n- `\"deps\"`\n- `\"features\"` (requires the `cargo-lock` feature of `built`)\n- `\"host\"`\n- `\"target\"`\n- `\"git\"` (requires the `git2` feature of `built`)\n\nBy default everything except `\"git\"` is enabled.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyo3%2Fpyo3-built","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyo3%2Fpyo3-built","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyo3%2Fpyo3-built/lists"}