- Notifications
You must be signed in to change notification settings - Fork7
Expose build variables obtained with built as a PyDict
License
PyO3/pyo3-built
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Simple macro to expose metadata obtained with thebuiltcrate as aPyDict
Add the following to yourCargo.toml manifest:
[build-dependencies]built = {version ="0.7",features = ["chrono"] }[dependencies]pyo3-built ="0.6"
Create yourbuild.rs as you normally would withbuilt, but activatedependencies metadata as well:
//! build.rsexterncrate built;fnmain(){ built::write_built_file().expect("Failed to acquire build-time information");}
Then, include the generated file anywhere in a dedicated module in your Pythonextension, and use thepyo3_built! macro to generate thePyDict:
//! lib.rs#[macro_use]externcrate pyo3_built;externcrate pyo3;use pyo3::prelude::*;#[allow(dead_code)]mod build{include!(concat!(env!("OUT_DIR"),"/built.rs"));}/// Module documentation string#[modinit("mymodule")]fninit(py:Python,m:&PyModule) ->PyResult<()>{// ... // m.add("__build__",pyo3_built!(py, build))?;Ok(())}
That's it ! After compiling your extension module, the__build__ attributewill contain the following metadata:
>>>importmymodule>>>mymodule.__build__{"build-time":datetime.datetime(2018,5,11,16,43,28),"debug":true,"dependencies": { ..."pyo3":"0.6.0","pyo3-built":"0.1.0","pyo3cls":"0.6.0", ... },"features": ["PYO3" ],"host": {"triple":"x86_64-unknown-linux-gnu" },"opt-level":"0","rustc":"rustc","rustc-version":"rustc 1.27.0-nightly (acd3871ba 2018-05-10)","target": {"arch":"x86_64","endianness":"little","env":"gnu","family":"unix","os":"linux","pointer-width":"64","profile":"debug","triple":"x86_64-unknown-linux-gnu" }}
When invoking the macro, one can control what will be addedto the build dictionary by postfixing the list of the parameters we want in the dictionary.See the following example:
m.add("__build__",pyo3_built!(py, build,"time","git","target"))?;
The following parameters are available, mirroring built categories:
"build""time"(requires thechronofeature ofbuilt)"deps""features"(requires thecargo-lockfeature ofbuilt)"host""target""git"(requires thegit2feature ofbuilt)
By default everything except"git" is enabled.
About
Expose build variables obtained with built as a PyDict
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.