wip 80k example
This commit is contained in:
		
							parent
							
								
									57d9e90b0f
								
							
						
					
					
						commit
						0d4bf5ac10
					
				
					 8 changed files with 115 additions and 44 deletions
				
			
		
							
								
								
									
										21
									
								
								Cargo.toml
									
										
									
									
									
								
							
							
						
						
									
										21
									
								
								Cargo.toml
									
										
									
									
									
								
							|  | @ -17,8 +17,17 @@ crate-type = ["staticlib", "cdylib", "rlib"] | |||
| [build-dependencies] | ||||
| cbindgen = "0.28.0" | ||||
| 
 | ||||
| [dependencies] | ||||
| servicepoint = { features = ["all_compressions"], git = "https://git.berlin.ccc.de/servicepoint/servicepoint/", branch = "next" } | ||||
| [dependencies.servicepoint] | ||||
| package = "servicepoint" | ||||
| version = "0.13.2" | ||||
| default-features = false | ||||
| features = ["protocol_udp"] | ||||
| git = "https://git.berlin.ccc.de/servicepoint/servicepoint/" | ||||
| branch = "next" | ||||
| 
 | ||||
| [features] | ||||
| full = ["servicepoint/all_compressions", "servicepoint/default"] | ||||
| default = ["full"] | ||||
| 
 | ||||
| [lints.rust] | ||||
| missing-docs = "warn" | ||||
|  | @ -26,3 +35,11 @@ unsafe_op_in_unsafe_fn = "warn" | |||
| 
 | ||||
| [package.metadata.docs.rs] | ||||
| all-features = true | ||||
| 
 | ||||
| [profile.size-optimized] | ||||
| inherits = "release" | ||||
| opt-level = 'z'     # Optimize for size | ||||
| lto = true          # Enable link-time optimization | ||||
| codegen-units = 1   # Reduce number of codegen units to increase optimizations | ||||
| panic = 'abort'     # Abort on panic | ||||
| strip = true        # Strip symbols from binary | ||||
|  |  | |||
|  | @ -26,7 +26,7 @@ sort_by = "Name" | |||
| parse_deps = false | ||||
| 
 | ||||
| [parse.expand] | ||||
| all_features = true | ||||
| features = ["full"] | ||||
| 
 | ||||
| [export] | ||||
| include = [] | ||||
|  |  | |||
|  | @ -2,14 +2,20 @@ | |||
| #include "servicepoint.h" | ||||
| 
 | ||||
| int main(void) { | ||||
|     SPUdpConnection *connection = sp_connection_open("localhost:2342"); | ||||
|     SPConnection *connection = sp_connection_open("localhost:2342"); | ||||
|     if (connection == NULL) | ||||
|         return 1; | ||||
| 
 | ||||
|     SPBitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT); | ||||
|     if (pixels == NULL) | ||||
|       return 1; | ||||
| 
 | ||||
|     sp_bitmap_fill(pixels, true); | ||||
| 
 | ||||
|     SPCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, SP_COMPRESSION_CODE_UNCOMPRESSED); | ||||
|     if (command == NULL) | ||||
|       return 1; | ||||
| 
 | ||||
|     sp_connection_send_command(connection, command); | ||||
| 
 | ||||
|     sp_connection_free(connection); | ||||
|  |  | |||
|  | @ -1,7 +1,47 @@ | |||
| CC := gcc | ||||
| CARGO := rustup run nightly cargo | ||||
| 
 | ||||
| THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) | ||||
| REPO_ROOT := $(THIS_DIR)/../../ | ||||
| RUST_TARGET_DIR := $(REPO_ROOT)/target/x86_64-unknown-linux-musl/size-optimized | ||||
| 
 | ||||
| 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 | ||||
| 
 | ||||
| CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \
 | ||||
| 	--profile=size-optimized \
 | ||||
| 	--no-default-features \
 | ||||
| 	--target=x86_64-unknown-linux-musl \
 | ||||
| 	-Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
 | ||||
| 	-Zbuild-std-features="panic_immediate_abort" \
 | ||||
| 
 | ||||
| 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 \
 | ||||
| 	#-fuse-ld=gold \ | ||||
| 	-fno-exceptions | ||||
| 	#-Wl,--icf=all \ | ||||
| 
 | ||||
| export SERVICEPOINT_HEADER_OUT := $(THIS_DIR)/include | ||||
| 
 | ||||
| build: out/lang_c | ||||
| 
 | ||||
|  | @ -15,20 +55,19 @@ run: out/lang_c | |||
| 
 | ||||
| PHONY: build clean dependencies run | ||||
| 
 | ||||
