From 2806ed7d55266ececb197196af2fb84ae8c3cb35 Mon Sep 17 00:00:00 2001 From: hachem Date: Sat, 6 Dec 2025 18:29:49 +0100 Subject: [add]: Docker and prepare day4 --- Dockerfile | 23 +++++++++++++++++++++++ Makefile | 21 ++++++++------------- README.md | 40 ++++++++++++++++++++-------------------- docker-entrypoint.sh | 26 ++++++++++++++++++++++++++ src/Day4.asm | 25 +++++++++++++++++++++++++ 5 files changed, 102 insertions(+), 33 deletions(-) create mode 100644 Dockerfile create mode 100644 docker-entrypoint.sh create mode 100644 src/Day4.asm 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"] + diff --git a/Makefile b/Makefile index b3b2f73..9faa0fb 100644 --- a/Makefile +++ b/Makefile @@ -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" diff --git a/README.md b/README.md index 8a84811..f2572bf 100644 --- a/README.md +++ b/README.md @@ -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 -- cgit v1.3