diff --git a/samples/breakout/build.bat b/samples/breakout/build.bat index 331320b..85a0d41 100644 --- a/samples/breakout/build.bat +++ b/samples/breakout/build.bat @@ -1,4 +1,16 @@ @echo off +setlocal enabledelayedexpansion + +:: The following code simply checks that you have a compatible version of Clang. +:: This code exists to improve the experience of first-time Orca users and can +:: be safely deleted in your own projects if you wish. +if exist "..\..\scripts\sample_build_check.py" ( + python ..\..\scripts\sample_build_check.py + if !ERRORLEVEL! neq 0 exit /b 1 +) else ( + echo Could not check if you have the necessary tools to build the Orca samples. + echo If you have copied this script to your own project, you can delete this code. +) set ORCA_DIR=..\.. set STDLIB_DIR=%ORCA_DIR%\src\libc-shim @@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^ -I%ORCA_DIR%\src\ext clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! orca bundle --orca-dir %ORCA_DIR% --name Breakout --icon icon.png --resource-dir data module.wasm diff --git a/samples/clock/build.bat b/samples/clock/build.bat index 95d92c8..55c3952 100644 --- a/samples/clock/build.bat +++ b/samples/clock/build.bat @@ -1,4 +1,16 @@ @echo off +setlocal enabledelayedexpansion + +:: The following code simply checks that you have a compatible version of Clang. +:: This code exists to improve the experience of first-time Orca users and can +:: be safely deleted in your own projects if you wish. +if exist "..\..\scripts\sample_build_check.py" ( + python ..\..\scripts\sample_build_check.py + if !ERRORLEVEL! neq 0 exit /b 1 +) else ( + echo Could not check if you have the necessary tools to build the Orca samples. + echo If you have copied this script to your own project, you can delete this code. +) set ORCA_DIR=..\.. set STDLIB_DIR=%ORCA_DIR%\src\libc-shim @@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^ -I%ORCA_DIR%\src\ext clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! orca bundle --orca-dir %ORCA_DIR% --name Clock --icon icon.png --resource-dir data module.wasm diff --git a/samples/fluid/build.bat b/samples/fluid/build.bat index 73f4d72..5f5f127 100644 --- a/samples/fluid/build.bat +++ b/samples/fluid/build.bat @@ -1,4 +1,16 @@ @echo off +setlocal enabledelayedexpansion + +:: The following code simply checks that you have a compatible version of Clang. +:: This code exists to improve the experience of first-time Orca users and can +:: be safely deleted in your own projects if you wish. +if exist "..\..\scripts\sample_build_check.py" ( + python ..\..\scripts\sample_build_check.py + if !ERRORLEVEL! neq 0 exit /b 1 +) else ( + echo Could not check if you have the necessary tools to build the Orca samples. + echo If you have copied this script to your own project, you can delete this code. +) set ORCA_DIR=..\.. set STDLIB_DIR=%ORCA_DIR%\src\libc-shim @@ -30,10 +42,10 @@ set shaders=src/shaders/advect.glsl^ src/shaders/subtract_pressure.glsl -call python3 ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_shaders.h %shaders% -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +call python ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_shaders.h %shaders% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! orca bundle --orca-dir %ORCA_DIR% --name Fluid --icon icon.png module.wasm \ No newline at end of file diff --git a/samples/triangle/build.bat b/samples/triangle/build.bat index e364017..465ae78 100644 --- a/samples/triangle/build.bat +++ b/samples/triangle/build.bat @@ -1,4 +1,16 @@ @echo off +setlocal enabledelayedexpansion + +:: The following code simply checks that you have a compatible version of Clang. +:: This code exists to improve the experience of first-time Orca users and can +:: be safely deleted in your own projects if you wish. +if exist "..\..\scripts\sample_build_check.py" ( + python ..\..\scripts\sample_build_check.py + if !ERRORLEVEL! neq 0 exit /b 1 +) else ( + echo Could not check if you have the necessary tools to build the Orca samples. + echo If you have copied this script to your own project, you can delete this code. +) set ORCA_DIR=..\.. set STDLIB_DIR=%ORCA_DIR%\src\libc-shim @@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^ -I%ORCA_DIR%\src\ext clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! orca bundle --orca-dir %ORCA_DIR% --name Triangle module.wasm diff --git a/samples/ui/build.bat b/samples/ui/build.bat index 46f5011..9137fa9 100644 --- a/samples/ui/build.bat +++ b/samples/ui/build.bat @@ -1,4 +1,16 @@ @echo off +setlocal enabledelayedexpansion + +:: The following code simply checks that you have a compatible version of Clang. +:: This code exists to improve the experience of first-time Orca users and can +:: be safely deleted in your own projects if you wish. +if exist "..\..\scripts\sample_build_check.py" ( + python ..\..\scripts\sample_build_check.py + if !ERRORLEVEL! neq 0 exit /b 1 +) else ( + echo Could not check if you have the necessary tools to build the Orca samples. + echo If you have copied this script to your own project, you can delete this code. +) set ORCA_DIR=..\.. set STDLIB_DIR=%ORCA_DIR%\src\libc-shim @@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^ -I%ORCA_DIR%\src\ext clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c -IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% +if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL! orca bundle --orca-dir %ORCA_DIR% --name UI --resource-dir data module.wasm diff --git a/scripts/sample_build_check.py b/scripts/sample_build_check.py new file mode 100644 index 0000000..96064ff --- /dev/null +++ b/scripts/sample_build_check.py @@ -0,0 +1,53 @@ +import platform +import re +import shutil +import subprocess +import textwrap + +CLANG_MAJOR, CLANG_MINOR = 11, 0 + +def printw(str=""): + print(textwrap.fill(str)) + +def print_clang_install_info(upgrade): + if platform.system() == "Windows": + printw(f"Please install Clang {CLANG_MAJOR}.{CLANG_MINOR} or newer. We recommend installing Clang via the Visual Studio installer. In the installer, search for \"C++ Clang Compiler\".") + elif platform.system() == "Darwin": + printw(f"Please install Clang {CLANG_MAJOR}.{CLANG_MINOR} or newer. We recommend installing Clang via Homebrew:") + printw() + if upgrade: + printw(" brew upgrade llvm") + else: + printw(" brew install llvm") + printw() + else: + printw(f"Please install Clang {CLANG_MAJOR}.{CLANG_MINOR} or newer.") + +try: + out = subprocess.run(["clang", "--version"], capture_output=True, text=True, check=True) + m = re.search(r"clang version (\d+)\.(\d+)\.(\d+)", out.stdout) + major, minor, patch = int(m.group(1)), int(m.group(2)), int(m.group(3)) + if major < CLANG_MAJOR or minor < CLANG_MINOR: + printw(f"ERROR: Your version of Clang is too old. You have version {major}.{minor}.{patch}, but version {CLANG_MAJOR}.{CLANG_MINOR} or greater is required.") + printw() + printw("This script is currently running the clang located at:") + printw(shutil.which("clang")) + printw() + print_clang_install_info(True) + exit(1) +except FileNotFoundError: + printw("ERROR: clang is not installed. The Orca samples require Clang in order to compile C programs to WebAssembly.") + printw() + print_clang_install_info(False) + exit(1) +except subprocess.CalledProcessError: + printw("WARNING: Could not check Clang version. You may encounter build errors.") + +try: + subprocess.run(["orca", "version"], capture_output=True, shell=True, check=True) +except subprocess.CalledProcessError: + printw("ERROR: The Orca tooling has not been installed to your system or is not on your PATH. From the root of the Orca source code, please run the following commands:") + printw() + printw(" python orca dev build-runtime") + printw(" python orca dev install") + exit(1)