Skip to content

Commit 5a582e2

Browse files
committed
Add rule python.cython
Add test python/cython/example Move test pybind to python/pybind
1 parent a68eff4 commit 5a582e2

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
print("Hello, world!")
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
add_rules("mode.debug", "mode.release")
2+
add_requires("python 3.x")
3+
4+
target("example")
5+
add_rules("python.cython")
6+
add_files("src/*.py")
7+
add_packages("python")
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
--!A cross-platform build utility based on Lua
2+
--
3+
-- Licensed under the Apache License, Version 2.0 (the "License");
4+
-- you may not use this file except in compliance with the License.
5+
-- You may obtain a copy of the License at
6+
--
7+
-- http://www.apache.org/licenses/LICENSE-2.0
8+
--
9+
-- Unless required by applicable law or agreed to in writing, software
10+
-- distributed under the License is distributed on an "AS IS" BASIS,
11+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
-- See the License for the specific language governing permissions and
13+
-- limitations under the License.
14+
--
15+
-- Copyright (C) 2015-present, TBOOX Open Source Group.
16+
--
17+
-- @author Wu, Zhenyu
18+
-- @file xmake.lua
19+
--
20+
21+
rule("python.cython")
22+
add_deps("python.library")
23+
set_extensions(".py", ".pyx")
24+
25+
on_load(function (target)
26+
local language = target:extraconf("rules", "python.cython", "language")
27+
if language == "c" then
28+
target:add("deps", "c")
29+
elseif language == "c++" then
30+
target:add("deps", "c++")
31+
end
32+
end)
33+
34+
before_buildcmd_file(function (target, batchcmds, sourcefile, opt)
35+
import("lib.detect.find_tool")
36+
37+
local cython = assert(find_tool("cython"), "cython not found! please `pip install cython`.")
38+
local language = target:extraconf("rules", "python.cython", "language")
39+
local ext = "c"
40+
local arg = "-3"
41+
if language == "c++" then
42+
ext = "cc"
43+
arg = arg .. "+"
44+
end
45+
local dirname = path.join(target:autogendir(), "rules", "python", "cython")
46+
local sourcefile_c = path.join(dirname, path.basename(sourcefile) .. "." .. ext)
47+
48+
-- add objectfile
49+
local objectfile = target:objectfile(sourcefile_c)
50+
table.insert(target:objectfiles(), objectfile)
51+
52+
-- add commands
53+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.python %s", sourcefile)
54+
batchcmds:mkdir(path.directory(sourcefile_c))
55+
batchcmds:vrunv(cython.program, {arg, "-o", path(sourcefile_c), path(sourcefile)})
56+
batchcmds:compile(sourcefile_c, objectfile)
57+
58+
-- add deps
59+
batchcmds:add_depfiles(sourcefile)
60+
batchcmds:set_depmtime(os.mtime(objectfile))
61+
batchcmds:set_depcache(target:dependfile(objectfile))
62+
end)

0 commit comments

Comments
 (0)