diff options
| author | Wu, Zhenyu <[email protected]> | 2025-01-12 14:42:05 +0800 |
|---|---|---|
| committer | Wu, Zhenyu <[email protected]> | 2025-05-15 03:09:30 +0800 |
| commit | 5a582e2c201ecfb7a5eeb68a126e4842a2391cd2 (patch) | |
| tree | 020597a2a35bec54552cad18e0a5f93f1a7a36a4 | |
| parent | a68eff4a47e81b8ea430ee4f4a86d1fd8ccc7df9 (diff) | |
Add rule python.cython
Add test python/cython/example
Move test pybind to python/pybind
| -rw-r--r-- | tests/projects/python/cython/example/src/example.py | 1 | ||||
| -rw-r--r-- | tests/projects/python/cython/example/xmake.lua | 7 | ||||
| -rw-r--r-- | tests/projects/python/pybind/example/src/example.cpp (renamed from tests/projects/pybind/example/src/example.cpp) | 0 | ||||
| -rw-r--r-- | tests/projects/python/pybind/example/xmake.lua (renamed from tests/projects/pybind/example/xmake.lua) | 0 | ||||
| -rw-r--r-- | tests/projects/python/pybind/example_with_soabi/src/example.cpp (renamed from tests/projects/pybind/example_with_soabi/src/example.cpp) | 0 | ||||
| -rw-r--r-- | tests/projects/python/pybind/example_with_soabi/xmake.lua (renamed from tests/projects/pybind/example_with_soabi/xmake.lua) | 0 | ||||
| -rw-r--r-- | xmake/rules/python/cython/xmake.lua | 62 |
7 files changed, 70 insertions, 0 deletions
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/pybind/example/src/example.cpp b/tests/projects/python/pybind/example/src/example.cpp index cb1bad194..cb1bad194 100644 --- a/tests/projects/pybind/example/src/example.cpp +++ b/tests/projects/python/pybind/example/src/example.cpp diff --git a/tests/projects/pybind/example/xmake.lua b/tests/projects/python/pybind/example/xmake.lua index 19b7b5a9e..19b7b5a9e 100644 --- a/tests/projects/pybind/example/xmake.lua +++ b/tests/projects/python/pybind/example/xmake.lua diff --git a/tests/projects/pybind/example_with_soabi/src/example.cpp b/tests/projects/python/pybind/example_with_soabi/src/example.cpp index cb1bad194..cb1bad194 100644 --- a/tests/projects/pybind/example_with_soabi/src/example.cpp +++ b/tests/projects/python/pybind/example_with_soabi/src/example.cpp diff --git a/tests/projects/pybind/example_with_soabi/xmake.lua b/tests/projects/python/pybind/example_with_soabi/xmake.lua index 12d8ad334..12d8ad334 100644 --- a/tests/projects/pybind/example_with_soabi/xmake.lua +++ b/tests/projects/python/pybind/example_with_soabi/xmake.lua diff --git a/xmake/rules/python/cython/xmake.lua b/xmake/rules/python/cython/xmake.lua new file mode 100644 index 000000000..78323dfb2 --- /dev/null +++ b/xmake/rules/python/cython/xmake.lua @@ -0,0 +1,62 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed under the Apache License, Version 2.0 (the "License"); +-- you may not use this file except in compliance with the License. +-- You may obtain a copy of the License at +-- +-- http://www.apache.org/licenses/LICENSE-2.0 +-- +-- Unless required by applicable law or agreed to in writing, software +-- distributed under the License is distributed on an "AS IS" BASIS, +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +-- See the License for the specific language governing permissions and +-- limitations under the License. +-- +-- Copyright (C) 2015-present, TBOOX Open Source Group. +-- +-- @author Wu, Zhenyu +-- @file xmake.lua +-- + +rule("python.cython") + add_deps("python.library") + set_extensions(".py", ".pyx") + + on_load(function (target) + local language = target:extraconf("rules", "python.cython", "language") + if language == "c" then + target:add("deps", "c") + elseif language == "c++" then + target:add("deps", "c++") + end + end) + + before_buildcmd_file(function (target, batchcmds, sourcefile, opt) + import("lib.detect.find_tool") + + local cython = assert(find_tool("cython"), "cython not found! please `pip install cython`.") + local language = target:extraconf("rules", "python.cython", "language") + local ext = "c" + local arg = "-3" + if language == "c++" then + ext = "cc" + arg = arg .. "+" + end + local dirname = path.join(target:autogendir(), "rules", "python", "cython") + local sourcefile_c = path.join(dirname, path.basename(sourcefile) .. "." .. ext) + + -- add objectfile + local objectfile = target:objectfile(sourcefile_c) + table.insert(target:objectfiles(), objectfile) + + -- add commands + batchcmds:show_progress(opt.progress, "${color.build.object}compiling.python %s", sourcefile) + batchcmds:mkdir(path.directory(sourcefile_c)) + batchcmds:vrunv(cython.program, {arg, "-o", path(sourcefile_c), path(sourcefile)}) + batchcmds:compile(sourcefile_c, objectfile) + + -- add deps + batchcmds:add_depfiles(sourcefile) + batchcmds:set_depmtime(os.mtime(objectfile)) + batchcmds:set_depcache(target:dependfile(objectfile)) + end) |
