Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
fix(c): simplify the template config files
Browse files Browse the repository at this point in the history
  • Loading branch information
Sigmanificient committed May 7, 2024
1 parent 57769ca commit 54e1b7e
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 107 deletions.
2 changes: 0 additions & 2 deletions c/.gitattributes

This file was deleted.

4 changes: 1 addition & 3 deletions c/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ hello
# build
*.[aod]

# config
# language support
compile_commands.json
.pre-commit-config.yaml
.cache

# nix
.direnv
.envrc
result
29 changes: 0 additions & 29 deletions c/Dockerfile

This file was deleted.

19 changes: 7 additions & 12 deletions c/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
.POSIX:
.SUFFIXES: .o

CC ?= gcc
CFLAGS += @compile_flags.txt

OUT := hello
BINDIR ?= /usr/bin

SRC += main.c
OBJ := $(SRC:.c=.o)

CFLAGS += @compile_flags.txt
CFLAGS += -ffunction-sections -fdata-sections

LDFLAGS := -fwhole-program -flto
LDFLAGS += -Wl,--gc-sections -s

RM ?= rm -f

.DEFAULT_GOAL: all
.PHONY: all
all: $(OUT)

Expand All @@ -33,3 +24,7 @@ fclean: clean
.PHONY: re
.NOTPARALLEL: re
re: fclean all

.PHONY: install
install:
install -D hello ${BINDIR}/hello --mode 0755
10 changes: 0 additions & 10 deletions c/compile_flags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
-pipe

-Wall
-Wcast-qual
-Wconversion
-Werror=return-type
-Werror=vla-larger-than=0
-Wextra
-Wmissing-prototypes
-Wshadow
-Wstrict-prototypes
-Wwrite-strings

-O2
-march=native
-mtune=native
13 changes: 0 additions & 13 deletions c/default.nix

This file was deleted.

29 changes: 6 additions & 23 deletions c/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,20 @@
let
forAllSystems =
function:
nixpkgs.lib.genAttrs [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
"i686-linux"
"mipsel-linux"
"powerpc64le-linux"
] (system: function nixpkgs.legacyPackages.${system});
nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed (
system: function nixpkgs.legacyPackages.${system}
);
in
rec {
devShells = forAllSystems (pkgs: {
default = pkgs.mkShell {
hardeningDisable = [ "fortify" ];
inputsFrom = pkgs.lib.attrsets.attrValues packages;
};
default = pkgs.mkShell { inputsFrom = [ packages.${pkgs.system}.hello ]; };
});

packages = forAllSystems (pkgs: rec {
default = hello;
hello = pkgs.callPackage ./default.nix { };
hello = pkgs.callPackage ./hello.nix { };
});

overlays.default = final: prev: { hello = final.callPackage ./default.nix { }; };

apps = forAllSystems (pkgs: rec {
default = hello;
hello = {
program = "${packages.${pkgs.system}.hello}/bin/hello";
type = "app";
};
});
overlays.default = final: prev: { hello = prev.callPackage ./default.nix { }; };
};
}
7 changes: 7 additions & 0 deletions c/hello.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{ stdenv }:
stdenv.mkDerivation {
name = "hello";
src = ./.;

env.BINDIR = "${placeholder "out"}/bin";
}
14 changes: 3 additions & 11 deletions c/main.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define lengthof(sstr) (sizeof (sstr) / sizeof *(sstr))
#define sstr_len(sstr) (lengthof(sstr) - 1)
#define sstr_unpack(sstr) (sstr), (sstr_len(sstr))

static const char GREETING[] = "hello, world!\n";

int main(void)
{
return (
write(STDOUT_FILENO, sstr_unpack(GREETING))
== sstr_len(GREETING)
) ? EXIT_SUCCESS : EXIT_FAILURE;
printf("hello, world!\n");
return EXIT_SUCCESS;
}
4 changes: 0 additions & 4 deletions c/tokei.toml

This file was deleted.

0 comments on commit 54e1b7e

Please sign in to comment.