Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scons: SConscript/SConstruct refactor #29207

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6912f55
Rename arch to target. Rename target specific third party dependencies
fredyshox Aug 1, 2023
914335e
Enable replay/cabana on linux-aarch64
fredyshox Aug 1, 2023
bbf12c8
Update submodules
fredyshox Aug 2, 2023
4f4ef55
Update pc files
fredyshox Aug 2, 2023
d0cc4f7
Add missing binaries
fredyshox Aug 2, 2023
d138f4b
Remove libyuv include symlink
fredyshox Aug 2, 2023
d905176
Add missing newline
fredyshox Aug 2, 2023
6efccdf
Rename larch64 to agnos-aarch64
fredyshox Aug 2, 2023
ac4172c
Rename prebuilt tici-specific spinner and text binaries
fredyshox Aug 2, 2023
4a14337
Add json11 dependency to every common dependent module
fredyshox Aug 2, 2023
f25f495
Update submodules
fredyshox Aug 2, 2023
c2a5202
Remove duplicate dependencies from proclogd
fredyshox Aug 2, 2023
0787777
Update submodules
fredyshox Aug 3, 2023
a5dee52
Change libs order
fredyshox Aug 3, 2023
0460523
Merge remote-tracking branch 'origin/master' into sconscript-refactor
fredyshox Aug 26, 2023
eb833c0
Merge branch 'master' into sconscript-refactor
fredyshox Aug 26, 2023
2f33078
Fix condition
fredyshox Aug 26, 2023
44c8631
Fix missing json11 references
fredyshox Aug 26, 2023
e049603
Update submodules
fredyshox Aug 26, 2023
ee2956a
Merge branch 'master' into sconscript-refactor
fredyshox Aug 26, 2023
4ec6047
Update submodules
fredyshox Aug 30, 2023
5e0c0fe
Merge remote-tracking branch 'origin/master' into sconscript-refactor
fredyshox Aug 30, 2023
e252771
Fix compilation condition for tools
fredyshox Aug 30, 2023
fce9cf4
Add widget src for lupdate
fredyshox Aug 30, 2023
9c1d610
Merge branch 'master' into sconscript-refactor
fredyshox Aug 30, 2023
c678145
Merge branch 'master' into sconscript-refactor
fredyshox Aug 30, 2023
2fa44c3
Fix common sconscript
fredyshox Aug 30, 2023
e72a50e
Merge branch 'master' into sconscript-refactor
fredyshox Aug 31, 2023
67edb84
Merge branch 'master' into sconscript-refactor
fredyshox Sep 2, 2023
b07d9a9
updates to modeld scons
fredyshox Sep 2, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 78 additions & 105 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -55,53 +55,57 @@ AddOption('--minimal',
default=os.path.islink(Dir('#laika/').abspath),
help='the minimum build to run openpilot. no tests, tools, etc.')

## Architecture name breakdown (arch)
## - larch64: linux tici aarch64
## - 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":
arch = "Darwin"
# *** Target and Architecture

## Target name breakdown (target)
## - agnos-aarch64: linux tici aarch64
Copy link
Contributor Author

@fredyshox fredyshox Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adeebshihadeh what do you think about replacing slightly ambiguous larch64 with agnos-aarch64 for TICI platform target?

## - linux-aarch64: linux pc aarch64
## - linux-x86_64: linux pc x64
## - Darwin: mac x64 or arm64
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
system = platform.system()
if system == "Darwin":
target = "Darwin"
brew_prefix = subprocess.check_output(['brew', '--prefix'], encoding='utf8').strip()
elif arch == "aarch64" and AGNOS:
arch = "larch64"
assert arch in ["larch64", "aarch64", "x86_64", "Darwin"]
elif system == "Linux":
if arch == "aarch64" and AGNOS:
target = "agnos-aarch64"
else:
target = f"linux-{arch}"
else:
raise Exception(f"Unsupported platform: {system}")

assert target in ["agnos-aarch64", "linux-aarch64", "linux-x86_64", "Darwin"]

# *** Environment setup
lenv = {
"PATH": os.environ['PATH'],
"LD_LIBRARY_PATH": [Dir(f"#third_party/acados/{arch}/lib").abspath],
"LD_LIBRARY_PATH": [Dir(f"#third_party/acados/{target}/lib").abspath],
"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"
"TERA_PATH": Dir("#").abspath + f"/third_party/acados/{target}/t_renderer"
}

rpath = lenv["LD_LIBRARY_PATH"].copy()

if arch == "larch64":
lenv["LD_LIBRARY_PATH"] += ['/data/data/com.termux/files/usr/lib']

if target == "agnos-aarch64":
cflags = ["-DQCOM2", "-mcpu=cortex-a57"]
cxxflags = ["-DQCOM2", "-mcpu=cortex-a57"]
cpppath = [
"#third_party/opencl/include",
]

libpath = [
"#third_party/acados/agnos-aarch64/lib",
"#third_party/snpe/agnos-aarch64",
"#third_party/libyuv/agnos-aarch64/lib",
"/usr/local/lib",
"/usr/lib",
"/system/vendor/lib64",
f"#third_party/acados/{arch}/lib",
]

libpath += [
"#third_party/snpe/larch64",
"#third_party/libyuv/larch64/lib",
"/usr/lib/aarch64-linux-gnu"
]
cflags = ["-DQCOM2", "-mcpu=cortex-a57"]
cxxflags = ["-DQCOM2", "-mcpu=cortex-a57"]
rpath += ["/usr/local/lib"]
lenv["LD_LIBRARY_PATH"] += ['/data/data/com.termux/files/usr/lib']
else:
cflags = []
cxxflags = []
Expand All @@ -112,10 +116,10 @@ else:
]

