-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example project using pyo3-built
- Loading branch information
Martin Larralde
committed
May 11, 2018
1 parent
f9c636d
commit eb1a4e3
Showing
5 changed files
with
171 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*,cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# IPython Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# dotenv | ||
.env | ||
|
||
# virtualenv | ||
venv/ | ||
ENV/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# Codacy token | ||
.codacy.token |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[package] | ||
name = 'hello' | ||
version = "0.1.0" | ||
authors = ["Martin Larralde <martin.larralde@ens-cachan.fr>"] | ||
build = "build.rs" | ||
|
||
[dependencies] | ||
pyo3 = "^0.2.6" | ||
pyo3-built = { path = "../.." } | ||
|
||
[build-dependencies] | ||
built = "^0.3.0" | ||
|
||
[lib] | ||
crate-type = ["cdylib"] | ||
path = "lib.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
extern crate built; | ||
|
||
use std::path::Path; | ||
use std::env; | ||
|
||
fn main() { | ||
|
||
let src = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
let dst = Path::new(&env::var("OUT_DIR").unwrap()).join("built.rs"); | ||
let mut opts = built::Options::default(); | ||
|
||
opts.set_dependencies(true) | ||
.set_compiler(true) | ||
.set_env(true); | ||
|
||
built::write_built_file_with_opts(&opts, src, dst) | ||
.expect("Failed to acquire build-time information"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#![feature(proc_macro)] | ||
|
||
#[macro_use] | ||
extern crate pyo3_built; | ||
extern crate pyo3; | ||
|
||
use pyo3::prelude::*; | ||
use pyo3::py::modinit; | ||
|
||
mod build { | ||
include!(concat!(env!("OUT_DIR"), "/built.rs")); | ||
} | ||
|
||
/// Module documentation string | ||
#[modinit("hello")] | ||
fn init(py: Python, m: &PyModule) -> PyResult<()> { | ||
|
||
#[pyfn(m, "hello")] | ||
fn hello(_py: Python) -> PyResult<()> { | ||
println!("Hello, world!"); | ||
Ok(()) | ||
} | ||
|
||
m.add("__build__", pyo3_built!(py, build))?; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/usr/bin/env python | ||
# coding: utf-8 | ||
import setuptools | ||
import setuptools_rust as rust | ||
|
||
setuptools.setup( | ||
name="hello", | ||
author="Martin Larralde", | ||
author_email="martin.larralde@ens-cachan.fr", | ||
description="Example Python module using pyo3-built", | ||
setup_requires=[ | ||
"setuptools", | ||
"setuptools-rust ~=0.9", | ||
], | ||
rust_extensions=rust.find_rust_extensions( | ||
binding=rust.Binding.PyO3, | ||
strip=rust.Strip.Debug, | ||
) | ||
) |