一个setuptools扩展,用于构建用golang编写的cpython扩展。
setuptools-golang的Python项目详细描述
设置工具golang
一个setuptools扩展,用于构建用golang编写的cpython扩展。
要求
这需要golang>;=1.5。目前测试的是1.10和1.11。
这需要python>;=2.7。目前它是根据2.7,3.6,3.7, 还有派比。
平台支架
- Linux
- MacOS
- win32(32位cpython,32位go 1.10+)
用法
在setup.py和
build_golang={'root': ...}
。root
是指
你的项目。
扩展名必须是main
go包中的单个文件(尽管整个
main
包将内置到扩展中)。那个包裹可能会进口
其他代码。
您的setup.py
中可能有多个扩展名。
setup(...build_golang={'root':'github.com/user/project'},ext_modules=[Extension('example',['example.go'])],setup_requires=['setuptools-golang'],...)
在golang中编写cpython扩展
这是一些examples
常见问题
undefined reference to `some_c_function'
Extension
默认情况下会带来列出的go文件,但不会带来
以及相关的C文件。在MANIFEST.in
中添加以下内容:
global-include *.c
global-include *.go
fatal: could not read Username for 'https://github.com':
您可能试图从不存在的外部源导入。 仔细检查您的输入是否正确。
package github.com/a/b/c: /tmp/.../github.com/a/b exists but /tmp/.../github.com/a/b/.git does not - stale checkout?
您可能输入了错误的导入。仔细检查您的输入是否正确。
duplicate symbol _XXX in: _cgo_export.o mod.cgo2.o
例如:
# github.com/asottile/dockerfile/pylib
duplicate symbol _PyDockerfile_GoParseError in:
$WORK/github.com/asottile/dockerfile/pylib/_obj/_cgo_export.o
$WORK/github.com/asottile/dockerfile/pylib/_obj/main.cgo2.o
确保将C中定义的全局变量标记为extern
。
Here's an example PR
制造Manylinux车轮
setuptools-golang
也为构建
PEP 513Manylinux1车轮
用户不需要安装go编译器就可以使用库。
只需从源代码运行setuptools-golang-build-manylinux-wheels
目录。生成的轮子将在./dist
中结束。
$ setuptools-golang-build-manylinux-wheels
...
+ ls /dist -al
total 8092
drwxrwxr-x 2 1000 1000 4096 Feb 1 04:16 .
drwxr-xr-x 41 root root 4096 Feb 1 04:15 ..
-rw-r--r-- 1 1000 1000 2065095 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp27-cp27mu-manylinux1_x86_64.whl
-rw-r--r-- 1 1000 1000 2063299 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp34-cp34m-manylinux1_x86_64.whl
-rw-r--r-- 1 1000 1000 2064862 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp35-cp35m-manylinux1_x86_64.whl
-rw-r--r-- 1 1000 1000 2064873 Feb 1 04:16 setuptools_golang_examples-0.1.1-cp36-cp36m-manylinux1_x86_64.whl
-rw-rw-r-- 1 1000 1000 4273 Feb 1 04:14 setuptools-golang-examples-0.1.1.tar.gz
*******************************************************************************
Your wheels have been built into ./dist
*******************************************************************************