Skip to content

Commit

Permalink
Make requested changes.
Browse files Browse the repository at this point in the history
Signed-off-by: Dusty DeWeese <[email protected]>
  • Loading branch information
HackerFoo committed Dec 16, 2020
1 parent e030368 commit 55191b5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
runs-on: ubuntu-20.04
strategy:
matrix:
antlr_runtime_type: [static, shared]
python_version: [3.5, 3.6, 3.7, 3.8, 3.9]
include:
- python-version: 3.5
TOXENV: py35
Expand All @@ -61,4 +63,4 @@ jobs:
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Tox
run: tox -e ${{ matrix.TOXENV }}
run: ANTLR4_RUNTIME_TYPE=${{ matrix.antlr_runtime_type }} tox -e ${{ matrix.TOXENV }}
20 changes: 13 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ def __init__(self, name, sourcedir='', prefix=''):
self.prefix = prefix


class CMakeBuild(build_ext):
class AntlrCMakeBuild(build_ext):
user_options = [
(
'antlr-runtime=', None,
"Whether to use a 'static' or 'shared' ANTLR runtime."),
]
ANTLR_RUNTIMES = ['static', 'shared']

def copy_extensions_to_source(self):
original_extensions = list(self.extensions)
Expand Down Expand Up @@ -99,8 +100,13 @@ def build_extension(self, ext):
env.get('CXXFLAGS', ''), self.distribution.get_version())
if not os.path.exists(self.build_temp):
os.makedirs(self.build_temp)
os.environ["CXXFLAGS"] = "-fPIC"
os.environ["CFLAGS"] = "-fPIC"

# When linking the ANTLR runtime statically, -fPIC is still
# necessary because libparse_fasm will be a shared library.
if self.antlr_runtime == 'static':
for flag in ["CFLAGS", "CXXFLAGS"]:
os.environ[flag] = os.environ.get(flag, "") + " -fPIC"

subprocess.check_call(
['cmake', ext.sourcedir] + cmake_args,
cwd=self.build_temp,
Expand All @@ -120,9 +126,9 @@ def initialize_options(self):

def finalize_options(self):
super().finalize_options()
assert self.antlr_runtime in [
'static', 'shared'
], 'Invalid antlr_runtime'
assert self.antlr_runtime in AntlrCMakeBuild.ANTLR_RUNTIMES, \
'Invalid antr_runtime {}, expected one of {}'.format(
self.antr_runtime, AntlrCMakeBuild.ANTLR_RUNTIMES)


setuptools.setup(
Expand All @@ -149,6 +155,6 @@ def finalize_options(self):
CMakeExtension('parse_fasm', sourcedir='src', prefix='fasm/parser')
] + cythonize("fasm/parser/antlr_to_tuple.pyx"),
cmdclass={
'build_ext': CMakeBuild,
'build_ext': AntlrCMakeBuild,
},
)
20 changes: 12 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,21 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4/
set(CMAKE_CXX_STANDARD 11)

if(ANTLR_RUNTIME_TYPE STREQUAL "static")
# required if linking to static library
# Required if linking to static library
add_definitions(-DANTLR4CPP_STATIC)

# add external build for antlrcpp
# Build the static library.
include(ExternalAntlr4Cpp)
set(ANTLR4_RUNTIME antlr4_static)
else()
# Look to see if the shared library is already available.
find_library(ANTLR4_RUNTIME NAMES antlr4-runtime REQUIRED)

# If not, build it.
if(NOT ANTLR4_RUNTIME)
include(ExternalAntlr4Cpp)
set(ANTLR4_RUNTIME antlr4_shared)
endif()
endif()

# add antrl4cpp artifacts to project environment
Expand All @@ -33,12 +43,6 @@ set(ANTLR_EXECUTABLE ${CMAKE_CURRENT_SOURCE_DIR}/../third_party/antlr4_lib/antlr
# add macros to generate ANTLR Cpp code from grammar
find_package(ANTLR REQUIRED)

if(ANTLR_RUNTIME_TYPE STREQUAL "static")
set(ANTLR4_RUNTIME antlr4_static)
else()
find_library(ANTLR4_RUNTIME NAMES antlr4-runtime REQUIRED)
endif()

# Unit testing library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../third_party/googletest EXCLUDE_FROM_ALL googletest)

Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ commands =
# This repository uses a Markdown long_description, so the -r flag to
# `setup.py check` is not needed. If your project contains a README.rst,
# use `python setup.py check -m -r -s` instead.
python setup.py build_ext --antlr-runtime={env:ANTLR4_RUNTIME_TYPE:static}
python setup.py develop
python setup.py check -m -s
flake8 --exclude .git,env,dist,build,third_party,.tox .
Expand All @@ -33,4 +34,6 @@ per-file-ignores =
ignore =
fasm/parser/tags.py
fasm/parser/libparse_fasm.*
# This is needed because this is an empty directory, which causes problems:
# https://stackoverflow.com/questions/2640378/include-empty-directory-with-python-setup-py-sdist
third_party/antlr4/runtime/PHP

0 comments on commit 55191b5

Please sign in to comment.