Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cargo-generate pacakge installation #80

Merged
merged 4 commits into from
Jun 8, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions install-rust-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,28 @@ function install_crate_from_xz() {
fi
}

function install_crate_from_tar_gz() {
CRATE_URL="$1"
CRATE_BIN="$2"

if [[ -z "${CRATE_BIN}" ]]; then
return
fi

if [[ -z "${CRATE_URL}" ]]; then
cargo install ${CRATE_BIN}
return
fi

if [[ ! -e "${CRATE_BIN}" ]]; then
echo "Downloading ${CRATE_URL} to ${CRATE_BIN}.tar.gz"
curl -L "${CRATE_URL}" -o "${CRATE_BIN}.tar.gz"
tar xf "${CRATE_BIN}.tar.gz" -C ${CARGO_HOME}/bin
chmod u+x "${CRATE_BIN}"
echo "Using ${CRATE_BIN} binary release"
fi
}

function install_extra_crates() {
if [[ "${EXTRA_CRATES}" =~ "cargo-espflash" ]]; then
install_crate_from_zip "${ESPFLASH_URL}" "${ESPFLASH_BIN}"
Expand All @@ -337,6 +359,11 @@ function install_extra_crates() {
EXTRA_CRATES="${EXTRA_CRATES/espmonitor/}"
fi

if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then
install_crate_from_tar_gz "${GENERATE_URL}" "${GENERATE_BIN}"
EXTRA_CRATES="${EXTRA_CRATES/cargo-generate/}"
fi

if ! [[ -z "${EXTRA_CRATES// }" ]];then
cargo install $EXTRA_CRATES
fi
Expand Down Expand Up @@ -381,6 +408,9 @@ LDPROXY_URL=""
LDPROXY_BIN=""
ESPMONITOR_BIN=""
ESPMONITOR_URL=""
GENERATE_URL=""
GENERATE_BIN=""
GENERATE_VERSION=`git ls-remote --refs --sort="version:refname" --tags "https://github.com/cargo-generate/cargo-generate" | cut -d/ -f3-|tail -n1`

# Configuration overrides for specific architectures
if [ ${ARCH} == "aarch64-apple-darwin" ]; then
Expand All @@ -392,6 +422,8 @@ elif [ ${ARCH} == "x86_64-apple-darwin" ]; then
GCC_ARCH="macos"
ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip"
ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash"
GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz"
GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate"
elif [ ${ARCH} == "x86_64-unknown-linux-gnu" ]; then
GCC_ARCH="linux-amd64"
ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip"
Expand All @@ -400,13 +432,18 @@ elif [ ${ARCH} == "x86_64-unknown-linux-gnu" ]; then
LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy"
ESPMONITOR_URL="https://github.com/esp-rs/rust-build/releases/download/v1.60.0.1/espmonitor-0.7.0-x86_64-unknown-linux-gnu.xz"
ESPMONITOR_BIN="${CARGO_HOME}/bin/espmonitor"
# cargo-generate does not have gnu package. See https://github.com/cargo-generate/cargo-generate/pull/602
GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-x86_64-unknown-linux-musl.tar.gz"
GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate"
elif [ ${ARCH} == "aarch64-unknown-linux-gnu" ]; then
GCC_ARCH="linux-arm64"
elif [ ${ARCH} == "x86_64-pc-windows-msvc" ]; then
#LLVM_ARCH="win64"
GCC_ARCH="win64"
ESPFLASH_URL="https://github.com/esp-rs/espflash/releases/latest/download/cargo-espflash-${ARCH}.zip"
ESPFLASH_BIN="${CARGO_HOME}/bin/cargo-espflash.exe"
GENERATE_URL="https://github.com/cargo-generate/cargo-generate/releases/latest/download/cargo-generate-${GENERATE_VERSION}-${ARCH}.tar.gz"
GENERATE_BIN="${CARGO_HOME}/bin/cargo-generate.exe"
fi

echo "Processing toolchain for ${ARCH} - operation: ${INSTALLATION_MODE}"
Expand Down