Skip to content

Instantly share code, notes, and snippets.

@kstep
Created June 4, 2015 16:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kstep/d0c7b0dcd5313c310d65 to your computer and use it in GitHub Desktop.
Save kstep/d0c7b0dcd5313c310d65 to your computer and use it in GitHub Desktop.
Build binaries from Crates.io
#!/bin/sh
REPO_URL="https://crates.io"
API_URL="$REPO_URL/api/v1"
die() {
echo "$@" >&2
exit 1
}
CRATE="$1"
DL_PATH="$(curl -s "$API_URL/crates/$CRATE/versions" | grep -E -o '"dl_path":"([^"]+)"' | head -n 1 | sed -e 's/"dl_path":"//' -e 's/"//')"
test -z "$DL_PATH" && die "Unable to find downloads for ${CRATE}!"
DL_URL="${REPO_URL}${DL_PATH}"
CRATE_VER="${DL_PATH#/api/v1/crates/$CRATE/}"
CRATE_VER="${CRATE_VER%/download}"
CRATE_DIR="${CRATE}-${CRATE_VER}"
CRATE_FILE="${CRATE_DIR}.crate"
mkdir -p "${CRATE_DIR}" || die "Error creating crate build directory!"
cd "${CRATE_DIR}"
echo "Found crate at $DL_URL, downloading..."
curl -Lo "${CRATE_FILE}" "${DL_URL}" || die "Error downloading crate file!"
tar xf "${CRATE_FILE}" && cd "${CRATE_DIR}" && \
cargo build --release && find ./target/release -maxdepth 1 -type f -executable -exec cp {} .. \; && \
cd .. && rm -rf "${CRATE_DIR}" "${CRATE_FILE}"
echo "Built binaries are at ${CRATE_DIR}."
@kstep
Copy link
Author

kstep commented Jun 4, 2015

$ cargo-build pulldown-cmark
...
Built binaries are at pulldown-cmark-0.0.1.
$ _

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment