Skip to content

Commit

Permalink
chore: cleanup repo
Browse files Browse the repository at this point in the history
clean flake
  • Loading branch information
drawbu committed Nov 30, 2024
1 parent 83eb2f8 commit b0c4d4e
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 83 deletions.
2 changes: 1 addition & 1 deletion 2022/day-1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_1

import (
"bufio"
"main/utils"
"aoc2022/utils"
"strconv"
)

Expand Down
2 changes: 1 addition & 1 deletion 2022/day-2/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_2

import (
"bufio"
"main/utils"
"aoc2022/utils"
"strconv"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-3/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package day_3
import (
"bufio"
"fmt"
"main/utils"
"aoc2022/utils"
"strconv"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-4/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_4

import (
"bufio"
"main/utils"
"aoc2022/utils"
"strconv"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-5/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_5

import (
"bufio"
"main/utils"
"aoc2022/utils"
"strconv"
"strings"
)
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-6/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_6

import (
"bufio"
"main/utils"
"aoc2022/utils"
"strconv"
)

Expand Down
2 changes: 1 addition & 1 deletion 2022/day-7/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_7

import (
"bufio"
"main/utils"
"aoc2022/utils"
"os"
"strconv"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-8/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package day_8

import (
"bufio"
"main/utils"
"aoc2022/utils"
"os"
"strconv"
)
Expand Down
2 changes: 1 addition & 1 deletion 2022/day-9/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package day_9
import (
"bufio"
"fmt"
"main/utils"
"aoc2022/utils"
"math"
"strconv"
"strings"
Expand Down
2 changes: 1 addition & 1 deletion 2022/go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module main
module aoc2022

go 1.19
20 changes: 10 additions & 10 deletions 2022/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package main

import (
"aoc2022/day-1"
"aoc2022/day-2"
"aoc2022/day-3"
"aoc2022/day-4"
"aoc2022/day-5"
"aoc2022/day-6"
"aoc2022/day-7"
"aoc2022/day-8"
"aoc2022/day-9"
"aoc2022/utils"
"fmt"
"main/day-1"
"main/day-2"
"main/day-3"
"main/day-4"
"main/day-5"
"main/day-6"
"main/day-7"
"main/day-8"
"main/day-9"
"main/utils"
)

func main() {
Expand Down
27 changes: 18 additions & 9 deletions 2023/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ DEPS := $(OBJ:.o=.d)
ASAN_DEPS := $(ASAN_OBJ:.o=.d)
TEST_DEPS := $(TEST_OBJ:.o=.d)


DEFAULT_GOAL := all
.PHONY: all
all: $(NAME)

# ↓ Compiling
$(BUILD_DIR)/source/%.o: %.c
@ mkdir -p $(dir $@)
Expand All @@ -41,7 +46,6 @@ $(BUILD_DIR)/source/%.o: %.c
$(NAME): $(OBJ)
$(CC) -o $@ $(OBJ) $(CFLAGS) $(LDFLAGS)

.PHONY: $(NAME)

# ↓ Asan
$(BUILD_DIR)/asan/%.o: %.c
Expand All @@ -52,36 +56,41 @@ $(ASAN_NAME): CFLAGS += -fsanitize=address,leak,undefined -g3
$(ASAN_NAME): $(ASAN_OBJ)
$(CC) -o $@ $(ASAN_OBJ) $(CFLAGS) $(LDFLAGS)

.PHONY: $(ASAN_NAME)

# ↓ Unit tests
$(BUILD_DIR)/tests/%.o: %.c
@ mkdir -p $(dir $@)
$(CC) -o $@ -c $< $(CFLAGS) $(DEPS_FLAGS)


# ↓ Unit tests
$(TEST_NAME): CFLAGS += -lcriterion -g3
$(TEST_NAME): $(TEST_OBJ)
$(CC) -o $@ $(TEST_OBJ) $(CFLAGS) $(LDFLAGS)

.PHONY: tests_run
tests_run: fclean $(TEST_NAME)
@ ./$(TEST_NAME)

.PHONY: $(TEST_NAME) tests_run

# ↓ Cleaning
.PHONY: clean
clean:
$(RM) $(OBJ) $(TEST_OBJ) $(ASAN_OBJ)

.PHONY: fclean
fclean: clean
$(RM) $(NAME) $(TEST_NAME) $(ASAN_NAME)
$(RM) -r $(BUILD_DIR)

.PHONY: clean fclean

re: fclean
@ $(MAKE) -s -C .

# ↓ Meta
.PHONY: re
.NOTPARALLEL: re
re: fclean all

.PHONY: install
install: $(NAME)
mkdir -p $(PREFIX)/bin
install -m 755 $(NAME) $(PREFIX)/bin

-include $(DEPS)
-include $(ASAN_DEPS)
Expand Down
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ Completed: `9/25`.

I made it to the day 9, and choose to discover Go with it. Pretty fun
experience.


## :snowflake: Nix

I use Nix to manage my dev environments, so you can build and run all years
binaries with nix:
```sh
# $YEAR = 2022, 2023, 2024, etc.
nix run github:drawbu/advent-of-code#${YEAR} # run solutions
nix develop github:drawbu/advent-of-code#${YEAR} # enter dev env
```
8 changes: 4 additions & 4 deletions flake.lock

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

85 changes: 35 additions & 50 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,74 +1,59 @@
{
description = "Advent of code";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, utils }:
utils.lib.eachDefaultSystem (system:
outputs =
{ ... }@inputs:
inputs.utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
aoc2022 = with pkgs; [ go ];
aoc2023 = rec {
cc = pkgs.gcc12;
deps = with pkgs; [
glibc
gnumake
criterion
] ++ [ cc ];
shell = with pkgs; [
ltrace
valgrind
python311Packages.compiledb
man-pages
man-pages-posix
gdb
] ++ deps;
};
pkgs = import inputs.nixpkgs { inherit system; };
inherit (pkgs) lib;
in
{
devShells.default = pkgs.mkShell {
packages = aoc2022 ++ aoc2023.shell;
rec {
formatter = pkgs.nixfmt-rfc-style;

devShells = {
"2022" = pkgs.mkShell {
inputsFrom = [ packages."2022" ];
};

"2023" = pkgs.mkShell {
inputsFrom = [ packages."2023" ];
packages =
with pkgs;
lib.optionals stdenv.isLinux [
gdb
ltrace
valgrind
];
};
};

formatter = pkgs.nixpkgs-fmt;
packages = {
aoc2022 = pkgs.buildGoModule rec {
"2022" = pkgs.buildGoModule {
name = "aoc2022";
version = "1.0.0";
src = ./2022;

vendorHash = null;
buildPhase = ''
${pkgs.go}/bin/go build -o ${name}
'';
installPhase = ''
mkdir -p $out/bin
cp ${name} $out/bin/
'';
};

aoc2023 = pkgs.stdenv.mkDerivation rec {
"2023" = pkgs.gcc12Stdenv.mkDerivation {
name = "aoc2023";
src = ./2023;

makeFlags = [ "CC=${aoc2023.cc}/bin/gcc" ];
buildInputs = aoc2023.deps;
buildInputs = with pkgs; [ criterion ];

hardeningDisable = [ "format" "fortify" ];
hardeningDisable = [
"format"
"fortify"
];
env.PREFIX = "${placeholder "out"}";
enableParallelBuilding = true;

buildPhase = ''
make ${name}
'';

installPhase = ''
mkdir -p $out/bin
cp ${name} $out/bin
'';
};
};
});
}
);
}

0 comments on commit b0c4d4e

Please sign in to comment.