forked from Distributive-Network/PythonMonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
62 lines (52 loc) · 1.94 KB
/
build.py
File metadata and controls
62 lines (52 loc) · 1.94 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
# @file build.py
# Main PythonMonkey build automation script. Run with `poetry build`.
# @author Hamada Gasmallah, hamada@distributive.network
# @date April 2023
#
import subprocess
import os, sys
import platform
TOP_DIR = os.path.abspath(os.path.dirname(__file__))
BUILD_DIR = os.path.join(TOP_DIR, "build")
# Get number of CPU cores
CPUS = os.cpu_count() or 1
def execute(cmd: str):
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
shell = True, text = True )
for stdout_line in iter(popen.stdout.readline, ""):
sys.stdout.write(stdout_line)
sys.stdout.flush()
popen.stdout.close()
return_code = popen.wait()
if return_code:
raise subprocess.CalledProcessError(return_code, cmd)
def ensure_spidermonkey():
# Check if SpiderMonkey libs already exist
spidermonkey_lib_exist = os.path.exists("./_spidermonkey_install/lib")
if spidermonkey_lib_exist:
return
# Build SpiderMonkey
execute("bash ./setup.sh")
def run_cmake_build():
os.makedirs(BUILD_DIR, exist_ok=True) # mkdir -p
os.chdir(BUILD_DIR)
if platform.system() == "Windows":
execute("cmake .. -T ClangCL") # use Clang/LLVM toolset for Visual Studio
else:
execute("cmake ..")
execute(f"cmake --build . -j{CPUS} --config Release")
os.chdir(TOP_DIR)
def copy_artifacts():
if platform.system() == "Windows":
execute("cp ./build/src/*/pythonmonkey.pyd ./python/pythonmonkey/") # Release or Debug build
execute("cp ./_spidermonkey_install/lib/mozjs-*.dll ./python/pythonmonkey/")
else:
execute("cp ./build/src/pythonmonkey.so ./python/pythonmonkey/")
execute("cp ./_spidermonkey_install/lib/libmozjs* ./python/pythonmonkey/")
def build():
execute("git submodule update --init --recursive")
ensure_spidermonkey()
run_cmake_build()
copy_artifacts()
if __name__ == "__main__":
build()