#!/usr/local/bin/fish # # A very messy script for making building Rust programs for # various platforms and then stuffing them into archives set cargocmd cargo metadata --format-version 1 --no-deps set packageCount ($cargocmd | jq '.packages | length') set package $argv[1] if test $packageCount -gt 1 -a -z "$argv[1]" echo "Multiple packages in workspace, but none provided!" echo "What package do I build for?" exit else if test $packageCount -eq 1 -a -z "$argv[1]" set parsedPackage ($cargocmd | jq --raw-output '.packages[0].name') set package $parsedPackage end set packageVersion ($cargocmd | jq --raw-output '.packages[] | select(.name == "'$package'") | .version') echo "building for $package version $packageVersion" set target ($cargocmd | jq --raw-output '.target_directory') set workroot ($cargocmd | jq --raw-output '.workspace_root') set temp $target/cutrel/working set done $target/cutrel set license $workroot/LICENSE echo "target=$target" echo "" if test ! -e $license echo "!! No license file in root!" #exit end mkdir -p $done mkdir -p $temp function build -a triple outName set windows false echo $triple | grep windows &>/dev/null if test $status -eq 0 echo "Windows detected, using xwin!" set windows true end set final "$done/$package-v$packageVersion""_""$outName.tar.gz" if test $windows = true set final "$done/$package-v$packageVersion""_""$outName.zip" end echo "window = $windows | final = $final" if test -e $final echo "Skipping $outName, already exists!" return end set thisWork $temp/$packageVersion-$outName set thisTarName $package-$packageVersion set thisTar $thisWork/$thisTarName echo "building for $outName..." set buildCmd cargo build if test $windows = true set buildCmd cargo xwin build end $buildCmd --release --target $triple &>/dev/null if test $status -ne 0 echo "!! ERROR building for $outName ($triple)" echo "!! Run the command below for more information" echo "!! \$ cargo build --release --target $triple" exit else echo "Build for $outName successful, compressing" end rm -rf $thisWork mkdir -p $thisTar cp $license $thisTar/LICENSE if test $windows = true cp $target/$triple/release/$package.exe $thisTar/ else cp $target/$triple/release/$package $thisTar/ end set wasAtDir (pwd) cd $thisWork if test $windows = true zip -r $final $thisTarName &>/dev/null else tar -czf $final $thisTarName &>/dev/null end if test $status -ne 0 echo "compressing failed!" exit end cd $wasAtDir end build x86_64-unknown-linux-gnu linux-x64 build aarch64-unknown-linux-gnu linux-aarch64 build x86_64-apple-darwin macos-x64 build aarch64-apple-darwin macos-aarch64 build x86_64-pc-windows-msvc windows-x64 rm -rf $temp