-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
194 lines (144 loc) · 5.01 KB
/
Copy pathbuild.py
File metadata and controls
194 lines (144 loc) · 5.01 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import dataclasses
from dataclasses import field
import platform
import sys
import os
import warnings
from pathlib import Path
import re
from typing import Any
import numpy as np
def parse_meson_options(file_path):
options = {}
# Define regex to capture option names and values
option_regex = re.compile(
r"option\(\s*'(?P<name>\w+)'\s*,\s*type:\s*'(?P<type>\w+)'\s*,\s*value:\s*(?P<value>[^,]+),?"
)
with open(file_path, 'r') as file:
for line in file:
match = option_regex.search(line)
if match:
name = match.group('name')
value = match.group('value').strip()
# Convert value based on type
if value in ["true", "false"]:
value = value == "true"
elif value.isdigit():
value = int(value)
elif value.startswith("'") and value.endswith("'"):
value = value.strip("'")
options[name] = value
return options
sys.path.append(os.getcwd())
if sys.platform.startswith("win"):
import pyMSVC
environment = pyMSVC.setup_environment()
#print(environment)
opt=Path(__file__).parent/"meson_options.txt"
if not opt.exists():
#print(opt ,"is missing")
meson_options={}
else:
meson_options=parse_meson_options(opt)
#print(meson_options)
import setuptools
import numpy
# rest of setup code here
from setuptools import Extension, Distribution
from setuptools.command.build_ext import build_ext
from Cython.Build import cythonize
from pathlib import Path
compile_args = ["-O3","-std=c++17","-DNPY_NO_DEPRECATED_API=NPY_2_0_API_VERSION"]
link_args = [ ]
include_dirs = [numpy.get_include(),os.getcwd()]
define_macros = []
#print(sys.platform)
if sys.platform == "darwin" and platform.machine()=="arm64":
#print("Darwin")
compile_args += [ "-mcpu=apple-m1", "-funroll-loops","-flto"]
OPENMP_PATH = '/opt/homebrew/opt/libomp'
if not Path(OPENMP_PATH).exists():
warnings.warn('OpenMP is not found. Install it using homebrew:\nbrew install libomp\n')
else:
compile_args += [
'-fopenmp'
]
link_args += [f'-L{OPENMP_PATH}/lib', '-fopenmp', '-lomp']
include_dirs += [f'{OPENMP_PATH}/include']
link_args += compile_args
elif sys.platform == "win32":
compile_args[1] = "/std:c++20"
compile_args[0] = "/Ox"
compile_args+=['/openmp','/fp:fast','/nologo', '/EHsc', '/MD' ,'/favor:Intel64' ]
link_args+=['/openmp']
link_args += compile_args
elif platform.machine()=="x86_64":
sys.path.append('/usr/include/x86_64-linux-gnu')
sys.path.append('/usr/lib/x86_64-linux-gnu')
compile_args += ['-lm']
include_dirs+=['/usr/include/x86_64-linux-gnu']
link_args += ['-L/usr/lib/x86_64-linux-gnu']
link_args += ['-fopenmp','-lgomp']
compile_args += [
'-msse', '-msse2', '-msse3', '-mssse3',
'-msse4.1', '-msse4.2', '-mavx', '-mavx2'
]
elif platform.machine() in ["arm64","aarch64"]:
compile_args+=[ '-lm','-mcpu=native','-march=armv8-a+simd']
compiler_args = ['-flto']
link_args += ['-fopenmp','-lgomp']
link_args+= compile_args
else:
raise Exception("unknown platform")
# see pyproject.toml for other metadata
print(compile_args,link_args,include_dirs,define_macros)
logo = f"""
------------------------------------------------------------------------------------------------------------------------
contextmachine bvh
------------------------------------------------------------------------------------------------------------------------
{platform.uname()}
compile_args: {compile_args}
"""
extensions = [
Extension("bvh._bvh", ["bvh/_bvh.pyx"],
extra_compile_args=compile_args,
extra_link_args=link_args,
define_macros=define_macros,
include_dirs=include_dirs,
language="c++"),
Extension("bvh.serialization", ["bvh/serialization.pyx"],
extra_compile_args=compile_args,
extra_link_args=link_args,
define_macros=define_macros,
include_dirs=include_dirs,
language="c++"),
]
compiler_directives = dict(
boundscheck=False,
wraparound=False,
cdivision=True,
nonecheck=False,
overflowcheck=False,
initializedcheck=False,
embedsignature=False,
language_level="3str",
)
print(__name__)
if __name__ == "__main__":
print(logo)
ext_modules = cythonize(
extensions,
include_path=include_dirs,
compiler_directives=compiler_directives,
force=True,
)
dist = Distribution({"ext_modules": ext_modules})
cmd = build_ext(dist)
cmd.ensure_finalized()
cmd.run()
import os, shutil
for output in cmd.get_outputs():
print(output)
relative_extension = os.path.relpath(output, cmd.build_lib)
print(relative_extension)
shutil.copyfile(output, relative_extension)