Revamp Clang checks for Windows; still need to do the same for Mac

This commit is contained in:
Ben Visness 2023-09-23 16:46:52 -05:00 committed by MartinFouilleul
parent fb18d3240a
commit 75c4f6f94d
6 changed files with 120 additions and 7 deletions

View File

@ -1,4 +1,16 @@
@echo off @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 ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^
-I%ORCA_DIR%\src\ext -I%ORCA_DIR%\src\ext
clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c 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 orca bundle --orca-dir %ORCA_DIR% --name Breakout --icon icon.png --resource-dir data module.wasm

View File

@ -1,4 +1,16 @@
@echo off @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 ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^
-I%ORCA_DIR%\src\ext -I%ORCA_DIR%\src\ext
clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c 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 orca bundle --orca-dir %ORCA_DIR% --name Clock --icon icon.png --resource-dir data module.wasm

View File

@ -1,4 +1,16 @@
@echo off @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 ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
@ -30,10 +42,10 @@ set shaders=src/shaders/advect.glsl^
src/shaders/subtract_pressure.glsl src/shaders/subtract_pressure.glsl
call python3 ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_shaders.h %shaders% call python ../../scripts/embed_text_files.py --prefix=glsl_ --output src/glsl_shaders.h %shaders%
IF %ERRORLEVEL% NEQ 0 EXIT /B %ERRORLEVEL% if !ERRORLEVEL! neq 0 exit /b !ERRORLEVEL!
clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c 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 orca bundle --orca-dir %ORCA_DIR% --name Fluid --icon icon.png module.wasm

View File

@ -1,4 +1,16 @@
@echo off @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 ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^
-I%ORCA_DIR%\src\ext -I%ORCA_DIR%\src\ext
clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c 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 orca bundle --orca-dir %ORCA_DIR% --name Triangle module.wasm

View File

@ -1,4 +1,16 @@
@echo off @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 ORCA_DIR=..\..
set STDLIB_DIR=%ORCA_DIR%\src\libc-shim set STDLIB_DIR=%ORCA_DIR%\src\libc-shim
@ -16,6 +28,6 @@ set wasmFlags=--target=wasm32^
-I%ORCA_DIR%\src\ext -I%ORCA_DIR%\src\ext
clang %wasmFlags% -o .\module.wasm %ORCA_DIR%\src\orca.c %STDLIB_DIR%\src\*.c src\main.c 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 orca bundle --orca-dir %ORCA_DIR% --name UI --resource-dir data module.wasm

View File

@ -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)