From 1cc8778982113c12d477f9d920c05dc3ea833757 Mon Sep 17 00:00:00 2001 From: Ben Visness Date: Sat, 23 Sep 2023 17:04:13 -0500 Subject: [PATCH] Do clang checks on Mac --- samples/breakout/build.bat | 2 +- samples/breakout/build.sh | 15 ++++++++------- samples/clock/build.bat | 2 +- samples/clock/build.sh | 15 ++++++++------- samples/fluid/build.bat | 2 +- samples/fluid/build.sh | 15 ++++++++------- samples/triangle/build.bat | 2 +- samples/triangle/build.sh | 15 ++++++++------- samples/ui/build.bat | 2 +- samples/ui/build.sh | 15 ++++++++------- scripts/sample_build_check.py | 10 +++++++++- 11 files changed, 54 insertions(+), 41 deletions(-) diff --git a/samples/breakout/build.bat b/samples/breakout/build.bat index 85a0d41..a63b8ae 100644 --- a/samples/breakout/build.bat +++ b/samples/breakout/build.bat @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -:: The following code simply checks that you have a compatible version of Clang. +:: The following code checks if you have the necessary programs to compile the samples. :: 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" ( diff --git a/samples/breakout/build.sh b/samples/breakout/build.sh index b21abed..28b2d5d 100755 --- a/samples/breakout/build.sh +++ b/samples/breakout/build.sh @@ -2,13 +2,14 @@ set -euo pipefail -if [[ -x /usr/local/opt/llvm/bin/clang ]]; then - CLANG=/usr/local/opt/llvm/bin/clang -elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang +# The following code checks if you have the necessary programs to compile the samples. +# 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 [ -f ../../scripts/sample_build_check.py ]; then + python3 ../../scripts/sample_build_check.py else - echo "Could not find Homebrew clang; this script will probably not work." - CLANG=clang + 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." fi ORCA_DIR=../.. @@ -25,6 +26,6 @@ wasmFlags="--target=wasm32 \ -I $ORCA_DIR/src \ -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 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 55c3952..f9579fb 100644 --- a/samples/clock/build.bat +++ b/samples/clock/build.bat @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -:: The following code simply checks that you have a compatible version of Clang. +:: The following code checks if you have the necessary programs to compile the samples. :: 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" ( diff --git a/samples/clock/build.sh b/samples/clock/build.sh index 41caf81..55b51fb 100755 --- a/samples/clock/build.sh +++ b/samples/clock/build.sh @@ -2,13 +2,14 @@ set -euo pipefail -if [[ -x /usr/local/opt/llvm/bin/clang ]]; then - CLANG=/usr/local/opt/llvm/bin/clang -elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang +# The following code checks if you have the necessary programs to compile the samples. +# 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 [ -f ../../scripts/sample_build_check.py ]; then + python3 ../../scripts/sample_build_check.py else - echo "Could not find Homebrew clang; this script will probably not work." - CLANG=clang + 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." fi ORCA_DIR=../.. @@ -25,6 +26,6 @@ wasmFlags="--target=wasm32 \ -I $ORCA_DIR/src \ -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 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 5f5f127..338a853 100644 --- a/samples/fluid/build.bat +++ b/samples/fluid/build.bat @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -:: The following code simply checks that you have a compatible version of Clang. +:: The following code checks if you have the necessary programs to compile the samples. :: 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" ( diff --git a/samples/fluid/build.sh b/samples/fluid/build.sh index 21e9cf2..79bbf06 100755 --- a/samples/fluid/build.sh +++ b/samples/fluid/build.sh @@ -2,13 +2,14 @@ set -euo pipefail -if [[ -x /usr/local/opt/llvm/bin/clang ]]; then - CLANG=/usr/local/opt/llvm/bin/clang -elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang +# The following code checks if you have the necessary programs to compile the samples. +# 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 [ -f ../../scripts/sample_build_check.py ]; then + python3 ../../scripts/sample_build_check.py else - echo "Could not find Homebrew clang; this script will probably not work." - CLANG=clang + 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." fi ORCA_DIR=../.. @@ -27,6 +28,6 @@ wasmFlags="--target=wasm32 \ -I $ORCA_DIR/src \ -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 orca bundle --orca-dir $ORCA_DIR --name Fluid --icon icon.png module.wasm diff --git a/samples/triangle/build.bat b/samples/triangle/build.bat index 465ae78..910e4c5 100644 --- a/samples/triangle/build.bat +++ b/samples/triangle/build.bat @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -:: The following code simply checks that you have a compatible version of Clang. +:: The following code checks if you have the necessary programs to compile the samples. :: 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" ( diff --git a/samples/triangle/build.sh b/samples/triangle/build.sh index cd74b6c..a83b61a 100755 --- a/samples/triangle/build.sh +++ b/samples/triangle/build.sh @@ -2,13 +2,14 @@ set -euo pipefail -if [[ -x /usr/local/opt/llvm/bin/clang ]]; then - CLANG=/usr/local/opt/llvm/bin/clang -elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang +# The following code checks if you have the necessary programs to compile the samples. +# 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 [ -f ../../scripts/sample_build_check.py ]; then + python3 ../../scripts/sample_build_check.py else - echo "Could not find Homebrew clang; this script will probably not work." - CLANG=clang + 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." fi ORCA_DIR=../.. @@ -25,6 +26,6 @@ wasmFlags="--target=wasm32 \ -I $ORCA_DIR/src \ -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 orca bundle --orca-dir $ORCA_DIR --name Triangle module.wasm diff --git a/samples/ui/build.bat b/samples/ui/build.bat index 9137fa9..4a7b1eb 100644 --- a/samples/ui/build.bat +++ b/samples/ui/build.bat @@ -1,7 +1,7 @@ @echo off setlocal enabledelayedexpansion -:: The following code simply checks that you have a compatible version of Clang. +:: The following code checks if you have the necessary programs to compile the samples. :: 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" ( diff --git a/samples/ui/build.sh b/samples/ui/build.sh index 2e15876..bffba7f 100755 --- a/samples/ui/build.sh +++ b/samples/ui/build.sh @@ -2,13 +2,14 @@ set -euo pipefail -if [[ -x /usr/local/opt/llvm/bin/clang ]]; then - CLANG=/usr/local/opt/llvm/bin/clang -elif [[ -x /opt/homebrew/opt/llvm/bin/clang ]]; then - CLANG=/opt/homebrew/opt/llvm/bin/clang +# The following code checks if you have the necessary programs to compile the samples. +# 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 [ -f ../../scripts/sample_build_check.py ]; then + python3 ../../scripts/sample_build_check.py else - echo "Could not find Homebrew clang; this script will probably not work." - CLANG=clang + 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." fi ORCA_DIR=../.. @@ -25,6 +26,6 @@ wasmFlags="--target=wasm32 \ -I $ORCA_DIR/src \ -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 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 index 96064ff..bc31e28 100644 --- a/scripts/sample_build_check.py +++ b/scripts/sample_build_check.py @@ -13,7 +13,7 @@ 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(f"Please install Clang {CLANG_MAJOR}.{CLANG_MINOR} or newer. We recommend installing Clang via Homebrew (https://brew.sh/):") printw() if upgrade: printw(" brew upgrade llvm") @@ -43,6 +43,14 @@ except FileNotFoundError: except subprocess.CalledProcessError: printw("WARNING: Could not check Clang version. You may encounter build errors.") +try: + subprocess.run(["wasm-ld", "--version"], capture_output=True, check=True) +except FileNotFoundError: + printw("ERROR: wasm-ld was not found on your system. This is a component of Clang that is required in order to produce WebAssembly modules. This likely means that an old or otherwise incompatible version of Clang is being used, such as Apple's version of Clang.") + printw() + print_clang_install_info(False) + exit(1) + try: subprocess.run(["orca", "version"], capture_output=True, shell=True, check=True) except subprocess.CalledProcessError: