This commit is contained in:
commit
95a533c876
451 changed files with 18255 additions and 0 deletions
1
templates/dev/c-hello/.envrc
Normal file
1
templates/dev/c-hello/.envrc
Normal file
|
|
@ -0,0 +1 @@
|
|||
use flake
|
||||
23
templates/dev/c-hello/.github/workflows/c-nix.yml
vendored
Normal file
23
templates/dev/c-hello/.github/workflows/c-nix.yml
vendored
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
name: C Nix Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build and Test
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Set up Nix
|
||||
uses: cachix/install-nix-action@v18
|
||||
with:
|
||||
nix_path: nixpkgs=channel:nixos-unstable
|
||||
|
||||
- name: Run nix flake check
|
||||
run: nix flake check
|
||||
7
templates/dev/c-hello/.gitignore
vendored
Normal file
7
templates/dev/c-hello/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
.cache/
|
||||
.direnv/
|
||||
.pre-commit-config.yaml
|
||||
bin/
|
||||
build/
|
||||
compile_commands.json
|
||||
result/
|
||||
51
templates/dev/c-hello/Makefile
Normal file
51
templates/dev/c-hello/Makefile
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
PNAME = hello-world
|
||||
|
||||
BUILD_DIR = build
|
||||
INCLUDE_DIR = include
|
||||
SRC_DIR = src
|
||||
|
||||
CC = gcc
|
||||
CFLAGS = -I$(INCLUDE_DIR) -Wall -Wextra -g
|
||||
|
||||
TARGET = $(BUILD_DIR)/$(PNAME)
|
||||
SRCS = $(wildcard $(SRC_DIR)/*.c)
|
||||
OBJS = $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS))
|
||||
|
||||
# Default target
|
||||
all: $(TARGET)
|
||||
|
||||
# Build the executable
|
||||
$(TARGET): $(OBJS)
|
||||
$(CC) $(OBJS) -o $@
|
||||
|
||||
# Compile source files into object files
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Create the build directory
|
||||
$(BUILD_DIR):
|
||||
mkdir -p $(BUILD_DIR)
|
||||
|
||||
# Run the executable
|
||||
run: $(TARGET)
|
||||
@$(TARGET)
|
||||
|
||||
# Clean built files
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
# Clean then build
|
||||
rebuild: clean all
|
||||
|
||||
# Display help information
|
||||
help:
|
||||
@echo "Makefile Usage:"
|
||||
@echo ""
|
||||
@echo " make - Builds the executable (default)"
|
||||
@echo " make all - Same as 'make'"
|
||||
@echo " make run - Builds the executable if needed and then runs it"
|
||||
@echo " make clean - Removes the build directory and all built files"
|
||||
@echo " make rebuild - Performs a clean first, then builds the project"
|
||||
@echo " make help - Displays this help message"
|
||||
|
||||
.PHONY: all clean run rebuild help
|
||||
2
templates/dev/c-hello/build.sh
Normal file
2
templates/dev/c-hello/build.sh
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
make clean
|
||||
bear --output build/compile_commands.json -- make all
|
||||
144
templates/dev/c-hello/flake.nix
Normal file
144
templates/dev/c-hello/flake.nix
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
{
|
||||
description = "A hello world template in C";
|
||||
|
||||
inputs = {
|
||||
nixpkgs.url = "nixpkgs/nixos-unstable";
|
||||
pre-commit-hooks = {
|
||||
url = "github:cachix/pre-commit-hooks.nix";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
};
|
||||
};
|
||||
|
||||
outputs =
|
||||
{
|
||||
self,
|
||||
nixpkgs,
|
||||
pre-commit-hooks,
|
||||
...
|
||||
}:
|
||||
let
|
||||
pname = "hello-world"; # Also change this in the Makefile
|
||||
version = "0.1.0";
|
||||
|
||||
supportedSystems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"aarch64-darwin"
|
||||
];
|
||||
|
||||
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
|
||||
|
||||
nixpkgsFor = forAllSystems (
|
||||
system:
|
||||
import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [ self.overlays.default ];
|
||||
}
|
||||
);
|
||||
in
|
||||
{
|
||||
overlays.default = final: prev: {
|
||||
"${pname}" = final.stdenv.mkDerivation rec {
|
||||
inherit pname version;
|
||||
src = ./.;
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp build/${pname} $out/bin/
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
packages = forAllSystems (system: {
|
||||
default = nixpkgsFor.${system}."${pname}";
|
||||
"${pname}" = nixpkgsFor.${system}."${pname}";
|
||||
});
|
||||
|
||||
devShells = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
in
|
||||
{
|
||||
default = pkgs.mkShell {
|
||||
buildInputs =
|
||||
self.checks.${system}.pre-commit-check.enabledPackages
|
||||
++ (with pkgs; [
|
||||
bear
|
||||
coreutils
|
||||
gcc
|
||||
gdb
|
||||
gnumake
|
||||
]);
|
||||
shellHook = self.checks.${system}.pre-commit-check.shellHook + ''
|
||||
export LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
formatter = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
config = self.checks.${system}.pre-commit-check.config;
|
||||
inherit (config) package configFile;
|
||||
script = ''
|
||||
${pkgs.lib.getExe package} run --all-files --config ${configFile}
|
||||
'';
|
||||
in
|
||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||
);
|
||||
|
||||
checks = forAllSystems (
|
||||
system:
|
||||
let
|
||||
pkgs = nixpkgsFor.${system};
|
||||
flakePkgs = self.packages.${system};
|
||||
in
|
||||
{
|
||||
build-packages = pkgs.linkFarm "flake-packages-${system}" flakePkgs;
|
||||
|
||||
integration-test =
|
||||
let
|
||||
exe = "${flakePkgs.${pname}}/bin/${pname}";
|
||||
in
|
||||
pkgs.runCommand "${pname}-test"
|
||||
{
|
||||
nativeBuildInputs = [
|
||||
pkgs.synixutils
|
||||
flakePkgs.${pname}
|
||||
];
|
||||
}
|
||||
''
|
||||
assert_equal() {
|
||||
if [[ "$1" != "$2" ]]; then
|
||||
echo "Test failed: Expected '$1' but got '$2'"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
exp1="Hello, world!"
|
||||
out1="$(${exe})"
|
||||
|
||||
assert_equal "$exp1" "$out1"
|
||||
|
||||
echo "Test passed!" > $out
|
||||
'';
|
||||
|
||||
pre-commit-check = pre-commit-hooks.lib.${system}.run {
|
||||
src = ./.;
|
||||
hooks = {
|
||||
nixfmt = {
|
||||
enable = true;
|
||||
};
|
||||
clang-format = {
|
||||
enable = true;
|
||||
types_or = nixpkgs.lib.mkForce [ "c" ];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
}
|
||||
8
templates/dev/c-hello/src/main.c
Normal file
8
templates/dev/c-hello/src/main.c
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
printf("Hello, world!\n");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue