Skip to content

Commit 875311a

Browse files
committed
hatch_build.py updated
1 parent 719747c commit 875311a

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

hatch_build.py

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,28 @@ def initialize(self, version, build_data):
5656
current_os = platform.system().lower()
5757
arch = platform.machine().lower()
5858
print(f"OS: {current_os}, arch: {arch}")
59-
# Build lua for linux
59+
# Lua build defines
6060
lua_version = "5.4.8"
6161
lua_src = f"lua-{lua_version}.tar.gz"
6262
lua_checksum = f"lua-{lua_version}.sha256"
63-
package_dir = "python_lua_helper"
64-
build_dir = "build"
63+
lua_patch = "build.patch"
64+
# Define paths
65+
root_dir = os.path.dirname(__file__)
66+
lua_dir = os.path.join(root_dir, "lua")
67+
package_dir = os.path.join(root_dir, "python_lua_helper")
68+
base_build_dir = os.path.join(lua_dir, "build")
69+
lua_build_dir = os.path.join(base_build_dir, f"lua-{lua_version}")
6570
if current_os == "linux":
6671
print("Linux detected - building Lua from source...")
67-
# Clean/create build directory
68-
if os.path.exists(build_dir):
69-
shutil.rmtree(build_dir)
70-
os.makedirs(build_dir, exist_ok=False)
72+
# Clean/create main build directory
73+
if os.path.exists(base_build_dir):
74+
shutil.rmtree(base_build_dir)
75+
os.makedirs(base_build_dir, exist_ok=False)
7176
# Download Lua source if it doesn't exist
72-
if not os.path.exists(lua_src):
77+
if not os.path.exists(os.path.join(lua_dir, lua_src)):
7378
print(f"Downloading {lua_src}")
7479
self.run(
75-
os.curdir,
80+
lua_dir,
7681
"curl",
7782
"-s",
7883
"-L",
@@ -82,14 +87,21 @@ def initialize(self, version, build_data):
8287
)
8388
# Check checksum
8489
print(f"Checking {lua_src}")
85-
self.check_sha256(lua_src, lua_checksum)
90+
self.check_sha256(
91+
os.path.join(lua_dir, lua_src),
92+
os.path.join(lua_dir, lua_checksum),
93+
)
8694
# Extract archive
87-
shutil.unpack_archive(lua_src, build_dir)
88-
lua_build_dir = os.path.join(build_dir, f"lua-{lua_version}")
95+
shutil.unpack_archive(os.path.join(lua_dir, lua_src), base_build_dir)
8996
# Apply patch
9097
print("Applying build patch...")
91-
patch_file = os.path.join("..", "..", "build.patch")
92-
self.run(lua_build_dir, "patch", "-p1", "-i", patch_file)
98+
self.run(
99+
lua_build_dir,
100+
"patch",
101+
"-p1",
102+
"-i",
103+
os.path.join(lua_dir, lua_patch),
104+
)
93105
# Build Lua with optimization flags
94106
print("Building Lua...")
95107
self.run(
@@ -113,9 +125,9 @@ def initialize(self, version, build_data):
113125
)
114126
target_binary = os.path.join(package_dir, "lua.exe")
115127
if arch in ["x86_64", "amd64"]:
116-
source_binary = "lua-windows-x86_64"
128+
source_binary = os.path.join(lua_dir, "lua-windows-x86_64")
117129
elif arch in ["i386", "i586", "i686", "x86"]:
118-
source_binary = "lua-windows-i686"
130+
source_binary = os.path.join(lua_dir, "lua-windows-i686")
119131
else:
120132
print(
121133
f"Warning: Unsupported Windows architecture '{arch}' - no Lua binary available"

0 commit comments

Comments
 (0)