Skip to content

Commit

Permalink
chore: minor touchup
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Apr 9, 2024
1 parent 919b6ab commit 5002525
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion content/week11/compute_pi_rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
fn main() {
let num_steps = 100000000;
let start = std::time::Instant::now();

let step = 1.0/f64::try_from(num_steps).unwrap();

let sum: f64 = (0..num_steps).map(|i| {
Expand Down
13 changes: 10 additions & 3 deletions content/week12/06-rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ creating extensions (very much like pybind11 for C++), and Maturin, a very
simple modern build system tied to Cargo (much like Scikit-build-core and CMake
for C/C++/Fortran languages).


## Getting started

Creating a new project is easy. Install maturin (`cargo install maturin`, `brew
Expand Down Expand Up @@ -116,13 +115,13 @@ supports it natively.

The function is annotated with `#[pyfunction]`, which will make it a function
you can add to Python. You return a `PyResult<...>` if a function could "throw"
an error in Python. Functions that don't ever throw errors can just return
an error in Python. Functions that don't ever throw errors can just return
normal Rust values that have known conversions. Otherwise, it's pretty normal.
(Actually, we don't ever return a non-OK value in this example, so feel free to
simplify this to just return `String`).

Now, we have a module. This is a function that sets up a module by taking a Bound
PyModule and running `.add_*` functions on it to add (much like pybind11). Functions
PyModule and running `.add_*` functions on it to add (much like pybind11). Functions
need to be given in the `wrap_pyfunction!` macro.

This is the classic interface; there's a new interface based
Expand Down Expand Up @@ -159,3 +158,11 @@ mod rust_example {
}
}
```

## Building and running

You can use all the usual Python tools (like pip, build, etc), but you can also
build directly with maturin. In many cases, this will skip many of the Python
calls altogether. The `maturin build` command will build a wheel. The `maturin
develop` command will do an editable install (requires `pip` in the venv you
are building in).
14 changes: 7 additions & 7 deletions content/week12/06-rust/.github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ on:
- main
- master
tags:
- '*'
- "*"
pull_request:
workflow_dispatch:

Expand Down Expand Up @@ -40,13 +40,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
sccache: "true"
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
Expand All @@ -67,14 +67,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: "3.10"
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand All @@ -94,13 +94,13 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
python-version: "3.10"
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
sccache: "true"
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
Expand Down
1 change: 0 additions & 1 deletion content/week12/06-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@ mod rust_example {
a + b
}
}

0 comments on commit 5002525

Please sign in to comment.