Skip to content

Instantly share code, notes, and snippets.

@DemwE
Last active September 12, 2023 13:37
Show Gist options
  • Save DemwE/2c3ee72443b4825d13c320e93ac2b062 to your computer and use it in GitHub Desktop.
Save DemwE/2c3ee72443b4825d13c320e93ac2b062 to your computer and use it in GitHub Desktop.
Build release of rust app for Windows, Linux, MacOS
#!/bin/bash
if [ ! -f build.conf ]; then
echo "File build.conf does not exist, creating it."
echo "UpdateRustTargets=true" >>build.conf
echo "BuildWindows=true" >>build.conf
echo "BuildLinux=true" >>build.conf
echo "BuildMac=true" >>build.conf
exit 0
fi
UpdateRustTargets=$(cat build.conf | grep UpdateRustTargets | cut -d "=" -f 2)
BuildWindows=$(cat build.conf | grep BuildWindows | cut -d "=" -f 2)
BuildLinux=$(cat build.conf | grep BuildLinux | cut -d "=" -f 2)
BuildMac=$(cat build.conf | grep BuildMac | cut -d "=" -f 2)
if [ "$UpdateRustTargets" == "true" ]; then
echo -e "\e[94mUpdating/Downloading rust targets\e[0m"
if [ "BuildWindows" == "true" ]; then
rustup target remove x86_64-pc-windows-gnu
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to update or download rust targets\e[0m"
fi
fi
if [ "BuildLinux" == "true" ]; then
rustup target remove x86_64-unknown-linux-gnu
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to update or download rust targets\e[0m"
fi
fi
if [ "BuildMac" == "true" ]; then
rustup target remove x86_64-apple-darwin
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to update or download rust targets\e[0m"
fi
fi
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to update or download rust targets\e[0m"
else
echo -e "\e[92mRust targets updated/downloaded\e[0m"
fi
elif [ "$UpdateRustTargets" == "false" ]; then
echo -e "\e[94mSkipping rust target update.\e[0m"
else
echo -e "\e[31mError: Invalid value for UpdateRustTargets: $UpdateRustTargets\e[0m"
fi
if [ "$BuildWindows" == "true" ]; then
echo -e "\e[94mBuilding for Windows\e[0m"
cargo build --release --target x86_64-pc-windows-gnu
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to build for Windows\e[0m"
else
echo -e "\e[92mDone!\e[0m"
fi
elif [ "$BuildWindows" == "false" ]; then
echo -e "\e[94mSkipping Windows build.\e[0m"
else
echo -e "\e[31mError: Invalid value for BuildWindows: $BuildWindows\e[0m"
fi
if [ "$BuildLinux" == "true" ]; then
echo -e "\e[94mBuilding for Linux\e[0m"
cargo build --release --target x86_64-unknown-linux-gnu
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to build for Linux\e[0m"
else
echo -e "\e[92mDone!\e[0m"
fi
elif [ "$BuildLinux" == "false" ]; then
echo -e "\e[94mSkipping Linux build.\e[0m"
else
echo -e "\e[31mError: Invalid value for BuildLinux: $BuildLinux\e[0m"
fi
if [ "$BuildMac" == "true" ]; then
echo -e "\e[94mBuilding for Mac\e[0m"
cargo build --release --target x86_64-apple-darwin
if [ $? -ne 0 ]; then
echo -e "\e[31mError: Failed to build for Mac\e[0m"
else
echo -e "\e[92mDone!\e[0m"
fi
elif [ "$BuildMac" == "false" ]; then
echo -e "\e[94mSkipping Mac build.\e[0m"
else
echo -e "\e[31mError: Invalid value for BuildMac: $BuildMac\e[0m"
fi
@DemwE
Copy link
Author

DemwE commented Sep 8, 2023

If you cant compile program for MacOS try this

curl -L https://github.com/roblabla/MacOSX-SDKs/releases/download/13.3/MacOSX13.3.sdk.tar.xz | tar xJ
export SDKROOT=$(pwd)/MacOSX13.3.sdk/
export PATH=$PATH:~/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin/
export CARGO_TARGET_X86_64_APPLE_DARWIN_LINKER=rust-lld

and then use build.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment