Skip to content

Commit

Permalink
Add example project using pyo3-built
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Larralde committed May 11, 2018
1 parent f9c636d commit eb1a4e3
Show file tree
Hide file tree
Showing 5 changed files with 171 additions and 0 deletions.
92 changes: 92 additions & 0 deletions example/.gitignore
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
16 changes: 16 additions & 0 deletions example/hello/Cargo.toml
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"
18 changes: 18 additions & 0 deletions example/hello/build.rs
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");
}
26 changes: 26 additions & 0 deletions example/hello/lib.rs
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(())
}
19 changes: 19 additions & 0 deletions example/setup.py
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,
)
)

0 comments on commit eb1a4e3

Please sign in to comment.