From e824baa4bad8a85e1d37b857cc0237e45e1ea0f7 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Fri, 30 May 2025 00:09:41 +0200 Subject: [PATCH] more configs work now ``` make LIBC=gnu LINK=dynamic make LIBC=musl LINK=dynamic CC=musl-gcc make LIBC=musl LINK=static CC=musl-gcc ``` --- example/Makefile | 18 +++++++++-------- flake.lock | 8 ++++---- flake.nix | 50 ++++++++++++++++++++++++++---------------------- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/example/Makefile b/example/Makefile index e2ac12e..1617552 100644 --- a/example/Makefile +++ b/example/Makefile @@ -36,11 +36,8 @@ THIS_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) REPO_ROOT := $(realpath $(THIS_DIR)/..) CARGO_OBJDIR := cargo/$(RUST_TARGET)/$(_profile) -# TODO: check if override is needed _rust_cli_profile := $(if $(filter $(_profile),debug),dev,$(_profile)) -# TODO: `make LINK=static` fails with linker error "undefined reference to `_dl_find_object'" in libgcc_eh.a - STRIPFLAGS += -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag STATIC_LINK_LIBS += -lservicepoint_binding_c @@ -57,7 +54,7 @@ CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \ CFLAGS += -Wall -Wextra -pedantic -fwhole-program -fPIE -pie _no_debug_cflags := -ffunction-sections -fdata-sections -Wl,--gc-sections size_optimized_CFLAGS += -Oz \ - -fwrapv -fomit-frame-pointer -fno-stack-protector\ + -fwrapv -fomit-frame-pointer -fno-stack-protector \ -fno-unroll-loops \ -fno-unwind-tables -fno-asynchronous-unwind-tables \ -fmerge-all-constants \ @@ -81,20 +78,25 @@ CFLAGS += $($(_libc)_CFLAGS) $($(_profile)_CFLAGS) $($(_link_type)_CFLAGS) $(_se ifeq ($(LTO), 1) CFLAGS += -flto endif +ifeq ($(_libc),gnu) + ifeq ($(_link_type),static) + CFLAGS += $(error "statically linking glibc is known to be broken") + endif +endif size_optimized_RUSTFLAGS += -Zlocation-detail=none \ -Zfmt-debug=none \ -C link-arg=-z,norelro \ - -C panic=abort - #-C link-arg=--hash-style=gnu -musl_RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=-crt-static + -C panic=abort \ + -C link-arg=-Wl,--hash-style=gnu +static_RUSTFLAGS += --crate-type=staticlib -Ctarget-feature=+crt-static RUSTFLAGS += $($(_libc)_RUSTFLAGS) $($(_profile)_RUSTFLAGS) $($(_link_type)_RUSTFLAGS) ifneq ($(_profile), debug) RUSTFLAGS += -C link-arg=-s -C link-arg=-Wl,--gc-sections endif -# TODO: wildcard does not work with VPATH +# ADD NEW EXAMPLES HERE _c_src := src/announce.c src/brightness_tester.c src/header_logger.c \ src/moving_line.c src/random_stuff.c src/wiping_clear.c _programs := $(basename $(notdir $(_c_src))) diff --git a/flake.lock b/flake.lock index c5f76d2..9091d9f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1748037224, - "narHash": "sha256-92vihpZr6dwEMV6g98M5kHZIttrWahb9iRPBm1atcPk=", + "lastModified": 1748302896, + "narHash": "sha256-ixMT0a8mM091vSswlTORZj93WQAJsRNmEvqLL+qwTFM=", "owner": "nixos", "repo": "nixpkgs", - "rev": "f09dede81861f3a83f7f06641ead34f02f37597f", + "rev": "7848cd8c982f7740edf76ddb3b43d234cb80fc4d", "type": "github" }, "original": { "owner": "nixos", - "ref": "nixos-24.11", + "ref": "nixos-25.05", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index 82983f7..2adaa88 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ description = "Flake for the servicepoint library."; inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-24.11"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-25.05"; }; outputs = @@ -31,37 +31,41 @@ { devShells = forAllSystems ( { pkgs, system }: + let + toolchain = pkgs.symlinkJoin { + name = "rust-toolchain"; + paths = with pkgs; [ + rustc + cargo + rustPlatform.rustcSrc + rustPlatform.rustLibSrc + rustfmt + clippy + cargo-expand + cargo-tarpaulin + ]; + }; + in { default = pkgs.mkShell rec { - buildInputs = with pkgs; [ + packages = with pkgs; [ + toolchain + gcc + gdb + gnumake + pkg-config xe xz libgcc libunwind + pkgsStatic.gcc + pkgsStatic.libgcc pkgsStatic.musl ]; - nativeBuildInputs = with pkgs; [ - (pkgs.symlinkJoin { - name = "rust-toolchain"; - paths = with pkgs; [ - rustc - cargo - rustPlatform.rustcSrc - rustfmt - clippy - cargo-expand - cargo-tarpaulin - ]; - }) - gcc - gdb - pkgsStatic.gcc - gnumake - pkg-config - ]; - - RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}"; + RUST_SRC_PATH = "${pkgs.rustPlatform.rustLibSrc}"; + RUST_BACKTRACE = 1; + RUST_LOG = "all"; }; } );