Skip to content

Commit

Permalink
add release build script
Browse files Browse the repository at this point in the history
  • Loading branch information
nick1udwig committed Jun 4, 2024
1 parent a23725e commit b9a04c2
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions scripts/build-release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/env python3

import os
import shutil
import subprocess
import zipfile

def get_system_info():
# Get OS and architecture information
os_info = subprocess.run(["uname"], capture_output=True, text=True, check=True).stdout.strip().lower()
arch_info = subprocess.run(["uname", "-m"], capture_output=True, text=True, check=True).stdout.strip().lower()

if os_info == "linux":
os_info = "unknown-linux-gnu"
elif os_info == "darwin":
os_info = "apple-darwin"

if arch_info == "arm":
arch_info = "aarch64"

return arch_info, os_info

def build_and_move(feature, tmp_dir, architecture, os_name):
print("\n" + "=" * 50)
print(f"BUILDING {feature if feature else 'default'}")
print("=" * 50 + "\n")

zip_prefix = f"kit-{architecture}-{os_name}"
release_env = os.environ.copy()
release_env["CARGO_PROFILE_RELEASE_LTO"] = f"fat"
release_env["CARGO_PROFILE_RELEASE_CODEGEN_UNITS"] = f"1"
release_env["CARGO_PROFILE_RELEASE_STRIP"] = f"symbols"
if feature:
subprocess.run(["cargo", "build", "--release", "--features", feature], check=True, env=release_env)
zip_name = f"{zip_prefix}-{feature}.zip"
else:
subprocess.run(["cargo", "build", "--release"], check=True, env=release_env)
zip_name = f"{zip_prefix}.zip"

# Move and rename the binary
binary_name = "kit"
source_path = f"target/release/{binary_name}"
dest_path = os.path.join(tmp_dir, binary_name)
shutil.move(source_path, dest_path)

# Create a zip archive of the binary
zip_path = os.path.join(tmp_dir, zip_name)
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipf.write(dest_path, os.path.basename(dest_path))

# Remove the original binary
os.remove(dest_path)

def main():
# Get system info
architecture, os_name = get_system_info()

# Modify the temporary directory path
tmp_dir = "/tmp/kit-release"
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.makedirs(tmp_dir)

# Features to compile with; add more features as needed
features = [""]

# Loop through the features and build
for feature in features:
build_and_move(feature, tmp_dir, architecture, os_name)

print(f"Build and move process completed.\nFind release in {tmp_dir}.")

if __name__ == "__main__":
main()

0 comments on commit b9a04c2

Please sign in to comment.