commit
157fd7b2cf
|
@ -54,7 +54,7 @@ fn sum_as_string(a: usize, b: usize) -> PyResult<String> {
|
||||||
Ok((a + b).to_string())
|
Ok((a + b).to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This module is a python moudle implemented in Rust.
|
/// This module is a python module implemented in Rust.
|
||||||
#[pymodinit]
|
#[pymodinit]
|
||||||
fn string_sum(py: Python, m: &PyModule) -> PyResult<()> {
|
fn string_sum(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
m.add_function(wrap_function!(sum_as_string))?;
|
m.add_function(wrap_function!(sum_as_string))?;
|
||||||
|
@ -63,7 +63,7 @@ fn string_sum(py: Python, m: &PyModule) -> PyResult<()> {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
On windows and linux, you can build normally with `cargo build --release`. On Mac OS, you need to set additional linker arguments. One option is to compile with `cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup`, the other is to create a `.cargo/config` with the following content:
|
On windows and linux, you can build normally with `cargo build --release`. On macOS, you need to set additional linker arguments. One option is to compile with `cargo rustc --release -- -C link-arg=-undefined -C link-arg=dynamic_lookup`, the other is to create a `.cargo/config` with the following content:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[target.x86_64-apple-darwin]
|
[target.x86_64-apple-darwin]
|
||||||
|
@ -73,7 +73,7 @@ rustflags = [
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
For developing, you can copy and rename the shared library from the target folder: On mac os, rename `libstring_sum.dylib` to `string_sum.so`, on windows `libstring_sum.dll` to `string_sum.pyd` and on linux `libstring_sum.so` to `libstring_sum.so`. Then open a python shell in the same folder and you'll be able to `import string_sum`.
|
For developing, you can copy and rename the shared library from the target folder: On macOS, rename `libstring_sum.dylib` to `string_sum.so`, on windows `libstring_sum.dll` to `string_sum.pyd` and on linux `libstring_sum.so` to `libstring_sum.so`. Then open a python shell in the same folder and you'll be able to `import string_sum`.
|
||||||
|
|
||||||
To build, test and publish your crate as python module, you can use [pyo3-pack](https://github.com/PyO3/pyo3-pack) or [setuptools-rust](https://github.com/PyO3/setuptools-rust). You can find an example for setuptools-rust in [examples/word-count](examples/word-count), while pyo3-pack should work on your crate without any configuration.
|
To build, test and publish your crate as python module, you can use [pyo3-pack](https://github.com/PyO3/pyo3-pack) or [setuptools-rust](https://github.com/PyO3/setuptools-rust). You can find an example for setuptools-rust in [examples/word-count](examples/word-count), while pyo3-pack should work on your crate without any configuration.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue