Support scons build on Mac (#1034)

* fix clock and add Darwin sconstruct

* it builds, this changes should be simplifications too

* fix boardd build

* that's the real type of EGLClientBuffer

* remove extra lines

* ui needs opencl on phone

old-commit-hash: f72f78f2b9
commatwo_master
George Hotz 5 years ago committed by GitHub
parent 0d0f17aad2
commit b846f88ade
  1. 50
      SConstruct
  2. 12
      common/clock.pyx
  3. 15
      selfdrive/boardd/boardd_setup.py
  4. 2
      selfdrive/common/framebuffer.h
  5. 2
      selfdrive/common/glutil.c
  6. 15
      selfdrive/common/glutil.h
  7. 4
      selfdrive/common/util.h
  8. 7
      selfdrive/common/visionimg.h
  9. 1
      selfdrive/locationd/paramsd.cc
  10. 1
      selfdrive/locationd/ubloxd_main.cc
  11. 10
      selfdrive/ui/SConscript
  12. 13
      selfdrive/ui/linux.cc
  13. 2
      selfdrive/ui/paint.cc
  14. 13
      selfdrive/ui/ui.hpp

@ -1,6 +1,7 @@
import os
import subprocess
import sys
import platform
AddOption('--test',
action='store_true',
@ -11,6 +12,8 @@ AddOption('--asan',
help='turn on ASAN')
arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin":
arch = "Darwin"
if arch == "aarch64":
lenv = {
@ -48,20 +51,33 @@ else:
"#phonelibs/zmq/x64/include",
"#external/tensorflow/include",
]
libpath = [
"#phonelibs/capnp-cpp/x64/lib",
"#phonelibs/capnp-c/x64/lib",
"#phonelibs/yaml-cpp/x64/lib",
"#phonelibs/snpe/x86_64-linux-clang",
"#phonelibs/zmq/x64/lib",
"#phonelibs/libyuv/x64/lib",
"#external/zmq/lib",
"#external/tensorflow/lib",
"#cereal",
"#selfdrive/common",
"/usr/lib",
"/usr/local/lib",
]
if arch == "Darwin":
libpath = [
"#phonelibs/capnp-cpp/mac/lib",
"#phonelibs/capnp-c/mac/lib",
"#phonelibs/yaml-cpp/mac/lib",
"#phonelibs/libyuv/mac/lib",
"#cereal",
"#selfdrive/common",
"/usr/local/lib",
"/System/Library/Frameworks/OpenGL.framework/Libraries",
]
else:
libpath = [
"#phonelibs/capnp-cpp/x64/lib",
"#phonelibs/capnp-c/x64/lib",
"#phonelibs/yaml-cpp/x64/lib",
"#phonelibs/snpe/x86_64-linux-clang",
"#phonelibs/zmq/x64/lib",
"#phonelibs/libyuv/x64/lib",
"#external/zmq/lib",
"#external/tensorflow/lib",
"#cereal",
"#selfdrive/common",
"/usr/lib",
"/usr/local/lib",
]
rpath = ["phonelibs/capnp-cpp/x64/lib",
"external/tensorflow/lib",
@ -195,8 +211,10 @@ SConscript(['common/SConscript'])
SConscript(['common/kalman/SConscript'])
SConscript(['phonelibs/SConscript'])
SConscript(['selfdrive/modeld/SConscript'])
SConscript(['selfdrive/camerad/SConscript'])
if arch != "Darwin":
SConscript(['selfdrive/camerad/SConscript'])
SConscript(['selfdrive/modeld/SConscript'])
SConscript(['selfdrive/controls/lib/cluster/SConscript'])
SConscript(['selfdrive/controls/lib/lateral_mpc/SConscript'])
SConscript(['selfdrive/controls/lib/longitudinal_mpc/SConscript'])

@ -1,6 +1,12 @@
from posix.time cimport clock_gettime, timespec, CLOCK_BOOTTIME, CLOCK_MONOTONIC_RAW
from posix.time cimport clock_gettime, timespec, CLOCK_MONOTONIC_RAW, clockid_t
cdef double readclock(int clock_id):
IF UNAME_SYSNAME == "Darwin":
# Darwin doesn't have a CLOCK_BOOTTIME
CLOCK_BOOTTIME = CLOCK_MONOTONIC_RAW
ELSE:
from posix.time cimport CLOCK_BOOTTIME
cdef double readclock(clockid_t clock_id):
cdef timespec ts
cdef double current
@ -8,9 +14,9 @@ cdef double readclock(int clock_id):
current = ts.tv_sec + (ts.tv_nsec / 1000000000.)
return current
def monotonic_time():
return readclock(CLOCK_MONOTONIC_RAW)
def sec_since_boot():
return readclock(CLOCK_BOOTTIME)

@ -1,4 +1,5 @@
import subprocess
import platform
from distutils.core import Extension, setup
from Cython.Build import cythonize
@ -10,14 +11,24 @@ import os
PHONELIBS = os.path.join(BASEDIR, 'phonelibs')
ARCH = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
ARCH_DIR = 'x64' if ARCH == "x86_64" else 'aarch64'
if ARCH == "x86_64":
if platform.system() == "Darwin":
libraries = ['can_list_to_can_capnp', 'capnp', 'kj']
ARCH_DIR = 'mac'
else:
libraries = [':libcan_list_to_can_capnp.a', ':libcapnp.a', ':libkj.a']
ARCH_DIR = 'x64'
else:
libraries = [':libcan_list_to_can_capnp.a', 'capnp', 'kj']
ARCH_DIR = 'aarch64'
setup(name='Boardd API Implementation',
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
ext_modules=cythonize(
Extension(
"boardd_api_impl",
libraries=[':libcan_list_to_can_capnp.a', ':libcapnp.a', ':libkj.a'] if ARCH == "x86_64" else [':libcan_list_to_can_capnp.a', 'capnp', 'kj'],
libraries=libraries,
library_dirs=[
'./',
PHONELIBS + '/capnp-cpp/' + ARCH_DIR + '/lib/',

@ -1,8 +1,6 @@
#ifndef FRAMEBUFFER_H
#define FRAMEBUFFER_H
#include <EGL/eglext.h>
#ifdef __cplusplus
extern "C" {
#endif

@ -1,8 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include <GLES3/gl3.h>
#include "glutil.h"
GLuint load_shader(GLenum shaderType, const char *src) {

@ -1,8 +1,21 @@
#ifndef COMMON_GLUTIL_H
#define COMMON_GLUTIL_H
#include <GLES3/gl3.h>
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#else
#include <GLES3/gl3.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
GLuint load_shader(GLenum shaderType, const char *src);
GLuint load_program(const char *vert_src, const char *frag_src);
#ifdef __cplusplus
}
#endif
#endif

@ -3,6 +3,10 @@
#include <stdio.h>
#ifndef sighandler_t
typedef void (*sighandler_t)(int sig);
#endif
#ifndef __cplusplus
#define min(a,b) \

@ -2,11 +2,16 @@
#define VISIONIMG_H
#include "common/visionbuf.h"
#include "common/glutil.h"
#include <GLES3/gl3.h>
#ifdef QCOM
#include <EGL/egl.h>
#include <EGL/eglext.h>
#undef Status
#else
typedef int EGLImageKHR;
typedef void *EGLClientBuffer;
#endif
#ifdef __cplusplus
extern "C" {

@ -20,6 +20,7 @@
#include "locationd_yawrate.h"
#include "params_learner.h"
#include "common/util.h"
void sigpipe_handler(int sig) {
LOGE("SIGPIPE received");

@ -19,6 +19,7 @@
#include <capnp/serialize.h>
#include "cereal/gen/cpp/log.capnp.h"
#include "common/util.h"
#include "common/params.h"
#include "common/swaglog.h"
#include "common/timing.h"

@ -1,15 +1,17 @@
Import('env', 'arch', 'common', 'messaging', 'gpucommon', 'visionipc', 'cereal')
src = ['ui.cc', 'paint.cc', '#phonelibs/nanovg/nanovg.c']
libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, 'json', messaging, 'OpenCL', gpucommon, visionipc]
libs = [common, 'zmq', 'czmq', 'capnp', 'capnp_c', 'm', cereal, 'json', messaging, gpucommon, visionipc]
if arch == "aarch64":
src += ['sound.cc', 'slplay.c']
libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', 'ui', 'CB', 'gsl', 'adreno_utils', 'OpenSLES', 'cutils', 'uuid']
libs += ['EGL', 'GLESv3', 'gnustl_shared', 'log', 'utils', 'gui', 'hardware', 'ui', 'CB', 'gsl', 'adreno_utils', 'OpenSLES', 'cutils', 'uuid', 'OpenCL']
linkflags = ['-Wl,-rpath=/system/lib64,-rpath=/system/comma/usr/lib']
else:
src += ['linux.cc']
libs += ['EGL', 'pthread', 'X11-xcb', 'xcb', 'X11', 'glfw']
libs += ['pthread', 'glfw']
linkflags = []
env.Program('_ui', src,
LINKFLAGS=['-Wl,-rpath=/system/lib64,-rpath=/system/comma/usr/lib'],
LINKFLAGS=linkflags,
LIBS=libs)

@ -6,19 +6,18 @@
#include "ui.hpp"
#ifndef __APPLE__
#define GLFW_INCLUDE_ES2
#else
#define GLFW_INCLUDE_GLCOREARB
#endif
#define GLFW_INCLUDE_GLEXT
#include <GLFW/glfw3.h>
typedef struct FramebufferState FramebufferState;
typedef struct TouchState TouchState;
#define FALSE 0
#define TRUE 1
#include <xcb/xcb.h>
#include <X11/Xlib-xcb.h>
extern "C" {
FramebufferState* framebuffer_init(
@ -90,7 +89,7 @@ GLuint visionimg_to_gl(const VisionImg *img, EGLImageKHR *pkhr, void **pph) {
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, img->width, img->height, 0, GL_RGB, GL_UNSIGNED_BYTE, *pph);
glGenerateMipmap(GL_TEXTURE_2D);
*pkhr = (EGLImageKHR *)1; // not NULL
*pkhr = (EGLImageKHR)1; // not NULL
return texture;
}

@ -951,7 +951,7 @@ static const mat4 full_to_wide_frame_transform = {{
void ui_nvg_init(UIState *s) {
// init drawing
s->vg = nvgCreateGLES3(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
s->vg = nvgCreate(NVG_ANTIALIAS | NVG_STENCIL_STROKES | NVG_DEBUG);
assert(s->vg);
s->font_courbd = nvgCreateFont(s->vg, "courbd", "../assets/fonts/courbd.ttf");

@ -1,13 +1,24 @@
#ifndef _UI_H
#define _UI_H
#ifdef __APPLE__
#include <OpenGL/gl3.h>
#define NANOVG_GL3_IMPLEMENTATION
#define nvgCreate nvgCreateGL3
#else
#include <GLES3/gl3.h>
#include <EGL/egl.h>
#define NANOVG_GLES3_IMPLEMENTATION
#define nvgCreate nvgCreateGLES3
#endif
#include <pthread.h>
#include "nanovg.h"
#include "common/mat.h"
#include "common/visionipc.h"
#include "common/visionimg.h"
#include "common/framebuffer.h"
#include "common/modeldata.h"
#include "messaging.hpp"
@ -141,8 +152,6 @@ typedef struct UIState {
// framebuffer
FramebufferState *fb;
int fb_w, fb_h;
EGLDisplay display;
EGLSurface surface;
// NVG
NVGcontext *vg;

Loading…
Cancel
Save