add command code constants, send header

This commit is contained in:
Vinzenz Schroeter 2025-04-12 21:47:23 +02:00
parent f193c659b9
commit ce70ecd9e2
12 changed files with 141 additions and 60 deletions

View file

@ -1,9 +1,12 @@
CC := gcc
CARGO := rustup run nightly cargo
TARGET := x86_64-unknown-linux-musl
PROFILE := size-optimized
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
REPO_ROOT := $(THIS_DIR)/..
RUST_TARGET_DIR := $(REPO_ROOT)/target/x86_64-unknown-linux-musl/size-optimized
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(PROFILE)
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
RUSTFLAGS := -Zlocation-detail=none \
@ -17,9 +20,9 @@ RUSTFLAGS := -Zlocation-detail=none \
-C panic=abort
CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \
--profile=size-optimized \
--profile=$(PROFILE) \
--no-default-features \
--target=x86_64-unknown-linux-musl \
--target=$(TARGET) \
-Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
-Zbuild-std-features="panic_immediate_abort" \
@ -45,23 +48,23 @@ CCFLAGS := -static -Os \
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag
c_src := $(wildcard *.c)
programs := $(basename $(c_src))
bins := $(addprefix out/, $(programs))
unstripped_bins := $(addsuffix _unstripped, $(bins))
run_programs := $(addprefix run_, $(programs))
rs_src := $(wildcard ../src/*.rs) ../Cargo.lock
_c_src := $(wildcard *.c)
_programs := $(basename $(_c_src))
_bins := $(addprefix out/, $(_programs))
_unstripped_bins := $(addsuffix _unstripped, $(_bins))
_run_programs := $(addprefix run_, $(_programs))
_rs_src := $(wildcard ../src/**.rs) ../Cargo.lock
all: $(bins)
all: $(_bins)
clean:
rm -r out || true
rm include/servicepoint.h || true
cargo clean
PHONY: all clean sizes $(run_programs)
PHONY: all clean sizes $(_run_programs)
$(unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
$(_unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
mkdir -p out || true
${CC} $^ \
-I $(SERVICEPOINT_HEADER_OUT) \
@ -69,18 +72,18 @@ $(unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoin
$(CCFLAGS) \
-o $@
$(bins): out/%: out/%_unstripped
$(_bins): out/%: out/%_unstripped
strip $(STRIPFLAGS) $^ -o $@
$(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a: $(rs_src)
$(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a: $(_rs_src)
mkdir -p include || true
# generate servicepoint header and binary to link against
${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS)
$(run_programs): run_%: out/% FORCE
$(_run_programs): run_%: out/% FORCE
./$<
sizes: $(bins)
sizes: $(_bins)
ls -lB out
#analyze-size: out/example_unstripped
@ -88,6 +91,4 @@ sizes: $(bins)
# | awk '{size=$$2+0; print size "\t" $$4}' \
# | less
FORCE: ;

View file

@ -1,16 +1,17 @@
#include "servicepoint.h"
int main(void) {
UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
//UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
if (connection == NULL)
return 1;
sp_udp_send_command(connection, sp_command_clear());
sp_udp_send_header(connection, (Header) {.command_code = COMMAND_CODE_CLEAR});
CharGrid *grid = sp_char_grid_new(5, 2);
if (grid == NULL)
return 1;
sp_char_grid_set(grid, 0, 0, 'H');
sp_char_grid_set(grid, 1, 0, 'e');
sp_char_grid_set(grid, 2, 0, 'l');
@ -22,7 +23,6 @@ int main(void) {
sp_char_grid_set(grid, 3, 1, 'l');
sp_char_grid_set(grid, 4, 1, 'd');
TypedCommand *command = sp_command_char_grid(0, 0, grid);
sp_udp_send_command(connection, command);