wip 80k example
This commit is contained in:
parent
57d9e90b0f
commit
69bed7c665
21
Cargo.toml
21
Cargo.toml
|
@ -17,8 +17,17 @@ crate-type = ["staticlib", "cdylib", "rlib"]
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
cbindgen = "0.28.0"
|
cbindgen = "0.28.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies.servicepoint]
|
||||||
servicepoint = { features = ["all_compressions"], git = "https://git.berlin.ccc.de/servicepoint/servicepoint/", branch = "next" }
|
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]
|
[lints.rust]
|
||||||
missing-docs = "warn"
|
missing-docs = "warn"
|
||||||
|
@ -26,3 +35,11 @@ unsafe_op_in_unsafe_fn = "warn"
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
all-features = true
|
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_deps = false
|
||||||
|
|
||||||
[parse.expand]
|
[parse.expand]
|
||||||
all_features = true
|
features = ["full"]
|
||||||
|
|
||||||
[export]
|
[export]
|
||||||
include = []
|
include = []
|
||||||
|
|
|
@ -2,14 +2,20 @@
|
||||||
#include "servicepoint.h"
|
#include "servicepoint.h"
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
SPUdpConnection *connection = sp_connection_open("localhost:2342");
|
SPConnection *connection = sp_connection_open("localhost:2342");
|
||||||
if (connection == NULL)
|
if (connection == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
SPBitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
|
SPBitmap *pixels = sp_bitmap_new(SP_PIXEL_WIDTH, SP_PIXEL_HEIGHT);
|
||||||
|
if (pixels == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
sp_bitmap_fill(pixels, true);
|
sp_bitmap_fill(pixels, true);
|
||||||
|
|
||||||
SPCommand *command = sp_command_bitmap_linear_win(0, 0, pixels, SP_COMPRESSION_CODE_UNCOMPRESSED);
|
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_send_command(connection, command);
|
||||||
|
|
||||||
sp_connection_free(connection);
|
sp_connection_free(connection);
|
||||||
|
|
|
@ -1,7 +1,47 @@
|
||||||
CC := gcc
|
CC := gcc
|
||||||
|
CARGO := rustup run nightly cargo
|
||||||
|
|
||||||
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
REPO_ROOT := $(THIS_DIR)/../../
|
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
|
build: out/lang_c
|
||||||
|
|
||||||
|
@ -15,20 +55,19 @@ run: out/lang_c
|
||||||
|
|
||||||
PHONY: build clean dependencies run
|
PHONY: build clean dependencies run
|
||||||
|
|
||||||
out/lang_c: dependencies src/main.c
|
out/lang_c_unstripped: dependencies src/main.c
|
||||||
mkdir -p out || true
|
mkdir -p out || true
|
||||||
${CC} src/main.c \
|
${CC} src/main.c \
|
||||||
-I include \
|
-I $(SERVICEPOINT_HEADER_OUT) \
|
||||||
-L $(REPO_ROOT)/target/release \
|
-L $(RUST_TARGET_DIR)\
|
||||||
-Wl,-Bstatic -lservicepoint_binding_c \
|
$(CCFLAGS) \
|
||||||
-Wl,-Bdynamic -llzma \
|
-o out/lang_c_unstripped
|
||||||
-o out/lang_c
|
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
|
dependencies: FORCE
|
||||||
mkdir -p include || true
|
mkdir -p include || true
|
||||||
# generate servicepoint header and binary to link against
|
# generate servicepoint header and binary to link against
|
||||||
SERVICEPOINT_HEADER_OUT=$(THIS_DIR)/include cargo build \
|
${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS)
|
||||||
--manifest-path=$(REPO_ROOT)/Cargo.toml \
|
|
||||||
--release
|
|
||||||
|
|
||||||
FORCE: ;
|
FORCE: ;
|
||||||
|
|
26
flake.nix
26
flake.nix
|
@ -33,25 +33,35 @@
|
||||||
{ pkgs, system }:
|
{ pkgs, system }:
|
||||||
{
|
{
|
||||||
default = pkgs.mkShell rec {
|
default = pkgs.mkShell rec {
|
||||||
packages = with pkgs; [
|
buildInputs = with pkgs;[
|
||||||
|
xe
|
||||||
|
xz
|
||||||
|
libgcc
|
||||||
|
#glibc.static
|
||||||
|
musl
|
||||||
|
libunwind
|
||||||
|
];
|
||||||
|
|
||||||
|
nativeBuildInputs = with pkgs;[
|
||||||
(pkgs.symlinkJoin {
|
(pkgs.symlinkJoin {
|
||||||
name = "rust-toolchain";
|
name = "rust-toolchain";
|
||||||
paths = with pkgs; [
|
paths = with pkgs; [
|
||||||
rustc
|
#rustc
|
||||||
cargo
|
#cargo
|
||||||
rustPlatform.rustcSrc
|
#rustPlatform.rustcSrc
|
||||||
rustfmt
|
#rustfmt
|
||||||
clippy
|
#clippy
|
||||||
cargo-expand
|
cargo-expand
|
||||||
cargo-tarpaulin
|
cargo-tarpaulin
|
||||||
|
rustup
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
gcc
|
gcc
|
||||||
gnumake
|
gnumake
|
||||||
xe
|
|
||||||
xz
|
|
||||||
pkg-config
|
pkg-config
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|
||||||
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,19 @@ typedef struct SPCharGrid SPCharGrid;
|
||||||
*/
|
*/
|
||||||
typedef struct SPCommand SPCommand;
|
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.
|
* A C-wrapper for grid containing codepage 437 characters.
|
||||||
*
|
*
|
||||||
|
@ -189,19 +202,6 @@ typedef struct SPCp437Grid SPCp437Grid;
|
||||||
*/
|
*/
|
||||||
typedef struct SPPacket SPPacket;
|
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.
|
* 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]
|
* [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].
|
* 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);
|
SPCharGrid *grid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Closes and deallocates a [SPUdpConnection].
|
* Closes and deallocates a [SPConnection].
|
||||||
*
|
*
|
||||||
* # Panics
|
* # Panics
|
||||||
*
|
*
|
||||||
|
@ -1466,13 +1466,13 @@ SPCommand *sp_command_utf8_data(size_t x,
|
||||||
*
|
*
|
||||||
* The caller has to make sure that:
|
* 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
|
* - `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
|
* 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
|
* - the returned instance is freed in some way, either by using a consuming function or
|
||||||
* by explicitly calling `sp_connection_free`.
|
* 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.
|
* The passed `command` gets consumed.
|
||||||
*
|
*
|
||||||
|
@ -1505,15 +1505,15 @@ SPUdpConnection *sp_connection_open(const char *host);
|
||||||
*
|
*
|
||||||
* The caller has to make sure that:
|
* 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` points to a valid instance of [SPPacket]
|
||||||
* - `command` is not used concurrently or after this call
|
* - `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);
|
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.
|
* The passed `packet` gets consumed.
|
||||||
*
|
*
|
||||||
|
@ -1528,11 +1528,11 @@ bool sp_connection_send_command(const SPUdpConnection *connection,
|
||||||
*
|
*
|
||||||
* The caller has to make sure that:
|
* 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` points to a valid instance of [SPPacket]
|
||||||
* - `packet` is not used concurrently or after this call
|
* - `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);
|
SPPacket *packet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//! prefix `sp_bitmap_`
|
//! prefix `sp_bitmap_`
|
||||||
|
|
||||||
use servicepoint::{DataRef, Grid};
|
use servicepoint::{DataRef, Grid};
|
||||||
use std::ptr::{null_mut, NonNull};
|
use std::ptr::{NonNull};
|
||||||
|
|
||||||
use crate::byte_slice::SPByteSlice;
|
use crate::byte_slice::SPByteSlice;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use crate::SPByteSlice;
|
use crate::SPByteSlice;
|
||||||
use servicepoint::{DataRef, Grid};
|
use servicepoint::{DataRef, Grid};
|
||||||
use std::convert::Into;
|
use std::convert::Into;
|
||||||
use std::intrinsics::transmute;
|
use std::mem::transmute;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// see [servicepoint::Brightness::MIN]
|
/// see [servicepoint::Brightness::MIN]
|
||||||
|
|
Loading…
Reference in a new issue