type per command, binding generation macros, nix package #4
					 3 changed files with 84 additions and 28 deletions
				
			
		| 
						 | 
					@ -39,16 +39,12 @@ CARGO_OBJDIR := cargo/$(RUST_TARGET)/$(_profile)
 | 
				
			||||||
_rust_cli_profile := $(if $(filter $(_profile),debug),dev,$(_profile))
 | 
					_rust_cli_profile := $(if $(filter $(_profile),debug),dev,$(_profile))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
STRIPFLAGS += -s --strip-unneeded -R .comment -R .gnu.version -R .note -R .note.gnu.build-id -R .note.ABI-tag
 | 
					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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
size_optimized_CARGOFLAGS += -Zbuild-std="core,std,alloc,proc_macro,panic_abort" \
 | 
					 | 
				
			||||||
	-Zbuild-std-features="panic_immediate_abort"
 | 
					 | 
				
			||||||
CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
 | 
					CARGOFLAGS += --manifest-path=$(REPO_ROOT)/Cargo.toml \
 | 
				
			||||||
	--profile=$(_rust_cli_profile) \
 | 
						--profile=$(_rust_cli_profile) \
 | 
				
			||||||
	--no-default-features \
 | 
						--no-default-features \
 | 
				
			||||||
	--features=$(FEATURES) \
 | 
						--features=$(FEATURES) \
 | 
				
			||||||
	--target=$(RUST_TARGET) \
 | 
						--target=$(RUST_TARGET) \
 | 
				
			||||||
	$($(_profile)_CARGOFLAGS) \
 | 
					 | 
				
			||||||
	--target-dir=cargo
 | 
						--target-dir=cargo
 | 
				
			||||||
 | 
					
 | 
				
			||||||
CFLAGS += -Wall -Wextra -pedantic -fwhole-program -fPIE -pie
 | 
					CFLAGS += -Wall -Wextra -pedantic -fwhole-program -fPIE -pie
 | 
				
			||||||
| 
						 | 
					@ -73,7 +69,7 @@ debug_CFLAGS += -Og
 | 
				
			||||||
static_CFLAGS += -static $(STATIC_LINK_LIBS)
 | 
					static_CFLAGS += -static $(STATIC_LINK_LIBS)
 | 
				
			||||||
dynamic_CFLAGS += -Wl,-Bstatic $(STATIC_LINK_LIBS) -Wl,-Bdynamic
 | 
					dynamic_CFLAGS += -Wl,-Bstatic $(STATIC_LINK_LIBS) -Wl,-Bdynamic
 | 
				
			||||||
 | 
					
 | 
				
			||||||
_servicepoint_cflags := -I $(REPO_ROOT)/include -L $(CARGO_OBJDIR)
 | 
					_servicepoint_cflags := $(pkg-config --libs servicepoint --cflags)
 | 
				
			||||||
CFLAGS += $($(_libc)_CFLAGS) $($(_profile)_CFLAGS) $($(_link_type)_CFLAGS) $(_servicepoint_cflags)
 | 
					CFLAGS += $($(_libc)_CFLAGS) $($(_profile)_CFLAGS) $($(_link_type)_CFLAGS) $(_servicepoint_cflags)
 | 
				
			||||||
ifeq ($(LTO), 1)
 | 
					ifeq ($(LTO), 1)
 | 
				
			||||||
	CFLAGS += -flto
 | 
						CFLAGS += -flto
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										13
									
								
								nix-build-all.sh
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										13
									
								
								nix-build-all.sh
									
										
									
									
									
										Executable file
									
								
							| 
						 | 
					@ -0,0 +1,13 @@
 | 
				
			||||||
 | 
					#!/usr/bin/env bash
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					set -e
 | 
				
			||||||
 | 
					set -x
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nix build .#servicepoint-binding-c
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nix build .#servicepoint-binding-c-stable-release
 | 
				
			||||||
 | 
					nix build .#servicepoint-binding-c-nightly-release
 | 
				
			||||||
 | 
					nix build .#servicepoint-binding-c-nightly-size
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					nix build .#all-examples
 | 
				
			||||||
 | 
					nix build .#all-examples-size
 | 
				
			||||||
							
								
								
									
										91
									
								
								packages.nix
									
										
									
									
									
								
							
							
						
						
									
										91
									
								
								packages.nix
									
										
									
									
									
								
							| 
						 | 
					@ -8,12 +8,9 @@
 | 
				
			||||||
