提交 ced7e4b6 编写于 作者: J Jim Anderson

helping jim

上级 0c983255
...@@ -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.
先完成此消息的编辑!
想要评论请 注册