| out/lang_c: dependencies src/main.c | ||||
| out/lang_c_unstripped: dependencies src/main.c | ||||
| 	mkdir -p out || true | ||||
| 	${CC} src/main.c \
 | ||||
| 		-I include \
 | ||||
| 		-L $(REPO_ROOT)/target/release \
 | ||||
| 		-Wl,-Bstatic -lservicepoint_binding_c \
 | ||||
| 		-Wl,-Bdynamic -llzma \
 | ||||
| 		-o out/lang_c | ||||
| 		-I $(SERVICEPOINT_HEADER_OUT) \
 | ||||
| 		-L $(RUST_TARGET_DIR)\
 | ||||
| 		$(CCFLAGS) \
 | ||||
| 		-o out/lang_c_unstripped | ||||
| out/lang_c: out/lang_c_unstripped | ||||
| 	strip -s -R .comment -R .gnu.version --strip-unneeded out/lang_c_unstripped -o out/lang_c | ||||
| #strip -S --strip-unneeded --remove-section=.note.gnu.gold-version --remove-section=.comment --remove-section=.note --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag
 | ||||
| 
 | ||||
| dependencies: FORCE | ||||
| 	mkdir -p include || true | ||||
| 	# generate servicepoint header and binary to link against | ||||
| 	SERVICEPOINT_HEADER_OUT=$(THIS_DIR)/include cargo build \
 | ||||
| 		--manifest-path=$(REPO_ROOT)/Cargo.toml \
 | ||||
| 		--release | ||||
| 
 | ||||
| 	${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) | ||||
| FORCE: ; | ||||
|  |  | |||
							
								
								
									
										15
									
								
								flake.nix
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								flake.nix
									
										
									
									
									
								
							|  | @ -33,7 +33,16 @@ | |||
