-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_win.py
45 lines (37 loc) · 1.33 KB
/
build_win.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
import os, sys, sysconfig
import re
cmd = ["go", "build", "-buildmode=c-shared", "-o", "build/pyutls.so", "."] #, '-n']
cmd = ["go", "build", "-buildmode=c-shared", "-o", "build/pyutls.so", '-x', "."]
def get_library_path():
return ""
import os.path as op;
libdir = sysconfig.get_config_var('LIBDIR')
libpl = sysconfig.get_config_var('LIBPL')
ldlib = sysconfig.get_config_var('LDLIBRARY')
fpaths = [op.join(pv, ldlib) for pv in (libdir, libpl)];
paths = set()
for path in filter(op.exists, fpaths):
dirpath = os.path.dirname(path)
paths.add(f"-L '{dirpath}'")
bldlib = 'BLDLIBRARY'
libpath = ' '.join(paths)
libpath += " " + (sysconfig.get_config_var("BLDLIBRARY") or "")
return libpath
config = sysconfig.get_config_vars()
# for k, v in config.items():
# if not isinstance(v, str):
# config[k] = str(v)
include = sysconfig.get_config_var('INCLUDEPY')
cflags = f"-I '{include}'"
libpath = config['prefix']
print(f"$env:CGO_LDFLAGS = \"-L '{libpath}' -l python311 \" ")
print(f"$env:CGO_CFLAGS = '{cflags}'")
# os.environ.update(config)
# os.system("env")
# sys.exit(0)
print(libpath, cflags)
os.environ['CGO_CFLAGS'] = cflags
os.environ['CGO_CXXFLAGS'] = cflags
os.environ['CGO_LDFLAGS'] = libpath
# os.system(" ".join(cmd))
# os.system("cp ./build/pyutls.so ./python/")