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

Support building and running on macOS #572

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ CFLAGS := -iquote $(OUT) -iquote src -iquote $(OUT)board-generic/ \
-Wold-style-definition $(call cc-option,$(CC),-Wtype-limits,) \
-ffunction-sections -fdata-sections -fno-delete-null-pointer-checks
CFLAGS += -flto=auto -fwhole-program -fno-use-linker-plugin -ggdb3
CFLAGS += $(EXTRA_CFLAGS)

ifeq ($(CONFIG_WANT_OPTIMIZE_SIZE), y)
CFLAGS += -Os
Expand Down
4 changes: 4 additions & 0 deletions klippy/chelper/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
#ifndef __always_inline
#define __always_inline inline __attribute__((always_inline))
#endif
#if !defined(clang)
#define __visible __attribute__((externally_visible))
#else
#define __visible __attribute__((visibility("default")))
#endif
#define __noreturn __attribute__((noreturn))

#define PACKED __attribute__((packed))
Expand Down
10 changes: 10 additions & 0 deletions klippy/chelper/serialqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
// clock times, prioritizes commands, and handles retransmissions. A
// background thread is launched to do this work and minimize latency.

#ifndef __APPLE__
#include <linux/can.h> // // struct can_frame
#endif
#include <math.h> // fabs
#include <pthread.h> // pthread_mutex_lock
#include <stddef.h> // offsetof
Expand Down Expand Up @@ -300,6 +302,7 @@ static void
input_event(struct serialqueue *sq, double eventtime)
{
if (sq->serial_fd_type == SQT_CAN) {
#ifndef __APPLE__
struct can_frame cf;
int ret = read(sq->serial_fd, &cf, sizeof(cf));
if (ret <= 0) {
Expand All @@ -311,6 +314,9 @@ input_event(struct serialqueue *sq, double eventtime)
return;
memcpy(&sq->input_buf[sq->input_pos], cf.data, cf.can_dlc);
sq->input_pos += cf.can_dlc;
#else
exit(1);
#endif
} else {
int ret = read(sq->serial_fd, &sq->input_buf[sq->input_pos]
, sizeof(sq->input_buf) - sq->input_pos);
Expand Down Expand Up @@ -366,6 +372,7 @@ do_write(struct serialqueue *sq, void *buf, int buflen)
report_errno("write", ret);
return;
}
#ifndef __APPLE__
// Write to CAN fd
struct can_frame cf;
while (buflen) {
Expand All @@ -389,6 +396,9 @@ do_write(struct serialqueue *sq, void *buf, int buflen)
buf += size;
buflen -= size;
}
#else
exit(1);
#endif
}

// Callback timer for when a retransmit should be done
Expand Down
5 changes: 5 additions & 0 deletions scripts/check-gcc.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#!/bin/sh
# This script checks for a broken Ubuntu 18.04 arm-none-eabi-gcc compile

if [ ! -f /etc/issue ] ; then
# doesn't exist on mac
exit 0
fi

f1="$1"
f2="$2"

Expand Down
Loading