Skip to content

Commit 50b7569

Browse files
authored
Merge pull request #69 from Distributive-Network/Xmader/chore/rewrite-build-script-in-python
Chore: Merge `build_script.sh` into `build.py`
2 parents f4a3fe0 + a0172db commit 50b7569

File tree

2 files changed

+22
-28
lines changed

2 files changed

+22
-28
lines changed

build.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
import os, sys
33
import platform
44

5+
TOP_DIR = os.path.abspath(os.path.dirname(__file__))
6+
BUILD_DIR = os.path.join(TOP_DIR, "build")
7+
8+
# Get number of CPU cores
9+
CPUS = os.cpu_count() or 1
10+
511
def execute(cmd: str):
612
popen = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT,
713
shell = True, text = True )
@@ -23,15 +29,28 @@ def ensure_spidermonkey():
2329
# Build SpiderMonkey
2430
execute("bash ./setup.sh")
2531

26-
def build():
27-
ensure_spidermonkey()
28-
execute(f"bash ./build_script.sh")
32+
def run_cmake_build():
33+
os.makedirs(BUILD_DIR, exist_ok=True) # mkdir -p
34+
os.chdir(BUILD_DIR)
35+
if platform.system() == "Windows":
36+
execute("cmake .. -T ClangCL") # use Clang/LLVM toolset for Visual Studio
37+
else:
38+
execute("cmake ..")
39+
execute(f"cmake --build . -j{CPUS} --config Release")
40+
os.chdir(TOP_DIR)
41+
42+
def copy_artifacts():
2943
if platform.system() == "Windows":
3044
execute("cp ./build/src/*/pythonmonkey.pyd ./python/pythonmonkey/") # Release or Debug build
3145
execute("cp ./_spidermonkey_install/lib/mozjs-*.dll ./python/pythonmonkey/")
3246
else:
3347
execute("cp ./build/src/pythonmonkey.so ./python/pythonmonkey/")
3448
execute("cp ./_spidermonkey_install/lib/libmozjs* ./python/pythonmonkey/")
3549

50+
def build():
51+
ensure_spidermonkey()
52+
run_cmake_build()
53+
copy_artifacts()
54+
3655
if __name__ == "__main__":
3756
build()

build_script.sh

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)