diff --git a/SConstruct b/SConstruct index 05885c0b5..4f04be624 100644 --- a/SConstruct +++ b/SConstruct @@ -2,6 +2,7 @@ import os import subprocess import sys import sysconfig +import platform import shlex import numpy as np @@ -23,8 +24,19 @@ AddOption('--minimal', default=os.path.exists(File('#.gitattributes').abspath), # minimal by default on release branch (where there's no LFS) help='the minimum build to run openpilot. no tests, tools, etc.') -# Detect platform (see scripts/platform.sh) -arch = subprocess.check_output(["bash", "-c", "source scripts/platform.sh >&2 && echo $OPENPILOT_ARCH"], encoding='utf8', stderr=subprocess.PIPE).rstrip() +# Detect platform +arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() +if platform.system() == "Darwin": + arch = "Darwin" + brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip() +elif arch == "aarch64" and os.path.isfile('/TICI'): + arch = "larch64" +assert arch in [ + "larch64", # linux tici arm64 + "aarch64", # linux pc arm64 + "x86_64", # linux pc x64 + "Darwin", # macOS arm64 (x86 not supported) +] env = Environment( ENV={ @@ -91,7 +103,6 @@ if arch == "larch64": env.Append(CCFLAGS=arch_flags) env.Append(CXXFLAGS=arch_flags) elif arch == "Darwin": - brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip() env.Append(LIBPATH=[ f"{brew_prefix}/lib", f"{brew_prefix}/opt/openssl@3.0/lib", diff --git a/scripts/platform.sh b/scripts/platform.sh deleted file mode 100755 index 1cbd8aa60..000000000 --- a/scripts/platform.sh +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env bash -# -# Centralized platform and architecture detection for openpilot. -# Source this script to get OPENPILOT_ARCH set to one of: -# larch64 - linux tici arm64 -# aarch64 - linux pc arm64 -# x86_64 - linux pc x64 -# Darwin - macOS arm64 -# - -RED='\033[0;31m' -GREEN='\033[0;32m' -NC='\033[0m' - -OPENPILOT_ARCH=$(uname -m) - -# ── check OS and normalize arch ────────────────────────────── -if [ -f /TICI ]; then - # TICI runs AGNOS — no OS validation needed - OPENPILOT_ARCH="larch64" - -elif [[ "$OSTYPE" == "darwin"* ]]; then - if [[ "$OPENPILOT_ARCH" == "x86_64" ]]; then - echo -e " ↳ [${RED}✗${NC}] Intel-based Macs are not supported!" - echo " openpilot requires an Apple Silicon Mac (M1 or newer)." - exit 1 - fi - echo -e " ↳ [${GREEN}✔${NC}] macOS detected." - OPENPILOT_ARCH="Darwin" - -elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - if [ -f "/etc/os-release" ]; then - source /etc/os-release - case "$VERSION_CODENAME" in - "jammy" | "kinetic" | "noble" | "focal") - echo -e " ↳ [${GREEN}✔${NC}] Ubuntu $VERSION_CODENAME detected." - ;; - *) - echo -e " ↳ [${RED}✗${NC}] Incompatible Ubuntu version $VERSION_CODENAME detected!" - exit 1 - ;; - esac - else - echo -e " ↳ [${RED}✗${NC}] No /etc/os-release on your system. Make sure you're running on Ubuntu, or similar!" - exit 1 - fi - -else - echo -e " ↳ [${RED}✗${NC}] OS type $OSTYPE not supported!" - exit 1 -fi diff --git a/third_party/acados/build.sh b/third_party/acados/build.sh index cca174350..95b3913c4 100755 --- a/third_party/acados/build.sh +++ b/third_party/acados/build.sh @@ -6,11 +6,10 @@ export ZERO_AR_DATE=1 DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" -source "$DIR/../../scripts/platform.sh" -ARCHNAME="$OPENPILOT_ARCH" - +ARCHNAME="x86_64" BLAS_TARGET="X64_AUTOMATIC" if [ -f /TICI ]; then + ARCHNAME="larch64" BLAS_TARGET="ARMV8A_ARM_CORTEX_A57" fi @@ -18,6 +17,7 @@ ACADOS_FLAGS="-DACADOS_WITH_QPOASES=ON -UBLASFEO_TARGET -DBLASFEO_TARGET=$BLAS_T if [[ "$OSTYPE" == "darwin"* ]]; then ACADOS_FLAGS="$ACADOS_FLAGS -DCMAKE_OSX_ARCHITECTURES=arm64 -DCMAKE_MACOSX_RPATH=1" + ARCHNAME="Darwin" fi if [ ! -d acados_repo/ ]; then diff --git a/third_party/libyuv/build.sh b/third_party/libyuv/build.sh index 0e4e10133..11f88ab46 100755 --- a/third_party/libyuv/build.sh +++ b/third_party/libyuv/build.sh @@ -6,8 +6,14 @@ export ZERO_AR_DATE=1 DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null && pwd)" -source "$DIR/../../scripts/platform.sh" -ARCHNAME="$OPENPILOT_ARCH" +ARCHNAME=$(uname -m) +if [ -f /TICI ]; then + ARCHNAME="larch64" +fi + +if [[ "$OSTYPE" == "darwin"* ]]; then + ARCHNAME="Darwin" +fi cd $DIR if [ ! -d libyuv ]; then diff --git a/third_party/raylib/build.sh b/third_party/raylib/build.sh index b8408cd88..d20f9d33a 100755 --- a/third_party/raylib/build.sh +++ b/third_party/raylib/build.sh @@ -20,9 +20,9 @@ cd $DIR RAYLIB_PLATFORM="PLATFORM_DESKTOP" -source "$DIR/../../scripts/platform.sh" -ARCHNAME="$OPENPILOT_ARCH" +ARCHNAME=$(uname -m) if [ -f /TICI ]; then + ARCHNAME="larch64" RAYLIB_PLATFORM="PLATFORM_COMMA" elif [[ "$OSTYPE" == "linux"* ]]; then # required dependencies on Linux PC @@ -33,6 +33,10 @@ elif [[ "$OSTYPE" == "linux"* ]]; then libxrandr-dev fi +if [[ "$OSTYPE" == "darwin"* ]]; then + ARCHNAME="Darwin" +fi + INSTALL_DIR="$DIR/$ARCHNAME" rm -rf $INSTALL_DIR mkdir -p $INSTALL_DIR diff --git a/tools/install_python_dependencies.sh b/tools/install_python_dependencies.sh index bf7accbbd..4454845fc 100755 --- a/tools/install_python_dependencies.sh +++ b/tools/install_python_dependencies.sh @@ -23,7 +23,7 @@ echo "installing python packages..." uv sync --frozen --all-extras source .venv/bin/activate -if [[ "$OSTYPE" == "darwin"* ]]; then +if [[ "$(uname)" == 'Darwin' ]]; then touch "$ROOT"/.env echo "export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES" >> "$ROOT"/.env fi diff --git a/tools/mac_setup.sh b/tools/mac_setup.sh index 7e126d4f5..82748e961 100755 --- a/tools/mac_setup.sh +++ b/tools/mac_setup.sh @@ -3,7 +3,6 @@ set -e DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" ROOT="$(cd $DIR/../ && pwd)" -source $ROOT/scripts/platform.sh # homebrew update is slow export HOMEBREW_NO_AUTO_UPDATE=1 diff --git a/tools/op.sh b/tools/op.sh index afee4cfb7..8c41926e0 100755 --- a/tools/op.sh +++ b/tools/op.sh @@ -122,7 +122,33 @@ function op_check_git() { function op_check_os() { echo "Checking for compatible os version..." - source "$OPENPILOT_ROOT/scripts/platform.sh" + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + + if [ -f "/etc/os-release" ]; then + source /etc/os-release + case "$VERSION_CODENAME" in + "jammy" | "kinetic" | "noble" | "focal") + echo -e " ↳ [${GREEN}✔${NC}] Ubuntu $VERSION_CODENAME detected." + ;; + * ) + echo -e " ↳ [${RED}✗${NC}] Incompatible Ubuntu version $VERSION_CODENAME detected!" + loge "ERROR_INCOMPATIBLE_UBUNTU" "$VERSION_CODENAME" + return 1 + ;; + esac + else + echo -e " ↳ [${RED}✗${NC}] No /etc/os-release on your system. Make sure you're running on Ubuntu, or similar!" + loge "ERROR_UNKNOWN_UBUNTU" + return 1 + fi + + elif [[ "$OSTYPE" == "darwin"* ]]; then + echo -e " ↳ [${GREEN}✔${NC}] macOS detected." + else + echo -e " ↳ [${RED}✗${NC}] OS type $OSTYPE not supported!" + loge "ERROR_UNKNOWN_OS" "$OSTYPE" + return 1 + fi } function op_check_python() {