# MacOS
if arch == "Darwin":
if target == "Darwin":
libpath = [
f"#third_party/libyuv/{arch}/lib",
f"#third_party/acados/{arch}/lib",
f"#third_party/libyuv/{target}/lib",
f"#third_party/acados/{target}/lib",
f"{brew_prefix}/lib",
f"{brew_prefix}/opt/[email protected]/lib",
"/System/Library/Frameworks/OpenGL.framework/Libraries",
Expand All @@ -131,21 +135,19 @@ else:
# Linux
else:
libpath = [
f"#third_party/acados/{arch}/lib",
f"#third_party/libyuv/{arch}/lib",
f"#third_party/mapbox-gl-native-qt/{arch}",
"#cereal",
"#common",
"/usr/lib",
f"#third_party/acados/{target}/lib",
f"#third_party/libyuv/{target}/lib",
f"#third_party/mapbox-gl-native-qt/{target}",
"/usr/local/lib",
"/usr/lib",
]

if arch == "x86_64":
if target == "linux-x86_64":
libpath += [
f"#third_party/snpe/{arch}"
f"#third_party/snpe/{target}"
]
rpath += [
Dir(f"#third_party/snpe/{arch}").abspath,
Dir(f"#third_party/snpe/{target}").abspath,
]

if GetOption('asan'):
Expand All @@ -158,11 +160,11 @@ else:
ccflags = []
ldflags = []

# no --as-needed on mac linker
if arch != "Darwin":
## no --as-needed on mac linker
if target != "Darwin":
ldflags += ["-Wl,--as-needed", "-Wl,--no-undefined"]

# Enable swaglog include in submodules
## Enable swaglog include in submodules
cflags += ['-DSWAGLOG="\\"common/swaglog.h\\""']
cxxflags += ['-DSWAGLOG="\\"common/swaglog.h\\""']

Expand Down Expand Up @@ -221,19 +223,20 @@ env = Environment(
tools=["default", "cython", "compilation_db"],
)

if arch == "Darwin":
# RPATH is not supported on macOS, instead use the linker flags
darwin_rpath_link_flags = [f"-Wl,-rpath,{path}" for path in env["RPATH"]]
env["LINKFLAGS"] += darwin_rpath_link_flags
## RPATH is not supported on macOS, instead use the linker flags
if target == "Darwin":
Darwin_rpath_link_flags = [f"-Wl,-rpath,{path}" for path in env["RPATH"]]
env["LINKFLAGS"] += Darwin_rpath_link_flags

if GetOption('compile_db'):
env.CompilationDatabase('compile_commands.json')

# Setup cache dir
## Setup cache dir
cache_dir = '/data/scons_cache' if AGNOS else '/tmp/scons_cache'
CacheDir(cache_dir)
Clean(["."], cache_dir)

## Setup optional progress bar
node_interval = 5
node_count = 0
def progress_function(node):
Expand All @@ -244,39 +247,25 @@ def progress_function(node):
if os.environ.get('SCONS_PROGRESS'):
Progress(progress_function, interval=node_interval)

SHARED = False

# TODO: this can probably be removed
def abspath(x):
if arch == 'aarch64':
pth = os.path.join("/data/pythonpath", x[0].path)
env.Depends(pth, x)
return File(pth)
else:
# rpath works elsewhere
return x[0].path.rsplit("/", 1)[1][:-3]

# Cython build environment
# *** Cython build environment
py_include = sysconfig.get_paths()['include']
envCython = env.Clone()
envCython["CPPPATH"] += [py_include, np.get_include()]
envCython["CCFLAGS"] += ["-Wno-#warnings", "-Wno-shadow", "-Wno-deprecated-declarations"]
envCython["CCFLAGS"].remove("-Werror")

envCython["LIBS"] = []
if arch == "Darwin":
envCython["LINKFLAGS"] = ["-bundle", "-undefined", "dynamic_lookup"] + darwin_rpath_link_flags
if target == "Darwin":
envCython["LINKFLAGS"] = ["-bundle", "-undefined", "dynamic_lookup"] + Darwin_rpath_link_flags
else:
envCython["LINKFLAGS"] = ["-pthread", "-shared"]

Export('envCython')

# Qt build environment
# *** Qt build environment
qt_env = env.Clone()
qt_modules = ["Widgets", "Gui", "Core", "Network", "Concurrent", "Multimedia", "Quick", "Qml", "QuickWidgets", "Location", "Positioning", "DBus", "Xml"]

qt_libs = []
if arch == "Darwin":
if target == "Darwin":
qt_env['QTDIR'] = f"{brew_prefix}/opt/qt@5"
qt_dirs = [
os.path.join(qt_env['QTDIR'], "include"),
Expand All @@ -296,15 +285,13 @@ else:
]
qt_dirs += [f"{qt_install_headers}/Qt{m}" for m in qt_modules]

qt_libs = [f"Qt5{m}" for m in qt_modules]
if arch == "larch64":
qt_libs = [f"Qt5{m}" for m in qt_modules] + ["GL"]
if target == "agnos-aarch64":
qt_libs += ["GLESv2", "wayland-client"]
qt_env.PrependENVPath('PATH', Dir("#third_party/qt5/larch64/bin/").abspath)
elif arch != "Darwin":
qt_libs += ["GL"]
qt_env.PrependENVPath('PATH', Dir("#third_party/qt5/agnos-aarch64/bin/").abspath)
qt_env['QT3DIR'] = qt_env['QTDIR']

# compatibility for older SCons versions
## compatibility for older SCons versions
try:
qt_env.Tool('qt3')
except SCons.Errors.UserError:
Expand Down Expand Up @@ -337,34 +324,29 @@ if GetOption("clazy"):
qt_env['ENV']['CLAZY_IGNORE_DIRS'] = qt_dirs[0]
qt_env['ENV']['CLAZY_CHECKS'] = ','.join(checks)

Export('env', 'qt_env', 'arch', 'real_arch', 'SHARED')
# *** Export environments and global variables
Export('env', 'envCython', 'qt_env', 'target', 'system', 'arch')

# *** Build common code
SConscript(['common/SConscript'])
Import('_common', '_gpucommon')

if SHARED:
common, gpucommon = abspath(common), abspath(gpucommon)
else:
common = [_common, 'json11']
gpucommon = [_gpucommon]

Export('common', 'gpucommon')

# cereal and messaging are shared with the system
# *** Build cereal and messaging
SConscript(['cereal/SConscript'])
if SHARED:
cereal = abspath([File('cereal/libcereal_shared.so')])
messaging = abspath([File('cereal/libmessaging_shared.so')])
else:
cereal = [File('#cereal/libcereal.a')]
messaging = [File('#cereal/libmessaging.a')]
visionipc = [File('#cereal/libvisionipc.a')]
messaging_python = [File('#cereal/messaging/messaging_pyx.so')]

cereal = [File('#cereal/libcereal.a')]
messaging = [File('#cereal/libmessaging.a')]
messaging_python = [File('#cereal/messaging/messaging_pyx.so')]
visionipc = [File('#cereal/libvisionipc.a')]
Export('cereal', 'messaging', 'messaging_python', 'visionipc')

# Build rednose library and ekf models
# *** Build other submodules
SConscript([
'body/board/SConscript',
'opendbc/can/SConscript',
'panda/SConscript',
])

# *** Build rednose library and ekf models
rednose_deps = [
"#selfdrive/locationd/models/constants.py",
"#selfdrive/locationd/models/gnss_helpers.py",
Expand All @@ -379,7 +361,7 @@ rednose_config = {
},
}

if arch != "larch64":
if target != "agnos-aarch64":
rednose_config['to_build'].update({
'loc_4': ('#selfdrive/locationd/models/loc_kf.py', True, [], rednose_deps),
'lane': ('#selfdrive/locationd/models/lane_kf.py', True, [], rednose_deps),
Expand All @@ -391,30 +373,21 @@ if arch != "larch64":
Export('rednose_config')
SConscript(['rednose/SConscript'])

# Build system services
# *** Build system services
SConscript([
'system/clocksd/SConscript',
'system/proclogd/SConscript',
'system/ubloxd/SConscript',
'system/loggerd/SConscript',
])
if arch != "Darwin":
if target != "Darwin":
SConscript([
'system/camerad/SConscript',
'system/sensord/SConscript',
'system/logcatd/SConscript',
])

# Build openpilot

# build submodules
SConscript([
'body/board/SConscript',
'cereal/SConscript',
'opendbc/can/SConscript',
'panda/SConscript',
])

# *** Build openpilot
SConscript(['third_party/SConscript'])

SConscript(['selfdrive/boardd/SConscript'])
Expand All @@ -425,7 +398,7 @@ SConscript(['selfdrive/navd/SConscript'])
SConscript(['selfdrive/modeld/SConscript'])
SConscript(['selfdrive/ui/SConscript'])

if arch in ['x86_64', 'aarch64', 'Darwin'] and Dir('#tools/cabana/').exists() and GetOption('extras'):
if (target in ['linux-x86_64', 'linux-aarch64', 'Darwin'] and Dir('#tools/cabana/').exists()) and GetOption('extras'):
SConscript(['tools/replay/SConscript'])
SConscript(['tools/cabana/SConscript'])

Expand Down
2 changes: 1 addition & 1 deletion cereal
32 changes: 13 additions & 19 deletions common/SConscript
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
Import('env', 'envCython', 'arch', 'SHARED')

if SHARED:
fxn = env.SharedLibrary
else:
fxn = env.Library
Import('env', 'envCython', 'target')

# *** common
common_libs = [
'params.cc',
'statlog.cc',
Expand All @@ -14,26 +10,24 @@ common_libs = [
'watchdog.cc',
'ratekeeper.cc'
]

if arch != "Darwin":
if target != "Darwin":
common_libs.append('gpio.cc')

_common = fxn('common', common_libs, LIBS="json11")
common = env.Library('common', common_libs, LIBS="json11")

files = [
# *** gpucommon
gpucommon_files = [
'clutil.cc',
]
gpucommon = env.Library('gpucommon', gpucommon_files)

_gpucommon = fxn('gpucommon', files)
Export('_common', '_gpucommon')

# *** tests
if GetOption('extras'):
env.Program('tests/test_common',
['tests/test_runner.cc', 'tests/test_util.cc', 'tests/test_swaglog.cc', 'tests/test_ratekeeper.cc'],
LIBS=[_common, 'json11', 'zmq', 'pthread'])
test_files = ['tests/test_runner.cc', 'tests/test_util.cc', 'tests/test_swaglog.cc', 'tests/test_ratekeeper.cc']
env.Program('tests/test_common', test_files, LIBS=[common, 'json11', 'zmq', 'pthread'])

# Cython bindings
params_python = envCython.Program('params_pyx.so', 'params_pyx.pyx', LIBS=envCython['LIBS'] + [_common, 'zmq', 'json11'])
# *** cython bindings
params_python = envCython.Program('params_pyx.so', 'params_pyx.pyx', LIBS=envCython['LIBS'] + [common, 'zmq', 'json11'])

SConscript([
'kalman/SConscript',
Expand All @@ -43,4 +37,4 @@ SConscript([
Import('simple_kalman_python', 'transformations_python')
common_python = [params_python, simple_kalman_python, transformations_python]

Export('common_python')
Export('common', 'gpucommon', 'common_python')
2 changes: 1 addition & 1 deletion opendbc
Submodule opendbc updated 3 files
+1 −1 Dockerfile
+9 −7 SConstruct
+4 −1 can/SConscript
2 changes: 1 addition & 1 deletion rednose_repo
Loading
Loading