Skip to content

Commit 824b38e

Browse files
template: add c project
1 parent 97e30d4 commit 824b38e

File tree

12 files changed

+231
-0
lines changed

12 files changed

+231
-0
lines changed

flake.nix

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
);
3030

3131
templates = {
32+
c = {
33+
path = ./template/c;
34+
description = "Setup C Project";
35+
};
3236
elm = {
3337
path = ./template/elm;
3438
description = "Setup Elm Project";

template/c/.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
UseTab: Never

template/c/.editorconfig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; https://editorconfig.org
2+
root = true
3+
4+
; default configuration
5+
[*]
6+
charset = utf-8
7+
end_of_line = lf
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
indent_style = unset
11+
12+
[{*.nix,flake.lock}]
13+
indent_style = space
14+
indent_size = 2
15+
16+
[*.{yml,yaml}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[*.md]
21+
indent_style = space
22+
indent_size = 2
23+
24+
[*.{c,h,zig}]
25+
indent_style = space
26+
indent_size = 4

template/c/.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: main
2+
on:
3+
pull_request:
4+
branches: [main]
5+
push:
6+
branches: [main]
7+
env:
8+
CI_NIX_FLAKE: .#default
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
- name: Setup Nix
16+
uses: DeterminateSystems/nix-installer-action@main
17+
- name: Cache Nix
18+
uses: DeterminateSystems/magic-nix-cache-action@main
19+
- name: Lint
20+
run: |
21+
nix develop ${{ env.CI_NIX_FLAKE }} --command \
22+
editorconfig-checker && echo "ok"
23+
test:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
- name: Setup Nix
29+
uses: DeterminateSystems/nix-installer-action@main
30+
- name: Cache Nix
31+
uses: DeterminateSystems/magic-nix-cache-action@main
32+
- name: Cache Go
33+
uses: actions/cache@v4
34+
with:
35+
key: ${{ runner.os }}-go-${{ hashfiles('go.mod', 'go.sum') }}
36+
path: |
37+
~/.cache/go-build
38+
~/go/pkg/mod
39+
- name: Test
40+
run: |
41+
nix develop ${{ env.CI_NIX_FLAKE }} --command \
42+
go test -v -cover -race ./...

template/c/.gitignore

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# https://github.com/github/gitignore/blob/main/Zig.gitignore
2+
3+
.zig-cache/
4+
zig-out/
5+
6+
# https://github.com/github/gitignore/blob/main/C.gitignore
7+
8+
# Prerequisites
9+
*.d
10+
11+
# Object files
12+
*.o
13+
*.ko
14+
*.obj
15+
*.elf
16+
17+
# Linker output
18+
*.ilk
19+
*.map
20+
*.exp
21+
22+
# Precompiled Headers
23+
*.gch
24+
*.pch
25+
26+
# Libraries
27+
*.lib
28+
*.a
29+
*.la
30+
*.lo
31+
32+
# Shared objects (inc. Windows DLLs)
33+
*.dll
34+
*.so
35+
*.so.*
36+
*.dylib
37+
38+
# Executables
39+
*.exe
40+
*.out
41+
*.app
42+
*.i*86
43+
*.x86_64
44+
*.hex
45+
46+
# Debug files
47+
*.dSYM/
48+
*.su
49+
*.idb
50+
*.pdb
51+
52+
# Kernel Module Compile Results
53+
*.mod*
54+
*.cmd
55+
.tmp_versions/
56+
modules.order
57+
Module.symvers
58+
Mkfile.old
59+
dkms.conf

template/c/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
nixpkgs/update:
2+
@nix flake lock --override-input nixpkgs github:NixOS/nixpkgs/$(rev)
3+
4+
.PHONY: build test run clean
5+
6+
run:
7+
@zig build run

template/c/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# C Project

template/c/build.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
7+
const run = b.step("run", "Run the app");
8+
{
9+
const exe = b.addExecutable(.{
10+
.name = "cproject",
11+
.root_module = b.createModule(.{
12+
.target = target,
13+
.optimize = optimize,
14+
}),
15+
});
16+
exe.addCSourceFile(.{ .file = b.path("main.c") });
17+
exe.linkLibC();
18+
run.dependOn(&b.addRunArtifact(exe).step);
19+
}
20+
}

template/c/flake.lock

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)