Skip to content

Commit

Permalink
Use plain setuptools.Extension for the parser extension.
Browse files Browse the repository at this point in the history
For reasons mysterious to me, using Pybind11Extension leads to the error
"ImportError: dynamic module does not define module export function
(PyInit_parser_ext)", even if I set include_pybind11=False.
  • Loading branch information
rchen152 committed Nov 4, 2020
1 parent ffe3c89 commit 5dd02dd
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import shutil
import sys

from setuptools import setup
from setuptools import setup, Extension

# Path to directory containing setup.py
here = os.path.abspath(os.path.dirname(__file__))
Expand All @@ -37,23 +37,27 @@

def get_parser_ext():
"""Get the parser extension."""
extra_compile_args = []
# We need some platform-dependent compile args for the C extensions.
if sys.platform == 'win32':
# windows does not have unistd.h; lex/yacc needs this define.
extra_compile_args.append('-DYY_NO_UNISTD_H')

# This is a setuptools.Extension, with an added include for pybind11, a few
# flags, and a cxx_std setting.
return Pybind11Extension(
extra_compile_args = ['-DYY_NO_UNISTD_H']
extra_link_args = []
elif sys.platform == 'darwin':
# clang on darwin requires some extra flags, which gcc does not support
extra_compile_args = ['-std=c++11', '-stdlib=libc++']
extra_link_args = ['-stdlib=libc++']
else:
extra_compile_args = ['-std=c++11']
extra_link_args = []
return Extension(
'pytype.pyi.parser_ext',
sources=[
'pytype/pyi/parser_ext.cc',
'pytype/pyi/lexer.lex.cc',
'pytype/pyi/parser.tab.cc',
],
cxx_std=11,
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
)


Expand Down

0 comments on commit 5dd02dd

Please sign in to comment.