11#!/usr/bin/env python
22# -*- coding: utf-8 -*-
33import os
4+ import struct
45from os .path import join , dirname
56
67from setuptools import setup
@@ -34,13 +35,23 @@ def is_pure(self):
3435 return False
3536
3637
38+ def get_system_bits ():
39+ """Return 32 for 32-bit systems and 64 for 64-bit"""
40+ return struct .calcsize ("P" ) * 8
41+
42+
43+ SYSTEM = os .name
44+ BITS = get_system_bits ()
45+ HAVE_SSE42 = "sse4_2" in CPU_FLAGS
46+ HAVE_AES = "aes" in CPU_FLAGS
47+
3748CXXFLAGS = []
3849
39- print ("building on platform:" , os . name )
50+ print ("system: %s-%d" % ( SYSTEM , BITS ) )
4051print ("available CPU flags:" , CPU_FLAGS )
4152print ("environment:" , ", " .join (["%s=%s" % (k , v ) for k , v in os .environ .items ()]))
4253
43- if os . name == "nt" :
54+ if SYSTEM == "nt" :
4455 CXXFLAGS .extend (["/O2" ])
4556else :
4657 CXXFLAGS .extend (
@@ -53,18 +64,23 @@ def is_pure(self):
5364
5465# The "cibuildwheel" tool sets the variable below to
5566# something like x86_64, aarch64, i686, and so on.
56- ARCH = os .environ .get ("AUDITWHEEL_ARCH" )
67+ TARGET_ARCH = os .environ .get ("AUDITWHEEL_ARCH" )
5768
58- # Note: Only -msse4.2 has significant effect on performance;
59- # so not using other flags such as -maes and -mavx
60- if "sse4_2" in CPU_FLAGS :
61- if ( ARCH in [ None , "x86_64" ]) and ( os . name != "nt" ):
62- print ( "enabling SSE4.2 on compile" )
69+ if HAVE_SSE42 and ( TARGET_ARCH in [ None , "x86_64" ]) and ( BITS == 64 ):
70+ print ( "enabling SSE4.2 on compile" )
71+ if SYSTEM == "nt" :
72+ CXXFLAGS . append ( "/D__SSE4_2__" )
73+ else :
6374 CXXFLAGS .append ("-msse4.2" )
64- else :
65- print ("the CPU does not appear to support SSE4.2" )
6675
6776
77+ if HAVE_AES and (TARGET_ARCH in [None , "x86_64" ]) and (BITS == 64 ):
78+ print ("enabling AES on compile" )
79+ if SYSTEM == "nt" :
80+ CXXFLAGS .append ("/D__AES__" )
81+ else :
82+ CXXFLAGS .append ("-maes" )
83+
6884CXXHEADERS = [
6985 "src/metro.h" ,
7086 "src/metrohash.h" ,
@@ -78,6 +94,7 @@ def is_pure(self):
7894 "src/metrohash128.cc" ,
7995]
8096
97+
8198if USE_CYTHON :
8299 print ("building extension using Cython" )
83100 CMDCLASS = {"build_ext" : build_ext }
@@ -99,7 +116,7 @@ def is_pure(self):
99116 ),
100117]
101118
102- VERSION = "0.2.0.post1 "
119+ VERSION = "0.2.1 "
103120URL = "https://github.com/escherba/python-metrohash"
104121
105122
0 commit comments