Last active
April 2, 2025 09:19
-
-
Save qguv/391d14fd2b60804250149e8c8d7fe6df to your computer and use it in GitHub Desktop.
Build a cargo project from a tar archive and write the output executable to a given path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
source_path="${1:?missing first argument: tar archive of cargo project}" | |
dest_path="${2:?missing second argument: path of output executable}" | |
rm -rf __proj | |
mkdir __proj | |
tar --strip-components=1 -xf "$source_path" -C __proj | |
cd __proj | |
cargo --offline build --release --target x86_64-unknown-linux-musl | |
target_dir="$(cargo metadata --format-version 1 --no-deps | jq -r '.target_directory')" | |
bin_name="$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[].targets[] | select( .kind | map(. == "bin") | any ) | .name')" | |
binary_path="$target_dir/release/$bin_name" | |
cd .. | |
cp "$binary_path" "$dest_path" | |
rm -rf __proj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment