summary refs log tree commit diff
path: root/cutrel.sh
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-11-23 14:15:40 -0600
committergennyble <gen@nyble.dev>2023-11-23 14:15:40 -0600
commitc5111b3482bd867e13b1d835c9779765dff73d4f (patch)
treeb95662e34012e26cd9a3c536466908a0a7d2d193 /cutrel.sh
download🌦-c5111b3482bd867e13b1d835c9779765dff73d4f.tar.gz
🌦-c5111b3482bd867e13b1d835c9779765dff73d4f.zip
init :)
Diffstat (limited to 'cutrel.sh')
-rwxr-xr-xcutrel.sh112
1 files changed, 112 insertions, 0 deletions
diff --git a/cutrel.sh b/cutrel.sh
new file mode 100755
index 0000000..83e613e
--- /dev/null
+++ b/cutrel.sh
@@ -0,0 +1,112 @@
+#!/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