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 all commits
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
61 changes: 52 additions & 9 deletions install-rust-toolchain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ function install_rust_xtensa_toolchain() {
fi
./${RUST_SRC_DIST}/install.sh --destdir=${TOOLCHAIN_DESTINATION_DIR} --prefix="" --without=rust-docs
fi

if [ "${ESP_IDF_VERSION}" == "" ]; then
if [ -z "${ESP_IDF_VERSION}" ]; then
echo "* installing ${IDF_TOOL_XTENSA_ELF_GCC} "
if [ ! -d ${IDF_TOOL_XTENSA_ELF_GCC} ]; then
if [ ! -f "${GCC_FILE}" ]; then
Expand Down Expand Up @@ -321,22 +320,49 @@ 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
if [[ "${EXTRA_CRATES}" =~ "cargo-espflash" ]] && [ -n "${ESPFLASH_URL}" ] && [ -n "${ESPFLASH_BIN}" ]; then
install_crate_from_zip "${ESPFLASH_URL}" "${ESPFLASH_BIN}"
EXTRA_CRATES="${EXTRA_CRATES/cargo-espflash/}"
fi

if [[ "${EXTRA_CRATES}" =~ "ldproxy" ]]; then
if [[ "${EXTRA_CRATES}" =~ "ldproxy" ]] && [ -n "${LDPROXY_URL}" ] && [ -n "${LDPROXY_BIN}" ]; then
install_crate_from_zip "${LDPROXY_URL}" "${LDPROXY_BIN}"
EXTRA_CRATES="${EXTRA_CRATES/ldproxy/}"
fi

if [[ "${EXTRA_CRATES}" =~ "espmonitor" ]]; then
if [[ "${EXTRA_CRATES}" =~ "espmonitor" ]] && [ -n "${ESPMONITOR_URL}" ] && [ -n "${ESPMONITOR_BIN}" ]; then
install_crate_from_xz "${ESPMONITOR_URL}" "${ESPMONITOR_BIN}"
EXTRA_CRATES="${EXTRA_CRATES/espmonitor/}"
fi

if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]] && [ -n "${GENERATE_URL}" ] && [ -n "${GENERATE_BIN}" ]; 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,17 +407,28 @@ LDPROXY_URL=""
LDPROXY_BIN=""
ESPMONITOR_BIN=""
ESPMONITOR_URL=""
GENERATE_URL=""
GENERATE_BIN=""
if [[ "${EXTRA_CRATES}" =~ "cargo-generate" ]]; then
GENERATE_VERSION=`git ls-remote --refs --sort="version:refname" --tags "https://github.com/cargo-generate/cargo-generate" | cut -d/ -f3-|tail -n1`
fi

# Configuration overrides for specific architectures
if [ ${ARCH} == "aarch64-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"
LDPROXY_URL="https://github.com/esp-rs/rust-build/releases/download/v1.60.0.1/ldproxy-0.3.0-x86_64-unknown-linux-gnu.xz"
LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy"
elif [ ${ARCH} == "x86_64-apple-darwin" ]; then
#LLVM_ARCH="macos"
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"
LDPROXY_URL="https://github.com/esp-rs/rust-build/releases/download/v1.60.0.1/ldproxy-0.3.0-x86_64-unknown-linux-gnu.xz"
LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy"
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 +437,19 @@ 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-${ARCH}.xz"
ESPMONITOR_BIN="${CARGO_HOME}/bin/espmonitor"
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} == "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"
LDPROXY_URL="https://github.com/esp-rs/rust-build/releases/download/v1.60.0.1/ldproxy-0.3.0-x86_64-unknown-linux-gnu.xz"
LDPROXY_BIN="${CARGO_HOME}/bin/ldproxy.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 Expand Up @@ -478,7 +521,7 @@ fi

echo "Add following command to $PROFILE_NAME"
if [ ${IS_XTENSA_INSTALLED} -eq 1 ]; then
if [ "${ESP_IDF_VERSION}" == "" ]; then
if [ -z "${ESP_IDF_VERSION}" ]; then
echo export PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/bin/:${IDF_TOOL_XTENSA_ELF_GCC}/bin/:\$PATH\"
else
echo export PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/bin/:\$PATH\"
Expand All @@ -488,23 +531,23 @@ if [ ${IS_XTENSA_INSTALLED} -eq 1 ]; then
echo 'export PIP_USER="no"'
fi

if [ "${ESP_IDF_VERSION}" != "" ]; then
if [ -n "${ESP_IDF_VERSION}" ]; then
echo "export IDF_TOOLS_PATH=${IDF_TOOLS_PATH}"
echo "source ${IDF_PATH}/export.sh"
fi

# Store export instructions in the file
if [[ ! -z "${EXPORT_FILE}" ]]; then
if [ ${IS_XTENSA_INSTALLED} -eq 1 ]; then
if [ "${ESP_IDF_VERSION}" == "" ]; then
if [ -z "${ESP_IDF_VERSION}" ]; then
echo export PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/bin/:${IDF_TOOL_XTENSA_ELF_GCC}/bin/:\$PATH\" > "${EXPORT_FILE}"
else
echo export PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/bin/:\$PATH\" > "${EXPORT_FILE}"
fi
echo export LIBCLANG_PATH=\"${IDF_TOOL_XTENSA_ELF_CLANG}/lib/\" >> "${EXPORT_FILE}"
echo 'export PIP_USER="no"' >> "${EXPORT_FILE}"
fi
if [ "${ESP_IDF_VERSION}" != "" ]; then
if [ -n "${ESP_IDF_VERSION}" ]; then
echo "export IDF_TOOLS_PATH=${IDF_TOOLS_PATH}" >> "${EXPORT_FILE}"
echo "source ${IDF_PATH}/export.sh /dev/null 2>&1" >> "${EXPORT_FILE}"
fi
Expand Down