-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup.py
104 lines (92 loc) · 3.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""Build Python extension."""
import json
import os
import subprocess
from glob import glob
from pathlib import Path
from setuptools import Extension, setup
from setuptools.command.build_ext import build_ext
def assemble(asm_file: str, asm_directory: Path) -> None:
"""Python extension assembling underlying objects."""
obj_file = asm_file.split(".")[0]+".o"
cwd = Path.cwd()
source_file = cwd / asm_directory / asm_file
obj_file = cwd / "artifacts" / obj_file
if obj_file.exists():
return
print(f"assembling {source_file}")
if not obj_file.parents[0].is_dir():
mkdir_command = f"mkdir {obj_file.parents[0]}"
print(mkdir_command)
subprocess.run(mkdir_command, shell=True, check=True)
assemble_command = f"as -mGOFF -I{source_file.parents[0]} -o {obj_file} {source_file}"
print(assemble_command)
subprocess.run(assemble_command, shell=True, check=True)
def build_json_schema_header() -> None:
schema_absolute_path = Path.cwd() / "schema.json"
with open(schema_absolute_path, "r") as f:
schema = json.dumps(json.load(f), separators=(",", ":"))
schema_header_absolute_path = Path.cwd() / "racfu" / "racfu_schema.hpp"
with open(schema_header_absolute_path, "w") as f:
f.write(
"\n".join(
[
"#ifndef __RACFU_SCHEMA_H_",
"#define __RACFU_SCHEMA_H_",
"",
f"#define RACFU_SCHEMA R\"({schema})\"_json",
"",
"#endif"
]
)
)
class build_with_asm_ext(build_ext):
def run(self):
os.environ["CC"] = "ibm-clang64"
os.environ["CFLAGS"] = "-std=c99"
os.environ["CXX"] = "ibm-clang++64"
os.environ["CXXFLAGS"] = "-std=c++14"
racfu_source_path = Path("racfu")
assemble("irrseq00.s", racfu_source_path / "irrseq00")
super().run()
def main():
"""Python extension build entrypoint."""
cwd = Path.cwd()
assembled_object_path = cwd / "artifacts" / "irrseq00.o"
build_json_schema_header()
setup_args = {
"ext_modules": [
Extension(
"racfu._C",
sources=(
glob("racfu/**/*.cpp")
+ glob("racfu/*.cpp")
+ glob("externals/json-schema-validator/*.cpp")
+ ["racfu/python/_racfu.c"]
),
include_dirs=(
glob("racfu/**/")
+ [
"racfu",
"externals/json",
"externals/json-schema-validator",
os.environ["ZOPEN_ROOTFS"] + "/usr/local/include"
]
),
extra_link_args = [
"-m64",
"-Wl,-b,edit=no",
"-Wl," + os.environ["ZOPEN_ROOTFS"] + "/usr/local/lib/libcrypto.a",
"-Wl," + os.environ["ZOPEN_ROOTFS"] + "/usr/local/lib/libssl.a",
"-Wl," + os.environ["ZOPEN_ROOTFS"] + "/usr/local/lib/libzoslib.a"
],
extra_objects = [
f"{assembled_object_path}"
]
)
],
"cmdclass": {"build_ext": build_with_asm_ext}
}
setup(**setup_args)
if __name__ == "__main__":
main()