|
| 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 = find_tool("cython") |
| 36 | + assert(cython, "cython not found! please `pip install cython`.") |
| 37 | + batchcmds:vrunv(cython.program, |
| 38 | + { "-3o", path(sourcefile_c), path(sourcefile) }) |
| 39 | + -- remember to add_rules("c") if you need |
| 40 | + batchcmds:compile(sourcefile_c, objectfile) |
| 41 | + |
| 42 | + -- add deps |
| 43 | + batchcmds:add_depfiles(sourcefile) |
| 44 | + batchcmds:set_depmtime(os.mtime(objectfile)) |
| 45 | + batchcmds:set_depcache(target:dependfile(objectfile)) |
| 46 | + end) |
0 commit comments