| 1 |
(library |
| 2 |
(name blake3_mini) |
| 3 |
(libraries unix) |
| 4 |
(foreign_archives blake3) |
| 5 |
(foreign_stubs |
| 6 |
(language c) |
| 7 |
(names blake3_stubs))) |
| 8 |
|
| 9 |
; There are 3 configrations for the blake3 rules: |
| 10 |
; 1. Handwritten assembly for x86_64 |
| 11 |
; 2. SIMD instructions with neon intrinsics for arm64 |
| 12 |
; 3. Portable C implementation |
| 13 |
|
| 14 |
; 1. Handwritten assembly for x86_64 |
| 15 |
|
| 16 |
(foreign_library |
| 17 |
(enabled_if |
| 18 |
(= %{architecture} "amd64")) |
| 19 |
(archive_name blake3) |
| 20 |
(language c) |
| 21 |
(names blake3 blake3_portable blake3_dispatch) |
| 22 |
(extra_objects |
| 23 |
blake3_avx2_x86-64 |
| 24 |
blake3_avx512_x86-64 |
| 25 |
blake3_sse2_x86-64 |
| 26 |
blake3_sse41_x86-64)) |
| 27 |
|
| 28 |
; 1.1: Unix assembly for x86_64 |
| 29 |
|
| 30 |
(rule |
| 31 |
(enabled_if |
| 32 |
(and |
| 33 |
(= %{architecture} "amd64") |
| 34 |
(or |
| 35 |
(= %{system} "linux") |
| 36 |
(= %{system} "macosx") |
| 37 |
(= %{system} "beos") |
| 38 |
(= %{system} "freebsd") |
| 39 |
(= %{system} "openbsd") |
| 40 |
(= %{system} "netbsd")))) |
| 41 |
(deps blake3_avx2_x86-64_unix.S) |
| 42 |
(targets blake3_avx2_x86-64%{ext_obj}) |
| 43 |
(action |
| 44 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 45 |
|
| 46 |
(rule |
| 47 |
(enabled_if |
| 48 |
(and |
| 49 |
(= %{architecture} "amd64") |
| 50 |
(or |
| 51 |
(= %{system} "linux") |
| 52 |
(= %{system} "macosx") |
| 53 |
(= %{system} "beos") |
| 54 |
(= %{system} "freebsd") |
| 55 |
(= %{system} "openbsd") |
| 56 |
(= %{system} "netbsd")))) |
| 57 |
(deps blake3_avx512_x86-64_unix.S) |
| 58 |
(targets blake3_avx512_x86-64%{ext_obj}) |
| 59 |
(action |
| 60 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 61 |
|
| 62 |
(rule |
| 63 |
(enabled_if |
| 64 |
(and |
| 65 |
(= %{architecture} "amd64") |
| 66 |
(or |
| 67 |
(= %{system} "linux") |
| 68 |
(= %{system} "macosx") |
| 69 |
(= %{system} "beos") |
| 70 |
(= %{system} "freebsd") |
| 71 |
(= %{system} "openbsd") |
| 72 |
(= %{system} "netbsd")))) |
| 73 |
(deps blake3_sse2_x86-64_unix.S) |
| 74 |
(targets blake3_sse2_x86-64%{ext_obj}) |
| 75 |
(action |
| 76 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 77 |
|
| 78 |
(rule |
| 79 |
(enabled_if |
| 80 |
(and |
| 81 |
(= %{architecture} "amd64") |
| 82 |
(or |
| 83 |
(= %{system} "linux") |
| 84 |
(= %{system} "macosx") |
| 85 |
(= %{system} "beos") |
| 86 |
(= %{system} "freebsd") |
| 87 |
(= %{system} "openbsd") |
| 88 |
(= %{system} "netbsd")))) |
| 89 |
(deps blake3_sse41_x86-64_unix.S) |
| 90 |
(targets blake3_sse41_x86-64%{ext_obj}) |
| 91 |
(action |
| 92 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 93 |
|
| 94 |
; 1.2: Windows GNU assembly for x86_64 |
| 95 |
|
| 96 |
(rule |
| 97 |
(enabled_if |
| 98 |
(and |
| 99 |
(= %{architecture} "amd64") |
| 100 |
(= %{os_type} "Win32") |
| 101 |
(= %{system} "mingw64") |
| 102 |
(<> %{ocaml-config:ccomp_type} "msvc"))) |
| 103 |
(deps blake3_avx2_x86-64_windows_gnu.S) |
| 104 |
(targets blake3_avx2_x86-64%{ext_obj}) |
| 105 |
(action |
| 106 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 107 |
|
| 108 |
(rule |
| 109 |
(enabled_if |
| 110 |
(and |
| 111 |
(= %{architecture} "amd64") |
| 112 |
(= %{os_type} "Win32") |
| 113 |
(= %{system} "mingw64") |
| 114 |
(<> %{ocaml-config:ccomp_type} "msvc"))) |
| 115 |
(deps blake3_avx512_x86-64_windows_gnu.S) |
| 116 |
(targets blake3_avx512_x86-64%{ext_obj}) |
| 117 |
(action |
| 118 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 119 |
|
| 120 |
(rule |
| 121 |
(enabled_if |
| 122 |
(and |
| 123 |
(= %{architecture} "amd64") |
| 124 |
(= %{os_type} "Win32") |
| 125 |
(= %{system} "mingw64") |
| 126 |
(<> %{ocaml-config:ccomp_type} "msvc"))) |
| 127 |
(deps blake3_sse2_x86-64_windows_gnu.S) |
| 128 |
(targets blake3_sse2_x86-64%{ext_obj}) |
| 129 |
(action |
| 130 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 131 |
|
| 132 |
(rule |
| 133 |
(enabled_if |
| 134 |
(and |
| 135 |
(= %{architecture} "amd64") |
| 136 |
(= %{os_type} "Win32") |
| 137 |
(= %{system} "mingw64") |
| 138 |
(<> %{ocaml-config:ccomp_type} "msvc"))) |
| 139 |
(deps blake3_sse41_x86-64_windows_gnu.S) |
| 140 |
(targets blake3_sse41_x86-64%{ext_obj}) |
| 141 |
(action |
| 142 |
(run %{cc} -c %{deps} -o %{targets}))) |
| 143 |
|
| 144 |
; 1.3: Windows MSVC assembly for x86_64 |
| 145 |
|
| 146 |
; %{ocaml-config:asm} has other flags that we don't want |
| 147 |
|
| 148 |
(rule |
| 149 |
(enabled_if |
| 150 |
(and |
| 151 |
(= %{architecture} "amd64") |
| 152 |
(= %{os_type} "Win32") |
| 153 |
(= %{ocaml-config:ccomp_type} "msvc"))) |
| 154 |
(deps blake3_avx2_x86-64_windows_msvc.asm) |
| 155 |
(targets blake3_avx2_x86-64%{ext_obj}) |
| 156 |
(action |
| 157 |
(run %{bin:ml64} /nologo /quiet /Fo%{targets} /c %{deps}))) |
| 158 |
|
| 159 |
(rule |
| 160 |
(enabled_if |
| 161 |
(and |
| 162 |
(= %{architecture} "amd64") |
| 163 |
(= %{os_type} "Win32") |
| 164 |
(= %{ocaml-config:ccomp_type} "msvc"))) |
| 165 |
(deps blake3_avx512_x86-64_windows_msvc.asm) |
| 166 |
(targets blake3_avx512_x86-64%{ext_obj}) |
| 167 |
(action |
| 168 |
(run %{bin:ml64} /nologo /quiet /Fo%{targets} /c %{deps}))) |
| 169 |
|
| 170 |
(rule |
| 171 |
(enabled_if |
| 172 |
(and |
| 173 |
(= %{architecture} "amd64") |
| 174 |
(= %{os_type} "Win32") |
| 175 |
(= %{ocaml-config:ccomp_type} "msvc"))) |
| 176 |
(deps blake3_sse2_x86-64_windows_msvc.asm) |
| 177 |
(targets blake3_sse2_x86-64%{ext_obj}) |
| 178 |
(action |
| 179 |
(run %{bin:ml64} /nologo /quiet /Fo%{targets} /c %{deps}))) |
| 180 |
|
| 181 |
(rule |
| 182 |
(enabled_if |
| 183 |
(and |
| 184 |
(= %{architecture} "amd64") |
| 185 |
(= %{os_type} "Win32") |
| 186 |
(= %{ocaml-config:ccomp_type} "msvc"))) |
| 187 |
(deps blake3_sse41_x86-64_windows_msvc.asm) |
| 188 |
(targets blake3_sse41_x86-64%{ext_obj}) |
| 189 |
(action |
| 190 |
(run %{bin:ml64} /nologo /quiet /Fo%{targets} /c %{deps}))) |
| 191 |
|
| 192 |
; 2. SIMD instructions with neon intrinsics for arm64 |
| 193 |
|
| 194 |
(foreign_library |
| 195 |
(enabled_if |
| 196 |
(or |
| 197 |
(= %{architecture} "arm64") |
| 198 |
(= %{architecture} "aarch64"))) |
| 199 |
(archive_name blake3) |
| 200 |
(language c) |
| 201 |
(flags :standard -Wno-unused-function) |
| 202 |
(names blake3 blake3_portable blake3_dispatch blake3_neon)) |
| 203 |
|
| 204 |
; 3. Portable C implementation |
| 205 |
|
| 206 |
(foreign_library |
| 207 |
(enabled_if |
| 208 |
(and |
| 209 |
(not |
| 210 |
(and |
| 211 |
(= %{architecture} "amd64") |
| 212 |
(or |
| 213 |
(= %{os_type} "Win32") |
| 214 |
(= %{system} "win64") |
| 215 |
(= %{system} "mingw64") |
| 216 |
(= %{system} "linux") |
| 217 |
(= %{system} "macosx") |
| 218 |
(= %{system} "beos") |
| •219 |
(= %{system} "gnu") |
| 220 |
(= %{system} "freebsd") |
| 221 |
(= %{system} "openbsd") |
| 222 |
(= %{system} "netbsd")))) |
| 223 |
(not |
| 224 |
(or |
| 225 |
(= %{architecture} "arm64") |
| 226 |
(= %{architecture} "aarch64"))))) |
| 227 |
(archive_name blake3) |
| 228 |
(language c) |
| 229 |
(flags |
| 230 |
:standard |
| 231 |
"-DBLAKE3_NO_SSE2" |
| 232 |
"-DBLAKE3_NO_SSE41" |
| 233 |
"-DBLAKE3_NO_AVX2" |
| 234 |
"-DBLAKE3_NO_AVX512") |
| 235 |
(names blake3 blake3_portable blake3_dispatch)) |