Skip to content

Commit 333866c

Browse files
feat: finally push Rust feature install code
This way laying around for way too long Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
1 parent 2a63ed6 commit 333866c

File tree

5 files changed

+144
-3
lines changed

5 files changed

+144
-3
lines changed

.github/workflows/testing.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
matrix:
3232
baseImage:
3333
- ubuntu:24.04
34+
- rust:1.90.0-slim-trixie
3435
feature:
3536
- lang-rust
3637

@@ -60,6 +61,7 @@ jobs:
6061
matrix:
6162
baseImage:
6263
- ubuntu:24.04
64+
- rust:1.90.0-slim-trixie
6365
feature:
6466
- lang-rust
6567

cspell.config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import: []
88

99
words:
1010
- debuggee
11+
- LLDB
1112
- Rustup
13+
- trixie
1214

1315
ignoreWords:
1416
- devcontainers

src/lang-rust/devcontainer-feature.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ref: https://github.com/devcontainers/spec/blob/main/schemas/devContainerFeature.schema.json
22
{
33
"id": "lang-rust",
4-
"version": "0.1.0",
4+
"version": "0.1.1",
55
"name": "Programming Language | Rust",
66
"documentationURL": "https://github.com/georglauterbach/dev-container-features/tree/main/src/rust",
77
"description": "Work efficiently and effortlessly with Rust",

src/lang-rust/install.sh

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,64 @@
22

33
set -e -u
44

5-
mkdir --parents /usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust/lifecycle_hooks
6-
cp on_create_command.sh /usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust/lifecycle_hooks/on_create_command.sh
5+
FEATURE_SHARE_DIR=/usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust
6+
readonly FEATURE_SHARE_DIR
7+
8+
log() {
9+
printf "%s %-5s: %s\n" "$(date +"%Y-%m-%dT%H:%M:%S.%6N%:z" || :)" "${1:-}" "${2:-}"
10+
}
11+
12+
parse_dev_container_options() {
13+
log 'info' 'Parsing input from options'
14+
15+
readonly GENERATE_SHELL_COMPLETIONS="${GENERATE_SHELL_COMPLETIONS:?GENERATE_SHELL_COMPLETIONS not set or null}"
16+
readonly RUSTUP_DISABLE_AUTO_SELF_UPDATE="${RUSTUP_DISABLE_AUTO_SELF_UPDATE:?RUSTUP_DISABLE_AUTO_SELF_UPDATE not set or null}"
17+
}
18+
19+
copy_lifecycle_hook_scripts() {
20+
mkdir --parents /usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust/lifecycle_hooks
21+
cp on_create_command.sh /usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust/lifecycle_hooks/on_create_command.sh
22+
}
23+
24+
rustup_adjustments() {
25+
if command -v rustup >/dev/null 2>/dev/null; then
26+
log 'info' "'rustup' is installed"
27+
else
28+
log 'warn' "'rustup' is not installed - not performing actions associated with 'rustup' (shell completions, disabling automatic self-update)"
29+
return 0
30+
fi
31+
32+
if [ "${GENERATE_SHELL_COMPLETIONS}" = 'true' ]; then
33+
log 'info' 'Generating completions for rustup and Cargo'
34+
mkdir --parents /usr/share/bash-completion/completions
35+
rustup completions bash >/usr/share/bash-completion/completions/rustup
36+
rustup completions bash cargo >/usr/share/bash-completion/completions/cargo
37+
else
38+
log 'info' 'Not generating completions for rustup and Cargo'
39+
fi
40+
41+
if [ "${RUSTUP_DISABLE_AUTO_SELF_UPDATE}" = 'true' ]; then
42+
log 'info' "Disabling rustup's self-update feature when container runs"
43+
touch "${FEATURE_SHARE_DIR}/.rustup_disable_auto_self_update"
44+
else
45+
log 'info' "Not disabling rustup's self-update feature when container runs"
46+
fi
47+
}
48+
49+
copy_lldb_prettifiers() {
50+
log 'info' 'Copying prettifier for LLDB'
51+
cp "lldb_prettifier.py" "${FEATURE_SHARE_DIR}/"
52+
chmod 777 "${FEATURE_SHARE_DIR}/prettifier_for_lldb.py"
53+
}
54+
55+
main() {
56+
parse_dev_container_options
57+
58+
mkdir --parents "${FEATURE_SHARE_DIR}"
59+
60+
copy_lifecycle_hook_scripts
61+
rustup_adjustments
62+
copy_lldb_prettifiers
63+
}
64+
65+
main "${@}"

src/lang-rust/on_create_command.sh

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,81 @@
11
#! /bin/sh
22

33
set -e -u
4+
5+
FEATURE_SHARE_DIR=/usr/local/share/dev_containers/features/ghcr_io/georglauterbach/lang_rust
6+
readonly FEATURE_SHARE_DIR
7+
8+
update_directory() {
9+
ENV_NAME=${1:?"(bug) environment variable name required"}
10+
ENV_VALUE=$(eval "echo \"\$${ENV_NAME}\"")
11+
12+
echo "Adjusting directory '${ENV_NAME}=${ENV_VALUE}'"
13+
14+
if [ -z "${ENV_VALUE}" ]; then
15+
echo " -> environment variable '${ENV_NAME}' not set, null or empty"
16+
return 1
17+
fi
18+
19+
if [ -d "${ENV_VALUE}" ]; then
20+
echo " -> directory already exists"
21+
else
22+
printf " -> creating directory: "
23+
24+
if mkdir --parents "${ENV_VALUE}" 2>/dev/null \
25+
|| sudo mkdir --parents "${ENV_VALUE}"; then
26+
echo 'done'
27+
else
28+
echo 'failed'
29+
return 1
30+
fi
31+
fi
32+
33+
if [ "$(stat -c '%u' "${ENV_VALUE}")" -ne "$(id -u)" ] \
34+
|| {
35+
# we check for Rustup's settings.toml here explicitly because
36+
# this file is known to make problems
37+
[ -f "${ENV_VALUE}/settings.toml" ] \
38+
&& [ "$(stat -c '%u' "${ENV_VALUE}/settings.toml")" -ne "$(id -u)" ]
39+
}; then
40+
printf " -> updating permissions: "
41+
42+
if chown --recursive "$(id -u):$(id -g)" "${ENV_VALUE}" 2>/dev/null \
43+
|| sudo chown --recursive "$(id -u):$(id -g)" "${ENV_VALUE}"; then
44+
echo 'done'
45+
else
46+
echo 'failed'
47+
return 1
48+
fi
49+
else
50+
echo " -> directory already has proper permissions"
51+
fi
52+
}
53+
54+
rustup_adjustments() {
55+
echo "Adjusting 'rustup'"
56+
if ! command -v rustup >/dev/null 2>/dev/null; then
57+
echo " -> 'rustup' is not installed"
58+
echo " -> not running other commands"
59+
return 0
60+
fi
61+
62+
echo " -> 'rustup' is installed"
63+
if [ -f "${FEATURE_SHARE_DIR}/.rustup_disable_auto_self_update" ]; then
64+
echo " -> disabling rustup's self-update feature"
65+
rustup set auto-self-update disable
66+
else
67+
echo " -> not disabling rustup's self-update feature"
68+
fi
69+
}
70+
71+
main() {
72+
for ENV_NAME in 'RUSTUP_HOME' 'CARGO_HOME'; do
73+
if ! update_directory "${ENV_NAME}"; then
74+
echo " -> not running other commands"
75+
fi
76+
done
77+
78+
rustup_adjustments
79+
}
80+
81+
main "${@}"

0 commit comments

Comments
 (0)