Skip to content

Commit 5dea92b

Browse files
committed
fixed build command; use PyO3 in example
1 parent 2036be6 commit 5dea92b

File tree

11 files changed

+63
-42
lines changed

11 files changed

+63
-42
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
Cargo.lock
99
/example/build/
1010
/example/dist/
11-
/example/extensions/target/
11+
/example/target/
1212
/example/*.egg-info
1313
.idea/

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ CHANGES
66

77
- Add support for PyO3 project https://github.com/PyO3/PyO3
88

9+
- Add support for no-binding mode
10+
911

1012
0.5.1 (2017-05-03)
1113
------------------

README.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ You can define rust extension with `RustExtension` class:
7474
None then build type is auto-detect. Inplace build is debug build
7575
otherwise release. Default: None
7676

77+
:param int binding: Controls which python binding is in use.
78+
`Binding.PyO3` uses PyO3
79+
`Binding.RustCPython` uses rust-cpython
80+
`Binding.NoBinding` uses no binding.
7781

7882
Commands
7983
--------

example/extensions/Cargo.toml renamed to example/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name = "hello-world"
33
version = "0.1.0"
44
authors = ["Nikolay Kim <[email protected]>"]
55

6-
[dependencies.cpython]
7-
git = "https://github.com/dgrunwald/rust-cpython.git"
6+
[dependencies.pyo3]
7+
git = "https://github.com/PyO3/PyO3.git"
88
default-features = false
99

1010
[lib]

example/extensions/src/lib.rs

Lines changed: 0 additions & 28 deletions
This file was deleted.

example/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
setup(name='hello-rust',
66
version='1.0',
77
rust_extensions=[
8-
RustExtension('hello_rust._helloworld', 'extensions/Cargo.toml')],
8+
RustExtension('hello_rust._helloworld', 'Cargo.toml')],
99
packages=['hello_rust'],
1010
# rust extensions are not zip safe, just like C-extensions.
1111
zip_safe=False)

example/src/lib.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#![feature(proc_macro)]
2+
3+
extern crate pyo3;
4+
5+
use pyo3::*;
6+
7+
#[py::modinit(_helloworld)]
8+
fn init(py: Python, m: &PyModule) -> PyResult<()> {
9+
m.add(py, "__doc__", "Module documentation string")?;
10+
11+
#[pyfn(m, "run", "*args, **kwargs")]
12+
fn run_fn(py: Python, args: &PyTuple, kwargs: Option<&PyDict>) -> PyResult<()> {
13+
run(py, args, kwargs)
14+
}
15+
16+
#[pyfn(m, "val")]
17+
fn val(_py: Python) -> PyResult<i32> {
18+
Ok(42)
19+
}
20+
21+
Ok(())
22+
}
23+
24+
fn run(py: Python, args: &PyTuple, kwargs: Option<&PyDict>) -> PyResult<()> {
25+
println!("Rust says: Hello Python!");
26+
for arg in args.iter(py) {
27+
println!("Rust got {}", arg);
28+
}
29+
if let Some(kwargs) = kwargs {
30+
for (key, val) in kwargs.items(py) {
31+
println!("{} = {}", key, val);
32+
}
33+
}
34+
Ok(())
35+
}

setuptools_rust/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def build_extension(self, ext):
7474
quiet = self.qbuild or ext.quiet
7575

7676
# build cargo command
77-
feature_args = ["--features " + " ".join(features)] if features else []
77+
feature_args = ["--features", " ".join(features)] if features else []
7878
args = (["cargo", "rustc", "--lib", "--manifest-path", ext.path]
7979
+ feature_args
8080
+ list(ext.args or []))

setuptools_rust/check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ def run(self):
5757
features = set(ext.features)
5858
features.update(cpython_feature(binding=ext.binding))
5959

60-
# build cargo command
61-
feature_args = ["--features" + " ".join(features)] if features else []
62-
args = (["cargo", "rustc", "--lib", "--manifest-path", ext.path]
60+
# check cargo command
61+
feature_args = ["--features", " ".join(features)] if features else []
62+
args = (["cargo", "check", "--lib", "--manifest-path", ext.path]
6363
+ feature_args
6464
+ list(ext.args or []))
6565

setuptools_rust/test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ def run(self):
5959
features = set(ext.features)
6060
features.update(cpython_feature(ext=False, binding=ext.binding))
6161

62-
# build cargo command
63-
feature_args = ["--features " + " ".join(features)] if features else []
64-
args = (["cargo", "rustc", "--lib", "--manifest-path", ext.path]
62+
# test cargo command
63+
feature_args = ["--features", " ".join(features)] if features else []
64+
args = (["cargo", "test", "--lib", "--manifest-path", ext.path]
6565
+ feature_args
6666
+ list(ext.args or []))
6767

0 commit comments

Comments
 (0)