build system cleanups (#36202)

* it's all common

* never getting fixed

* it's just tici

* reorders

* qcom2 -> tici

* Revert "qcom2 -> tici"

This reverts commit f4d849b295.

* Reapply "qcom2 -> tici"

This reverts commit 58b193cb8d.

* is tici

* lil more

* Revert "is tici"

This reverts commit a169be18d3.

* Revert "Reapply "qcom2 -> tici""

This reverts commit 26f9c0e7d0.

* qcom2 -> __tici__

* lil more

* mv lenv

* clean that up

* lil more]

* fix

* lil more
pull/36192/merge
Adeeb Shihadeh 2 days ago committed by GitHub
parent 2c377e534f
commit cf5b743de6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 250
      SConstruct
  2. 11
      common/SConscript
  3. 4
      selfdrive/modeld/SConscript
  4. 2
      selfdrive/ui/qt/qt_window.cc
  5. 2
      selfdrive/ui/qt/qt_window.h
  6. 12
      selfdrive/ui/qt/widgets/cameraview.cc
  7. 4
      selfdrive/ui/qt/widgets/cameraview.h
  8. 4
      system/camerad/SConscript
  9. 2
      system/camerad/cameras/camera_qcom2.cc
  10. 2
      system/hardware/hw.h
  11. 2
      system/loggerd/encoderd.cc

