-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from jdno/refactor-dev-desktop-scripts
Refactor scripts to set up Rust on dev desktops
- Loading branch information
Showing
7 changed files
with
106 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "# Available scripts for managing your Rust checkouts" | ||
echo "init.sh | first time setup, you should only have to execute this once on a new machine" | ||
echo "setup_rustup.sh | first time setup, you should only have to execute this once on a new machine" | ||
echo "status.sh | list the branches and git status of all copies of the Rust repo" | ||
echo "new_worktree.sh | creates a worktree (shallow copy of the main git checkout of Rust, sharing the .git folder)" | ||
echo "detach_merged_prs.sh | invokes \"git pull --fast-forward-only\" on all worktrees and detaches those that are equal to the \"master\" branch" | ||
echo "" | ||
echo "# Rarer commands:" | ||
echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken" | ||
|
||
echo "set_defaults.sh | connects the global config.toml with all worktrees. Use this when your setup is broken" | ||
echo "setup_rust.sh | Clone your fork of rust-lang/rust, compile, and then link it" |
14 changes: 4 additions & 10 deletions
14
ansible/roles/dev-desktop/files/scripts/init.sh
100755 → 100644
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
username=`id -u -n` | ||
gh_name=${username#"gh-"} | ||
|
||
# Using https instead of git urls because vscode only handles login on push/pull | ||
git clone https://github.com/$gh_name/rust.git | ||
pushd rust | ||
git remote add upstream https://github.com/rust-lang/rust.git | ||
git fetch upstream | ||
git checkout upstream/master | ||
popd | ||
# Enable strict mode for Bash | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
init_git.py | ||
setup_rustup.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Enable strict mode for Bash | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
# Discover target triple (e.g. "aarch64-unknown-linux-gnu") | ||
target="$(rustc -vV | awk '/host/ { print $2 }')" | ||
|
||
rustc_dummy=$( | ||
cat <<EOF | ||
#!/usr/bin/env bash | ||
echo "This is a dummy file to trick rustup into thinking this is a sysroot" | ||
echo 'Run "x.py build --stage 1 library/std" to create a real sysroot you can use with rustup' | ||
EOF | ||
) | ||
|
||
for D in rust*; do | ||
if [ -d "$D" ]; then | ||
pushd "$D" | ||
|
||
bootstrap_version=$(grep 'pub const VERSION' src/bootstrap/lib.rs | grep -o '[0-9]*') | ||
|
||
if [ "$bootstrap_version" -gt 2 ]; then | ||
stages=(stage1-sysroot stage2-sysroot) | ||
else | ||
stages=(stage1 stage2) | ||
fi | ||
|
||
for stage in "${stages[@]}"; do | ||
directory="build/${target}/${stage}" | ||
|
||
if [ ! -d "$directory" ]; then | ||
mkdir -p "${directory}/lib" | ||
mkdir -p "${directory}/bin" | ||
echo "$rustc_dummy" >> "${directory}/bin/rustc" | ||
chmod +x "${directory}/bin/rustc" | ||
fi | ||
|
||
rustup toolchain link "${D}_${stage}" "$directory" | ||
done | ||
|
||
popd | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,4 @@ git checkout upstream/master | |
ln -s ../config.toml | ||
popd | ||
|
||
setup_rustup.sh | ||
link_rust.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,16 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Enable strict mode for Bash | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
for D in rust*; do | ||
if [ -d "${D}" ]; then | ||
pushd $D | ||
ln -s ../config.toml | ||
popd | ||
pushd "${D}" || exit | ||
if [[ ! -f config.toml ]]; then | ||
ln -s ~/config.toml . | ||
fi | ||
popd || exit | ||
fi | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Enable strict mode for Bash | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
username=$(id -u -n) | ||
gh_name=${username#"gh-"} | ||
|
||
set -x | ||
|
||
if [[ ! -d "rust" ]]; then | ||
# Using https instead of git urls because vscode only handles login on push/pull | ||
git clone "https://github.com/${gh_name}/rust.git" | ||
fi | ||
|
||
pushd rust | ||
|
||
if ! git remote | grep upstream; then | ||
git remote add upstream https://github.com/rust-lang/rust.git | ||
fi | ||
|
||
git fetch upstream | ||
git checkout upstream/master | ||
popd | ||
|
||
set_defaults.sh | ||
link_rust.sh |
25 changes: 13 additions & 12 deletions
25
ansible/roles/dev-desktop/files/scripts/setup_rustup.sh
100644 → 100755
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -x | ||
|
||
rustup --version || curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
|
||
source "$HOME/.cargo/env" | ||
|
||
for D in rust*; do | ||
if [ -d "${D}" ]; then | ||
rustup toolchain link "$D"_stage1 "$D/build/x86_64-unknown-linux-gnu/stage1" | ||
rustup toolchain link "$D"_stage2 "$D/build/x86_64-unknown-linux-gnu/stage2" | ||
fi | ||
done | ||
# Enable strict mode for Bash | ||
# http://redsymbol.net/articles/unofficial-bash-strict-mode/ | ||
set -euo pipefail | ||
IFS=$'\n\t' | ||
|
||
# Check if rustup is already installed and exit if that's the case. | ||
if command -v rustup &>/dev/null; then | ||
rustup --version | ||
exit 0 | ||
fi | ||
|
||
echo "Installing rustup..." | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y |