fix many configurations
Some checks failed
Rust / build (pull_request) Failing after 1m24s

This commit is contained in:
Vinzenz Schroeter 2025-05-03 19:15:20 +02:00
parent 04223022a2
commit 2f4124c0cd
6 changed files with 57 additions and 55 deletions

View file

@ -1,7 +1,7 @@
CARGO ?= rustup run nightly cargo CARGO ?= cargo
STRIP ?= strip STRIP ?= strip
FEATURES := protocol_udp FEATURES :=
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
REPO_ROOT := $(realpath $(THIS_DIR)/..) REPO_ROOT := $(realpath $(THIS_DIR)/..)
@ -10,42 +10,31 @@ export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0)) override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0))
override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release)) override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release))
CCFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wall -fwhole-program CCFLAGS += -Wall -fwhole-program
RUSTFLAGS += -C link-arg=-s \
-C link-arg=-Wl,--gc-sections \
--crate-type=staticlib
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag
ifeq ($(CFG_MUSL), 1) ifeq ($(CFG_MUSL), 1)
TARGET ?= x86_64-unknown-linux-musl TARGET ?= x86_64-unknown-linux-musl
CC ?= musl-gcc CC ?= musl-gcc
CCFLAGS += -static CCFLAGS += -static -lservicepoint_binding_c
RUSTFLAGS += --crate-type=staticlib
else else
TARGET ?= x86_64-unknown-linux-gnu TARGET ?= x86_64-unknown-linux-gnu
CC ?= gcc CC ?= gcc
CCFLAGS += -shared #CCFLAGS += -shared
CCFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic
endif endif
RUSTFLAGS += -C linker=$(CC)
#ifeq ($(CFG_PROFILE), size-optimized) #ifeq ($(CFG_PROFILE), size-optimized)
# CCFLAGS += -nodefaultlibs -lc # CCFLAGS += -nodefaultlibs -lc
#endif #endif
CCFLAGS += -lservicepoint_binding_c
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE) RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE)
OUT_BASE_DIR := $(realpath $(THIS_DIR)/out/) OUT_DIR := $(realpath $(THIS_DIR)/out/)
OUT_DIR := $(realpath $(OUT_BASE_DIR)/$(CFG_PROFILE)/)
CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
--profile=$(CFG_PROFILE) \
--no-default-features \
--features=$(FEATURES) \
--target=$(TARGET)
ifeq ($(CFG_PROFILE), size-optimized) ifeq ($(CFG_PROFILE), size-optimized)
CARGO_PROFILE := size-optimized
CCFLAGS += -Oz \ CCFLAGS += -Oz \
-fwrapv -fomit-frame-pointer -fno-stack-protector\ -fwrapv -fomit-frame-pointer -fno-stack-protector\
-fno-unroll-loops \ -fno-unroll-loops \
@ -63,16 +52,29 @@ ifeq ($(CFG_PROFILE), size-optimized)
RUSTFLAGS += -Zlocation-detail=none \ RUSTFLAGS += -Zlocation-detail=none \
-Zfmt-debug=none \ -Zfmt-debug=none \
-C link-arg=-z,norelro \ -C link-arg=-z,norelro \
-C link-arg=--hash-style=gnu \
-C panic=abort -C panic=abort
#-C link-arg=--hash-style=gnu
else ifeq ($(CFG_PROFILE), release) else ifeq ($(CFG_PROFILE), release)
CARGO_PROFILE := release
CCFLAGS += -O2 CCFLAGS += -O2
else ifeq ($(CFG_PROFILE), debug) else ifeq ($(CFG_PROFILE), debug)
CCFLAGS += -Og CCFLAGS += -Og
CARGO_PROFILE := dev
else else
CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized") CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized")
endif endif
CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
--profile=$(CARGO_PROFILE) \
--no-default-features \
--features=$(FEATURES) \
--target=$(TARGET)
ifneq ($(CFG_PROFILE), debug)
CCFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections
RUSTFLAGS += -C link-arg=-s -C link-arg=-Wl,--gc-sections
endif
ifeq ($(LTO), 1) ifeq ($(LTO), 1)
CCFLAGS += -flto CCFLAGS += -flto
endif endif
@ -87,12 +89,16 @@ _sp_artifacts := $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/li
all: $(_bins) all: $(_bins)
clean: clean: clean-c clean-rust
echo rm -r $(OUT_DIR) || true
clean-c:
rm -r $(OUT_DIR) || true
clean-rust:
rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true
cargo clean cargo clean
.PHONY: all clean sizes $(_run_programs) .PHONY: all clean sizes $(_run_programs) clean-c clean-rust
$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) $(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts)
mkdir -p out || true mkdir -p out || true
@ -116,7 +122,7 @@ $(_run_programs): run_%: out/% FORCE
sizes: $(_bins) sizes: $(_bins)
ls -lB out ls -lB out
analyze-size: $(OUT_DIR)/$(BIN)_unstripped analyze-size: out/$(BIN)_unstripped
nm --print-size --size-sort --reverse-sort --radix=d --demangle $(OUT_DIR)/$(BIN)_unstripped \ nm --print-size --size-sort --reverse-sort --radix=d --demangle $(OUT_DIR)/$(BIN)_unstripped \
| awk '{size=$$2+0; print size "\t" $$4}' \ | awk '{size=$$2+0; print size "\t" $$4}' \
| less | less

View file