@ -3,144 +3,52 @@ import subprocess
import sys import sys
import sysconfig import sysconfig
import platform import platform
import shlex
import numpy as np import numpy as np
import SCons.Errors import SCons.Errors
SCons.Warnings.warningAsException(True) SCons.Warnings.warningAsException(True)
# pending upstream fix - https://github.com/SCons/scons/issues/4461
#SetOption('warn', 'all')
TICI = os.path.isfile('/TICI')
AGNOS = TICI
Decider('MD5-timestamp') Decider('MD5-timestamp')
SetOption('num_jobs', max(1, int(os.cpu_count()/2))) SetOption('num_jobs', max(1, int(os.cpu_count()/2)))
AddOption('--kaitai', AddOption('--kaitai', action='store_true', help='Regenerate kaitai struct parsers')
action='store_true', AddOption('--asan', action='store_true', help='turn on ASAN')
help='Regenerate kaitai struct parsers') AddOption('--ubsan', action='store_true', help='turn on UBSan')
AddOption('--mutation', action='store_true', help='generate mutation-ready code')
AddOption('--asan', AddOption('--ccflags', action='store', type='string', default='', help='pass arbitrary flags over the command line')
action='store_true',
help='turn on ASAN')
AddOption('--ubsan',
action='store_true',
help='turn on UBSan')
AddOption('--ccflags',
action='store',
type='string',
default='',
help='pass arbitrary flags over the command line')
AddOption('--mutation',
action='store_true',
help='generate mutation-ready code')
AddOption('--minimal', AddOption('--minimal',
action='store_false', action='store_false',
dest='extras', dest='extras',
default=os.path.exists(File('#.lfsconfig').abspath), # minimal by default on release branch (where there's no LFS) default=os.path.exists(File('#.lfsconfig').abspath), # minimal by default on release branch (where there's no LFS)
help='the minimum build to run openpilot. no tests, tools, etc.') help='the minimum build to run openpilot. no tests, tools, etc.')
## Architecture name breakdown (arch) # Detect platform
## - larch64: linux tici aarch64 arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
## - aarch64: linux pc aarch64
## - x86_64: linux pc x64
## - Darwin: mac x64 or arm64
real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin": if platform.system() == "Darwin":
arch = "Darwin" arch = "Darwin"
brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip() brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip()
elif arch == "aarch64" and AGNOS: elif arch == "aarch64" and os.path.isfile('/TICI'):
arch = "larch64" arch = "larch64"
assert arch in ["larch64", "aarch64", "x86_64", "Darwin"] assert arch in [
"larch64", # linux tici arm64
lenv = { "aarch64", # linux pc arm64
"PATH": os.environ['PATH'], "x86_64", # linux pc x64
"PYTHONPATH": Dir("#").abspath + ':' + Dir(f"#third_party/acados").abspath, "Darwin", # macOS arm64 (x86 not supported)
]
"ACADOS_SOURCE_DIR": Dir("#third_party/acados").abspath,
"ACADOS_PYTHON_INTERFACE_PATH": Dir("#third_party/acados/acados_template").abspath,
"TERA_PATH": Dir("#").abspath + f"/third_party/acados/{arch}/t_renderer"
}
rpath = []
if arch == "larch64":
cpppath = [
"#third_party/opencl/include",
]
libpath = [
"/usr/local/lib",
"/system/vendor/lib64",
f"#third_party/acados/{arch}/lib",
]
libpath += [
"#third_party/libyuv/larch64/lib",
"/usr/lib/aarch64-linux-gnu"
]
cflags = ["-DQCOM2", "-mcpu=cortex-a57"]
cxxflags = ["-DQCOM2", "-mcpu=cortex-a57"]
rpath += ["/usr/local/lib"]
else:
cflags = []
cxxflags = []
cpppath = []
rpath += []
# MacOS
if arch == "Darwin":
libpath = [
f"#third_party/libyuv/{arch}/lib",
f"#third_party/acados/{arch}/lib",
f"{brew_prefix}/lib",
f"{brew_prefix}/opt/openssl@3.0/lib",
f"{brew_prefix}/opt/llvm/lib/c++",
"/System/Library/Frameworks/OpenGL.framework/Libraries",
]
cflags += ["-DGL_SILENCE_DEPRECATION"]
cxxflags += ["-DGL_SILENCE_DEPRECATION"]
cpppath += [
f"{brew_prefix}/include",
f"{brew_prefix}/opt/openssl@3.0/include",
]
# Linux
else:
libpath = [
f"#third_party/acados/{arch}/lib",
f"#third_party/libyuv/{arch}/lib",
"/usr/lib",
"/usr/local/lib",
]
if GetOption('asan'):
ccflags = ["-fsanitize=address", "-fno-omit-frame-pointer"]
ldflags = ["-fsanitize=address"]
elif GetOption('ubsan'):
ccflags = ["-fsanitize=undefined"]
ldflags = ["-fsanitize=undefined"]
else:
ccflags = []
ldflags = []
# no --as-needed on mac linker
if arch != "Darwin":
ldflags += ["-Wl,--as-needed", "-Wl,--no-undefined"]
ccflags_option = GetOption('ccflags')
if ccflags_option:
ccflags += ccflags_option.split(' ')
env = Environment( env = Environment(
ENV=lenv, ENV={
"PATH": os.environ['PATH'],
"PYTHONPATH": Dir("#").abspath + ':' + Dir(f"#third_party/acados").abspath,
"ACADOS_SOURCE_DIR": Dir("#third_party/acados").abspath,
"ACADOS_PYTHON_INTERFACE_PATH": Dir("#third_party/acados/acados_template").abspath,
"TERA_PATH": Dir("#").abspath + f"/third_party/acados/{arch}/t_renderer"
},
CC='clang',
CXX='clang++',
CCFLAGS=[ CCFLAGS=[
"-g", "-g",
"-fPIC", "-fPIC",
@ -153,36 +61,31 @@ env = Environment(
"-Wno-c99-designator", "-Wno-c99-designator",
"-Wno-reorder-init-list", "-Wno-reorder-init-list",
"-Wno-vla-cxx-extension", "-Wno-vla-cxx-extension",
] + cflags + ccflags, ],
CFLAGS=["-std=gnu11"],
CPPPATH=cpppath + [ CXXFLAGS=["-std=c++1z"],
CPPPATH=[
"#", "#",
"#msgq",
"#third_party",
"#third_party/json11",
"#third_party/linux/include",
"#third_party/acados/include", "#third_party/acados/include",
"#third_party/acados/include/blasfeo/include", "#third_party/acados/include/blasfeo/include",
"#third_party/acados/include/hpipm/include", "#third_party/acados/include/hpipm/include",
"#third_party/catch2/include", "#third_party/catch2/include",
"#third_party/libyuv/include", "#third_party/libyuv/include",
"#third_party/json11",
"#third_party/linux/include",
"#third_party",
"#msgq",
], ],
LIBPATH=[
CC='clang', "#common",
CXX='clang++',
LINKFLAGS=ldflags,
RPATH=rpath,
CFLAGS=["-std=gnu11"] + cflags,
CXXFLAGS=["-std=c++1z"] + cxxflags,
LIBPATH=libpath + [
"#msgq_repo", "#msgq_repo",
"#third_party", "#third_party",
"#selfdrive/pandad", "#selfdrive/pandad",
"#common",
"#rednose/helpers", "#rednose/helpers",
f"#third_party/libyuv/{arch}/lib",
f"#third_party/acados/{arch}/lib",
], ],
RPATH=[],
CYTHONCFILESUFFIX=".cpp", CYTHONCFILESUFFIX=".cpp",
COMPILATIONDB_USE_ABSPATH=True, COMPILATIONDB_USE_ABSPATH=True,
REDNOSE_ROOT="#", REDNOSE_ROOT="#",
@ -190,29 +93,63 @@ env = Environment(
toolpath=["#site_scons/site_tools", "#rednose_repo/site_scons/site_tools"], toolpath=["#site_scons/site_tools", "#rednose_repo/site_scons/site_tools"],
) )
if arch == "Darwin": # Arch-specific flags and paths
# RPATH is not supported on macOS, instead use the linker flags if arch == "larch64":
darwin_rpath_link_flags = [f"-Wl,-rpath,{path}" for path in env["RPATH"]] env.Append(CPPPATH=["#third_party/opencl/include"])
env["LINKFLAGS"] += darwin_rpath_link_flags env.Append(LIBPATH=[
"/usr/local/lib",
"/system/vendor/lib64",
"/usr/lib/aarch64-linux-gnu",
])
arch_flags = ["-D__TICI__", "-mcpu=cortex-a57"]
env.Append(CCFLAGS=arch_flags)
env.Append(CXXFLAGS=arch_flags)
elif arch == "Darwin":
env.Append(LIBPATH=[
f"{brew_prefix}/lib",
f"{brew_prefix}/opt/openssl@3.0/lib",
f"{brew_prefix}/opt/llvm/lib/c++",
"/System/Library/Frameworks/OpenGL.framework/Libraries",
])
env.Append(CCFLAGS=["-DGL_SILENCE_DEPRECATION"])
env.Append(CXXFLAGS=["-DGL_SILENCE_DEPRECATION"])
env.Append(CPPPATH=[
f"{brew_prefix}/include",
f"{brew_prefix}/opt/openssl@3.0/include",
])
else:
env.Append(LIBPATH=[
"/usr/lib",
"/usr/local/lib",
])
env.CompilationDatabase('compile_commands.json') # Sanitizers and extra CCFLAGS from CLI
if GetOption('asan'):
env.Append(CCFLAGS=["-fsanitize=address", "-fno-omit-frame-pointer"])
env.Append(LINKFLAGS=["-fsanitize=address"])
elif GetOption('ubsan'):
env.Append(CCFLAGS=["-fsanitize=undefined"])
env.Append(LINKFLAGS=["-fsanitize=undefined"])
# Setup cache dir _extra_cc = shlex.split(GetOption('ccflags') or '')
cache_dir = '/data/scons_cache' if AGNOS else '/tmp/scons_cache' if _extra_cc:
CacheDir(cache_dir) env.Append(CCFLAGS=_extra_cc)
Clean(["."], cache_dir)
# no --as-needed on mac linker
if arch != "Darwin":
env.Append(LINKFLAGS=["-Wl,--as-needed", "-Wl,--no-undefined"])
# progress output
node_interval = 5 node_interval = 5
node_count = 0 node_count = 0
def progress_function(node): def progress_function(node):
global node_count global node_count
node_count += node_interval node_count += node_interval
sys.stderr.write("progress: %d\n" % node_count) sys.stderr.write("progress: %d\n" % node_count)
if os.environ.get('SCONS_PROGRESS'): if os.environ.get('SCONS_PROGRESS'):
Progress(progress_function, interval=node_interval) Progress(progress_function, interval=node_interval)
# Cython build environment # ********** Cython build environment **********
py_include = sysconfig.get_paths()['include'] py_include = sysconfig.get_paths()['include']
envCython = env.Clone() envCython = env.Clone()
envCython["CPPPATH"] += [py_include, np.get_include()] envCython["CPPPATH"] += [py_include, np.get_include()]
@ -221,14 +158,14 @@ envCython["CCFLAGS"].remove("-Werror")
envCython["LIBS"] = [] envCython["LIBS"] = []
if arch == "Darwin": if arch == "Darwin":
envCython["LINKFLAGS"] = ["-bundle", "-undefined", "dynamic_lookup"] + darwin_rpath_link_flags envCython["LINKFLAGS"] = env["LINKFLAGS"] + ["-bundle", "-undefined", "dynamic_lookup"]
else: else:
envCython["LINKFLAGS"] = ["-pthread", "-shared"] envCython["LINKFLAGS"] = ["-pthread", "-shared"]
np_version = SCons.Script.Value(np.__version__) np_version = SCons.Script.Value(np.__version__)
Export('envCython', 'np_version') Export('envCython', 'np_version')
# Qt build environment # ********** Qt build environment **********
qt_env = env.Clone() qt_env = env.Clone()
qt_modules = ["Widgets", "Gui", "Core", "Network", "Concurrent", "DBus", "Xml"] qt_modules = ["Widgets", "Gui", "Core", "Network", "Concurrent", "DBus", "Xml"]
@ -278,16 +215,20 @@ qt_env['CXXFLAGS'] += qt_flags
qt_env['LIBPATH'] += ['#selfdrive/ui', ] qt_env['LIBPATH'] += ['#selfdrive/ui', ]
qt_env['LIBS'] = qt_libs qt_env['LIBS'] = qt_libs
Export('env', 'qt_env', 'arch', 'real_arch') Export('env', 'qt_env', 'arch')
# Setup cache dir
cache_dir = '/data/scons_cache' if arch == "larch64" else '/tmp/scons_cache'
CacheDir(cache_dir)
Clean(["."], cache_dir)
# ********** start building stuff **********
# Build common module # Build common module
SConscript(['common/SConscript']) SConscript(['common/SConscript'])
Import('_common', '_gpucommon') Import('_common')
common = [_common, 'json11', 'zmq'] common = [_common, 'json11', 'zmq']
gpucommon = [_gpucommon] Export('common')
Export('common', 'gpucommon')
# Build messaging (cereal + msgq + socketmaster + their dependencies) # Build messaging (cereal + msgq + socketmaster + their dependencies)
# Enable swaglog include in submodules # Enable swaglog include in submodules
@ -327,3 +268,6 @@ if Dir('#tools/cabana/').exists() and GetOption('extras'):
SConscript(['tools/replay/SConscript']) SConscript(['tools/replay/SConscript'])
if arch != "larch64": if arch != "larch64":
SConscript(['tools/cabana/SConscript']) SConscript(['tools/cabana/SConscript'])
env.CompilationDatabase('compile_commands.json')

@ -5,17 +5,12 @@ common_libs = [
'swaglog.cc', 'swaglog.cc',
'util.cc', 'util.cc',
'watchdog.cc', 'watchdog.cc',
'ratekeeper.cc' 'ratekeeper.cc',
]
_common = env.Library('common', common_libs, LIBS="json11")
files = [
'clutil.cc', 'clutil.cc',
] ]
_gpucommon = env.Library('gpucommon', files) _common = env.Library('common', common_libs, LIBS="json11")
Export('_common', '_gpucommon') Export('_common')
if GetOption('extras'): if GetOption('extras'):
env.Program('tests/test_common', env.Program('tests/test_common',

@ -1,11 +1,11 @@
import os import os
import glob import glob
Import('env', 'envCython', 'arch', 'cereal', 'messaging', 'common', 'gpucommon', 'visionipc', 'transformations') Import('env', 'envCython', 'arch', 'cereal', 'messaging', 'common', 'visionipc', 'transformations')
lenv = env.Clone() lenv = env.Clone()
lenvCython = envCython.Clone() lenvCython = envCython.Clone()
libs = [cereal, messaging, visionipc, gpucommon, common, 'capnp', 'kj', 'pthread'] libs = [cereal, messaging, visionipc, common, 'capnp', 'kj', 'pthread']
frameworks = [] frameworks = []
common_src = [ common_src = [

@ -13,7 +13,7 @@ void setMainWindow(QWidget *w) {
} }
w->show(); w->show();
#ifdef QCOM2 #ifdef __TICI__
QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface(); QPlatformNativeInterface *native = QGuiApplication::platformNativeInterface();
wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", w->windowHandle())); wl_surface *s = reinterpret_cast<wl_surface*>(native->nativeResourceForWindow("surface", w->windowHandle()));
wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270); wl_surface_set_buffer_transform(s, WL_OUTPUT_TRANSFORM_270);

@ -6,7 +6,7 @@
#include <QScreen> #include <QScreen>
#include <QWidget> #include <QWidget>
#ifdef QCOM2 #ifdef __TICI__
#include <qpa/qplatformnativeinterface.h> #include <qpa/qplatformnativeinterface.h>
#include <wayland-client-protocol.h> #include <wayland-client-protocol.h>
#include <QPlatformSurfaceEvent> #include <QPlatformSurfaceEvent>

@ -27,7 +27,7 @@ const char frame_vertex_shader[] =
"}\n"; "}\n";
const char frame_fragment_shader[] = const char frame_fragment_shader[] =
#ifdef QCOM2 #ifdef __TICI__
"#version 300 es\n" "#version 300 es\n"
"#extension GL_OES_EGL_image_external_essl3 : enable\n" "#extension GL_OES_EGL_image_external_essl3 : enable\n"
"precision mediump float;\n" "precision mediump float;\n"
@ -79,7 +79,7 @@ CameraWidget::~CameraWidget() {
glDeleteVertexArrays(1, &frame_vao); glDeleteVertexArrays(1, &frame_vao);
glDeleteBuffers(1, &frame_vbo); glDeleteBuffers(1, &frame_vbo);
glDeleteBuffers(1, &frame_ibo); glDeleteBuffers(1, &frame_ibo);
#ifndef QCOM2 #ifndef __TICI__
glDeleteTextures(2, textures); glDeleteTextures(2, textures);
#endif #endif
} }
@ -137,7 +137,7 @@ void CameraWidget::initializeGL() {
glUseProgram(program->programId()); glUseProgram(program->programId());
#ifdef QCOM2 #ifdef __TICI__
glUniform1i(program->uniformLocation("uTexture"), 0); glUniform1i(program->uniformLocation("uTexture"), 0);
#else #else
glGenTextures(2, textures); glGenTextures(2, textures);
@ -165,7 +165,7 @@ void CameraWidget::stopVipcThread() {
vipc_thread = nullptr; vipc_thread = nullptr;
} }
#ifdef QCOM2 #ifdef __TICI__
EGLDisplay egl_display = eglGetCurrentDisplay(); EGLDisplay egl_display = eglGetCurrentDisplay();
assert(egl_display != EGL_NO_DISPLAY); assert(egl_display != EGL_NO_DISPLAY);
for (auto &pair : egl_images) { for (auto &pair : egl_images) {
@ -226,7 +226,7 @@ void CameraWidget::paintGL() {
glUseProgram(program->programId()); glUseProgram(program->programId());
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
#ifdef QCOM2 #ifdef __TICI__
// no frame copy // no frame copy
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_images[frame->idx]); glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, egl_images[frame->idx]);
@ -263,7 +263,7 @@ void CameraWidget::vipcConnected(VisionIpcClient *vipc_client) {
stream_height = vipc_client->buffers[0].height; stream_height = vipc_client->buffers[0].height;
stream_stride = vipc_client->buffers[0].stride; stream_stride = vipc_client->buffers[0].stride;
#ifdef QCOM2 #ifdef __TICI__
EGLDisplay egl_display = eglGetCurrentDisplay(); EGLDisplay egl_display = eglGetCurrentDisplay();
assert(egl_display != EGL_NO_DISPLAY); assert(egl_display != EGL_NO_DISPLAY);
for (auto &pair : egl_images) { for (auto &pair : egl_images) {

@ -13,7 +13,7 @@
#include <QOpenGLWidget> #include <QOpenGLWidget>
#include <QThread> #include <QThread>
#ifdef QCOM2 #ifdef __TICI__
#define EGL_EGLEXT_PROTOTYPES #define EGL_EGLEXT_PROTOTYPES
#define EGL_NO_X11 #define EGL_NO_X11
#define GL_TEXTURE_EXTERNAL_OES 0x8D65 #define GL_TEXTURE_EXTERNAL_OES 0x8D65
@ -63,7 +63,7 @@ protected:
std::unique_ptr<QOpenGLShaderProgram> program; std::unique_ptr<QOpenGLShaderProgram> program;
QColor bg = QColor("#000000"); QColor bg = QColor("#000000");
#ifdef QCOM2 #ifdef __TICI__
std::map<int, EGLImageKHR> egl_images; std::map<int, EGLImageKHR> egl_images;
#endif #endif

@ -1,6 +1,6 @@
Import('env', 'arch', 'messaging', 'common', 'gpucommon', 'visionipc') Import('env', 'arch', 'messaging', 'common', 'visionipc')
libs = [common, 'OpenCL', messaging, visionipc, gpucommon] libs = [common, 'OpenCL', messaging, visionipc]
if arch != "Darwin": if arch != "Darwin":
camera_obj = env.Object(['cameras/camera_qcom2.cc', 'cameras/camera_common.cc', 'cameras/spectra.cc', camera_obj = env.Object(['cameras/camera_qcom2.cc', 'cameras/camera_common.cc', 'cameras/spectra.cc',

@ -12,7 +12,7 @@
#include <string> #include <string>
#include <vector> #include <vector>
#ifdef QCOM2 #ifdef __TICI__
#include "CL/cl_ext_qcom.h" #include "CL/cl_ext_qcom.h"
#else #else
#define CL_PRIORITY_HINT_HIGH_QCOM NULL #define CL_PRIORITY_HINT_HIGH_QCOM NULL

@ -5,7 +5,7 @@
#include "system/hardware/base.h" #include "system/hardware/base.h"
#include "common/util.h" #include "common/util.h"
#if QCOM2 #if __TICI__
#include "system/hardware/tici/hardware.h" #include "system/hardware/tici/hardware.h"
#define Hardware HardwareTici #define Hardware HardwareTici
#else #else

@ -3,7 +3,7 @@
#include "system/loggerd/loggerd.h" #include "system/loggerd/loggerd.h"
#include "system/loggerd/encoder/jpeg_encoder.h" #include "system/loggerd/encoder/jpeg_encoder.h"
#ifdef QCOM2 #ifdef __TICI__
#include "system/loggerd/encoder/v4l_encoder.h" #include "system/loggerd/encoder/v4l_encoder.h"
#define Encoder V4LEncoder #define Encoder V4LEncoder
#else #else

Loading…
Cancel
Save