let version $ list.at 0 process.args $ or? :0.1.0
let release-dir :releases
let project-name :shik

print "=========================================="
print "Building Shik v${VERSION} release"
print "=========================================="

file.mkdir release-dir

let os shell.os
let arch shell.arch

print "Current platform: {os} {arch}"

print "Building optimized release binary..."

shell! "cargo build --release"

let bin-size $ file.list :target/release/shik $> list.map file.size $> list.sum $> bytes->string
print "Binary size: {bin-size}\n"

let platform "{os}-{arch}"

let archive-name "{project-name}-v{version}-{platform}"

print "Creating tar.xz archive..."

shell-cmd [:tar :-cJf "${RELEASE_DIR}/${ARCHIVE_NAME}.tar.xz"
    :-C :target/release :shik
    :--transform "'s,^,shik-v'\"{VERSION}\"'/,'"
    :2>/dev/null :||]
shell-cmd [:tar :-cJf "{RELEASE_DIR}/{ARCHIVE_NAME}.tar.xz" :-C :target/release :shik]


print "Created: {RELEASE_DIR}/{ARCHIVE_NAME}.tar.xz"

shell "tar -czf \"{RELEASE_DIR}/{ARCHIVE_NAME}.tar.gz\" -C target/release shik"

