Skip to content

Commit ab7e8aa

Browse files
committed
Allow cpu counting on multiple platforms
1 parent 81bd5ba commit ab7e8aa

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ def build_isa_l():
9797
build_env = os.environ.copy()
9898
# Add -fPIC flag to allow static compilation
9999
build_env["CFLAGS"] = build_env.get("CFLAGS", "") + " -fPIC"
100-
100+
if hasattr(os, "sched_getaffinity"):
101+
cpu_count = len(os.sched_getaffinity(0))
102+
else: # sched_getaffinity not available on all platforms
103+
cpu_count = os.cpu_count() or 1 # os.cpu_count() can return None
101104
run_args = dict(cwd=build_dir, env=build_env)
102105
subprocess.run(os.path.join(build_dir, "autogen.sh"), **run_args)
103106
subprocess.run([os.path.join(build_dir, "configure"),
104107
"--prefix", temp_prefix], **run_args)
105-
subprocess.run(["make", "-j", str(len(os.sched_getaffinity(0)))],
108+
subprocess.run(["make", "-j", str(cpu_count)],
106109
**run_args)
107110
subprocess.run(["make", "install"], **run_args)
108111
shutil.rmtree(build_dir)

0 commit comments

Comments
 (0)