added rust support (#50)
* added rust support * move binding files to their respective directories * updated README.md * updated pypi ci package-dir * add ruapu::rua() for rust
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
[build-system]
|
||||
requires = ["setuptools", "cython", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "ruapu"
|
||||
authors = [
|
||||
{name = "nihui", email = "shuizhuyuanluo@126.com"},
|
||||
{name = "cocoa-xu", email = "i@uwucocoa.moe"},
|
||||
]
|
||||
description = "The Python binding of ruapu."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.5"
|
||||
keywords = ["ruapu", "cpu", "isa", "detect"]
|
||||
license = {"text" = "MIT"}
|
||||
version = "0.1.0"
|
||||
|
||||
[project.urls]
|
||||
"Homepage" = "https://github.com/nihui/ruapu"
|
||||
|
||||
[tool.setuptools]
|
||||
package-dir = {"" = "."}
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["."]
|
||||
@@ -0,0 +1,37 @@
|
||||
#define RUAPU_IMPLEMENTATION
|
||||
#include "../ruapu.h"
|
||||
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
|
||||
static PyObject *ruapu_supports_py(PyObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = {"isa", NULL};
|
||||
const char *isa;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &isa))
|
||||
return NULL;
|
||||
if (ruapu_supports(isa))
|
||||
Py_RETURN_TRUE;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyMethodDef ruapu_methods[] =
|
||||
{
|
||||
{"supports", ruapu_supports_py, METH_VARARGS | METH_KEYWORDS, "Check if the CPU supports an instruction set"},
|
||||
{NULL, NULL, 0, NULL}
|
||||
};
|
||||
|
||||
static struct PyModuleDef ruapu_module =
|
||||
{
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"ruapu",
|
||||
"ruapu module",
|
||||
-1,
|
||||
ruapu_methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_ruapu(void)
|
||||
{
|
||||
ruapu_init();
|
||||
return PyModule_Create(&ruapu_module);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from setuptools import setup, find_packages, Extension
|
||||
from wheel.bdist_wheel import bdist_wheel
|
||||
|
||||
class bdist_wheel_abi3(bdist_wheel):
|
||||
def get_tag(self):
|
||||
python, abi, plat = super().get_tag()
|
||||
|
||||
if python.startswith("cp"):
|
||||
# on CPython, our wheels are abi3 and compatible back to 3.6
|
||||
return "cp36", "abi3", plat
|
||||
|
||||
return python, abi, plat
|
||||
|
||||
ext = Extension(
|
||||
name = 'ruapu',
|
||||
sources = ['ruapu-binding.c'],
|
||||
py_limited_api = True
|
||||
)
|
||||
|
||||
setup_args = dict(
|
||||
name = 'ruapu',
|
||||
packages = find_packages(where="."),
|
||||
package_dir = {"": "."},
|
||||
ext_modules = [ext],
|
||||
cmdclass = {"bdist_wheel": bdist_wheel_abi3},
|
||||
)
|
||||
|
||||
setup(**setup_args)
|
||||
Reference in New Issue
Block a user