From 613f21310e7126ed4db2e6739dcc86ae3c491e8b Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Sat, 12 Apr 2025 16:33:39 +0200 Subject: [PATCH] fix rebase --- example/Makefile | 59 +++++++++++++++++++++++++++----- examples/.gitignore | 4 --- examples/lang_c/Makefile | 73 ---------------------------------------- 3 files changed, 51 insertions(+), 85 deletions(-) delete mode 100644 examples/.gitignore delete mode 100644 examples/lang_c/Makefile diff --git a/example/Makefile b/example/Makefile index abdd69f..e7d858f 100644 --- a/example/Makefile +++ b/example/Makefile @@ -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 := $(REPO_ROOT)/include build: out/example @@ -15,16 +55,19 @@ run: out/example PHONY: build clean dependencies run -out/example: dependencies main.c +out/example_unstripped: dependencies main.c mkdir -p out || true ${CC} main.c \ - -I $(REPO_ROOT)/include \ - -L $(REPO_ROOT)/target/release \ - -Wl,-Bstatic -lservicepoint_binding_c \ - -Wl,-Bdynamic -llzma \ - -o out/example + -I $(SERVICEPOINT_HEADER_OUT) \ + -L $(RUST_TARGET_DIR)\ + $(CCFLAGS) \ + -o out/example_unstripped +out/example: out/example_unstripped + strip -s -R .comment -R .gnu.version --strip-unneeded out/example_unstripped -o out/example +#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 - cargo build --manifest-path=$(REPO_ROOT)/Cargo.toml --release - + mkdir -p include || true + # generate servicepoint header and binary to link against + ${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) FORCE: ; diff --git a/examples/.gitignore b/examples/.gitignore deleted file mode 100644 index 9415aeb..0000000 --- a/examples/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# examples only use library in this repo -Cargo.lock -out -target diff --git a/examples/lang_c/Makefile b/examples/lang_c/Makefile deleted file mode 100644 index aa31733..0000000 --- a/examples/lang_c/Makefile +++ /dev/null @@ -1,73 +0,0 @@ -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 - -clean: - rm -r out || true - rm include/servicepoint.h || true - cargo clean - -run: out/lang_c - out/lang_c - -PHONY: build clean dependencies run - -out/lang_c_unstripped: dependencies src/main.c - mkdir -p out || true - ${CC} src/main.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 - ${CARGO} rustc $(CARGOFLAGS) -- $(RUSTFLAGS) -FORCE: ;