Skip to content

Commit 136c39d

Browse files
committed
Add rule python.cython
1 parent 5bc5ce5 commit 136c39d

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

xmake/rules/python/cython/xmake.lua

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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+
before_buildcmd_file(function(target, batchcmds, sourcefile, opt)
24+
local dirname = path.join(target:autogendir(), "rules", "python", "cython")
25+
local sourcefile_c = path.join(dirname, path.basename(sourcefile) .. ".c")
26+
27+
-- add objectfile
28+
local objectfile = target:objectfile(sourcefile_c)
29+
table.insert(target:objectfiles(), objectfile)
30+
31+
-- add commands
32+
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.python %s", sourcefile)
33+
batchcmds:mkdir(path.directory(sourcefile_c))
34+
import("lib.detect.find_tool")
35+
local cython = assert(find_tool("cython"), "cython not found!")
36+
batchcmds:vrunv(cython.program,
37+
{ "-3o", path(sourcefile_c), path(sourcefile) })
38+
-- remember to add_rules("c") if you need
39+
batchcmds:compile(sourcefile_c, objectfile)
40+
41+
-- add deps
42+
batchcmds:add_depfiles(sourcefile)
43+
batchcmds:set_depmtime(os.mtime(objectfile))
44+
batchcmds:set_depcache(target:dependfile(objectfile))
45+
end)

0 commit comments

Comments
 (0)