nectar/scripts/build-release.py

79 lines
2.5 KiB
Python
Raw Normal View History

2023-12-09 20:56:41 +03:00
#!/usr/bin/env python3
import os
import shutil
import subprocess
import zipfile
2023-12-09 20:56:41 +03:00
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):
2023-12-09 20:56:41 +03:00
print("\n" + "=" * 50)
print(f"BUILDING {feature if feature else 'default'}")
print("=" * 50 + "\n")
zip_prefix = f"kinode-{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"
2023-12-09 20:56:41 +03:00
if feature:
2024-02-02 08:17:46 +03:00
subprocess.run(["cargo", "+nightly", "build", "--release", "-p", "kinode", "--features", feature], check=True, env=release_env)
zip_name = f"{zip_prefix}-{feature}.zip"
2023-12-09 20:56:41 +03:00
else:
2024-02-02 08:17:46 +03:00
subprocess.run(["cargo", "+nightly", "build", "--release", "-p", "kinode"], check=True, env=release_env)
zip_name = f"{zip_prefix}.zip"
2023-12-09 20:56:41 +03:00
# Move and rename the binary
binary_name = "kinode"
source_path = f"target/release/{binary_name}"
2023-12-09 20:56:41 +03:00
dest_path = os.path.join(tmp_dir, binary_name)
shutil.move(source_path, dest_path)
os.chmod(dest_path, 0o664)
2023-12-09 20:56:41 +03:00
# Create a zip archive of the binary
zip_path = os.path.join(tmp_dir, zip_name)
2024-01-20 04:08:42 +03:00
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
zipf.write(dest_path, os.path.basename(dest_path))
os.chmod(zip_path, 0o664)
# Remove the original binary
os.remove(dest_path)
2023-12-09 20:56:41 +03:00
def main():
# Get system info
architecture, os_name = get_system_info()
2023-12-09 20:56:41 +03:00
# Modify the temporary directory path
2024-01-16 01:51:07 +03:00
tmp_dir = "/tmp/kinode-release"
2023-12-09 20:56:41 +03:00
if os.path.exists(tmp_dir):
shutil.rmtree(tmp_dir)
os.makedirs(tmp_dir)
# Features to compile with; add more features as needed
features = ["", "simulation-mode"]
2023-12-09 20:56:41 +03:00
# Loop through the features and build
for feature in features:
build_and_move(feature, tmp_dir, architecture, os_name)
2023-12-09 20:56:41 +03:00
2024-06-11 02:01:45 +03:00
linked_dir = f"\033]8;;file://{tmp_dir}\033\\{tmp_dir}\033]8;;\033\\"
print(f"Build and move process completed.\nFind release in {linked_dir}.")
2023-12-09 20:56:41 +03:00
if __name__ == "__main__":
main()