Skip to content

Commit 78613eb

Browse files
authored
Merge pull request #132 from jdno/refactor-dev-desktop-scripts
Refactor scripts to set up Rust on dev desktops
2 parents 8877977 + 0da6994 commit 78613eb

File tree

7 files changed

+106
-29
lines changed

7 files changed

+106
-29
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#!/usr/bin/env bash
22

33
echo "# Available scripts for managing your Rust checkouts"
4-
echo "init.sh | first time setup, you should only have to execute this once on a new machine"
4+
echo "setup_rustup.sh | first time setup, you should only have to execute this once on a new machine"
55
echo "status.sh | list the branches and git status of all copies of the Rust repo"
66
echo "new_worktree.sh | creates a worktree (shallow copy of the main git checkout of Rust, sharing the .git folder)"
77
echo "detach_merged_prs.sh | invokes \"git pull --fast-forward-only\" on all worktrees and detaches those that are equal to the \"master\" branch"
88
echo ""
99
echo "# Rarer commands:"
10-
echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken"
11-
10+
echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken"
11+
echo "setup_rust.sh | Clone your fork of rust-lang/rust, compile, and then link it"

ansible/roles/dev-desktop/files/scripts/init.sh

100755100644
Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
#!/usr/bin/env bash
22

3-
username=`id -u -n`
4-
gh_name=${username#"gh-"}
5-
6-
# Using https instead of git urls because vscode only handles login on push/pull
7-
git clone https://github.com/$gh_name/rust.git
8-
pushd rust
9-
git remote add upstream https://github.com/rust-lang/rust.git
10-
git fetch upstream
11-
git checkout upstream/master
12-
popd
3+
# Enable strict mode for Bash
4+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
5+
set -euo pipefail
6+
IFS=$'\n\t'
137

148
init_git.py
159
setup_rustup.sh
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
# Enable strict mode for Bash
4+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
5+
set -euo pipefail
6+
IFS=$'\n\t'
7+
8+
# Discover target triple (e.g. "aarch64-unknown-linux-gnu")
9+
target="$(rustc -vV | awk '/host/ { print $2 }')"
10+
11+
rustc_dummy=$(
12+
cat <<EOF
13+
#!/usr/bin/env bash
14+
echo "This is a dummy file to trick rustup into thinking this is a sysroot"
15+
echo 'Run "x.py build --stage 1 library/std" to create a real sysroot you can use with rustup'
16+
EOF
17+
)
18+
19+
for D in rust*; do
20+
if [ -d "$D" ]; then
21+
pushd "$D"
22+
23+
bootstrap_version=$(grep 'pub const VERSION' src/bootstrap/lib.rs | grep -o '[0-9]*')
24+
25+
if [ "$bootstrap_version" -gt 2 ]; then
26+
stages=(stage1-sysroot stage2-sysroot)
27+
else
28+
stages=(stage1 stage2)
29+
fi
30+
31+
for stage in "${stages[@]}"; do
32+
directory="build/${target}/${stage}"
33+
34+
if [ ! -d "$directory" ]; then
35+
mkdir -p "${directory}/lib"
36+
mkdir -p "${directory}/bin"
37+
echo "$rustc_dummy" >> "${directory}/bin/rustc"
38+
chmod +x "${directory}/bin/rustc"
39+
fi
40+
41+
rustup toolchain link "${D}_${stage}" "$directory"
42+
done
43+
44+
popd
45+
fi
46+
done

ansible/roles/dev-desktop/files/scripts/new_worktree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ git checkout upstream/master
1313
ln -s ../config.toml
1414
popd
1515

16-
setup_rustup.sh
16+
link_rust.sh
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
#!/usr/bin/env bash
22

3+
# Enable strict mode for Bash
4+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
5+
set -euo pipefail
6+
IFS=$'\n\t'
7+
38
for D in rust*; do
49
if [ -d "${D}" ]; then
5-
pushd $D
6-
ln -s ../config.toml
7-
popd
10+
pushd "${D}" || exit
11+
if [[ ! -f config.toml ]]; then
12+
ln -s ~/config.toml .
13+
fi
14+
popd || exit
815
fi
916
done
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
# Enable strict mode for Bash
4+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
5+
set -euo pipefail
6+
IFS=$'\n\t'
7+
8+
username=$(id -u -n)
9+
gh_name=${username#"gh-"}
10+
11+
set -x
12+
13+
if [[ ! -d "rust" ]]; then
14+
# Using https instead of git urls because vscode only handles login on push/pull
15+
git clone "https://github.com/${gh_name}/rust.git"
16+
fi
17+
18+
pushd rust
19+
20+
if ! git remote | grep upstream; then
21+
git remote add upstream https://github.com/rust-lang/rust.git
22+
fi
23+
24+
git fetch upstream
25+
git checkout upstream/master
26+
popd
27+
28+
set_defaults.sh
29+
link_rust.sh

ansible/roles/dev-desktop/files/scripts/setup_rustup.sh

100644100755
Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#!/usr/bin/env bash
22

3-
set -x
4-
5-
rustup --version || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
6-
7-
source "$HOME/.cargo/env"
8-
9-
for D in rust*; do
10-
if [ -d "${D}" ]; then
11-
rustup toolchain link "$D"_stage1 "$D/build/x86_64-unknown-linux-gnu/stage1"
12-
rustup toolchain link "$D"_stage2 "$D/build/x86_64-unknown-linux-gnu/stage2"
13-
fi
14-
done
3+
# Enable strict mode for Bash
4+
# http://redsymbol.net/articles/unofficial-bash-strict-mode/
5+
set -euo pipefail
6+
IFS=$'\n\t'
7+
8+
# Check if rustup is already installed and exit if that's the case.
9+
if command -v rustup &>/dev/null; then
10+
rustup --version
11+
exit 0
12+
fi
13+
14+
echo "Installing rustup..."
15+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

0 commit comments

Comments
 (0)