Skip to content

Commit

Permalink
Add C template
Browse files Browse the repository at this point in the history
  • Loading branch information
42LoCo42 committed Dec 10, 2023
1 parent eef8a03 commit 335b0c2
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 26 deletions.
51 changes: 25 additions & 26 deletions packages/musializer.nix
Original file line number Diff line number Diff line change
@@ -1,51 +1,50 @@
{ fetchFromGitHub
, stdenv

, pkg-config
, autoPatchelfHook
, makeBinaryWrapper

, glfw
, raylib
, libglvnd
, xorg
}: stdenv.mkDerivation rec {
pname = "musializer";
version = "be42432";
version = "d971539";

src = fetchFromGitHub {
owner = "tsoding";
repo = pname;
rev = version;
hash = "sha256-1uxsgG8t6WhgkHe2QhdyYeALP2e6+4to7LWu0OK8qmg=";
hash = "sha256-s2NnoSNNe0iWAPfIgfUNqLp6ArbRHGNsicm/bHE5EPU=";
};

nativeBuildInputs = [
pkg-config
autoPatchelfHook
makeBinaryWrapper
];

buildInputs = [
glfw
raylib
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXinerama
xorg.libXrandr
];

patchPhase = ''
substituteInPlace build.sh \
--replace clang gcc
substituteInPlace src/plug.c \
--replace \
'"./fonts/Alegreya-Regular.ttf"' \
'"${src}/fonts/Alegreya-Regular.ttf"' \
--replace \
'"./shaders/circle.fs"' \
'"${src}/shaders/circle.fs"' \
--replace \
'"./shaders/smear.fs"' \
'"${src}/shaders/smear.fs"'
'';
runtimeDependencies = [
xorg.libX11
libglvnd
];

buildPhase = "./build.sh";
buildPhase = ''
cc -Wall -Wextra nob.c -o nob
./nob
'';

installPhase = ''
mkdir $out
cp -r build $out/bin
mkdir -p $out/bin
cp -r resources $out
cp build/musializer $out/bin
wrapProgram $out/bin/musializer --chdir $out/resources
'';

meta = {
Expand Down
16 changes: 16 additions & 0 deletions templates/c/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# -*- mode: yaml; -*-
IndentWidth: 4
TabWidth: 4
UseTab: AlignWithSpaces

SpaceAfterCStyleCast: true
SpaceBeforeParens: Never

AlignAfterOpenBracket: BlockIndent
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
PointerAlignment: Left

AllowShortBlocksOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
2 changes: 2 additions & 0 deletions templates/c/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake . -L
[ -f compile_commands.json ] || bear -- make -B
5 changes: 5 additions & 0 deletions templates/c/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.cache
/.direnv
/compile_commands.json
/main
/result
9 changes: 9 additions & 0 deletions templates/c/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DEPS :=
CFLAGS := $(shell pkg-config --cflags $(DEPS)) -Wall -Wextra
LDFLAGS := $(shell pkg-config --libs $(DEPS))

all: main

run: main
./$<
.PHONY: run
58 changes: 58 additions & 0 deletions templates/c/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions templates/c/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
outputs = { nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = import nixpkgs { inherit system; }; in rec {
defaultPackage = pkgs.stdenv.mkDerivation {
pname = "example";
version = "0.0.1";
src = ./.;

nativeBuildInputs = with pkgs; [
pkg-config
];
};

devShell = pkgs.mkShell {
inputsFrom = [ defaultPackage ];
packages = with pkgs; [
bear
clang-tools
];
};
});
}
5 changes: 5 additions & 0 deletions templates/c/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

int main(void) {
puts("Hello, World!");
}

0 comments on commit 335b0c2

Please sign in to comment.