diff options
| author | hachem <im@hachem.wtf> | 2025-12-06 18:29:49 +0100 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2025-12-06 18:29:49 +0100 |
| commit | 2806ed7d55266ececb197196af2fb84ae8c3cb35 (patch) | |
| tree | 7ba5dbdfb637b9f337cdc0f68c16b18c535122f2 | |
| parent | c6d077bfbf36012c66cd34bf8c97af791212b858 (diff) | |
[add]: Docker and prepare day4
| -rw-r--r-- | Dockerfile | 23 | ||||
| -rw-r--r-- | Makefile | 21 | ||||
| -rw-r--r-- | README.md | 40 | ||||
| -rw-r--r-- | docker-entrypoint.sh | 26 | ||||
| -rw-r--r-- | src/Day4.asm | 25 |
5 files changed, 102 insertions, 33 deletions
diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ead2a68 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +FROM debian:bookworm-slim + +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + build-essential \ + make \ + nasm \ + && rm -rf /var/lib/apt/lists/* + +WORKDIR /app + +COPY Makefile ./ +COPY src ./src +COPY input ./input +COPY README.md LICENSE ./ +COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh + +RUN chmod +x /usr/local/bin/docker-entrypoint.sh \ + && mkdir -p build + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["list"] + @@ -7,14 +7,12 @@ BUILD_DIR := build NASMFLAGS ?= -f elf64
LDFLAGS ?= -m elf_x86_64
-DAYS := Day1 Day2 Day3
-ASM_SRCS := $(addprefix $(SRC_DIR)/,$(addsuffix .asm,$(DAYS)))
-OBJ_FILES := $(addprefix $(BUILD_DIR)/,$(addsuffix .o,$(DAYS)))
+DAYS := Day1 Day2 Day3 Day4 Day5 Day6 \
+ Day7 Day8 Day9 Day10 Day11 Day12
BINARIES := $(addprefix $(BUILD_DIR)/,$(DAYS))
-.PHONY: all clean \
- day1 day2 day3 \
- list run-day%
+.PHONY: all clean list
+.PHONY: day% run-day%
all: $(BINARIES)
@@ -22,17 +20,14 @@ $(BUILD_DIR): @mkdir -p $(BUILD_DIR)
$(BUILD_DIR)/Day%.o: $(SRC_DIR)/Day%.asm | $(BUILD_DIR)
- $(NASM) $(NASMFLAGS) $< -o $@
+ @$(NASM) $(NASMFLAGS) $< -o $@
$(BUILD_DIR)/Day%: $(BUILD_DIR)/Day%.o
- $(LD) $(LDFLAGS) -o $@ $<
-
-day1: $(BUILD_DIR)/Day1
-day2: $(BUILD_DIR)/Day2
-day3: $(BUILD_DIR)/Day3
+ @$(LD) $(LDFLAGS) -o $@ $<
+day%: $(BUILD_DIR)/Day%
run-day%: $(BUILD_DIR)/Day%
- ./$(BUILD_DIR)/Day$*
+ @./$<
list:
@printf "Available days:\n"
@@ -1,37 +1,37 @@ # Advent of Code - 2025
-yes, i started late.
-yes, i wrote it in x86_64 assembly.
-no, there is no absolutely no good reason for this.
-no, i'm not okay.
+Yes, I started late.
+Yes, I wrote it in x86_64 assembly.
+No, there is no absolutely no good reason for this.
+No, I'm not okay.
### Why assembly?
-because i was really bored and i wanted more of an excuse to procrastinate.
+Because I was really bored and I wanted more of an excuse to procrastinate.
also: **aura**.
-## Building
-```sh
-$ make day[1-12]
-# example:
-$ make day1
-$ make day2
-```
-
-## Running
+## Building & Running
```sh
$ make run-day[1-12]
# example:
$ make run-day1
$ make run-day2
```
-or manually, after building
+If you just want to build the binaries without running them do `make day[1-12]`.
+## Docker
+If you do not have `nasm`/`ld` locally, build the container:
+```sh
+$ docker build -t aoc-2025 .
+```
+Run a specific puzzle directly
+```sh
+$ docker run aoc-2025 day4
+$ docker run aoc-2025 day5
+```
+Running with no arguments (`docker run aoc-2025`) will list the available targets. If you only want to build a binary, use `build-day[1-12]`.
+When you're done, delete the image:
```sh
-$ ./build/day[1-12]
-# example
-$ ./build/day1
-$ ./build/day2
-$ ./build/day3
+$ docker rmi aoc-2025
```
## License
diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100644 index 0000000..1344e85 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,26 @@ +#!/bin/sh +set -eu + +if [ "$#" -eq 0 ]; then + set -- list +fi + +target="$1" +shift + +case "$target" in + day[0-9]*) + target="run-$target" + ;; + build-day[0-9]*) + target="${target#build-}" + ;; + run-day[0-9]*) + ;; + *) + # allow raw make targets + ;; +esac + +exec make "$target" "$@" + diff --git a/src/Day4.asm b/src/Day4.asm new file mode 100644 index 0000000..475f2ef --- /dev/null +++ b/src/Day4.asm @@ -0,0 +1,25 @@ +bits 64 +default rel + +global _start + +%define SYS_EXIT 60 +%define SYS_WRITE 1 + +%define STDOUT 1 + +section .data + message db "Hello Day 4!", 0xA + length equ $-message + +section .text +_start: + mov rax, SYS_WRITE + mov rdi, STDOUT + mov rsi, message + mov rdx, length + syscall + + mov rax, SYS_EXIT + xor rdi, rdi + syscall |