@ -1,8 +1,12 @@
#include <stdio.h>
#include "servicepoint.h" #include "servicepoint.h"
int main(void) { int main(void) {
//UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); printf("test\n");
UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
UdpSocket *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
//UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
if (connection == NULL) if (connection == NULL)
return 1; return 1;

View file

@ -1,8 +1,8 @@
#include "servicepoint.h" #include "servicepoint.h"
int main(void) { int main(void) {
// UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); UdpSocket *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342);
UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); //UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
if (connection == NULL) if (connection == NULL)
return -1; return -1;

View file

@ -1,9 +1,7 @@
//#include <stdarg.h>
#include "servicepoint.h" #include "servicepoint.h"
//#include <stdio.h>
int main(void) { int main(void) {
UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
if (connection == NULL) if (connection == NULL)
return 1; return 1;

View file

@ -225,14 +225,7 @@ typedef struct SPBitVec SPBitVec;
*/ */
typedef struct TypedCommand TypedCommand; typedef struct TypedCommand TypedCommand;
/** typedef struct UdpSocket UdpSocket;
* A connection using the UDP protocol.
*
* Use this when sending commands directly to the display.
*
* Requires the feature "`protocol_udp`" which is enabled by default.
*/
typedef struct UdpConnection UdpConnection;
/** /**
* A 2D grid of values. * A 2D grid of values.
@ -298,7 +291,7 @@ typedef struct {
* grid.set(1, 1, Brightness::MIN); * grid.set(1, 1, Brightness::MIN);
* *
* # let connection = FakeConnection; * # let connection = FakeConnection;
* connection.send(BrightnessGridCommand { * connection.send_command(BrightnessGridCommand {
* origin: Origin::new(3, 7), * origin: Origin::new(3, 7),
* grid * grid
* }).unwrap() * }).unwrap()
@ -318,7 +311,7 @@ typedef ValueGrid_Brightness BrightnessGrid;
* *
* let b = Brightness::try_from(7).unwrap(); * let b = Brightness::try_from(7).unwrap();
* # let connection = FakeConnection; * # let connection = FakeConnection;
* let result = connection.send(GlobalBrightnessCommand::from(b)); * let result = connection.send_command(GlobalBrightnessCommand::from(b));
* ``` * ```
*/ */
typedef uint8_t Brightness; typedef uint8_t Brightness;
@ -347,7 +340,7 @@ typedef uint8_t Brightness;
* *
* # let connection = FakeConnection; * # let connection = FakeConnection;
* let command = CharGridCommand { origin: Origin::ZERO, grid }; * let command = CharGridCommand { origin: Origin::ZERO, grid };
* connection.send(command).unwrap() * connection.send_command(command).unwrap()
* ``` * ```
*/ */
typedef ValueGrid_char CharGrid; typedef ValueGrid_char CharGrid;
@ -1220,7 +1213,7 @@ bool sp_u16_to_command_code(uint16_t code,
/** /**
* Closes and deallocates a [UdpConnection]. * Closes and deallocates a [UdpConnection].
*/ */
void sp_udp_free(UdpConnection */*notnull*/ connection); void sp_udp_free(UdpSocket */*notnull*/ connection);
/** /**
* Creates a new instance of [UdpConnection]. * Creates a new instance of [UdpConnection].
@ -1235,7 +1228,7 @@ void sp_udp_free(UdpConnection */*notnull*/ connection);
* sp_udp_send_command(connection, sp_command_clear()); * sp_udp_send_command(connection, sp_command_clear());
* ``` * ```
*/ */
UdpConnection *sp_udp_open(char */*notnull*/ host); UdpSocket *sp_udp_open(char */*notnull*/ host);
/** /**
* Creates a new instance of [UdpConnection]. * Creates a new instance of [UdpConnection].
@ -1250,7 +1243,7 @@ UdpConnection *sp_udp_open(char */*notnull*/ host);
* sp_udp_send_command(connection, sp_command_clear()); * sp_udp_send_command(connection, sp_command_clear());
* ``` * ```
*/ */
UdpConnection *sp_udp_open_ipv4(uint8_t ip1, UdpSocket *sp_udp_open_ipv4(uint8_t ip1,
uint8_t ip2, uint8_t ip2,
uint8_t ip3, uint8_t ip3,
uint8_t ip4, uint8_t ip4,
@ -1269,7 +1262,7 @@ UdpConnection *sp_udp_open_ipv4(uint8_t ip1,
* sp_udp_send_command(connection, sp_command_brightness(5)); * sp_udp_send_command(connection, sp_command_brightness(5));
* ``` * ```
*/ */
bool sp_udp_send_command(UdpConnection */*notnull*/ connection, bool sp_udp_send_command(UdpSocket */*notnull*/ connection,
TypedCommand */*notnull*/ command); TypedCommand */*notnull*/ command);
/** /**
@ -1283,8 +1276,7 @@ bool sp_udp_send_command(UdpConnection */*notnull*/ connection,
* sp_udp_send_header(connection, sp_command_brightness(5)); * sp_udp_send_header(connection, sp_command_brightness(5));
* ``` * ```
*/ */
bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection, bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header);
Header header);
/** /**
* Sends a [Packet] to the display using the [UdpConnection]. * Sends a [Packet] to the display using the [UdpConnection].
@ -1293,7 +1285,7 @@ bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection,
* *
* returns: true in case of success * returns: true in case of success
*/ */
bool sp_udp_send_packet(UdpConnection */*notnull*/ connection, bool sp_udp_send_packet(UdpSocket */*notnull*/ connection,
Packet */*notnull*/ packet); Packet */*notnull*/ packet);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -67,3 +67,5 @@ pub(crate) unsafe fn heap_drop<T>(x: NonNull<T>) {
pub(crate) unsafe fn heap_remove<T>(x: NonNull<T>) -> T { pub(crate) unsafe fn heap_remove<T>(x: NonNull<T>) -> T {
unsafe { *Box::from_raw(x.as_ptr()) } unsafe { *Box::from_raw(x.as_ptr()) }
} }
pub struct UdpSocket;