-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
76 lines (65 loc) · 2.74 KB
/
setup.py
File metadata and controls
76 lines (65 loc) · 2.74 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
import os
import subprocess
import sys
from setuptools import setup, find_packages, Extension
from setuptools.command.build_ext import build_ext
# Read the README.md for the PyPI project description
with open(os.path.join(os.path.dirname(__file__), "README.md"), encoding="utf-8") as f:
long_description = f.read()
class ReactxpyBuildExt(build_ext):
"""Custom command to build the C++ reactxpy compiler using g++."""
def run(self):
# We need g++ to compile the PYSX compiler
try:
subprocess.check_output(['g++', '--version'])
except OSError:
raise RuntimeError("g++ must be installed to build ReactXPy")
source_dir = os.path.abspath("compiler")
# Ensure we place the binary inside the Python package directory
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath("reactxpy.dummy")))
is_windows = sys.platform == "win32"
binary_name = "reactxpy_compiler.exe" if is_windows else "reactxpy_compiler"
output_binary = os.path.join(extdir, binary_name)
# Ensure the output directory exists
os.makedirs(extdir, exist_ok=True)
# Check if pre-compiled binary exists in compiler directory
precompiled = os.path.join(source_dir, binary_name)
if os.path.exists(precompiled):
print(f"Using pre-compiled binary: {precompiled}")
import shutil
shutil.copy2(precompiled, output_binary)
return
# Source files for the C++ compiler
sources = [
os.path.join(source_dir, "main.cpp"),
os.path.join(source_dir, "parser.cpp"),
os.path.join(source_dir, "lexer.cpp"),
os.path.join(source_dir, "generator.cpp"),
os.path.join(source_dir, "linker.cpp"),
os.path.join(source_dir, "errors.cpp"),
]
# Compile command
compile_cmd = ["g++", "-std=c++17"] + sources + ["-o", output_binary]
print(f"Building ReactXPy compiler: {' '.join(compile_cmd)}")
subprocess.check_call(compile_cmd)
# Define a dummy extension to trigger our custom build step
reactxpy_ext = Extension("reactxpy.dummy", sources=[])
setup(
name="reactxpy",
version="0.3.2",
description="ReactXPy compiler for web applications.",
long_description=long_description,
long_description_content_type="text/markdown",
author="Anish Kumar",
packages=find_packages(),
ext_modules=[reactxpy_ext],
cmdclass={"build_ext": ReactxpyBuildExt},
entry_points={
"console_scripts": [
"reactxpy = reactxpy.cli:main",
"create-reactxpy-app = reactxpy.create_app:main",
]
},
include_package_data=True,
zip_safe=False,
)