let
 | 
					let
 | 
				
			||||||
  version = "0.15.0";
 | 
					  version = "0.15.0";
 | 
				
			||||||
  mkServicepoint =
 | 
					  mkServicepoint =
 | 
				
			||||||
    {
 | 
					    rustPlatform:
 | 
				
			||||||
      rustPlatform,
 | 
					 | 
				
			||||||
      buildType,
 | 
					 | 
				
			||||||
    }:
 | 
					 | 
				
			||||||
    rustPlatform.buildRustPackage (finalAttrs: {
 | 
					    rustPlatform.buildRustPackage (finalAttrs: {
 | 
				
			||||||
      inherit buildType version;
 | 
					      inherit version;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      pname = "servicepoint-binding-c";
 | 
					      pname = "servicepoint-binding-c";
 | 
				
			||||||
      src = lib.filter {
 | 
					      src = lib.filter {
 | 
				
			||||||
| 
						 | 
					@ -28,14 +25,15 @@ let
 | 
				
			||||||
        ];
 | 
					        ];
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      cargoLock.lockFile = ./Cargo.lock;
 | 
					      cargoLock.lockFile = ./Cargo.lock;
 | 
				
			||||||
 | 
					      useFetchCargoVendor = true;
 | 
				
			||||||
      meta = {
 | 
					      meta = {
 | 
				
			||||||
        description = "C bindings for the servicepoint crate.";
 | 
					        description = "C bindings for the servicepoint crate.";
 | 
				
			||||||
        homepage = "https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c";
 | 
					        homepage = "https://git.berlin.ccc.de/servicepoint/servicepoint-binding-c";
 | 
				
			||||||
        license = lib.licenses.gpl3Plus;
 | 
					        license = lib.licenses.gpl3Plus;
 | 
				
			||||||
        pkgConfigModules = [ "servicepoint" ];
 | 
					        pkgConfigModules = [ "servicepoint" ];
 | 
				
			||||||
      };
 | 
					      };
 | 
				
			||||||
      nativeBuildInputs = with pkgs; [ pkg-config ];
 | 
					      nativeBuildInputs = [ pkgs.pkg-config ];
 | 
				
			||||||
      buildInputs = with pkgs; [ xz ];
 | 
					      buildInputs = [ pkgs.xz ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      preBuild = ''
 | 
					      preBuild = ''
 | 
				
			||||||
        mkdir -p include
 | 
					        mkdir -p include
 | 
				
			||||||
| 
						 | 
					@ -56,16 +54,17 @@ let
 | 
				
			||||||
    pkgs.stdenv.mkDerivation {
 | 
					    pkgs.stdenv.mkDerivation {
 | 
				
			||||||
      inherit version;
 | 
					      inherit version;
 | 
				
			||||||
      pname = "servicepoint-c-example-${name}";
 | 
					      pname = "servicepoint-c-example-${name}";
 | 
				
			||||||
 | 
					      nativeBuildInputs = [ pkgs.pkg-config ];
 | 
				
			||||||
      nativeBuildInputs = with pkgs; [ pkg-config ];
 | 
					      buildInputs = [
 | 
				
			||||||
      buildInputs = [ servicepointBinding ];
 | 
					        servicepointBinding
 | 
				
			||||||
 | 
					        pkgs.xz
 | 
				
			||||||
 | 
					      ];
 | 
				
			||||||
      src = ./example/src;
 | 
					      src = ./example/src;
 | 
				
			||||||
 | 
					 | 
				
			||||||
      #dontUnpack = true;
 | 
					 | 
				
			||||||
      buildPhase = ''
 | 
					      buildPhase = ''
 | 
				
			||||||
 | 
					        set -e
 | 
				
			||||||
 | 
					        set -x
 | 
				
			||||||
        mkdir -p $out/bin
 | 
					        mkdir -p $out/bin
 | 
				
			||||||
 | 
					        gcc ${name}.c $(pkg-config --libs --cflags servicepoint) $(pkg-config --libs --cflags liblzma) $EXTRA_CFLAGS -o $out/bin/${name}
 | 
				
			||||||
        gcc ${name}.c $(pkg-config --libs servicepoint --cflags) -o $out/bin/${name}
 | 
					 | 
				
			||||||
      '';
 | 
					      '';
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
  rustPlatform-stable = pkgs.rustPlatform;
 | 
					  rustPlatform-stable = pkgs.rustPlatform;
 | 
				
			||||||
| 
						 | 
					@ -83,21 +82,29 @@ let
 | 
				
			||||||
  ];
 | 
					  ];
 | 
				
			||||||
in
 | 
					in
 | 
				
			||||||
rec {
 | 
					rec {
 | 
				
			||||||
  servicepoint-binding-c-release = mkServicepoint {
 | 
					  servicepoint-binding-c-stable-release = mkServicepoint rustPlatform-stable;
 | 
				
			||||||
    buildType = "release";
 | 
					  servicepoint-binding-c-nightly-release = mkServicepoint rustPlatform-unstable;
 | 
				
			||||||
    rustPlatform = rustPlatform-stable;
 | 
					  servicepoint-binding-c-nightly-size = servicepoint-binding-c-nightly-release // {
 | 
				
			||||||
  };
 | 
					 | 
				
			||||||
  servicepoint-binding-c-size-optimized = mkServicepoint {
 | 
					 | 
				
			||||||
    buildType = "size_optimized";
 | 
					    buildType = "size_optimized";
 | 
				
			||||||
    rustPlatform = rustPlatform-unstable;
 | 
					    buildNoDefaultFeatures = true;
 | 
				
			||||||
 | 
					    # TODO: do these override the nix flags?
 | 
				
			||||||
 | 
					    #CARGOFLAGS = ''-Zbuild-std="core,std,alloc,proc_macro,panic_abort" -Zbuild-std-features="panic_immediate_abort"'';
 | 
				
			||||||
 | 
					    # TODO: those override the nix flags
 | 
				
			||||||
 | 
					    # NIX_CFLAGS_COMPILE = builtins.toString ["-Oz" "-fwrapv" "-fomit-frame-pointer" "-fno-stack-protector" "-fno-unroll-loops" "-fno-unwind-tables" "-fno-asynchronous-unwind-tables" "-fmerge-all-constants" "-fvisibility=hidden" "-Bsymbolic" "-fno-ident" "-fno-exceptions" "-ffunction-sections" "-fdata-sections"];
 | 
				
			||||||
 | 
					    # NIX_CFLAGS_LINK = builtins.toString ["Wl,-z,norelro" "-Wl,--hash-style=gnu" "-Wl,--gc-sections" "-Wl,--exclude-libs,ALL"];
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
  servicepoint-binding-c = servicepoint-binding-c-release;
 | 
					  servicepoint-binding-c = servicepoint-binding-c-stable-release;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  all-examples = pkgs.symlinkJoin {
 | 
					  all-examples = pkgs.symlinkJoin {
 | 
				
			||||||
    name = "servicepoint-all-examples";
 | 
					    name = "servicepoint-all-examples";
 | 
				
			||||||
    paths = builtins.map (e: selfPkgs.${e}) examples;
 | 
					    paths = builtins.map (e: selfPkgs."${e}") examples;
 | 
				
			||||||
 | 
					  };
 | 
				
			||||||
 | 
					  all-examples-size = pkgs.symlinkJoin {
 | 
				
			||||||
 | 
					    name = "servicepoint-all-examples-size";
 | 
				
			||||||
 | 
					    paths = builtins.map (e: selfPkgs."${e}-size") examples;
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					# construct one package per example
 | 
				
			||||||
// (lib.genAttrs examples (
 | 
					// (lib.genAttrs examples (
 | 
				
			||||||
  name:
 | 
					  name:
 | 
				
			||||||
  mkExample {
 | 
					  mkExample {
 | 
				
			||||||
| 
						 | 
					@ -105,3 +112,43 @@ rec {
 | 
				
			||||||
    servicepointBinding = selfPkgs.servicepoint-binding-c;
 | 
					    servicepointBinding = selfPkgs.servicepoint-binding-c;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
))
 | 
					))
 | 
				
			||||||
 | 
					# construct another pakage per example, but with a different name and compiler options
 | 
				
			||||||
 | 
					// (lib.mapAttrs'
 | 
				
			||||||
 | 
					  (
 | 
				
			||||||
 | 
					    name: value:
 | 
				
			||||||
 | 
					    lib.nameValuePair ("${name}-size") (
 | 
				
			||||||
 | 
					      value
 | 
				
			||||||
 | 
					      // {
 | 
				
			||||||
 | 
					        EXTRA_CFLAGS = builtins.toString [
 | 
				
			||||||
 | 
					          "-Oz"
 | 
				
			||||||
 | 
					          "-fwrapv"
 | 
				
			||||||
 | 
					          "-fomit-frame-pointer"
 | 
				
			||||||
 | 
					          "-fno-stack-protector"
 | 
				
			||||||
 | 
					          "-fno-unroll-loops"
 | 
				
			||||||
 | 
					          "-fno-unwind-tables"
 | 
				
			||||||
 | 
					          "-fno-asynchronous-unwind-tables"
 | 
				
			||||||
 | 
					          "-fmerge-all-constants"
 | 
				
			||||||
 | 
					          "-fvisibility=hidden"
 | 
				
			||||||
 | 
					          "-Bsymbolic"
 | 
				
			||||||
 | 
					          "-fno-ident"
 | 
				
			||||||
 | 
					          "-fno-exceptions"
 | 
				
			||||||
 | 
					          "-ffunction-sections"
 | 
				
			||||||
 | 
					          "-fdata-sections"
 | 
				
			||||||
 | 
					          "-Wl,-z,norelro"
 | 
				
			||||||
 | 
					          "-Wl,--hash-style=gnu"
 | 
				
			||||||
 | 
					          "-Wl,--gc-sections"
 | 
				
			||||||
 | 
					          "-Wl,--exclude-libs,ALL"
 | 
				
			||||||
 | 
					        ];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					  (
 | 
				
			||||||
 | 
					    lib.genAttrs examples (
 | 
				
			||||||
 | 
					      name:
 | 
				
			||||||
 | 
					      mkExample {
 | 
				
			||||||
 | 
					        inherit name;
 | 
				
			||||||
 | 
					        servicepointBinding = selfPkgs.servicepoint-binding-c-nightly-size;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					  )
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue