Skip to content

Commit

Permalink
attempting to fix macos builds
Browse files Browse the repository at this point in the history
  • Loading branch information
dleemiller committed Jul 28, 2024
1 parent 73757b0 commit 757b145
Showing 1 changed file with 31 additions and 17 deletions.
48 changes: 31 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,33 @@
from Cython.Build import cythonize
import numpy as np
import platform
import sys

numpy_include = np.get_include()

extra_compile_args = []
extra_link_args = []

if platform.machine().startswith('arm'):
if platform.architecture()[0] == '32bit':
extra_compile_args.extend(["-march=armv7-a", "-mfpu=neon"])
extra_link_args.extend(["-march=armv7-a", "-mfpu=neon"])
else: # 64-bit ARM
extra_compile_args.extend(["-march=armv8-a+simd"])
extra_link_args.extend(["-march=armv8-a+simd"])
elif platform.machine() in ["x86_64", "AMD64"]:
extra_compile_args.extend(["-march=native", "-mpopcnt"])
extra_link_args.extend(["-march=native", "-mpopcnt"])
if platform.system() == "Darwin":
if platform.machine() == "arm64":
extra_compile_args.extend(["-arch", "arm64", "-O3", "-ffast-math"])
extra_link_args.extend(["-arch", "arm64"])
else:
extra_compile_args.extend(["-arch", "x86_64", "-O3", "-ffast-math"])
extra_link_args.extend(["-arch", "x86_64"])
elif platform.system() == "Windows":
extra_compile_args.extend(["/O2"])
else: # Linux and others
if platform.machine().startswith("arm"):
if platform.architecture()[0] == "32bit":
extra_compile_args.extend(["-march=armv7-a", "-mfpu=neon"])
extra_link_args.extend(["-march=armv7-a", "-mfpu=neon"])
else: # 64-bit ARM
extra_compile_args.extend(["-march=armv8-a"])
extra_link_args.extend(["-march=armv8-a"])
elif platform.machine() in ["x86_64", "AMD64"]:
extra_compile_args.extend(["-march=native", "-mpopcnt"])
extra_link_args.extend(["-march=native", "-mpopcnt"])

extra_compile_args.extend(["-O3", "-ffast-math"])

Expand All @@ -37,16 +48,16 @@
extra_link_args=extra_link_args,
),
Extension(
"wordllama.algorithms.kmeans_helpers",
["wordllama/algorithms/kmeans_helpers.pyx"],
"wordllama.algorithms.deduplicate_helpers",
["wordllama/algorithms/deduplicate_helpers.pyx"],
include_dirs=[numpy_include],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
),
Extension(
"wordllama.algorithms.deduplicate_helpers",
["wordllama/algorithms/deduplicate_helpers.pyx"],
"wordllama.algorithms.kmeans_helpers",
["wordllama/algorithms/kmeans_helpers.pyx"],
include_dirs=[numpy_include],
define_macros=[("NPY_NO_DEPRECATED_API", "NPY_1_7_API_VERSION")],
extra_compile_args=extra_compile_args,
Expand All @@ -58,10 +69,13 @@
name="Text Processing Tools",
ext_modules=cythonize(
extensions,
compiler_directives={"language_level": "3", "boundscheck": False, "wraparound": False},
annotate=True
compiler_directives={
"language_level": "3",
"boundscheck": False,
"wraparound": False,
},
annotate=True,
),
zip_safe=False,
install_requires=["numpy"],
)

0 comments on commit 757b145

Please sign in to comment.