|         { pkgs, system }: | ||||
|         { | ||||
|           default = pkgs.mkShell rec { | ||||
|             packages = with pkgs; [ | ||||
|             buildInputs = with pkgs;[ | ||||
|               xe | ||||
|               xz | ||||
|               libgcc | ||||
|               #glibc.static | ||||
|               musl | ||||
|               libunwind | ||||
|               ]; | ||||
| 
 | ||||
|             nativeBuildInputs = with pkgs;[ | ||||
|               (pkgs.symlinkJoin { | ||||
|                 name = "rust-toolchain"; | ||||
|                 paths = with pkgs; [ | ||||
|  | @ -48,10 +57,10 @@ | |||
|               }) | ||||
|               gcc | ||||
|               gnumake | ||||
|               xe | ||||
|               xz | ||||
|               pkg-config | ||||
| 
 | ||||
|             ]; | ||||
| 
 | ||||
|             RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; | ||||
|           }; | ||||
|         } | ||||
|  |  | |||
|  | @ -168,6 +168,19 @@ typedef struct SPCharGrid SPCharGrid; | |||
|  */ | ||||
| typedef struct SPCommand SPCommand; | ||||
| 
 | ||||
| /**
 | ||||
|  * A connection to the display. | ||||
|  * | ||||
|  * # Examples | ||||
|  * | ||||
|  * ```C | ||||
|  * CConnection connection = sp_connection_open("172.23.42.29:2342"); | ||||
|  * if (connection != NULL) | ||||
|  *     sp_connection_send_command(connection, sp_command_clear()); | ||||
|  * ``` | ||||
|  */ | ||||
| typedef struct SPConnection SPConnection; | ||||
| 
 | ||||
| /**
 | ||||
|  * A C-wrapper for grid containing codepage 437 characters. | ||||
|  * | ||||
|  | @ -189,19 +202,6 @@ typedef struct SPCp437Grid SPCp437Grid; | |||
|  */ | ||||
| typedef struct SPPacket SPPacket; | ||||
| 
 | ||||
| /**
 | ||||
|  * A connection to the display. | ||||
|  * | ||||
|  * # Examples | ||||
|  * | ||||
|  * ```C | ||||
|  * CConnection connection = sp_connection_open("172.23.42.29:2342"); | ||||
|  * if (connection != NULL) | ||||
|  *     sp_connection_send_command(connection, sp_command_clear()); | ||||
|  * ``` | ||||
|  */ | ||||
| typedef struct SPUdpConnection SPUdpConnection; | ||||
| 
 | ||||
| /**
 | ||||
|  * Represents a span of memory (`&mut [u8]` ) as a struct usable by C code. | ||||
|  * | ||||
|  | @ -290,7 +290,7 @@ void sp_bitmap_fill(SPBitmap *bitmap, bool value); | |||
|  * | ||||
|  * [SPCommand]: [crate::SPCommand] | ||||
|  */ | ||||
| void sp_bitmap_free(SPBitmap **bitmap); | ||||
| void sp_bitmap_free(SPBitmap *bitmap); | ||||
| 
 | ||||
| /**
 | ||||
|  * Gets the current value at the specified position in the [SPBitmap]. | ||||
|  | @ -1456,7 +1456,7 @@ SPCommand *sp_command_utf8_data(size_t x, | |||
|                                 SPCharGrid *grid); | ||||
| 
 | ||||
| /**
 | ||||
|  * Closes and deallocates a [SPUdpConnection]. | ||||
|  * Closes and deallocates a [SPConnection]. | ||||
|  * | ||||
|  * # Panics | ||||
|  * | ||||
|  | @ -1466,13 +1466,13 @@ SPCommand *sp_command_utf8_data(size_t x, | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `connection` points to a valid [SPUdpConnection] | ||||
|  * - `connection` points to a valid [SPConnection] | ||||
|  * - `connection` is not used concurrently or after this call | ||||
|  */ | ||||
| void sp_connection_free(SPUdpConnection *connection); | ||||
| void sp_connection_free(SPConnection *connection); | ||||
| 
 | ||||
| /**
 | ||||
|  * Creates a new instance of [SPUdpConnection]. | ||||
|  * Creates a new instance of [SPConnection]. | ||||
|  * | ||||
|  * returns: NULL if connection fails, or connected instance | ||||
|  * | ||||
|  | @ -1487,10 +1487,10 @@ void sp_connection_free(SPUdpConnection *connection); | |||
|  * - the returned instance is freed in some way, either by using a consuming function or | ||||
|  *   by explicitly calling `sp_connection_free`. | ||||
|  */ | ||||
| SPUdpConnection *sp_connection_open(const char *host); | ||||
| SPConnection *sp_connection_open(const char *host); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sends a [SPCommand] to the display using the [SPUdpConnection]. | ||||
|  * Sends a [SPCommand] to the display using the [SPConnection]. | ||||
|  * | ||||
|  * The passed `command` gets consumed. | ||||
|  * | ||||
|  | @ -1505,15 +1505,15 @@ SPUdpConnection *sp_connection_open(const char *host); | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `connection` points to a valid instance of [SPUdpConnection] | ||||
|  * - `connection` points to a valid instance of [SPConnection] | ||||
|  * - `command` points to a valid instance of [SPPacket] | ||||
|  * - `command` is not used concurrently or after this call | ||||
|  */ | ||||
| bool sp_connection_send_command(const SPUdpConnection *connection, | ||||
| bool sp_connection_send_command(const SPConnection *connection, | ||||
|                                 SPCommand *command); | ||||
| 
 | ||||
| /**
 | ||||
|  * Sends a [SPPacket] to the display using the [SPUdpConnection]. | ||||
|  * Sends a [SPPacket] to the display using the [SPConnection]. | ||||
|  * | ||||
|  * The passed `packet` gets consumed. | ||||
|  * | ||||
|  | @ -1528,11 +1528,11 @@ bool sp_connection_send_command(const SPUdpConnection *connection, | |||
|  * | ||||
|  * The caller has to make sure that: | ||||
|  * | ||||
|  * - `connection` points to a valid instance of [SPUdpConnection] | ||||
|  * - `connection` points to a valid instance of [SPConnection] | ||||
|  * - `packet` points to a valid instance of [SPPacket] | ||||
|  * - `packet` is not used concurrently or after this call | ||||
|  */ | ||||
| bool sp_connection_send_packet(const SPUdpConnection *connection, | ||||
| bool sp_connection_send_packet(const SPConnection *connection, | ||||
|                                SPPacket *packet); | ||||
| 
 | ||||
| /**
 | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ | |||
| //! prefix `sp_bitmap_`
 | ||||
| 
 | ||||
| use servicepoint::{DataRef, Grid}; | ||||
| use std::ptr::{null_mut, NonNull}; | ||||
| use std::ptr::{NonNull}; | ||||
| 
 | ||||
| use crate::byte_slice::SPByteSlice; | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ | |||
| use crate::SPByteSlice; | ||||
| use servicepoint::{DataRef, Grid}; | ||||
| use std::convert::Into; | ||||
| use std::intrinsics::transmute; | ||||
| use std::mem::transmute; | ||||
| use std::ptr::NonNull; | ||||
| 
 | ||||
| /// see [servicepoint::Brightness::MIN]
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vinzenz Schroeter
						Vinzenz Schroeter