]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core.git/commitdiff
lib/oeqa/files/maturin: update guessing_game
authorTim Orling <tim.orling@konsulko.com>
Wed, 21 Jan 2026 21:07:18 +0000 (13:07 -0800)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 27 Jan 2026 11:35:05 +0000 (11:35 +0000)
Update to include changes in upstream Maturin Tutorial [1]
and for newer Rust and Python.

Cargo.toml:
* version: 0.1.0 -> 0.3.0 (to align with [2])
* edition: 2021 -> 2024
* Dependencies:
  - rand: 0.8.5 -> 0.9.0
  - pyo3: 0.21.2 -> 0.27.2
  - abi3-py38 -> abi3-py39 (Python 3.8 reached EOL in October 2024)

pyproject.toml:
* restrict maturin to >=1.7 to ensure PyO3 27.0+ and python 3.13+ support

src/lib.rs:
* rand 0.9 API change: rand::thread_rng() was removed. Use rand::rng() or
  the convenience function rand::random_range().
* PyO3 0.27 has breaking API changes from 0.21. The #[pymodule] function
  signature changed from fn module_name(py: Python, m: &PyModule) to
  fn module_name(m: &Bound<'_, PyModule>).

With help from Claude.ai

[1] https://www.maturin.rs/tutorial.html
[2] https://github.com/moto-timo/guessing-game/releases/tag/v0.3.0

Signed-off-by: Tim Orling <tim.orling@konsulko.com>
Signed-off-by: Antonin Godard <antonin.godard@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
meta/lib/oeqa/files/maturin/guessing-game/Cargo.toml
meta/lib/oeqa/files/maturin/guessing-game/pyproject.toml
meta/lib/oeqa/files/maturin/guessing-game/src/lib.rs

index a78ada2593dd98d8156adf8373fedcb7a91035b4..5c0c06db4bc5b76a2112c776a72c029ee004dce2 100644 (file)
@@ -1,7 +1,7 @@
 [package]
 name = "guessing-game"
-version = "0.1.0"
-edition = "2021"
+version = "0.3.0"
+edition = "2024"
 
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
@@ -11,10 +11,10 @@ name = "guessing_game"
 crate-type = ["cdylib"]
 
 [dependencies]
-rand = "0.8.4"
+rand = "0.9.0"
 
 [dependencies.pyo3]
-version = "0.24.1"
-# "abi3-py38" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.8
-features = ["abi3-py38"]
+version = "0.27.2"
+# "abi3-py39" tells pyo3 (and maturin) to build using the stable ABI with minimum Python version 3.9
+features = ["abi3-py39"]
 
index ff35abc472b0b859c6efd1b97fa45b93e0bbb393..ecd34372a5fc833182dda1776de6658ffd3d9dc9 100644 (file)
@@ -1,5 +1,5 @@
 [build-system]
-requires = ["maturin>=1.0,<2.0"]
+requires = ["maturin>=1.7,<2.0"]
 build-backend = "maturin"
 
 [tool.maturin]
index 6828466ed1a1e99ea8cf991218a11304218055d4..0c757c291f12c582bcec0d760edd599342b31bfb 100644 (file)
@@ -7,7 +7,7 @@ use std::io;
 fn guess_the_number() {
     println!("Guess the number!");
 
-    let secret_number = rand::thread_rng().gen_range(1..101);
+    let secret_number = rand::rng().random_range(1..101);
 
     loop {
         println!("Please input your guess.");
@@ -40,7 +40,7 @@ fn guess_the_number() {
 /// the `lib.name` setting in the `Cargo.toml`, else Python will not be able to
 /// import the module.
 #[pymodule]
-fn guessing_game(_py: Python, m: &PyModule) -> PyResult<()> {
+fn guessing_game(m: &Bound<'_, PyModule>) -> PyResult<()> {
     m.add_function(wrap_pyfunction!(guess_the_number, m)?)?;
 
     Ok(())