66# This file is part of python-isal which is distributed under the
77# PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2.
88
9- import copy
109import functools
1110import os
11+ import platform
1212import shutil
1313import subprocess
1414import sys
@@ -72,32 +72,17 @@ def build_extension(self, ext):
7272 raise NotImplementedError (
7373 f"Unsupported platform: { sys .platform } " )
7474 else :
75- if self .compiler .compiler_type == "msvc" :
76- compiler = copy .deepcopy (self .compiler )
77- if not compiler .initialized :
78- compiler .initialize ()
79- compiler_command = f'"{ compiler .cc } "'
80- compiler_args = compiler .compile_options
81- elif self .compiler .compiler_type == "unix" :
82- compiler_command = self .compiler .compiler [0 ]
83- compiler_args = self .compiler .compiler [1 :]
84- else :
85- raise NotImplementedError ("Unknown compiler" )
86- isa_l_prefix_dir = build_isa_l (compiler_command ,
87- " " .join (compiler_args ))
75+ isa_l_build_dir = build_isa_l ()
8876 if SYSTEM_IS_UNIX :
8977 ext .extra_objects = [
90- os .path .join (isa_l_prefix_dir , "lib " , "libisal .a" )]
78+ os .path .join (isa_l_build_dir , "bin " , "isa-l .a" )]
9179 elif SYSTEM_IS_WINDOWS :
9280 ext .extra_objects = [
93- os .path .join (isa_l_prefix_dir , "isa-l_static.lib" )]
81+ os .path .join (isa_l_build_dir , "isa-l_static.lib" )]
9482 else :
9583 raise NotImplementedError (
9684 f"Unsupported platform: { sys .platform } " )
97- ext .include_dirs = [os .path .join (isa_l_prefix_dir ,
98- "include" )]
99- # -fPIC needed for proper static linking
100- ext .extra_compile_args = ["-fPIC" ]
85+ ext .include_dirs = [isa_l_build_dir ]
10186 super ().build_extension (ext )
10287
10388
@@ -106,62 +91,51 @@ def build_extension(self, ext):
10691# 'cache' is only available from python 3.9 onwards.
10792# see: https://docs.python.org/3/library/functools.html#functools.cache
10893@functools .lru_cache (maxsize = None )
109- def build_isa_l (compiler_command : str , compiler_options : str ):
94+ def build_isa_l ():
11095 # Check for cache
11196 if BUILD_CACHE :
11297 if BUILD_CACHE_FILE .exists ():
11398 cache_path = Path (BUILD_CACHE_FILE .read_text ())
114- if (cache_path / "include" / " isa-l" ).exists ():
99+ if (cache_path / "isa-l.h " ).exists ():
115100 return str (cache_path )
116101
117102 # Creating temporary directories
118103 build_dir = tempfile .mktemp ()
119- temp_prefix = tempfile .mkdtemp ()
120104 shutil .copytree (ISA_L_SOURCE , build_dir )
121105
122106 # Build environment is a copy of OS environment to allow user to influence
123107 # it.
124108 build_env = os .environ .copy ()
125- # Add -fPIC flag to allow static compilation
126- build_env ["CC" ] = compiler_command
127109 if SYSTEM_IS_UNIX :
128- build_env ["CFLAGS" ] = compiler_options + " -fPIC"
129- elif SYSTEM_IS_WINDOWS :
130- # The nmake file has CLFAGS_REL for all the compiler options.
131- # This is added to CFLAGS with all the necessary include options.
132- build_env ["CFLAGS_REL" ] = compiler_options
110+ build_env ["CFLAGS" ] = build_env .get ("CFLAGS" , "" ) + " -fPIC"
133111 if hasattr (os , "sched_getaffinity" ):
134112 cpu_count = len (os .sched_getaffinity (0 ))
135113 else : # sched_getaffinity not available on all platforms
136114 cpu_count = os .cpu_count () or 1 # os.cpu_count() can return None
137115 run_args = dict (cwd = build_dir , env = build_env )
138116 if SYSTEM_IS_UNIX :
139- subprocess .run (os .path .join (build_dir , "autogen.sh" ), ** run_args )
140- subprocess .run ([os .path .join (build_dir , "configure" ),
141- "--prefix" , temp_prefix ], ** run_args )
142- subprocess .run (["make" , "-j" , str (cpu_count )], ** run_args )
143- subprocess .run (["make" , "-j" , str (cpu_count ), "install" ], ** run_args )
117+ if platform .machine () == "aarch64" :
118+ cflags_param = "CFLAGS_aarch64"
119+ else :
120+ cflags_param = "CFLAGS_"
121+ subprocess .run (["make" , "-j" , str (cpu_count ), "-f" , "Makefile.unx" ,
122+ "isa-l.h" , "bin/isa-l.a" ,
123+ f"{ cflags_param } ={ build_env .get ('CFLAGS' , '' )} " ],
124+ ** run_args )
144125 elif SYSTEM_IS_WINDOWS :
145- subprocess .run (["nmake" , "/E" , "/f" , "Makefile.nmake" ], ** run_args )
146- Path (temp_prefix , "include" ).mkdir ()
147- print (temp_prefix , file = sys .stderr )
148- shutil .copytree (os .path .join (build_dir , "include" ),
149- Path (temp_prefix , "include" , "isa-l" ))
150- shutil .copy (os .path .join (build_dir , "isa-l_static.lib" ),
151- os .path .join (temp_prefix , "isa-l_static.lib" ))
152- shutil .copy (os .path .join (build_dir , "isa-l.h" ),
153- os .path .join (temp_prefix , "include" , "isa-l.h" ))
126+ subprocess .run (["nmake" , "/f" , "Makefile.nmake" ], ** run_args )
154127 else :
155128 raise NotImplementedError (f"Unsupported platform: { sys .platform } " )
156- shutil .rmtree (build_dir )
129+ shutil .copytree (os .path .join (build_dir , "include" ),
130+ os .path .join (build_dir , "isa-l" ))
157131 if BUILD_CACHE :
158- BUILD_CACHE_FILE .write_text (temp_prefix )
159- return temp_prefix
132+ BUILD_CACHE_FILE .write_text (build_dir )
133+ return build_dir
160134
161135
162136setup (
163137 name = "isal" ,
164- version = "1.1 .0" ,
138+ version = "1.2 .0" ,
165139 description = "Faster zlib and gzip compatible compression and "
166140 "decompression by providing python bindings for the ISA-L "
167141 "library." ,
0 commit comments