2

I need to generate unit-test and integration-test reports (cargo test command) of a Rust project. To do this I am using RobotFramework. When I try to run cargo test command it fails with an error /usr/bin/ld: cannot find -lpython3.12: No such file or directory.

lib.rs

/* * Copyright (c) 2023 Markus Neifer. * Licensed under the MIT License. * See LICENSE in the project root for license information. * * Adopted from https://pyo3.rs/v0.18.1/ */ // The following line allows non snake-case name for Robot test library #![allow(non_snake_case)] use std::collections::HashMap; use pyo3::prelude::*; #[pyfunction] fn sum_as_string(a: i32, b: i32) -> PyResult<String> { Ok((a + b).to_string()) } #[pyfunction] fn join_strings(a: Vec<String>) -> PyResult<String> { Ok(a.join(",")) } #[pyfunction] fn sum_values(a: HashMap<String, i32>) -> PyResult<i32> { let mut values_sum = 0; for (_key, value) in &a { values_sum += value; } Ok(values_sum) } #[pymodule] fn RustyLibrary(_py: Python, m: &PyModule) -> PyResult<()> { m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; m.add_function(wrap_pyfunction!(join_strings, m)?)?; m.add_function(wrap_pyfunction!(sum_values, m)?)?; Ok(()) } #[cfg(test)] mod tests { use super::*; #[test] fn sum_as_string_test() { assert_eq!("25", sum_as_string(5, 20).unwrap()); } #[test] fn join_strings_test() { let foo = String::from("foo"); let bar = String::from("bar"); let the_strings = vec![foo, bar]; assert_eq!("foo, bar", join_strings(the_strings).unwrap()); } #[test] fn sum_values_test() { let mut values = HashMap::new(); values.insert(String::from("abc"), 6); values.insert(String::from("def"), 15); values.insert(String::from("ghi"), 24); assert_eq!(45, sum_values(values).unwrap()); } } 

Cargo.toml

[package] name = "RustyLibrary" version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] name = "RustyLibrary" crate-type = ["cdylib"] [dependencies] pyo3 = "0.18.1" 

pyproject.toml

[build-system] requires = ["maturin>=1.9.2"] build-backend = "maturin" [project] name = "RustyLibrary" version = "0.1.0" requires-python = ">=3.12" classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] dependencies = [ "maturin>=1.9.2", "robotframework>=7.3.2", ] [tool.maturin] features = ["pyo3/extension-module"] 

If I build the Rust library using maturin develop, it builds successfully with the below output

📦 Including license file `LICENSE` 🔗 Found pyo3 bindings 🐍 Found CPython 3.12 at /home/harsha/rust_robot/robot-rust-test-library/.venv/bin/python 📡 Using build options features from pyproject.toml Audited 2 packages in 14ms Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s 📦 Built wheel for CPython 3.12 to /tmp/.tmpssq3RX/RustyLibrary-0.1.0-cp312-cp312-linux_x86_64.whl ✏️ Setting installed package as editable 🛠 Installed RustyLibrary-0.1.0 
4
  • Do you have python 3.12 installed? Commented Aug 4 at 8:29
  • 1
    @Randommm Yes, the output of python3 --version is Python 3.12.3. Commented Aug 4 at 8:32
  • Seems to have found Python 3.12, but is the venv activated when running the program? Commented Aug 4 at 9:40
  • 1
    @Helio Yes, I ran source .venv/bin/activate Commented Aug 4 at 10:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.