Add rule python.cython#6061
Merged
waruqi merged 3 commits intoxmake-io:devfrom May 16, 2025
Freed-Wu:cython
Merged
Conversation
waruqi
reviewed
Jan 12, 2025
Member
Author
print(1)$ cython -3omain.c main.py
$ cythonize -b main.c
$ python -c 'import main'
1For xmake: add_rules("mode.debug", "mode.release")
add_requires("python 3.x")
rule("python.cython")
set_extensions(".py", ".pyx")
before_buildcmd_file(function(target, batchcmds, sourcefile, opt)
local language = target:extraconf("rules", "python.cython", "language")
local ext
local arg = "-3"
if language == "c" then
ext = "c"
local rule = target:rule("python.cython"):clone()
rule:add("deps", "c", {order = true})
target:rule_add(rule)
elseif language == "c++" then
ext = "cc"
arg = arg .. "+"
local rule = target:rule("python.cython"):clone()
rule:add("deps", "c++", {order = true})
target:rule_add(rule)
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))
import("lib.detect.find_tool")
local cython = find_tool("cython")
assert(cython, "cython not found! please `pip install cython`.")
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)
target("main")
add_rules("python.library", "python.cython", { soabi = true, language = "c++" })
add_files("src/*.py")
add_packages("python")$ xmake --rebuild --verbose
[ 50%]: compiling.python src/main.py
/usr/bin/cython -3+ -o build/.gens/shm/linux/x86_64/release/rules/python/cython/main.cc src/main.py
/usr/bin/gcc -c -m64 -fPIC -fvisibility=hidden -fvisibility-inlines-hidden -O3 -isystem /usr/include/python3.13 -DNDEBUG -o build/.objs/shm/linux/x86_64/release/gens/rules/python/cython/main.cc.o build/.gens/shm/linux/x86_64/release/rules/python/cython/main.cc
checking for g++ ... /usr/bin/g++
checking for the shared library linker (sh) ... g++
checking for flags (-fPIC) ... ok
[ 75%]: linking.release shm.cpython-313-x86_64-linux-gnu.so
/usr/bin/g++ -o build/linux/x86_64/release/shm.cpython-313-x86_64-linux-gnu.so build/.objs/shm/linux/x86_64/release/gens/rules/python/cython/main.cc.o -shared -m64 -fPIC
[100%]: build ok, spent 0.804s
$ cd build/linux/x86_64/release/
$ python -c 'import main'
Traceback (most recent call last):
File "<string>", line 1, in <module>
import main
ImportError: dynamic module does not define module export function (PyInit_main) |
Member
Author
|
python.library should be renamed to python.module, same as nodejs.module, lua.module, platform.linux.module, etc. |
waruqi
reviewed
Jan 14, 2025
Member
|
please add some examples in tests |
waruqi
reviewed
Jan 14, 2025
waruqi
reviewed
Jan 14, 2025
waruqi
reviewed
Jan 16, 2025
Member
|
please add an example in https://github.com/xmake-io/xmake/tree/dev/tests/projects/pybind |
Member
Author
add_deps("python.library", {soabi = true} )cannot work. And why not set soabit's default value is true? a correct python module must set soabi to be recognized correctly. |
Add test python/cython/example Move test pybind to python/pybind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Future work:
*.hto*.pxd-Ifor*.pxdcython use a header file with extension pxd. Should we use same
add_includedirs()for it?That is, if we
We will