Skip to content

Commit 22e9730

Browse files
committed
Add rule python.cython
1 parent 58c00fc commit 22e9730

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

xmake/rules/python/cython/xmake.lua

+62
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+
set_extensions(".py", ".pyx")
23+
on_load(function(target)
24+
local language = target:extraconf("rules", "python.cython", "language")
25+
if language == "c" then
26+
target:add("deps", "c")
27+
elseif language == "c++" then
28+
target:add("deps", "c++")
29+
end
30+
end)
31+
before_buildcmd_file(function(target, batchcmds, sourcefile, opt)
32+
import("lib.detect.find_tool")
33+
local language = target:extraconf("rules", "python.cython", "language")
34+
local ext
35+
local arg = "-3"
36+
if language == "c" then
37+
ext = "c"
38+
elseif language == "c++" then
39+
ext = "cc"
40+
arg = arg .. "+"
41+
end
42+
local dirname = path.join(target:autogendir(), "rules", "python", "cython")
43+
local sourcefile_c = path.join(dirname, path.basename(sourcefile) .. "." .. ext)
44+
45+
-- add objectfile
46+
local objectfile = target:objectfile(sourcefile_c)
47+
table.insert(target:objectfiles(), objectfile)
48+
49+
-- add commands
50+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.python %s", sourcefile)
51+
batchcmds:mkdir(path.directory(sourcefile_c))
52+
local cython = find_tool("cython")
53+
assert(cython, "cython not found! please `pip install cython`.")
54+
batchcmds:vrunv(cython.program,
55+
{ 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)