Skip to content
This repository was archived by the owner on Nov 30, 2023. It is now read-only.

Commit 36d6744

Browse files
authored
Option to specify nightly version of Rust (#1554)
* correct systemctl path * support for nightly rust versions
1 parent 413e995 commit 36d6744

File tree

2 files changed

+50
-4
lines changed

2 files changed

+50
-4
lines changed

containers/rust/.devcontainer/library-scripts/rust-debian.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ find_version_from_git_tags() {
9595
echo "${variable_name}=${!variable_name}"
9696
}
9797

98+
check_nightly_version() {
99+
local variable_name=$1
100+
local requested_version=${!variable_name}
101+
if [ "${requested_version}" = "none" ]; then return; fi
102+
103+
local version_date=$(echo ${requested_version} | sed -e "s/^nightly-//")
104+
105+
date -d ${version_date} &>/dev/null
106+
if [ $? != 0 ]; then
107+
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should be in the format nightly-YYYY-MM-DD" >&2
108+
exit 1
109+
fi
110+
111+
if [ $(date -d ${version_date} +%s) -ge $(date +%s) ]; then
112+
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should not exceed current date" >&2
113+
exit 1
114+
fi
115+
}
116+
98117
updaterc() {
99118
if [ "${UPDATE_RC}" = "true" ]; then
100119
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
@@ -154,13 +173,17 @@ chmod g+r+w+s "${RUSTUP_HOME}" "${CARGO_HOME}"
154173
if [ "${RUST_VERSION}" = "none" ] || type rustup > /dev/null 2>&1; then
155174
echo "Rust already installed. Skipping..."
156175
else
157-
if [ "${RUST_VERSION}" != "latest" ] && [ "${RUST_VERSION}" != "lts" ] && [ "${RUST_VERSION}" != "stable" ]; then
176+
if [ "${RUST_VERSION}" != "latest" ] && [ "${RUST_VERSION}" != "lts" ] && [ "${RUST_VERSION}" != "stable" ] && [ "${RUST_VERSION}" != "nightly" ]; then
158177
# Find version using soft match
159178
if ! type git > /dev/null 2>&1; then
160179
apt_get_update_if_needed
161180
apt-get -y install --no-install-recommends git
162181
fi
163-
find_version_from_git_tags RUST_VERSION "https://github.com/rust-lang/rust" "tags/"
182+
if [ $(echo ${RUST_VERSION} | grep -q "nightly") ]; then
183+
find_version_from_git_tags RUST_VERSION "https://github.com/rust-lang/rust" "tags/"
184+
else
185+
check_nightly_version RUST_VERSION
186+
fi
164187
default_toolchain_arg="--default-toolchain ${RUST_VERSION}"
165188
fi
166189
echo "Installing Rust..."

script-library/rust-debian.sh

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,25 @@ find_version_from_git_tags() {
9595
echo "${variable_name}=${!variable_name}"
9696
}
9797

98+
check_nightly_version() {
99+
local variable_name=$1
100+
local requested_version=${!variable_name}
101+
if [ "${requested_version}" = "none" ]; then return; fi
102+
103+
local version_date=$(echo ${requested_version} | sed -e "s/^nightly-//")
104+
105+
date -d ${version_date} &>/dev/null
106+
if [ $? != 0 ]; then
107+
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should be in the format nightly-YYYY-MM-DD" >&2
108+
exit 1
109+
fi
110+
111+
if [ $(date -d ${version_date} +%s) -ge $(date +%s) ]; then
112+
echo -e "Invalid ${variable_name} value: ${requested_version}\nNightly version should not exceed current date" >&2
113+
exit 1
114+
fi
115+
}
116+
98117
updaterc() {
99118
if [ "${UPDATE_RC}" = "true" ]; then
100119
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
@@ -154,13 +173,17 @@ chmod g+r+w+s "${RUSTUP_HOME}" "${CARGO_HOME}"
154173
if [ "${RUST_VERSION}" = "none" ] || type rustup > /dev/null 2>&1; then
155174
echo "Rust already installed. Skipping..."
156175
else
157-
if [ "${RUST_VERSION}" != "latest" ] && [ "${RUST_VERSION}" != "lts" ] && [ "${RUST_VERSION}" != "stable" ]; then
176+
if [ "${RUST_VERSION}" != "latest" ] && [ "${RUST_VERSION}" != "lts" ] && [ "${RUST_VERSION}" != "stable" ] && [ "${RUST_VERSION}" != "nightly" ]; then
158177
# Find version using soft match
159178
if ! type git > /dev/null 2>&1; then
160179
apt_get_update_if_needed
161180
apt-get -y install --no-install-recommends git
162181
fi
163-
find_version_from_git_tags RUST_VERSION "https://github.com/rust-lang/rust" "tags/"
182+
if [ $(echo ${RUST_VERSION} | grep -q "nightly") ]; then
183+
find_version_from_git_tags RUST_VERSION "https://github.com/rust-lang/rust" "tags/"
184+
else
185+
check_nightly_version RUST_VERSION
186+
fi
164187
default_toolchain_arg="--default-toolchain ${RUST_VERSION}"
165188
fi
166189
echo "Installing Rust..."

0 commit comments

Comments
 (0)