This repository has been archived by the owner on Aug 21, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2
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 #1 from CleanCut/zld
Add zld linker
- Loading branch information
Showing
2 changed files
with
67 additions
and
43 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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
function ask_yn() { | ||
read -rp "❓ $1 (Y/n) " answer | ||
if [[ "$answer" == "" || "$answer" == "y" || "$answer" == "Y" || "$answer" == "yes" || "$answer" == "Yes" ]] ; then | ||
if [[ "$answer" == "" || "$answer" == "y" || "$answer" == "Y" || "$answer" == "yes" || "$answer" == "Yes" ]]; then | ||
return 0 | ||
else | ||
return 1 | ||
|
@@ -17,28 +17,37 @@ function info() { | |
echo "💡 $1" | ||
} | ||
|
||
function die() { | ||
echo "🛑 FATAL: $1" | ||
} | ||
|
||
function warn() { | ||
echo "⚠️ $1" | ||
} | ||
|
||
# --- Set package.name in Cargo.toml --- | ||
name_with_ext=$(git remote show -n origin | grep "Fetch URL" | cut -d / -f 2-) | ||
name="${name_with_ext%.*}" | ||
if grep -q "bevy_template" Cargo.toml ; then | ||
if ask_yn "Set the package name to ${name}?" ; then | ||
sed -e "s/bevy_template/${name}/" -i "" Cargo.toml \ | ||
&& result "Set package name to ${name}" | ||
if grep -q "bevy_template" Cargo.toml; then | ||
if ask_yn "Set the package name to ${name}?"; then | ||
sed -e "s/bevy_template/${name}/" -i "" Cargo.toml || die "Couldn't set the package name to ${name}" | ||
result "Set package name to ${name}" | ||
else | ||
result "Okay, you should go set the package name in Cargo.toml manually." | ||
warn "Okay, you should go set the package name in Cargo.toml manually." | ||
fi | ||
else | ||
info "Package name already set." | ||
fi | ||
|
||
# --- Set package.authors in Cargo.toml --- | ||
if grep -q "Unknown Author" Cargo.toml ; then | ||
if grep -q "Unknown Author" Cargo.toml; then | ||
DEFAULT_AUTHOR="$(git config --global user.name) <$(git config --global user.email)>" | ||
if ask_yn "Set the author to ${DEFAULT_AUTHOR}?" ; then | ||
sed -E -e "s/Unknown Author <[email protected]>/${DEFAULT_AUTHOR}/" -i "" Cargo.toml \ | ||
&& result "Set author to ${DEFAULT_AUTHOR}" | ||
if ask_yn "Set the author to ${DEFAULT_AUTHOR}?"; then | ||
sed -E -e "s/Unknown Author <[email protected]>/${DEFAULT_AUTHOR}/" -i "" Cargo.toml || | ||
die "Couldn't set the author." | ||
result "Set author to ${DEFAULT_AUTHOR}" | ||
else | ||
result "Okay, you should go set the author in Cargo.toml manually." | ||
warn "Okay, you should go set the author in Cargo.toml manually." | ||
fi | ||
else | ||
info "Author already set." | ||
|
@@ -47,79 +56,92 @@ fi | |
# --- Set latest version of Bevy --- | ||
json=$(curl --silent --user-agent "bevy_template (github.com/cleancut/bevy_template)" https://crates.io/api/v1/crates/bevy) | ||
version=$(echo "${json}" | grep -oE '"max_version":".*?"' | cut -d '"' -f 4) | ||
if ! grep -qE "^bevy = \"${version}\"\$" Cargo.toml ; then | ||
if ask_yn "Try to update to the latest version of Bevy ($version)? If you have customized the version string, say no here." ; then | ||
sed -E -e "s/^bevy = \".*\"\$/bevy = \"${version}\"/" -i "" Cargo.toml | ||
result "Updated to version $version" | ||
if ! grep -qE "^bevy = \"${version}\"\$" Cargo.toml; then | ||
if ask_yn "Try to update to the latest version of Bevy ($version)? If you have customized the version string, say no here."; then | ||
sed -E -e "s/^bevy = \".*\"\$/bevy = \"${version}\"/" -i "" Cargo.toml || die "Couldn't update Bevy version to ${version}" | ||
result "Updated to version ${version}" | ||
else | ||
result "Okay, leaving the version alone." | ||
warn "Okay, leaving the version alone." | ||
fi | ||
else | ||
info "Bevy is already on the latest version (${version}), skipping version update." | ||
fi | ||
|
||
# --- Configure fast-compile --- | ||
if [[ -f .cargo/config.fast ]] ; then | ||
if ask_yn "Fast-compile is not configured. Would you like me to set it up now? If you don't want to use the nightly compiler, answer 'no'." ; then | ||
mv .cargo/config.fast .cargo/config | ||
result "Configured fast-compile." | ||
if [[ $(uname) != "Darwin" ]] ; then | ||
echo "⚠️ PLEASE INSTALL LLD! Instructions are available at https://bevyengine.org/learn/book/getting-started/setup/" | ||
fi | ||
if [[ -f .cargo/config.fast ]]; then | ||
if ask_yn "Fast-compile is not configured. Would you like me to set it up now? This involves installing an external linker and using the nightly Rust compiler."; then | ||
mv .cargo/config.fast .cargo/config || die "Failed moving config file into place" | ||
result "Configured fast-compile to use zld/lld linker for debug builds." | ||
else | ||
result "Okay, not configuring fast-compile." | ||
warn "Okay, not configuring fast-compile." | ||
fi | ||
elif [[ -f .cargo/config ]] && grep -q -- "-Zshare-generics=y" .cargo/config ; then | ||
elif [[ -f .cargo/config ]] && grep -q -- "-Zshare-generics=y" .cargo/config; then | ||
info "Fast-compile is already configured. If you want to disable it, delete or comment out .cargo/config" | ||
fi | ||
|
||
if [[ $(uname) == "Darwin" ]]; then | ||
if brew list michaeleisel/zld/zld > /dev/null 2> /dev/null ; then | ||
info "zld is installed" | ||
else | ||
if ask_yn "Install zld? Answer yes if you configured fast-install." ; then | ||
brew install michaeleisel/zld/zld \ | ||
|| die "Failed running 'brew install michaeleisel/zld/zld -- do you have brew installed? https://brew.sh/" | ||
result "installed zld" | ||
else | ||
warn "Okay, not installing zld." | ||
fi | ||
fi | ||
else | ||
warn "PLEASE MAKE SURE YOU HAVE LLD INSTALLED! Instructions are available at https://bevyengine.org/learn/book/getting-started/setup/" | ||
fi | ||
|
||
# --- Install nightly compiler --- | ||
if rustup toolchain list | grep -q nightly ; then | ||
if rustup toolchain list | grep -q nightly; then | ||
info "Nightly compiler already installed." | ||
else | ||
if ask_yn "No nightly compiler installed. Install it via rustup? Answer 'yes' if you configured fast-compile." ; then | ||
rustup install nightly | ||
if ask_yn "No nightly compiler installed. Install it via rustup? Answer 'yes' if you configured fast-compile."; then | ||
rustup install nightly || die "Failed to install nightly compiler. Do you have rustup installed?" | ||
result "Done installing nightly compiler." | ||
else | ||
result "Okay, not installing nightly compiler." | ||
warn "Okay, not installing nightly compiler." | ||
fi | ||
fi | ||
|
||
# --- Configure project to use nightly compiler --- | ||
if rustup toolchain list | grep -q nightly ; then | ||
if rustup override list | grep -qE "$(pwd).*nightly" ; then | ||
if rustup toolchain list | grep -q nightly; then | ||
if rustup override list | grep -qE "$(pwd).*nightly"; then | ||
info "Already using nightly compiler for this project." | ||
else | ||
if ask_yn "Configure this project to use the nightly compiler? Answer 'yes' if you configured fast-compile." ; then | ||
rustup override set nightly | ||
if ask_yn "Configure this project to use the nightly compiler? Answer 'yes' if you configured fast-compile."; then | ||
rustup override set nightly || die "Failed configuring project to use nightly compiler" | ||
result "Configured project to use the nightly compiler." | ||
else | ||
result "Okay, not configuring project to use the nightly compiler." | ||
warn "Okay, not configuring project to use the nightly compiler." | ||
fi | ||
fi | ||
else | ||
info "Nightly is not installed, skipping step for configuring project to use nightly." | ||
fi | ||
|
||
# --- Replace README.md --- | ||
if [[ -f README.md ]] && grep -q "Bevy Template" README.md ; then | ||
if ask_yn "Replace template README.md with a blank one?" ; then | ||
echo "# My Project" > README.md | ||
if [[ -f README.md ]] && grep -q "Bevy Template" README.md; then | ||
if ask_yn "Replace template README.md with a blank one?"; then | ||
echo "# My Project" > README.md || die "Failed replacing README.md" | ||
result "Replaced README.md with blank one." | ||
else | ||
result "Okay, left template README.md in place." | ||
warn "Okay, left template README.md in place." | ||
fi | ||
else | ||
info "README.md has already been replaced" | ||
fi | ||
|
||
# --- Delete the license --- | ||
if [[ -f LICENSE ]] && grep -q "Nathan Stocks" LICENSE ; then | ||
if ask_yn "Delete the LICENSE file so you can add your own?" ; then | ||
rm LICENSE | ||
if [[ -f LICENSE ]] && grep -q "Nathan Stocks" LICENSE; then | ||
if ask_yn "Delete the LICENSE file so you can add your own?"; then | ||
rm LICENSE || die "Failed deleting LICENSE file." | ||
result "Deleted the LICENSE file that belonged to the template. Feel free to license your project in whatever way you choose." | ||
else | ||
result "Left LICENSE alone." | ||
warn "Okay, left LICENSE alone." | ||
fi | ||
else | ||
info "Template license has already been removed." | ||
|