-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.py
More file actions
82 lines (64 loc) · 2.57 KB
/
Copy pathbuild.py
File metadata and controls
82 lines (64 loc) · 2.57 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
import os
import platform
import shutil
import subprocess
import requests
ROOT_DIR = "."
BUILD_DIR = "build"
def is_win():
return platform.system().lower().startswith('win')
def dlfcn_win32_gitfetch():
try:
url = "https://github.com/dlfcn-win32/dlfcn-win32.git"
clone_dir = os.path.join(ROOT_DIR, "dlfcn-win32")
print(f"Cloning {url} into {clone_dir} ...")
subprocess.run(["git", "clone", url, clone_dir], check=True)
print("Clone complete.")
except Exception as e:
print(f"Error cloning dlfcn-win32: {e}")
def cmake_build():
cmake_args = [
"cmake",
"-G", "Ninja",
"-DCMAKE_C_COMPILER=clang",
"-DCMAKE_CXX_COMPILER=clang++",
"-S", ".",
"-B", BUILD_DIR
]
subprocess.run(cmake_args)
subprocess.run(["cmake", "--build", BUILD_DIR])
def copy_libs():
print("Copying shared libraries to the root directory...")
if is_win():
lib_prefix = ""
dl_ext = "dll"
else:
lib_prefix = "lib"
dl_ext = "so"
output_path = os.path.join(ROOT_DIR, "out")
os.makedirs(output_path, exist_ok=True)
shutil.copy(os.path.join(BUILD_DIR, f"{lib_prefix}loader.{dl_ext}"), output_path)
shutil.copy(os.path.join(BUILD_DIR, "sum", f"{lib_prefix}sum.{dl_ext}"), output_path)
shutil.copy(os.path.join(BUILD_DIR, "multiply", f"{lib_prefix}multiply.{dl_ext}"), output_path)
if is_win():
# shutil.copy(os.path.join(BUILD_DIR, "bin", f"dl.{dl_ext}"), output_path)
shutil.copy(os.path.join(ROOT_DIR, "lib/win32", f"dl.{dl_ext}"), output_path)
zig_output_path = os.path.join(ROOT_DIR, "zig-out")
if is_win():
shutil.copy(os.path.join(zig_output_path, "bin/app.exe"), output_path)
shutil.copy(os.path.join(zig_output_path, "bin/app.dll"), output_path)
shutil.copy(os.path.join(zig_output_path, "bin/app.pdb"), output_path)
shutil.copy(os.path.join(zig_output_path, "lib/app.lib"), output_path)
else:
shutil.copy(os.path.join(zig_output_path, "bin/app"), output_path)
shutil.copy(os.path.join(zig_output_path, "lib/libapp.a"), output_path)
shutil.copy(os.path.join(zig_output_path, "lib/libapp.so"), output_path)
print("Shared libraries copied successfully.")
def zig_build():
# dlfcn_win32_gitfetch()
cmake_build()
zig_args = ["zig", "build"]
subprocess.run(zig_args)
copy_libs()
if str(__name__).upper() in ("__MAIN__",):
zig_build()