Compare commits
No commits in common. "577ba02d2217f4ce4ee3051d1e80c4ba135655e9" and "3589a90385b7bf33f165fe8fb663f2798bd523d7" have entirely different histories.
577ba02d22
...
3589a90385
14
.github/workflows/rust.yml
vendored
14
.github/workflows/rust.yml
vendored
|
@ -40,15 +40,5 @@ jobs:
|
||||||
- name: build
|
- name: build
|
||||||
run: cargo build
|
run: cargo build
|
||||||
|
|
||||||
- name: build example -- glibc release
|
- name: build example
|
||||||
run: cd example && make clean && make PROFILE=release
|
run: cd example && make
|
||||||
- name: build example -- glibc debug
|
|
||||||
run: cd example && make clean && make PROFILE=debug
|
|
||||||
- name: build example -- glibc size-optimized
|
|
||||||
run: cd example && make clean && make PROFILE=size-optimized
|
|
||||||
- name: build example -- musl release
|
|
||||||
run: cd example && make clean && make PROFILE=release MUSL=1
|
|
||||||
- name: build example -- musl debug
|
|
||||||
run: cd example && make clean && make PROFILE=debug MUSL=1
|
|
||||||
- name: build example -- musl size-optimized
|
|
||||||
run: cd example && make clean && make PROFILE=size-optimized MUSL=1
|
|
||||||
|
|
|
@ -26,9 +26,8 @@ git = "https://git.berlin.ccc.de/servicepoint/servicepoint/"
|
||||||
branch = "next"
|
branch = "next"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
protocol_udp = ["servicepoint/protocol_udp"]
|
full = ["servicepoint/all_compressions", "servicepoint/default"]
|
||||||
all_compressions = ["servicepoint/all_compressions"]
|
default = ["full"]
|
||||||
default = ["all_compressions", "servicepoint/default", "protocol_udp"]
|
|
||||||
|
|
||||||
[lints.rust]
|
[lints.rust]
|
||||||
missing-docs = "warn"
|
missing-docs = "warn"
|
||||||
|
|
144
example/Makefile
144
example/Makefile
|
@ -1,113 +1,83 @@
|
||||||
CARGO ?= rustup run nightly cargo
|
CC := gcc
|
||||||
STRIP ?= strip
|
CARGO := rustup run nightly cargo
|
||||||
|
|
||||||
FEATURES := protocol_udp
|
TARGET := x86_64-unknown-linux-musl
|
||||||
|
PROFILE := size-optimized
|
||||||
|
|
||||||
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
REPO_ROOT := $(realpath $(THIS_DIR)/..)
|
REPO_ROOT := $(THIS_DIR)/..
|
||||||
|
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(PROFILE)
|
||||||
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
|
export SERVICEPOINT_HEADER_OUT := $(REPO_ROOT)/include
|
||||||
|
|
||||||
override CFG_MUSL := $(if $(CFG_MUSL),$(CFG_MUSL),$(if $(MUSL),$(MUSL),0))
|
RUSTFLAGS := -Zlocation-detail=none \
|
||||||
override CFG_PROFILE := $(if $(CFG_PROFILE),$(CFG_PROFILE),$(if $(PROFILE),$(PROFILE),release))
|
-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
|
||||||
|
|
||||||
CCFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wall -fwhole-program
|
CARGOFLAGS := --manifest-path=$(REPO_ROOT)/Cargo.toml \
|
||||||
|
--profile=$(PROFILE) \
|
||||||
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
|
|
||||||
|
|
||||||
ifeq ($(CFG_MUSL), 1)
|
|
||||||
TARGET ?= x86_64-unknown-linux-musl
|
|
||||||
CC ?= musl-gcc
|
|
||||||
CCFLAGS += -static
|
|
||||||
else
|
|
||||||
TARGET ?= x86_64-unknown-linux-gnu
|
|
||||||
CC ?= gcc
|
|
||||||
CCFLAGS += -shared
|
|
||||||
endif
|
|
||||||
|
|
||||||
RUSTFLAGS += -C linker=$(CC)
|
|
||||||
|
|
||||||
#ifeq ($(CFG_PROFILE), size-optimized)
|
|
||||||
# CCFLAGS += -nodefaultlibs -lc
|
|
||||||
#endif
|
|
||||||
|
|
||||||
CCFLAGS += -lservicepoint_binding_c
|
|
||||||
RUST_TARGET_DIR := $(REPO_ROOT)/target/$(TARGET)/$(CFG_PROFILE)
|
|
||||||
OUT_BASE_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 \
|
--no-default-features \
|
||||||
--features=$(FEATURES) \
|
--target=$(TARGET) \
|
||||||
--target=$(TARGET)
|
-Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
|
||||||
|
-Zbuild-std-features="panic_immediate_abort" \
|
||||||
|
|
||||||
ifeq ($(CFG_PROFILE), size-optimized)
|
CCFLAGS := -static -Os \
|
||||||
CCFLAGS += -Oz \
|
-ffunction-sections -fdata-sections \
|
||||||
-fwrapv -fomit-frame-pointer -fno-stack-protector\
|
-fwrapv -fomit-frame-pointer -fno-stack-protector\
|
||||||
-fno-unroll-loops \
|
-fwhole-program \
|
||||||
-fno-unwind-tables -fno-asynchronous-unwind-tables \
|
-nodefaultlibs -lservicepoint_binding_c -lc \
|
||||||
-fmerge-all-constants \
|
-Wl,--gc-sections \
|
||||||
-Wl,-z,norelro \
|
-fno-unroll-loops \
|
||||||
-Wl,--hash-style=gnu \
|
-fno-unwind-tables -fno-asynchronous-unwind-tables \
|
||||||
-fvisibility=hidden \
|
-fmerge-all-constants \
|
||||||
-Bsymbolic \
|
-Wl,-z,norelro \
|
||||||
-Wl,--exclude-libs,ALL \
|
-Wl,--hash-style=gnu \
|
||||||
-fno-ident \
|
-fvisibility=hidden \
|
||||||
-fno-exceptions
|
-Bsymbolic \
|
||||||
CARGOFLAGS += -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
|
-Wl,--exclude-libs,ALL \
|
||||||
-Zbuild-std-features="panic_immediate_abort"
|
-fno-ident \
|
||||||
RUSTFLAGS += -Zlocation-detail=none \
|
-Wall
|
||||||
-Zfmt-debug=none \
|
#-fuse-ld=gold \
|
||||||
-C link-arg=-z,norelro \
|
-fno-exceptions
|
||||||
-C link-arg=--hash-style=gnu \
|
#-Wl,--icf=all \
|
||||||
-C panic=abort
|
|
||||||
else ifeq ($(CFG_PROFILE), release)
|
|
||||||
CCFLAGS += -O2
|
|
||||||
else ifeq ($(CFG_PROFILE), debug)
|
|
||||||
CCFLAGS += -Og
|
|
||||||
else
|
|
||||||
CFG_PROFILE := $(error "PROFILE has to be set to one of: debug, release, size-optimized")
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(LTO), 1)
|
STRIPFLAGS := -s --strip-unneeded -R .comment -R .gnu.version -R .comment -R .note -R .note.gnu.build-id -R .note.ABI-tag
|
||||||
CCFLAGS += -flto
|
|
||||||
endif
|
|
||||||
|
|
||||||
_c_src := $(wildcard ./src/*.c)
|
_c_src := $(wildcard *.c)
|
||||||
_programs := $(basename $(notdir $(_c_src)))
|
_programs := $(basename $(_c_src))
|
||||||
_bins := $(addprefix out/, $(_programs))
|
_bins := $(addprefix out/, $(_programs))
|
||||||
_unstripped_bins := $(addsuffix _unstripped, $(_bins))
|
_unstripped_bins := $(addsuffix _unstripped, $(_bins))
|
||||||
_run_programs := $(addprefix run_, $(_programs))
|
_run_programs := $(addprefix run_, $(_programs))
|
||||||
_rs_src := $(wildcard ../src/**.rs) ../Cargo.lock ../Cargo.toml ../cbindgen.toml
|
_rs_src := $(wildcard ../src/**.rs) ../Cargo.lock
|
||||||
_sp_artifacts := $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a $(RUST_TARGET_DIR)/libservicepoint_binding_c.so
|
|
||||||
|
|
||||||
all: $(_bins)
|
all: $(_bins)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
echo rm -r $(OUT_DIR) || true
|
rm -r out || true
|
||||||
rm $(SERVICEPOINT_HEADER_OUT)/servicepoint.h || true
|
rm include/servicepoint.h || true
|
||||||
cargo clean
|
cargo clean
|
||||||
|
|
||||||
.PHONY: all clean sizes $(_run_programs)
|
PHONY: all clean sizes $(_run_programs)
|
||||||
|
|
||||||
$(_unstripped_bins): out/%_unstripped: src/%.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(_sp_artifacts)
|
$(_unstripped_bins): out/%_unstripped: %.c $(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a
|
||||||
mkdir -p out || true
|
mkdir -p out || true
|
||||||
${CC} $< \
|
${CC} $^ \
|
||||||
-I $(SERVICEPOINT_HEADER_OUT) \
|
-I $(SERVICEPOINT_HEADER_OUT) \
|
||||||
-L $(RUST_TARGET_DIR) \
|
-L $(RUST_TARGET_DIR)\
|
||||||
$(CCFLAGS) \
|
$(CCFLAGS) \
|
||||||
-o $@
|
-o $@
|
||||||
|
|
||||||
$(_bins): out/%: out/%_unstripped
|
$(_bins): out/%: out/%_unstripped
|
||||||
$(STRIP) $(STRIPFLAGS) $^ -o $@
|
strip $(STRIPFLAGS) $^ -o $@
|
||||||
|
|
||||||
$(_sp_artifacts): $(_rs_src)
|
$(SERVICEPOINT_HEADER_OUT)/servicepoint.h $(RUST_TARGET_DIR)/libservicepoint_binding_c.a: $(_rs_src)
|
||||||
mkdir -p $(SERVICEPOINT_HEADER_OUT) || true
|
mkdir -p include || true
|
||||||
# generate servicepoint header and library to link against
|
# generate servicepoint header and binary to link against
|
||||||
${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS)
|
${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS)
|
||||||
|
|
||||||
$(_run_programs): run_%: out/% FORCE
|
$(_run_programs): run_%: out/% FORCE
|
||||||
|
@ -116,9 +86,9 @@ $(_run_programs): run_%: out/% FORCE
|
||||||
sizes: $(_bins)
|
sizes: $(_bins)
|
||||||
ls -lB out
|
ls -lB out
|
||||||
|
|
||||||
analyze-size: $(OUT_DIR)/$(BIN)_unstripped
|
#analyze-size: out/example_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/example_unstripped \
|
||||||
| awk '{size=$$2+0; print size "\t" $$4}' \
|
# | awk '{size=$$2+0; print size "\t" $$4}' \
|
||||||
| less
|
# | less
|
||||||
|
|
||||||
FORCE: ;
|
FORCE: ;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
//#include <stdarg.h>
|
#include <stdio.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);
|
UdpConnection *connection = sp_udp_open_ipv4(127, 0, 0, 1, 2342);
|
||||||
|
@ -18,7 +17,7 @@ int main(void) {
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
Header *header = sp_packet_get_header(packet);
|
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);
|
sp_udp_send_packet(connection, packet);
|
||||||
|
|
20
flake.nix
20
flake.nix
|
@ -33,17 +33,16 @@
|
||||||
{ pkgs, system }:
|
{ pkgs, system }:
|
||||||
{
|
{
|
||||||
default = pkgs.mkShell rec {
|
default = pkgs.mkShell rec {
|
||||||
buildInputs = with pkgs; [
|
buildInputs = with pkgs;[
|
||||||
xe
|
xe
|
||||||
xz
|
xz
|
||||||
#libgcc
|
libgcc
|
||||||
#glibc
|
#glibc.static
|
||||||
pkgsStatic.musl
|
musl
|
||||||
# libunwind
|
libunwind
|
||||||
|
];
|
||||||
|
|
||||||
];
|
nativeBuildInputs = with pkgs;[
|
||||||
|
|
||||||
nativeBuildInputs = with pkgs; [
|
|
||||||
(pkgs.symlinkJoin {
|
(pkgs.symlinkJoin {
|
||||||
name = "rust-toolchain";
|
name = "rust-toolchain";
|
||||||
paths = with pkgs; [
|
paths = with pkgs; [
|
||||||
|
@ -58,14 +57,11 @@
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
gcc
|
gcc
|
||||||
gdb
|
|
||||||
pkgsStatic.gcc
|
|
||||||
gnumake
|
gnumake
|
||||||
pkg-config
|
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";
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
use crate::byte_slice::ByteSlice;
|
use crate::byte_slice::ByteSlice;
|
||||||
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, SPBitVec};
|
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, SPBitVec};
|
||||||
use servicepoint::{
|
use servicepoint::{Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet};
|
||||||
Bitmap, BitmapCommand, CompressionCode, DataRef, Grid, Origin, Packet,
|
|
||||||
};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Creates a new [Bitmap] with the specified dimensions.
|
/// Creates a new [Bitmap] with the specified dimensions.
|
||||||
|
@ -212,7 +210,7 @@ pub unsafe extern "C" fn sp_bitmap_into_packet(
|
||||||
bitmap: NonNull<Bitmap>,
|
bitmap: NonNull<Bitmap>,
|
||||||
x: usize,
|
x: usize,
|
||||||
y: usize,
|
y: usize,
|
||||||
compression: CompressionCode,
|
compression: CompressionCode
|
||||||
) -> *mut Packet {
|
) -> *mut Packet {
|
||||||
let bitmap = unsafe { heap_remove(bitmap) };
|
let bitmap = unsafe { heap_remove(bitmap) };
|
||||||
match Packet::try_from(BitmapCommand {
|
match Packet::try_from(BitmapCommand {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, ByteSlice};
|
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, ByteSlice};
|
||||||
use servicepoint::{
|
use servicepoint::{BinaryOperation, BitVecCommand, BitVecU8Msb0, CompressionCode, Packet};
|
||||||
BinaryOperation, BitVecCommand, BitVecU8Msb0, CompressionCode, Packet,
|
|
||||||
};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// A vector of bits
|
/// A vector of bits
|
||||||
|
@ -159,7 +157,7 @@ pub unsafe extern "C" fn sp_bitvec_into_packet(
|
||||||
bitvec: NonNull<SPBitVec>,
|
bitvec: NonNull<SPBitVec>,
|
||||||
offset: usize,
|
offset: usize,
|
||||||
operation: BinaryOperation,
|
operation: BinaryOperation,
|
||||||
compression: CompressionCode,
|
compression: CompressionCode
|
||||||
) -> *mut Packet {
|
) -> *mut Packet {
|
||||||
let bitvec = unsafe { heap_remove(bitvec) }.0;
|
let bitvec = unsafe { heap_remove(bitvec) }.0;
|
||||||
match Packet::try_from(BitVecCommand {
|
match Packet::try_from(BitVecCommand {
|
||||||
|
|
3
src/commands/mod.rs
Normal file
3
src/commands/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
mod typed;
|
||||||
|
|
||||||
|
pub use typed::*;
|
|
@ -1,7 +1,5 @@
|
||||||
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, ByteSlice};
|
use crate::{heap_drop, heap_move, heap_move_nonnull, heap_remove, ByteSlice};
|
||||||
use servicepoint::{
|
use servicepoint::{Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet};
|
||||||
Cp437Grid, Cp437GridCommand, DataRef, Grid, Origin, Packet,
|
|
||||||
};
|
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
|
|
||||||
/// Creates a new [Cp437Grid] with the specified dimensions.
|
/// Creates a new [Cp437Grid] with the specified dimensions.
|
||||||
|
|
12
src/lib.rs
12
src/lib.rs
|
@ -30,26 +30,22 @@ pub use crate::bitvec::*;
|
||||||
pub use crate::brightness_grid::*;
|
pub use crate::brightness_grid::*;
|
||||||
pub use crate::byte_slice::*;
|
pub use crate::byte_slice::*;
|
||||||
pub use crate::char_grid::*;
|
pub use crate::char_grid::*;
|
||||||
|
pub use crate::commands::*;
|
||||||
|
pub use crate::connection::*;
|
||||||
pub use crate::cp437_grid::*;
|
pub use crate::cp437_grid::*;
|
||||||
pub use crate::packet::*;
|
pub use crate::packet::*;
|
||||||
pub use servicepoint::CommandCode;
|
pub use servicepoint::CommandCode;
|
||||||
use std::ptr::NonNull;
|
use std::ptr::NonNull;
|
||||||
pub use typed_command::*;
|
|
||||||
|
|
||||||
mod bitmap;
|
mod bitmap;
|
||||||
mod bitvec;
|
mod bitvec;
|
||||||
mod brightness_grid;
|
mod brightness_grid;
|
||||||
mod byte_slice;
|
mod byte_slice;
|
||||||
mod char_grid;
|
mod char_grid;
|
||||||
|
mod commands;
|
||||||
|
mod connection;
|
||||||
mod cp437_grid;
|
mod cp437_grid;
|
||||||
mod packet;
|
mod packet;
|
||||||
mod typed_command;
|
|
||||||
|
|
||||||
#[cfg(feature = "protocol_udp")]
|
|
||||||
mod udp;
|
|
||||||
|
|
||||||
#[cfg(feature = "protocol_udp")]
|
|
||||||
pub use udp::*;
|
|
||||||
|
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue