Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mikes zhang
001
提交
ced7e4b6
0
001
项目概览
mikes zhang
/
001
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
0
001
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
ced7e4b6
编写于
1月 01, 2020
作者:
J
Jim Anderson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
helping jim
上级
0c983255
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
50 addition
and
15 deletion
+50
-15
python-bindings/overview_article/tasks.py
python-bindings/overview_article/tasks.py
+50
-15
未找到文件。
python-bindings/overview_article/tasks.py
浏览文件 @
ced7e4b6
...
@@ -3,6 +3,11 @@
...
@@ -3,6 +3,11 @@
import
cffi
import
cffi
import
invoke
import
invoke
import
pathlib
import
pathlib
import
platform
# Flag if we are on windows as that will require a different command line
# for the compilers
WINDOWS
=
platform
.
system
().
startswith
(
"Windows"
)
@
invoke
.
task
@
invoke
.
task
...
@@ -21,8 +26,15 @@ def print_banner(msg):
...
@@ -21,8 +26,15 @@ def print_banner(msg):
def
build_cmult
(
c
):
def
build_cmult
(
c
):
""" Build the shared library for the sample C code """
""" Build the shared library for the sample C code """
print_banner
(
"Building C Library"
)
print_banner
(
"Building C Library"
)
invoke
.
run
(
"gcc -c -Wall -Werror -fpic cmult.c -I /usr/include/python3.7"
)
if
WINDOWS
:
invoke
.
run
(
"gcc -shared -o libcmult.so cmult.o"
)
invoke
.
run
(
"cl.exe /LD cmult.c /OUT:libcmult.dll"
)
else
:
invoke
.
run
(
"gcc -Wall -Werror -fpic cmult.c -I /usr/include/python3.7 "
"-shared -o libcmult.so"
)
print
(
"* Complete"
)
print
(
"* Complete"
)
...
@@ -44,6 +56,14 @@ def build_cffi(c):
...
@@ -44,6 +56,14 @@ def build_cffi(c):
with
open
(
h_file_name
)
as
h_file
:
with
open
(
h_file_name
)
as
h_file
:
ffi
.
cdef
(
h_file
.
read
())
ffi
.
cdef
(
h_file
.
read
())
# need to set the rpath so the new Python module lib can find the .so file
# in linux
if
WINDOWS
:
extra_links
=
[]
else
:
extra_links
=
[
"-Wl,-rpath,."
]
ffi
.
set_source
(
ffi
.
set_source
(
"cffi_example"
,
"cffi_example"
,
# Since we are calling a fully built library directly no custom source
# Since we are calling a fully built library directly no custom source
...
@@ -55,7 +75,7 @@ def build_cffi(c):
...
@@ -55,7 +75,7 @@ def build_cffi(c):
# libraries we are linking against:
# libraries we are linking against:
libraries
=
[
"cmult"
],
libraries
=
[
"cmult"
],
library_dirs
=
[
this_dir
.
as_posix
()],
library_dirs
=
[
this_dir
.
as_posix
()],
extra_link_args
=
[
"-Wl,-rpath,."
]
,
extra_link_args
=
extra_links
,
)
)
ffi
.
compile
()
ffi
.
compile
()
...
@@ -73,22 +93,37 @@ def test_cffi(c):
...
@@ -73,22 +93,37 @@ def test_cffi(c):
def
build_cppmult
(
c
):
def
build_cppmult
(
c
):
""" Build the shared library for the sample C++ code """
""" Build the shared library for the sample C++ code """
print_banner
(
"Building C++ Library"
)
print_banner
(
"Building C++ Library"
)
invoke
.
run
(
if
WINDOWS
:
"g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC cppmult.cpp "
invoke
.
run
(
"-o libcppmult.so "
"cl.exe /LD cmult.c /OUT:libcmult.dll"
)
)
else
:
invoke
.
run
(
"g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC cppmult.cpp "
"-o libcppmult.so "
)
print
(
"* Complete"
)
print
(
"* Complete"
)
def
compile_python_module
(
cpp_name
,
extension_name
):
def
compile_python_module
(
cpp_name
,
extension_name
):
invoke
.
run
(
if
WINDOWS
:
"g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
# This needs to get updated with a way to call the python3.7-config
"`python3 -m pybind11 --includes` "
# tool
"-I /usr/include/python3.7 -I . "
# This is the command line - possbily we jsut want a different function
"{0} "
# for windows. The 'spam.lib' portion is going to be the cppmult lib.
"-o {1}`python3.7-config --extension-suffix` "
# cl /LD /I/python/include ni.c spam.lib ../libs/pythonXY.lib
"-L. -lcppmult -Wl,-rpath,."
.
format
(
cpp_name
,
extension_name
)
invoke
.
run
(
)
"cl.exe /LD {0} /OUT:{1}"
.
format
(
cpp_name
,
extension_name
)
)
else
:
invoke
.
run
(
"g++ -O3 -Wall -Werror -shared -std=c++11 -fPIC "
"`python3 -m pybind11 --includes` "
"-I /usr/include/python3.7 -I . "
"{0} "
"-o {1}`python3.7-config --extension-suffix` "
"-L. -lcppmult -Wl,-rpath,."
.
format
(
cpp_name
,
extension_name
)
)
@
invoke
.
task
(
build_cppmult
)
@
invoke
.
task
(
build_cppmult
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录