feat: C templates
This commit is contained in:
parent
e5faf58ba8
commit
f5427d28a9
15 changed files with 236 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
result*
|
||||
.direnv/
|
||||
build/
|
||||
|
|
|
|||
2
c/basic/nixpkgs/.envrc
Normal file
2
c/basic/nixpkgs/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
use flake
|
||||
43
c/basic/nixpkgs/flake.lock
generated
Normal file
43
c/basic/nixpkgs/flake.lock
generated
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1768783163,
|
||||
"narHash": "sha256-tLj4KcRDLakrlpvboTJDKsrp6z2XLwyQ4Zmo+w8KsY4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bde09022887110deb780067364a0818e89258968",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
23
c/basic/nixpkgs/flake.nix
Normal file
23
c/basic/nixpkgs/flake.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
systems.url = "github:nix-systems/default";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, systems, ... }:
|
||||
let eachSystem = nixpkgs.lib.genAttrs (import systems);
|
||||
in {
|
||||
packages = eachSystem (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
hello = pkgs.callPackage ./package.nix {};
|
||||
default = self.packages.${system}.hello;
|
||||
});
|
||||
|
||||
devShells = eachSystem (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
default = import ./shell.nix { inherit pkgs; };
|
||||
});
|
||||
};
|
||||
}
|
||||
23
c/basic/nixpkgs/package.nix
Normal file
23
c/basic/nixpkgs/package.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
stdenv
|
||||
}:
|
||||
let
|
||||
source = "src/hello.c";
|
||||
exec = "hello";
|
||||
in stdenv.mkDerivation {
|
||||
pname = "hello";
|
||||
version = "0.1";
|
||||
src = ./.;
|
||||
|
||||
buildPhase = ''
|
||||
runHook preBuild
|
||||
gcc ${source} -o ${exec}.bin
|
||||
runHook postBuild
|
||||
'';
|
||||
installPhase = ''
|
||||
runHook preInstall
|
||||
mkdir -p $out/bin
|
||||
install ${exec}.bin $out/bin/${exec}
|
||||
runHook postInstall
|
||||
'';
|
||||
}
|
||||
8
c/basic/nixpkgs/shell.nix
Normal file
8
c/basic/nixpkgs/shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
let inherit (pkgs)
|
||||
mkShell
|
||||
llvmPackages_21
|
||||
;
|
||||
in mkShell {
|
||||
packages = [ llvmPackages_21.clang-tools ];
|
||||
}
|
||||
6
c/basic/nixpkgs/src/hello.c
Normal file
6
c/basic/nixpkgs/src/hello.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
2
c/make/nixpkgs/.envrc
Normal file
2
c/make/nixpkgs/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
#!/usr/bin/env bash
|
||||
use flake
|
||||
37
c/make/nixpkgs/Makefile
Normal file
37
c/make/nixpkgs/Makefile
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
##
|
||||
# Example GCC Nix Project
|
||||
#
|
||||
# @file
|
||||
# @version 0.1
|
||||
|
||||
SRC_DIR := ./src
|
||||
BUILD_DIR := ./build
|
||||
|
||||
EXEC ?= hello
|
||||
INSTALL ?= $(PREFIX)/bin/
|
||||
|
||||
# Find all the C files we want to compile
|
||||
SRCS := $(shell find $(SRC_DIR) -name '*.c')
|
||||
OBJS := $(SRCS:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
|
||||
|
||||
.PHONY: build install clean
|
||||
|
||||
build: $(BUILD_DIR)/$(EXEC)
|
||||
install: build
|
||||
mkdir -p $(INSTALL)
|
||||
cp $(BUILD_DIR)/$(EXEC) $(INSTALL)
|
||||
|
||||
|
||||
# Link
|
||||
$(BUILD_DIR)/$(EXEC): $(OBJS)
|
||||
$(CC) $^ -o $@ $(LDFLAGS)
|
||||
|
||||
# Compile
|
||||
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
mkdir -p $(dir $@)
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm -r $(BUILD_DIR)
|
||||
|
||||
# end
|
||||
43
c/make/nixpkgs/flake.lock
generated
Normal file
43
c/make/nixpkgs/flake.lock
generated
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1768783163,
|
||||
"narHash": "sha256-tLj4KcRDLakrlpvboTJDKsrp6z2XLwyQ4Zmo+w8KsY4=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "bde09022887110deb780067364a0818e89258968",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixpkgs-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
23
c/make/nixpkgs/flake.nix
Normal file
23
c/make/nixpkgs/flake.nix
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||
systems.url = "github:nix-systems/default";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, systems, ... }:
|
||||
let eachSystem = nixpkgs.lib.genAttrs (import systems);
|
||||
in {
|
||||
packages = eachSystem (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
hello = pkgs.callPackage ./package.nix {};
|
||||
default = self.packages.${system}.hello;
|
||||
});
|
||||
|
||||
devShells = eachSystem (system:
|
||||
let pkgs = nixpkgs.legacyPackages.${system};
|
||||
in {
|
||||
default = import ./shell.nix { inherit pkgs; };
|
||||
});
|
||||
};
|
||||
}
|
||||
10
c/make/nixpkgs/package.nix
Normal file
10
c/make/nixpkgs/package.nix
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
stdenv
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation rec {
|
||||
pname = "hello";
|
||||
version = "0.1";
|
||||
src = ./.;
|
||||
installFlags = [ "PREFIX=$(out)" "EXEC=${pname}" ];
|
||||
}
|
||||
8
c/make/nixpkgs/shell.nix
Normal file
8
c/make/nixpkgs/shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
let inherit (pkgs)
|
||||
mkShell
|
||||
llvmPackages_21
|
||||
;
|
||||
in mkShell {
|
||||
packages = [ llvmPackages_21.clang-tools ];
|
||||
}
|
||||
6
c/make/nixpkgs/src/hello.c
Normal file
6
c/make/nixpkgs/src/hello.c
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
aliases = {
|
||||
bash = "bash_script_nixpkgs";
|
||||
fish = "fish_script_nixpkgs";
|
||||
c = "c_make_nixpkgs";
|
||||
python = "python_pyproject_nixpkgs_basic";
|
||||
rust = "rust_cargo-nightly_crane+fenix";
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue