Skip to content

Commit

Permalink
Make: Forward compilation settings for JS/Py
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Nov 9, 2023
1 parent 5d6e2ca commit 3578c50
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
9 changes: 6 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
"include_dirs": [
"<!@(node -p \"require('node-addon-api').include\")",
"include",
"fp16/include",
"simsimd/include",
"<!(echo $USEARCH_USE_SIMSIMD == '1' ? 'simsimd/include' : '')",
"<!(echo $USEARCH_USE_NATIVE_F16 == '1' ? 'fp16/include' : '')",
],
"dependencies": ["<!(node -p \"require('node-addon-api').gyp\")"],
"defines": ["USEARCH_USE_SIMSIMD=1", "USEARCH_USE_NATIVE_F16=0"],
"defines": [
"<!(echo $USEARCH_USE_SIMSIMD == '1' ? 'USEARCH_USE_SIMSIMD=1' : 'USEARCH_USE_SIMSIMD=0')",
"<!(echo $USEARCH_USE_NATIVE_F16 == '1' ? 'USEARCH_USE_NATIVE_F16=1' : 'USEARCH_USE_NATIVE_F16=0')"
],
"cflags": [
"-fexceptions",
"-Wno-unknown-pragmas",
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"node-addon-api": "^3.0.0"
},
"scripts": {
"preinstall": "git submodule update --init --recursive",
"test": "node --test ./javascript/usearch.test.js",
"install": "node-gyp rebuild"
},
Expand Down
27 changes: 20 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@

from pybind11.setup_helpers import Pybind11Extension


compile_args = []
link_args = []
macros_args = []

# Check the environment variables
use_simsimd = os.environ.get("USEARCH_USE_SIMSIMD", "1") == "1"
use_native_f16 = os.environ.get("USEARCH_USE_NATIVE_F16", "0") == "1"


def is_gcc():
try:
compiler_version = subprocess.check_output(["c++", "--version"], universal_newlines=True)
compiler_version = subprocess.check_output(
["c++", "--version"], universal_newlines=True
)
return "gcc" in compiler_version.lower()
except Exception:
return False


# Common arguments for all platforms
macros_args.append(("USEARCH_USE_SIMSIMD", "1" if use_simsimd else "0"))
macros_args.append(("USEARCH_USE_NATIVE_F16", "1" if use_native_f16 else "0"))

if sys.platform == "linux":
compile_args.append("-std=c++17")
compile_args.append("-O3") # Maximize performance
Expand All @@ -27,9 +38,6 @@ def is_gcc():
# Simplify debugging, but the normal `-g` may make builds much longer!
compile_args.append("-g1")

macros_args.append(("USEARCH_USE_NATIVE_F16", "0"))
macros_args.append(("USEARCH_USE_SIMSIMD", "1"))

if is_gcc():
macros_args.append(("USEARCH_USE_OPENMP", "1"))
compile_args.append("-fopenmp")
Expand Down Expand Up @@ -80,11 +88,16 @@ def is_gcc():
__version__ = open("VERSION", "r").read().strip()
__lib_name__ = "usearch"


this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, "README.md")) as f:
long_description = f.read()

# Depending on the macros, adjust the include directories
include_dirs = ["include"]
if use_simsimd:
include_dirs.append("simsimd/include")
if use_native_f16:
include_dirs.append("fp16/include")

setup(
name=__lib_name__,
Expand Down Expand Up @@ -118,7 +131,7 @@ def is_gcc():
"Topic :: Database :: Database Engines/Servers",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
include_dirs=["include", "fp16/include", "simsimd/include"],
include_dirs=include_dirs,
ext_modules=ext_modules,
install_requires=[
"numpy",
Expand Down

0 comments on commit 3578c50

Please sign in to comment.