diff --git a/README.md b/README.md index 198496a5..d1190a95 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ However, both of them lost interest at some point, and now Cubyz is maintained b ## The Easy Way (no tools needed) 1. Download the latest [source code](https://codeload.github.com/PixelGuys/Cubyz/zip/refs/heads/master) 2. Extract the zip file -3. Go into the extraced folder and double click the `run_release.sh` (Linux) or `run_release.bat` (Windows) +3. Go into the extraced folder and double click the `run_linux.sh` or `run_windows.bat` depending on your operating system. 4. Congratulations: You just compiled your first program! ### It doesn't work? @@ -45,7 +45,7 @@ sudo apt install libgl-dev libasound2-dev libx11-dev libxcursor-dev libxrandr-de ## The Better Way 1. Install Git 2. Clone this repository `git clone https://github.com/pixelguys/Cubyz` -3. Run `run_release.sh` (Linux) or `run_release.bat` (Windows), if you already have Zig installed on your computer (it must be a compatible version) you can also just use `zig build run` +3. Run `run_linux.sh` or `run_windows.bat`, if you already have Zig installed on your computer (it must be a compatible version) you can also just use `zig build run` 4. When you want to update your local version you can use `git pull`. This keeps everything in one place, avoiding repeatedly downloading the compiler on every update. # Contributing diff --git a/debug_linux.sh b/debug_linux.sh new file mode 100755 index 00000000..22bf7854 --- /dev/null +++ b/debug_linux.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +fail () { + exit 1 +} + +echo "Detecting Zig compiler..." + +BASE_VERSION=$(< .zig-version) + +case "$(uname -s)" in +"Darwin") + OS=macos;; +*) + OS=linux;; +esac + +if [ -n $ARCH ] +then + case "$(uname -m)" in + "arm64" | "aarch64") + ARCH=aarch64;; + "arm*") + ARCH=armv7a;; + "amd64" | "x86_64") + ARCH=x86_64;; + "x86*") + ARCH=x86;; + *) + echo "Machine architecture could not be recognized ($(uname -m)). Report this bug with the result of \`uname -m\` and your preferred Zig release name." + echo "Defaulting architecture to x86_64." + ARCH=x86_64;; + esac +fi + +VERSION=zig-$OS-$ARCH-$BASE_VERSION + +mkdir -p compiler/zig +touch compiler/version.txt + +CURRENT_VERSION=$(< compiler/version.txt) + +if [[ "$CURRENT_VERSION" != "$VERSION" ]]; then + echo "Your Zig is the wrong version." + echo "Deleting current Zig installation..." + rm -r compiler/zig + mkdir compiler/zig + echo "Downloading $VERSION..." + wget -O compiler/archive.tar.xz https://ziglang.org/builds/"$VERSION".tar.xz + if [ $? != 0 ] + then + echo "Failed to download the Zig compiler." + fail + fi + echo "Extracting tar file..." + tar --xz -xf compiler/archive.tar.xz --directory compiler/zig --strip-components 1 + rm compiler/archive.tar.xz + echo "$VERSION" > compiler/version.txt + echo "Done updating Zig." +else + echo "Zig compiler is valid." +fi + +echo "Building Zig Cubyz ($@) from source. This may take a few minutes..." + +./compiler/zig/zig build "$@" + +if [ $? != 0 ] +then + fail +fi + +echo "Cubyz successfully built!" +echo "Launching Cubyz." + +./compiler/zig/zig build run "$@" diff --git a/debug_windows.bat b/debug_windows.bat new file mode 100644 index 00000000..d5aa5a86 --- /dev/null +++ b/debug_windows.bat @@ -0,0 +1,58 @@ +@echo off + +cd /D "%~dp0" + +echo Detecting Zig compiler... + +set /p baseVersion=<".zig-version" + +IF "%PROCESSOR_ARCHITECTURE%"=="AMD64" (set arch=x86_64) +IF "%PROCESSOR_ARCHITECTURE%"=="IA64" (set arch=x86_64) +IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set arch=x86) +IF "%PROCESSOR_ARCHITECTURE%"=="ARM64" (set arch=aarch64) +IF "%arch%"=="" ( + echo Machine architecture could not be recognized: %arch%. Please file a bug report. + echo Defaulting architecture to x86_64. + set arch=x86_64 +) + +set version=zig-windows-%arch%-%baseVersion% + +if not exist compiler mkdir compiler +if not exist compiler\version.txt copy NUL compiler\version.txt >NUL + +set currVersion= +set /p currVersion=<"compiler\version.txt" + +if not "%version%" == "%currVersion%" ( + echo Your Zig is the wrong version. + echo Deleting current Zig installation ... + if exist compiler\zig rmdir /s /q compiler\zig + echo Downloading %version% ... + powershell -Command $ProgressPreference = 'SilentlyContinue'; "Invoke-WebRequest -uri https://ziglang.org/builds/%version%.zip -OutFile compiler\archive.zip" + if errorlevel 1 ( + echo Failed to download the Zig compiler. + exit /b 1 + ) + echo Extracting zip file ... + powershell $ProgressPreference = 'SilentlyContinue'; Expand-Archive compiler\archive.zip -DestinationPath compiler + ren compiler\%version% zig + del compiler\archive.zip + echo %version%> compiler\version.txt + echo Done updating Zig. +) ELSE ( + echo Zig compiler is valid. +) + +echo Building Zig Cubyz (%*^) from source. This may take a few minutes... + +compiler\zig\zig build %* + +if errorlevel 1 ( + exit /b 1 +) + +echo Cubyz successfully built! +echo Launching Cubyz. + +compiler\zig\zig build run %* diff --git a/run.bat b/run.bat deleted file mode 100644 index a26773d2..00000000 --- a/run.bat +++ /dev/null @@ -1,25 +0,0 @@ -@echo off - -set /p baseVersion=<".zig-version" -set version=zig-windows-x86_64-%baseVersion% - -if not exist compiler mkdir compiler -if not exist compiler\version.txt copy NUL compiler\version.txt >NUL - -set currVersion= -set /p currVersion=<"compiler\version.txt" - -if not "%version%" == "%currVersion%" ( - echo Deleting old zig installation ... - if exist compiler\zig rmdir /s /q compiler\zig - echo Downloading zig version %version% ... - powershell -Command $ProgressPreference = 'SilentlyContinue'; "Invoke-WebRequest -uri https://ziglang.org/builds/%version%.zip -OutFile compiler\archive.zip" - echo Extracting zip file ... - powershell $ProgressPreference = 'SilentlyContinue'; Expand-Archive compiler\archive.zip -DestinationPath compiler - ren compiler\%version% zig - echo Done downloading zig. - del compiler\archive.zip - echo %version%> compiler\version.txt -) - -compiler\zig\zig build run %* \ No newline at end of file diff --git a/run.sh b/run.sh deleted file mode 100755 index 15bb8990..00000000 --- a/run.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash - -BASE_VERSION=$(< .zig-version) -VERSION=zig-linux-x86_64-$BASE_VERSION - -mkdir -p compiler/zig -touch compiler/version.txt - -CURRENT_VERSION=$(< compiler/version.txt) - -if [[ "$CURRENT_VERSION" != "$VERSION" ]]; then - echo "Deleting old zig installation..." - rm -r compiler/zig - mkdir compiler/zig - echo "Downloading $VERSION..." - wget -O compiler/archive.tar.xz https://ziglang.org/builds/"$VERSION".tar.xz - echo "Extracting tar file..." - tar --xz -xf compiler/archive.tar.xz --directory compiler/zig --strip-components 1 - echo "Done downloading zig." - rm compiler/archive.tar.xz - echo "$VERSION" > compiler/version.txt -fi - -./compiler/zig/zig build run "$@" \ No newline at end of file diff --git a/run_linux.sh b/run_linux.sh new file mode 100755 index 00000000..879b7385 --- /dev/null +++ b/run_linux.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +cd "$(dirname "$0")" + +./debug_linux.sh -Doptimize=ReleaseFast "$@" + +if [ ! $NO_PAUSE ]; then + echo "Press enter key to continue. (Or export NO_PAUSE=1 to skip this prompt.)" + read +fi diff --git a/run_release.bat b/run_release.bat deleted file mode 100644 index 32e4aa6b..00000000 --- a/run_release.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off - -.\run.bat -Doptimize=ReleaseFast %* \ No newline at end of file diff --git a/run_release.sh b/run_release.sh deleted file mode 100755 index d4184ae8..00000000 --- a/run_release.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -./run.sh -Doptimize=ReleaseFast "$@" \ No newline at end of file diff --git a/run_windows.bat b/run_windows.bat new file mode 100644 index 00000000..bdcfd319 --- /dev/null +++ b/run_windows.bat @@ -0,0 +1,10 @@ +@echo off + +cd /D "%~dp0" + +call debug_windows.bat -Doptimize=ReleaseFast %* + +IF "%NO_PAUSE%" == "" ( + echo Press enter key to continue. (Or set NO_PAUSE=1 to skip this prompt.^) + pause +)