aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/s2n/.yandex_meta/__init__.py
blob: 226a7c2e2bad55f4b9c24e7cd6036d156bbf1b90 (plain) (blame)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from devtools.yamaker.modules import Linkable, Switch
from devtools.yamaker.project import CMakeNinjaNixProject


def post_install(self):
    with self.yamakes["."] as m:
        pclmul_srcs = []
        avx2_srcs = []
        avx2_asm_srcs = []
        avx512_srcs = []
        for src in sorted(m.SRCS):
            if src.endswith("_pclmul.c"):
                m.SRCS.remove(src)
                pclmul_srcs.append(src)
            elif src.endswith("_avx2.c"):
                m.SRCS.remove(src)
                avx2_srcs.append(src)
            elif src.endswith("_avx2.S"):
                m.SRCS.remove(src)
                avx2_asm_srcs.append(src)
            elif src.endswith("_avx512.c"):
                m.SRCS.remove(src)
                avx512_srcs.append(src)

        x86_flags = [
            "-DS2N_CPUID_AVAILABLE",
            "-DS2N_KYBER512R3_AVX2_BMI2",
        ]
        for flag in x86_flags:
            m.CFLAGS.remove(flag)

        x86_only_section = Linkable(
            CFLAGS=x86_flags,
            SRCS=avx2_asm_srcs,
        )

        for src in pclmul_srcs:
            x86_only_section.after("SRCS", f"SRC_C_PCLMUL({src})")

        for src in avx2_srcs:
            x86_only_section.after("SRCS", f"SRC_C_AVX2({src})")

        for src in avx512_srcs:
            x86_only_section.after("SRCS", f"SRC_C_AVX512({src})")

        # Support Darwin.
        m.CFLAGS.remove("-DS2N_FEATURES_AVAILABLE")
        m.CFLAGS.remove("-DS2N_LINUX_SENDFILE")
        m.CFLAGS.remove("-DS2N_KTLS_SUPPORTED")
        m.after(
            "CFLAGS",
            Switch(
                OS_LINUX=Linkable(
                    CFLAGS=[
                        "-DS2N_FEATURES_AVAILABLE",
                        "-DS2N_LINUX_SENDFILE",
                        "-DS2N_KTLS_SUPPORTED",
                    ],
                )
            ),
        )

        # Support musl.
        m.CFLAGS.remove("-DS2N_STACKTRACE")
        m.after("CFLAGS", Switch({"NOT MUSL": Linkable(CFLAGS=["-DS2N_STACKTRACE"])}))

        m.after(
            "CFLAGS",
            Switch({"ARCH_X86_64": x86_only_section}),
        )


s2n = CMakeNinjaNixProject(
    arcdir="contrib/restricted/aws/s2n",
    nixattr="s2n",
    disable_includes=[
        "openssl/mem.h",
        "openssl/provider.h",
        "openssl/hkdf.h",
        "sys/isa_defs.h",
    ],
    post_install=post_install,
)