From 8cfce0a390fcabadbb06ea5f6fecaab8d65fb1cb Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 24 Apr 2025 22:47:27 +0200 Subject: [PATCH 1/7] a bunch of options for the Makefile --- example/Makefile | 150 ++++++++++++++++---------- example/{ => src}/announce.c | 10 +- example/{ => src}/brightness_tester.c | 4 +- example/{ => src}/random_stuff.c | 5 +- flake.nix | 20 ++-- include/servicepoint.h | 35 +++--- src/lib.rs | 3 + 7 files changed, 133 insertions(+), 94 deletions(-) rename example/{ => src}/announce.c (82%) rename example/{ => src}/brightness_tester.c (84%) rename example/{ => src}/random_stuff.c (72%) diff --git a/example/Makefile b/example/Makefile index 7e5bfe7..a35aa5c 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,85 +1,119 @@ -CC := gcc -CARGO := rustup run nightly cargo +CARGO ?= cargo +STRIP ?= strip -TARGET := x86_64-unknown-linux-musl -PROFILE := size-optimized -FEATURES := protocol_udp +FEATURES := THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -REPO_ROOT := $(THIS_DIR)/.. -RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(PROFILE) +REPO_ROOT := $(realpath $(THIS_DIR)/..) export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include -RUSTFLAGS := -Zlocation-detail=none \ - -Zfmt-debug=none \ - -C linker=musl-gcc \ - -C link-arg=-s \ - -C link-arg=--gc-sections \ - -C link-arg=-z,norelro \ - -C link-arg=--hash-style=gnu \ - --crate-type=staticlib \ - -C panic=abort +override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0)) +override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release)) -CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \ - --profile=$(PROFILE) \ +CCFLAGS += -Wall -fwhole-program + +STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag + +ifeq ($(CFG_MUSL), 1) + TARGET ?= x86_64-unknown-linux-musl + CC ?= musl-gcc + CCFLAGS += -static -lservicepoint_binding_c + RUSTFLAGS += --crate-type=staticlib +else + TARGET ?= x86_64-unknown-linux-gnu + CC ?= gcc + #CCFLAGS += -shared + CCFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic +endif + +#ifeq ($(CFG_PROFILE), size-optimized) +# CCFLAGS += -nodefaultlibs -lc +#endif + +RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE) +OUT_DIR := $(realpath $(THIS_DIR)/out/) + +ifeq ($(CFG_PROFILE), size-optimized) + CARGO_PROFILE := size-optimized + CCFLAGS += -Oz \ + -fwrapv -fomit-frame-pointer -fno-stack-protector\ + -fno-unroll-loops \ + -fno-unwind-tables -fno-asynchronous-unwind-tables \ + -fmerge-all-constants \ + -Wl,-z,norelro \ + -Wl,--hash-style=gnu \ + -fvisibility=hidden \ + -Bsymbolic \ + -Wl,--exclude-libs,ALL \ + -fno-ident \ + -fno-exceptions + CARGOFLAGS += -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \ + -Zbuild-std-features="panic_immediate_abort" + RUSTFLAGS += -Zlocation-detail=none \ + -Zfmt-debug=none \ + -C link-arg=-z,norelro \ + -C panic=abort + #-C link-arg=--hash-style=gnu +else ifeq ($(CFG_PROFILE), release) + CARGO_PROFILE := release + CCFLAGS += -O2 +else ifeq ($(CFG_PROFILE), debug) + CCFLAGS += -Og + CARGO_PROFILE := dev +else + CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized") +endif + +CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \ + --profile=$(CARGO_PROFILE) \ --no-default-features \ --features=$(FEATURES) \ - --target=$(TARGET) \ - -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \ - -Zbuild-std-features="panic_immediate_abort" \ + --target=$(TARGET) -CCFLAGS := -static -Os \ - -ffunction-sections -fdata-sections \ - -fwrapv -fomit-frame-pointer -fno-stack-protector\ - -fwhole-program \ - -nodefaultlibs -lservicepoint_binding_c -lc \ - -Wl,--gc-sections \ - -fno-unroll-loops \ - -fno-unwind-tables -fno-asynchronous-unwind-tables \ - -fmerge-all-constants \ - -Wl,-z,norelro \ - -Wl,--hash-style=gnu \ - -fvisibility=hidden \ - -Bsymbolic \ - -Wl,--exclude-libs,ALL \ - -fno-ident \ - -Wall - #-fuse-ld=gold \ - -fno-exceptions - #-Wl,--icf=all \ +ifneq ($(CFG_PROFILE), debug) + CCFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections + RUSTFLAGS += -C link-arg=-s -C link-arg=-Wl,--gc-sections +endif -STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag +ifeq ($(LTO), 1) + CCFLAGS += -flto +endif -_c_src := $(wildcard *.c) -_programs := $(basename $(_c_src)) +_c_src := $(wildcard ./src/*.c) +_programs := $(basename $(notdir $(_c_src))) _bins := $(addprefix out/, $(_programs)) _unstripped_bins := $(addsuffix _unstripped, $(_bins)) _run_programs := $(addprefix run_, $(_programs)) _rs_src := $(wildcard ../src/**.rs) ../Cargo.lock ../Cargo.toml ../cbindgen.toml +_sp_artifacts := $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a $(RUST_TARGET_DIR)/libservicepoint_binding_c.so all: $(_bins) -clean: - rm -r out || true - rm include/servicepoint.h || true +clean: clean-c clean-rust + +clean-c: + rm -r $(OUT_DIR) || true + +clean-rust: + rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true cargo clean -PHONY: all clean sizes $(_run_programs) +.PHONY: all clean sizes $(_run_programs) clean-c clean-rust -$(_unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a +$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) mkdir -p out || true - ${CC} $^ \ + ${CC} $< \ -I $(SERVICEPOINT_HEADER_OUT) \ - -L $(RUST_TARGET_DIR)\ + -L $(RUST_TARGET_DIR) \ $(CCFLAGS) \ -o $@ $(_bins): out/%: out/%_unstripped - strip $(STRIPFLAGS) $^ -o $@ + $(STRIP) $(STRIPFLAGS) $^ -o $@ -$(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 +$(_sp_artifacts): $(_rs_src) + mkdir -p $(SERVICEPOINT_HEADER_OUT) || true + # generate servicepoint header and library to link against ${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) $(_run_programs): run_%: out/% FORCE @@ -88,9 +122,9 @@ $(_run_programs): run_%: out/% FORCE sizes: $(_bins) ls -lB out -#analyze-size: out/example_unstripped -# nm --print-size --size-sort --reverse-sort --radix=d --demangle out/example_unstripped \ -# | awk '{size=$$2+0; print size "\t" $$4}' \ -# | less +analyze-size: out/$(BIN)_unstripped + nm --print-size --size-sort --reverse-sort --radix=d --demangle $(OUT_DIR)/$(BIN)_unstripped \ + | awk '{size=$$2+0; print size "\t" $$4}' \ + | less FORCE: ; diff --git a/example/announce.c b/example/src/announce.c similarity index 82% rename from example/announce.c rename to example/src/announce.c index 737eff5..d256cff 100644 --- a/example/announce.c +++ b/example/src/announce.c @@ -1,8 +1,12 @@ +#include #include "servicepoint.h" + int main(void) { - //UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); - UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); + printf("test\n"); + + 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) return 1; @@ -11,7 +15,7 @@ int main(void) { 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'); diff --git a/example/brightness_tester.c b/example/src/brightness_tester.c similarity index 84% rename from example/brightness_tester.c rename to example/src/brightness_tester.c index d06d30d..c3e42ba 100644 --- a/example/brightness_tester.c +++ b/example/src/brightness_tester.c @@ -1,8 +1,8 @@ #include "servicepoint.h" int main(void) { - // UdpConnection *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(172, 23, 42, 29, 2342); + //UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); if (connection == NULL) return -1; diff --git a/example/random_stuff.c b/example/src/random_stuff.c similarity index 72% rename from example/random_stuff.c rename to example/src/random_stuff.c index ca5a14d..96beefb 100644 --- a/example/random_stuff.c +++ b/example/src/random_stuff.c @@ -1,8 +1,7 @@ -#include #include "servicepoint.h" 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) return 1; @@ -17,7 +16,7 @@ int main(void) { return 1; Header *header = sp_packet_get_header(packet); - printf("[%d, %d, %d, %d, %d]\n", header->command_code, header->a, header->b, header->c, header->d); + // printf("[%d, %d, %d, %d, %d]\n", header->command_code, header->a, header->b, header->c, header->d); sp_udp_send_packet(connection, packet); diff --git a/flake.nix b/flake.nix index b4f874f..9d67ae9 100644 --- a/flake.nix +++ b/flake.nix @@ -33,16 +33,17 @@ { pkgs, system }: { default = pkgs.mkShell rec { - buildInputs = with pkgs;[ + buildInputs = with pkgs; [ xe xz - libgcc - #glibc.static - musl - libunwind - ]; + #libgcc + #glibc + pkgsStatic.musl + # libunwind - nativeBuildInputs = with pkgs;[ + ]; + + nativeBuildInputs = with pkgs; [ (pkgs.symlinkJoin { name = "rust-toolchain"; paths = with pkgs; [ @@ -57,11 +58,14 @@ ]; }) gcc + gdb + pkgsStatic.gcc gnumake pkg-config ]; - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + #RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + CARGO = "rustup run nightly cargo"; }; } ); diff --git a/include/servicepoint.h b/include/servicepoint.h index 77d2e36..5863ef5 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -226,13 +226,9 @@ typedef struct SPBitVec SPBitVec; typedef struct TypedCommand TypedCommand; /** - * 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. + * This is a type only used by cbindgen to have a type for pointers. */ -typedef struct UdpConnection UdpConnection; +typedef struct UdpSocket UdpSocket; /** * A 2D grid of values. @@ -298,7 +294,7 @@ typedef struct { * grid.set(1, 1, Brightness::MIN); * * # let connection = FakeConnection; - * connection.send(BrightnessGridCommand { + * connection.send_command(BrightnessGridCommand { * origin: Origin::new(3, 7), * grid * }).unwrap() @@ -318,7 +314,7 @@ typedef ValueGrid_Brightness BrightnessGrid; * * let b = Brightness::try_from(7).unwrap(); * # let connection = FakeConnection; - * let result = connection.send(GlobalBrightnessCommand::from(b)); + * let result = connection.send_command(GlobalBrightnessCommand::from(b)); * ``` */ typedef uint8_t Brightness; @@ -347,7 +343,7 @@ typedef uint8_t Brightness; * * # let connection = FakeConnection; * let command = CharGridCommand { origin: Origin::ZERO, grid }; - * connection.send(command).unwrap() + * connection.send_command(command).unwrap() * ``` */ typedef ValueGrid_char CharGrid; @@ -1220,7 +1216,7 @@ bool sp_u16_to_command_code(uint16_t code, /** * 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]. @@ -1235,7 +1231,7 @@ void sp_udp_free(UdpConnection */*notnull*/ connection); * 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]. @@ -1250,11 +1246,11 @@ UdpConnection *sp_udp_open(char */*notnull*/ host); * sp_udp_send_command(connection, sp_command_clear()); * ``` */ -UdpConnection *sp_udp_open_ipv4(uint8_t ip1, - uint8_t ip2, - uint8_t ip3, - uint8_t ip4, - uint16_t port); +UdpSocket *sp_udp_open_ipv4(uint8_t ip1, + uint8_t ip2, + uint8_t ip3, + uint8_t ip4, + uint16_t port); /** * Sends a [TypedCommand] to the display using the [UdpConnection]. @@ -1269,7 +1265,7 @@ UdpConnection *sp_udp_open_ipv4(uint8_t ip1, * 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); /** @@ -1283,8 +1279,7 @@ bool sp_udp_send_command(UdpConnection */*notnull*/ connection, * sp_udp_send_header(connection, sp_command_brightness(5)); * ``` */ -bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection, - Header header); +bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header); /** * Sends a [Packet] to the display using the [UdpConnection]. @@ -1293,7 +1288,7 @@ bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection, * * 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); #ifdef __cplusplus diff --git a/src/lib.rs b/src/lib.rs index 52aac4c..60c42ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,3 +67,6 @@ pub(crate) unsafe fn heap_drop(x: NonNull) { pub(crate) unsafe fn heap_remove(x: NonNull) -> T { unsafe { *Box::from_raw(x.as_ptr()) } } + +/// This is a type only used by cbindgen to have a type for pointers. +pub struct UdpSocket; From 091b79887cf3223d1b2c1950c786279c6a9e73b0 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 24 Apr 2025 23:31:34 +0200 Subject: [PATCH 2/7] build variations in CI to keep track of what works --- .github/workflows/rust.yml | 73 ++++++++++++++++++++++++++++++-------- example/Makefile | 6 ++-- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9089694..47cb9ee 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,32 +13,77 @@ env: RUSTFLAGS: "-Dwarnings" jobs: - build: - + build-gnu-apt: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - name: Update repos run: sudo apt-get update -qq - - name: Install rust toolchain - run: sudo apt-get install -qy cargo rust-clippy - - name: install lzma - run: sudo apt-get install -qy liblzma-dev - - name: install gcc - run: sudo apt-get install -qy gcc make + - name: Install toolchain + run: sudo apt-get install -qy cargo rust-clippy liblzma-dev gcc make pkgconf - name: Run Clippy run: cargo clippy + - name: build + run: cargo build + - name: generate bindings run: ./generate-binding.sh - name: check that generated files did not change run: output=$(git status --porcelain) && [ -z "$output" ] - - - name: build - run: cargo build - - name: build example - run: cd example && make + - name: build example -- glibc release + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=release + - name: build example -- glibc debug + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=debug + + # this _should_ have been -stable, but there is a bug when running in the container ("Invalid cross-device link") + build-musl-beta: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup + - name: install rust target + run: rustup default beta && rustup target add aarch64-unknown-linux-musl && rustup component add rust-src && rustup update + + - name: build example -- musl release + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=release MUSL=1 CARGO="rustup run beta cargo" + - name: build example -- musl debug + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=debug MUSL=1 CARGO="rustup run beta cargo" + + build-size-gnu-unstable: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf rustup + - name: install rust targets + run: rustup toolchain install nightly -t aarch64-unknown-linux-gnu -c rust-src --no-self-update + + - name: build example -- glibc size-optimized + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=size-optimized CARGO="rustup run nightly cargo" LTO=1 + + + build-size-musl-unstable: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup + - name: install rust targets + run: rustup toolchain install nightly -t aarch64-unknown-linux-musl -c rust-src --no-self-update + + - name: build example -- musl size-optimized + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=size-optimized MUSL=1 LTO=1 CARGO="rustup run nightly cargo" diff --git a/example/Makefile b/example/Makefile index a35aa5c..353e298 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,7 +1,7 @@ CARGO ?= cargo STRIP ?= strip -FEATURES := +FEATURES := "" THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) REPO_ROOT := $(realpath $(THIS_DIR)/..) @@ -10,7 +10,7 @@ export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0)) override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release)) -CCFLAGS += -Wall -fwhole-program +CCFLAGS += -Wall -fwhole-program -fPIE -pie STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag @@ -18,7 +18,7 @@ ifeq ($(CFG_MUSL), 1) TARGET ?= x86_64-unknown-linux-musl CC ?= musl-gcc CCFLAGS += -static -lservicepoint_binding_c - RUSTFLAGS += --crate-type=staticlib + RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=-crt-static else TARGET ?= x86_64-unknown-linux-gnu CC ?= gcc From e659b84025b2b4de9d164fd2c67c9ddc0a83c264 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 4 May 2025 12:22:27 +0200 Subject: [PATCH 3/7] remove musl builds --- .github/workflows/rust.yml | 35 +---------------------------------- example/Makefile | 5 ++--- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 47cb9ee..e9947d5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,6 +13,7 @@ env: RUSTFLAGS: "-Dwarnings" jobs: + build-gnu-apt: runs-on: ubuntu-latest steps: @@ -39,24 +40,6 @@ jobs: - name: build example -- glibc debug run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=debug - # this _should_ have been -stable, but there is a bug when running in the container ("Invalid cross-device link") - build-musl-beta: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Update repos - run: sudo apt-get update -qq - - name: Install toolchain - run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup - - name: install rust target - run: rustup default beta && rustup target add aarch64-unknown-linux-musl && rustup component add rust-src && rustup update - - - name: build example -- musl release - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=release MUSL=1 CARGO="rustup run beta cargo" - - name: build example -- musl debug - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=debug MUSL=1 CARGO="rustup run beta cargo" - build-size-gnu-unstable: runs-on: ubuntu-latest steps: @@ -71,19 +54,3 @@ jobs: - name: build example -- glibc size-optimized run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=size-optimized CARGO="rustup run nightly cargo" LTO=1 - - - build-size-musl-unstable: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Update repos - run: sudo apt-get update -qq - - name: Install toolchain - run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup - - name: install rust targets - run: rustup toolchain install nightly -t aarch64-unknown-linux-musl -c rust-src --no-self-update - - - name: build example -- musl size-optimized - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=size-optimized MUSL=1 LTO=1 CARGO="rustup run nightly cargo" diff --git a/example/Makefile b/example/Makefile index 353e298..f7111b1 100644 --- a/example/Makefile +++ b/example/Makefile @@ -31,7 +31,6 @@ endif #endif RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE) -OUT_DIR := $(realpath $(THIS_DIR)/out/) ifeq ($(CFG_PROFILE), size-optimized) CARGO_PROFILE := size-optimized @@ -92,7 +91,7 @@ all: $(_bins) clean: clean-c clean-rust clean-c: - rm -r $(OUT_DIR) || true + rm -r out || true clean-rust: rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true @@ -123,7 +122,7 @@ sizes: $(_bins) ls -lB out 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/$(BIN)_unstripped \ | awk '{size=$$2+0; print size "\t" $$4}' \ | less From 3ffc96cdbe54c1ad00057acb07a2693dbe8e4b19 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 24 Apr 2025 22:47:27 +0200 Subject: [PATCH 4/7] a bunch of options for the Makefile --- example/Makefile | 150 ++++++++++++++++---------- example/{ => src}/announce.c | 10 +- example/{ => src}/brightness_tester.c | 4 +- example/{ => src}/random_stuff.c | 2 +- flake.nix | 20 ++-- include/servicepoint.h | 35 +++--- src/lib.rs | 3 + 7 files changed, 132 insertions(+), 92 deletions(-) rename example/{ => src}/announce.c (82%) rename example/{ => src}/brightness_tester.c (84%) rename example/{ => src}/random_stuff.c (89%) diff --git a/example/Makefile b/example/Makefile index 7e5bfe7..a35aa5c 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,85 +1,119 @@ -CC := gcc -CARGO := rustup run nightly cargo +CARGO ?= cargo +STRIP ?= strip -TARGET := x86_64-unknown-linux-musl -PROFILE := size-optimized -FEATURES := protocol_udp +FEATURES := THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) -REPO_ROOT := $(THIS_DIR)/.. -RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(PROFILE) +REPO_ROOT := $(realpath $(THIS_DIR)/..) export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include -RUSTFLAGS := -Zlocation-detail=none \ - -Zfmt-debug=none \ - -C linker=musl-gcc \ - -C link-arg=-s \ - -C link-arg=--gc-sections \ - -C link-arg=-z,norelro \ - -C link-arg=--hash-style=gnu \ - --crate-type=staticlib \ - -C panic=abort +override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0)) +override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release)) -CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \ - --profile=$(PROFILE) \ +CCFLAGS += -Wall -fwhole-program + +STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag + +ifeq ($(CFG_MUSL), 1) + TARGET ?= x86_64-unknown-linux-musl + CC ?= musl-gcc + CCFLAGS += -static -lservicepoint_binding_c + RUSTFLAGS += --crate-type=staticlib +else + TARGET ?= x86_64-unknown-linux-gnu + CC ?= gcc + #CCFLAGS += -shared + CCFLAGS += -Wl,-Bstatic -lservicepoint_binding_c -Wl,-Bdynamic +endif + +#ifeq ($(CFG_PROFILE), size-optimized) +# CCFLAGS += -nodefaultlibs -lc +#endif + +RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE) +OUT_DIR := $(realpath $(THIS_DIR)/out/) + +ifeq ($(CFG_PROFILE), size-optimized) + CARGO_PROFILE := size-optimized + CCFLAGS += -Oz \ + -fwrapv -fomit-frame-pointer -fno-stack-protector\ + -fno-unroll-loops \ + -fno-unwind-tables -fno-asynchronous-unwind-tables \ + -fmerge-all-constants \ + -Wl,-z,norelro \ + -Wl,--hash-style=gnu \ + -fvisibility=hidden \ + -Bsymbolic \ + -Wl,--exclude-libs,ALL \ + -fno-ident \ + -fno-exceptions + CARGOFLAGS += -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \ + -Zbuild-std-features="panic_immediate_abort" + RUSTFLAGS += -Zlocation-detail=none \ + -Zfmt-debug=none \ + -C link-arg=-z,norelro \ + -C panic=abort + #-C link-arg=--hash-style=gnu +else ifeq ($(CFG_PROFILE), release) + CARGO_PROFILE := release + CCFLAGS += -O2 +else ifeq ($(CFG_PROFILE), debug) + CCFLAGS += -Og + CARGO_PROFILE := dev +else + CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized") +endif + +CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \ + --profile=$(CARGO_PROFILE) \ --no-default-features \ --features=$(FEATURES) \ - --target=$(TARGET) \ - -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \ - -Zbuild-std-features="panic_immediate_abort" \ + --target=$(TARGET) -CCFLAGS := -static -Os \ - -ffunction-sections -fdata-sections \ - -fwrapv -fomit-frame-pointer -fno-stack-protector\ - -fwhole-program \ - -nodefaultlibs -lservicepoint_binding_c -lc \ - -Wl,--gc-sections \ - -fno-unroll-loops \ - -fno-unwind-tables -fno-asynchronous-unwind-tables \ - -fmerge-all-constants \ - -Wl,-z,norelro \ - -Wl,--hash-style=gnu \ - -fvisibility=hidden \ - -Bsymbolic \ - -Wl,--exclude-libs,ALL \ - -fno-ident \ - -Wall - #-fuse-ld=gold \ - -fno-exceptions - #-Wl,--icf=all \ +ifneq ($(CFG_PROFILE), debug) + CCFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections + RUSTFLAGS += -C link-arg=-s -C link-arg=-Wl,--gc-sections +endif -STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag +ifeq ($(LTO), 1) + CCFLAGS += -flto +endif -_c_src := $(wildcard *.c) -_programs := $(basename $(_c_src)) +_c_src := $(wildcard ./src/*.c) +_programs := $(basename $(notdir $(_c_src))) _bins := $(addprefix out/, $(_programs)) _unstripped_bins := $(addsuffix _unstripped, $(_bins)) _run_programs := $(addprefix run_, $(_programs)) _rs_src := $(wildcard ../src/**.rs) ../Cargo.lock ../Cargo.toml ../cbindgen.toml +_sp_artifacts := $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a $(RUST_TARGET_DIR)/libservicepoint_binding_c.so all: $(_bins) -clean: - rm -r out || true - rm include/servicepoint.h || true +clean: clean-c clean-rust + +clean-c: + rm -r $(OUT_DIR) || true + +clean-rust: + rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true cargo clean -PHONY: all clean sizes $(_run_programs) +.PHONY: all clean sizes $(_run_programs) clean-c clean-rust -$(_unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a +$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts) mkdir -p out || true - ${CC} $^ \ + ${CC} $< \ -I $(SERVICEPOINT_HEADER_OUT) \ - -L $(RUST_TARGET_DIR)\ + -L $(RUST_TARGET_DIR) \ $(CCFLAGS) \ -o $@ $(_bins): out/%: out/%_unstripped - strip $(STRIPFLAGS) $^ -o $@ + $(STRIP) $(STRIPFLAGS) $^ -o $@ -$(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 +$(_sp_artifacts): $(_rs_src) + mkdir -p $(SERVICEPOINT_HEADER_OUT) || true + # generate servicepoint header and library to link against ${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) $(_run_programs): run_%: out/% FORCE @@ -88,9 +122,9 @@ $(_run_programs): run_%: out/% FORCE sizes: $(_bins) ls -lB out -#analyze-size: out/example_unstripped -# nm --print-size --size-sort --reverse-sort --radix=d --demangle out/example_unstripped \ -# | awk '{size=$$2+0; print size "\t" $$4}' \ -# | less +analyze-size: out/$(BIN)_unstripped + nm --print-size --size-sort --reverse-sort --radix=d --demangle $(OUT_DIR)/$(BIN)_unstripped \ + | awk '{size=$$2+0; print size "\t" $$4}' \ + | less FORCE: ; diff --git a/example/announce.c b/example/src/announce.c similarity index 82% rename from example/announce.c rename to example/src/announce.c index 737eff5..d256cff 100644 --- a/example/announce.c +++ b/example/src/announce.c @@ -1,8 +1,12 @@ +#include #include "servicepoint.h" + int main(void) { - //UdpConnection *connection = sp_udp_open_ipv4(172, 23, 42, 29, 2342); - UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); + printf("test\n"); + + 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) return 1; @@ -11,7 +15,7 @@ int main(void) { 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'); diff --git a/example/brightness_tester.c b/example/src/brightness_tester.c similarity index 84% rename from example/brightness_tester.c rename to example/src/brightness_tester.c index d06d30d..c3e42ba 100644 --- a/example/brightness_tester.c +++ b/example/src/brightness_tester.c @@ -1,8 +1,8 @@ #include "servicepoint.h" int main(void) { - // UdpConnection *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(172, 23, 42, 29, 2342); + //UdpSocket *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342); if (connection == NULL) return -1; diff --git a/example/random_stuff.c b/example/src/random_stuff.c similarity index 89% rename from example/random_stuff.c rename to example/src/random_stuff.c index ca5a14d..2ebd485 100644 --- a/example/random_stuff.c +++ b/example/src/random_stuff.c @@ -2,7 +2,7 @@ #include "servicepoint.h" 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) return 1; diff --git a/flake.nix b/flake.nix index b4f874f..9d67ae9 100644 --- a/flake.nix +++ b/flake.nix @@ -33,16 +33,17 @@ { pkgs, system }: { default = pkgs.mkShell rec { - buildInputs = with pkgs;[ + buildInputs = with pkgs; [ xe xz - libgcc - #glibc.static - musl - libunwind - ]; + #libgcc + #glibc + pkgsStatic.musl + # libunwind - nativeBuildInputs = with pkgs;[ + ]; + + nativeBuildInputs = with pkgs; [ (pkgs.symlinkJoin { name = "rust-toolchain"; paths = with pkgs; [ @@ -57,11 +58,14 @@ ]; }) gcc + gdb + pkgsStatic.gcc gnumake pkg-config ]; - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + #RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + CARGO = "rustup run nightly cargo"; }; } ); diff --git a/include/servicepoint.h b/include/servicepoint.h index 77d2e36..5863ef5 100644 --- a/include/servicepoint.h +++ b/include/servicepoint.h @@ -226,13 +226,9 @@ typedef struct SPBitVec SPBitVec; typedef struct TypedCommand TypedCommand; /** - * 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. + * This is a type only used by cbindgen to have a type for pointers. */ -typedef struct UdpConnection UdpConnection; +typedef struct UdpSocket UdpSocket; /** * A 2D grid of values. @@ -298,7 +294,7 @@ typedef struct { * grid.set(1, 1, Brightness::MIN); * * # let connection = FakeConnection; - * connection.send(BrightnessGridCommand { + * connection.send_command(BrightnessGridCommand { * origin: Origin::new(3, 7), * grid * }).unwrap() @@ -318,7 +314,7 @@ typedef ValueGrid_Brightness BrightnessGrid; * * let b = Brightness::try_from(7).unwrap(); * # let connection = FakeConnection; - * let result = connection.send(GlobalBrightnessCommand::from(b)); + * let result = connection.send_command(GlobalBrightnessCommand::from(b)); * ``` */ typedef uint8_t Brightness; @@ -347,7 +343,7 @@ typedef uint8_t Brightness; * * # let connection = FakeConnection; * let command = CharGridCommand { origin: Origin::ZERO, grid }; - * connection.send(command).unwrap() + * connection.send_command(command).unwrap() * ``` */ typedef ValueGrid_char CharGrid; @@ -1220,7 +1216,7 @@ bool sp_u16_to_command_code(uint16_t code, /** * 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]. @@ -1235,7 +1231,7 @@ void sp_udp_free(UdpConnection */*notnull*/ connection); * 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]. @@ -1250,11 +1246,11 @@ UdpConnection *sp_udp_open(char */*notnull*/ host); * sp_udp_send_command(connection, sp_command_clear()); * ``` */ -UdpConnection *sp_udp_open_ipv4(uint8_t ip1, - uint8_t ip2, - uint8_t ip3, - uint8_t ip4, - uint16_t port); +UdpSocket *sp_udp_open_ipv4(uint8_t ip1, + uint8_t ip2, + uint8_t ip3, + uint8_t ip4, + uint16_t port); /** * Sends a [TypedCommand] to the display using the [UdpConnection]. @@ -1269,7 +1265,7 @@ UdpConnection *sp_udp_open_ipv4(uint8_t ip1, * 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); /** @@ -1283,8 +1279,7 @@ bool sp_udp_send_command(UdpConnection */*notnull*/ connection, * sp_udp_send_header(connection, sp_command_brightness(5)); * ``` */ -bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection, - Header header); +bool sp_udp_send_header(UdpSocket */*notnull*/ udp_connection, Header header); /** * Sends a [Packet] to the display using the [UdpConnection]. @@ -1293,7 +1288,7 @@ bool sp_udp_send_header(UdpConnection */*notnull*/ udp_connection, * * 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); #ifdef __cplusplus diff --git a/src/lib.rs b/src/lib.rs index 52aac4c..60c42ab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,3 +67,6 @@ pub(crate) unsafe fn heap_drop(x: NonNull) { pub(crate) unsafe fn heap_remove(x: NonNull) -> T { unsafe { *Box::from_raw(x.as_ptr()) } } + +/// This is a type only used by cbindgen to have a type for pointers. +pub struct UdpSocket; From 125f4158f97226932eaa6767e84a13470a8cc194 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Thu, 24 Apr 2025 23:31:34 +0200 Subject: [PATCH 5/7] build variations in CI to keep track of what works --- .github/workflows/rust.yml | 73 ++++++++++++++++++++++++++++++-------- example/Makefile | 6 ++-- 2 files changed, 62 insertions(+), 17 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 9089694..47cb9ee 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,32 +13,77 @@ env: RUSTFLAGS: "-Dwarnings" jobs: - build: - + build-gnu-apt: runs-on: ubuntu-latest - steps: - uses: actions/checkout@v4 - name: Update repos run: sudo apt-get update -qq - - name: Install rust toolchain - run: sudo apt-get install -qy cargo rust-clippy - - name: install lzma - run: sudo apt-get install -qy liblzma-dev - - name: install gcc - run: sudo apt-get install -qy gcc make + - name: Install toolchain + run: sudo apt-get install -qy cargo rust-clippy liblzma-dev gcc make pkgconf - name: Run Clippy run: cargo clippy + - name: build + run: cargo build + - name: generate bindings run: ./generate-binding.sh - name: check that generated files did not change run: output=$(git status --porcelain) && [ -z "$output" ] - - - name: build - run: cargo build - - name: build example - run: cd example && make + - name: build example -- glibc release + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=release + - name: build example -- glibc debug + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=debug + + # this _should_ have been -stable, but there is a bug when running in the container ("Invalid cross-device link") + build-musl-beta: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup + - name: install rust target + run: rustup default beta && rustup target add aarch64-unknown-linux-musl && rustup component add rust-src && rustup update + + - name: build example -- musl release + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=release MUSL=1 CARGO="rustup run beta cargo" + - name: build example -- musl debug + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=debug MUSL=1 CARGO="rustup run beta cargo" + + build-size-gnu-unstable: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf rustup + - name: install rust targets + run: rustup toolchain install nightly -t aarch64-unknown-linux-gnu -c rust-src --no-self-update + + - name: build example -- glibc size-optimized + run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=size-optimized CARGO="rustup run nightly cargo" LTO=1 + + + build-size-musl-unstable: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Update repos + run: sudo apt-get update -qq + - name: Install toolchain + run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup + - name: install rust targets + run: rustup toolchain install nightly -t aarch64-unknown-linux-musl -c rust-src --no-self-update + + - name: build example -- musl size-optimized + run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=size-optimized MUSL=1 LTO=1 CARGO="rustup run nightly cargo" diff --git a/example/Makefile b/example/Makefile index a35aa5c..353e298 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,7 +1,7 @@ CARGO ?= cargo STRIP ?= strip -FEATURES := +FEATURES := "" THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) REPO_ROOT := $(realpath $(THIS_DIR)/..) @@ -10,7 +10,7 @@ export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0)) override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release)) -CCFLAGS += -Wall -fwhole-program +CCFLAGS += -Wall -fwhole-program -fPIE -pie STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag @@ -18,7 +18,7 @@ ifeq ($(CFG_MUSL), 1) TARGET ?= x86_64-unknown-linux-musl CC ?= musl-gcc CCFLAGS += -static -lservicepoint_binding_c - RUSTFLAGS += --crate-type=staticlib + RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=-crt-static else TARGET ?= x86_64-unknown-linux-gnu CC ?= gcc From 36bb1c340900ae10062d5c6c16ed77537659b15c Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 4 May 2025 12:22:27 +0200 Subject: [PATCH 6/7] remove musl builds --- .github/workflows/rust.yml | 35 +---------------------------------- example/Makefile | 5 ++--- 2 files changed, 3 insertions(+), 37 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 47cb9ee..e9947d5 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -13,6 +13,7 @@ env: RUSTFLAGS: "-Dwarnings" jobs: + build-gnu-apt: runs-on: ubuntu-latest steps: @@ -39,24 +40,6 @@ jobs: - name: build example -- glibc debug run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=debug - # this _should_ have been -stable, but there is a bug when running in the container ("Invalid cross-device link") - build-musl-beta: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Update repos - run: sudo apt-get update -qq - - name: Install toolchain - run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup - - name: install rust target - run: rustup default beta && rustup target add aarch64-unknown-linux-musl && rustup component add rust-src && rustup update - - - name: build example -- musl release - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=release MUSL=1 CARGO="rustup run beta cargo" - - name: build example -- musl debug - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=debug MUSL=1 CARGO="rustup run beta cargo" - build-size-gnu-unstable: runs-on: ubuntu-latest steps: @@ -71,19 +54,3 @@ jobs: - name: build example -- glibc size-optimized run: cd example && make clean && make TARGET=aarch64-unknown-linux-gnu PROFILE=size-optimized CARGO="rustup run nightly cargo" LTO=1 - - - build-size-musl-unstable: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Update repos - run: sudo apt-get update -qq - - name: Install toolchain - run: sudo apt-get install -qy liblzma-dev gcc make pkgconf musl-dev musl-tools rustup - - name: install rust targets - run: rustup toolchain install nightly -t aarch64-unknown-linux-musl -c rust-src --no-self-update - - - name: build example -- musl size-optimized - run: cd example && make clean && make TARGET=aarch64-unknown-linux-musl PROFILE=size-optimized MUSL=1 LTO=1 CARGO="rustup run nightly cargo" diff --git a/example/Makefile b/example/Makefile index 353e298..f7111b1 100644 --- a/example/Makefile +++ b/example/Makefile @@ -31,7 +31,6 @@ endif #endif RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE) -OUT_DIR := $(realpath $(THIS_DIR)/out/) ifeq ($(CFG_PROFILE), size-optimized) CARGO_PROFILE := size-optimized @@ -92,7 +91,7 @@ all: $(_bins) clean: clean-c clean-rust clean-c: - rm -r $(OUT_DIR) || true + rm -r out || true clean-rust: rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true @@ -123,7 +122,7 @@ sizes: $(_bins) ls -lB out 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/$(BIN)_unstripped \ | awk '{size=$$2+0; print size "\t" $$4}' \ | less From 13571de8e3c370a236e931f024c06464c9fa54e6 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sun, 4 May 2025 13:07:45 +0200 Subject: [PATCH 7/7] version 0.14.1 --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 46f05cc..78e2169 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -430,7 +430,7 @@ dependencies = [ [[package]] name = "servicepoint_binding_c" -version = "0.13.1" +version = "0.14.1" dependencies = [ "cbindgen", "servicepoint", diff --git a/Cargo.toml b/Cargo.toml index 0a6e289..0eba069 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "servicepoint_binding_c" -version = "0.13.1" +version = "0.14.1" publish = true edition = "2021" license = "GPL-3.0-or-later"