-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsetup.py
67 lines (52 loc) · 1.76 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
from setuptools import setup
from setuptools_rust import Binding, RustExtension
# Ensure these are present (in case we are not using PEP-518 compatible build
# system).
import setuptools_scm
def env_true(env):
return env == "1"
noflags = env_true(os.environ.get("SCALIB_NOFLAGS"))
portable = not noflags and env_true(os.environ.get("SCALIB_PORTABLE"))
x86_64_v3 = not noflags and env_true(os.environ.get("SCALIB_X86_64_V3"))
if portable and x86_64_v3:
raise ValueError("Cannot have both SCALIB_PORTABLE and SCALIB_X86_64_V3.")
# We check only for X86_64_V3, as this is the CI default, otherwise we assume local
# builds.
with open("src/scalib/build_config.py", "w") as f:
f.write(f"REQUIRE_X86_64_V3 = {x86_64_v3}\n")
rustflags = os.environ.get("RUSTFLAGS", "")
if noflags or portable:
pass
elif x86_64_v3:
rustflags += " -C target-cpu=x86-64-v3"
else:
rustflags += " -C target-cpu=native"
print(f"Build config: {noflags=} {portable=} {x86_64_v3=} {rustflags=}.")
scalib_features = ["pyo3/abi3"]
if env_true(os.environ.get("SCALIB_BLIS")):
scalib_features.append("blis")
if env_true(os.environ.get("SCALIB_NTL")):
scalib_features.append("ntl")
extension_args = dict(
binding=Binding.PyO3,
py_limited_api=True,
rust_version=">=1.83",
)
setup(
rust_extensions=[
RustExtension(
"scalib._scalib_ext",
path="src/scalib_ext/scalib-py/Cargo.toml",
features=scalib_features,
env=os.environ | {"RUSTFLAGS": rustflags},
**extension_args,
),
RustExtension(
"scalib._cpu_check",
path="src/scalib_ext/cpu-check/Cargo.toml",
**extension_args,
),
],
options={"bdist_wheel": {"py_limited_api": "cp310"}},
)