From 5a582e2c201ecfb7a5eeb68a126e4842a2391cd2 Mon Sep 17 00:00:00 2001 From: "Wu, Zhenyu" Date: Sun, 12 Jan 2025 14:42:05 +0800 Subject: Add rule python.cython Add test python/cython/example Move test pybind to python/pybind --- .../projects/python/cython/example/src/example.py | 1 + tests/projects/python/cython/example/xmake.lua | 7 ++++ .../projects/python/pybind/example/src/example.cpp | 38 ++++++++++++++++++++++ tests/projects/python/pybind/example/xmake.lua | 8 +++++ .../pybind/example_with_soabi/src/example.cpp | 38 ++++++++++++++++++++++ .../python/pybind/example_with_soabi/xmake.lua | 8 +++++ 6 files changed, 100 insertions(+) create mode 100644 tests/projects/python/cython/example/src/example.py create mode 100644 tests/projects/python/cython/example/xmake.lua create mode 100644 tests/projects/python/pybind/example/src/example.cpp create mode 100644 tests/projects/python/pybind/example/xmake.lua create mode 100644 tests/projects/python/pybind/example_with_soabi/src/example.cpp create mode 100644 tests/projects/python/pybind/example_with_soabi/xmake.lua (limited to 'tests/projects/python') diff --git a/tests/projects/python/cython/example/src/example.py b/tests/projects/python/cython/example/src/example.py new file mode 100644 index 000000000..f7cf60e14 --- /dev/null +++ b/tests/projects/python/cython/example/src/example.py @@ -0,0 +1 @@ +print("Hello, world!") diff --git a/tests/projects/python/cython/example/xmake.lua b/tests/projects/python/cython/example/xmake.lua new file mode 100644 index 000000000..f7461dbc2 --- /dev/null +++ b/tests/projects/python/cython/example/xmake.lua @@ -0,0 +1,7 @@ +add_rules("mode.debug", "mode.release") +add_requires("python 3.x") + +target("example") + add_rules("python.cython") + add_files("src/*.py") + add_packages("python") diff --git a/tests/projects/python/pybind/example/src/example.cpp b/tests/projects/python/pybind/example/src/example.cpp new file mode 100644 index 000000000..cb1bad194 --- /dev/null +++ b/tests/projects/python/pybind/example/src/example.cpp @@ -0,0 +1,38 @@ +#include + +#define STRINGIFY(x) #x +#define MACRO_STRINGIFY(x) STRINGIFY(x) + +int add(int i, int j) { + return i + j; +} + +namespace py = pybind11; + +PYBIND11_MODULE(example, m) { + m.doc() = R"pbdoc( + Pybind11 example plugin + ----------------------- + .. currentmodule:: example + .. autosummary:: + :toctree: _generate + add + subtract + )pbdoc"; + + m.def("add", &add, R"pbdoc( + Add two numbers + Some other explanation about the add function. + )pbdoc"); + + m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc( + Subtract two numbers + Some other explanation about the subtract function. + )pbdoc"); + +#ifdef VERSION_INFO + m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); +#else + m.attr("__version__") = "dev"; +#endif +} diff --git a/tests/projects/python/pybind/example/xmake.lua b/tests/projects/python/pybind/example/xmake.lua new file mode 100644 index 000000000..19b7b5a9e --- /dev/null +++ b/tests/projects/python/pybind/example/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.release", "mode.debug") +add_requires("pybind11") + +target("example") + add_rules("python.library") + add_files("src/*.cpp") + add_packages("pybind11") + set_languages("c++11") diff --git a/tests/projects/python/pybind/example_with_soabi/src/example.cpp b/tests/projects/python/pybind/example_with_soabi/src/example.cpp new file mode 100644 index 000000000..cb1bad194 --- /dev/null +++ b/tests/projects/python/pybind/example_with_soabi/src/example.cpp @@ -0,0 +1,38 @@ +#include + +#define STRINGIFY(x) #x +#define MACRO_STRINGIFY(x) STRINGIFY(x) + +int add(int i, int j) { + return i + j; +} + +namespace py = pybind11; + +PYBIND11_MODULE(example, m) { + m.doc() = R"pbdoc( + Pybind11 example plugin + ----------------------- + .. currentmodule:: example + .. autosummary:: + :toctree: _generate + add + subtract + )pbdoc"; + + m.def("add", &add, R"pbdoc( + Add two numbers + Some other explanation about the add function. + )pbdoc"); + + m.def("subtract", [](int i, int j) { return i - j; }, R"pbdoc( + Subtract two numbers + Some other explanation about the subtract function. + )pbdoc"); + +#ifdef VERSION_INFO + m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO); +#else + m.attr("__version__") = "dev"; +#endif +} diff --git a/tests/projects/python/pybind/example_with_soabi/xmake.lua b/tests/projects/python/pybind/example_with_soabi/xmake.lua new file mode 100644 index 000000000..12d8ad334 --- /dev/null +++ b/tests/projects/python/pybind/example_with_soabi/xmake.lua @@ -0,0 +1,8 @@ +add_rules("mode.release", "mode.debug") +add_requires("pybind11") + +target("example") + add_rules("python.library", {soabi = true}) + add_files("src/*.cpp") + add_packages("pybind11") + set_languages("c++11") -- cgit v1.3.1