Skip to content

Commit a114034

Browse files
committed
fixup! Add initial zig bindings.
1 parent 7427ede commit a114034

File tree

2 files changed

+36
-33
lines changed

2 files changed

+36
-33
lines changed

bindings/zig/blst.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
// The file is auto-generated by generate.py
44
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
55

6+
// Copyright Supranational LLC
7+
// SPDX-License-Identifier: Apache-2.0
8+
69
const std = @import("std");
710

811
pub const c = @import("c.zig");

bindings/zig/generate.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
11
#!/usr/bin/env python3
22

3-
import os
4-
import sys
5-
import subprocess
6-
import re
3+
import os, re, sys, subprocess
74

8-
here = re.split(r'/(?=[^/]*$)', sys.argv[0])
9-
if len(here) > 1:
10-
os.chdir(here[0])
11-
12-
13-
def newer(*files):
14-
assert len(files) > 1
15-
rh = files[-1]
16-
if not os.path.exists(rh):
17-
return True
18-
for lh in files[:-1]:
19-
if os.stat(lh).st_mtime > os.stat(rh).st_mtime:
20-
return True
21-
return False
22-
23-
24-
if newer("../blst.h", "c.zig"):
25-
print("generating c.zig...") or sys.stdout.flush()
26-
ret = subprocess.run(["zig", "translate-c", "../blst.h", "-D__BLST_ZIG__"],
27-
capture_output=True, text=True)
28-
with open("c.zig", "w") as fd:
29-
print("// automatically generated with 'zig translate-c'", file=fd)
30-
for line in ret.stdout.splitlines():
31-
if "no file" in line:
32-
break
33-
elif not line.startswith("pub const _"):
34-
print(line, file=fd)
35-
36-
print("generating root.zig...") or sys.stdout.flush()
375
root_zig = """
6+
// Copyright Supranational LLC
7+
// SPDX-License-Identifier: Apache-2.0
8+
389
const std = @import("std");
3910
4011
pub const c = @import("c.zig");
@@ -393,6 +364,35 @@ def newer(*files):
393364
}
394365
};
395366
"""
367+
here = re.split(r'/(?=[^/]*$)', sys.argv[0])
368+
if len(here) > 1:
369+
os.chdir(here[0])
370+
371+
372+
def newer(*files):
373+
assert len(files) > 1
374+
rh = files[-1]
375+
if not os.path.exists(rh):
376+
return True
377+
for lh in files[:-1]:
378+
if os.stat(lh).st_mtime > os.stat(rh).st_mtime:
379+
return True
380+
return False
381+
382+
383+
if newer("../blst.h", "c.zig"):
384+
print("generating c.zig...") or sys.stdout.flush()
385+
ret = subprocess.run(["zig", "translate-c", "../blst.h", "-D__BLST_ZIG__"],
386+
capture_output=True, text=True)
387+
with open("c.zig", "w") as fd:
388+
print("// automatically generated with 'zig translate-c'", file=fd)
389+
for line in ret.stdout.splitlines():
390+
if "no file" in line:
391+
break
392+
elif not line.startswith("pub const _"):
393+
print(line, file=fd)
394+
395+
print("generating root.zig...") or sys.stdout.flush()
396396

397397

398398
def xchg_1vs2(matchobj):

0 commit comments

Comments
 (0)