From cd04e59647a9440e6b362b3a46b36f46bf2b2576 Mon Sep 17 00:00:00 2001 From: hachem Date: Sun, 30 Aug 2026 00:39:55 +0200 Subject: setup: prepare docker and build system --- .dockerignore | 5 +++ .gitignore | 9 +++++ Dockerfile | 17 +++++++++ docker-compose.yml | 9 +++++ examples/fibonacci.hdasm | 60 ++++++++++++++++++++++++++++++ examples/hello_world.hdass | 19 ++++++++++ premake5.lua | 92 ++++++++++++++++++++++++++++++++++++++++++++++ src/main.c | 6 +++ 8 files changed, 217 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 examples/fibonacci.hdasm create mode 100644 examples/hello_world.hdass create mode 100644 premake5.lua create mode 100644 src/main.c diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..adb7332 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +bin/ +bin-int/ +.git/ +*.make +Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..08734cb --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +bin/ +bin-int/ + +# premake-generated files +Makefile +*.make +*.sln +*.vcxproj +*.vcxproj.* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..66740c0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM --platform=linux/amd64 debian:bookworm-slim + +ARG PREMAKE_VERSION=5.0.0-beta7 + +RUN apt-get update && apt-get install -y --no-install-recommends \ + build-essential \ + nasm \ + binutils \ + make \ + curl \ + ca-certificates \ + && rm -rf /var/lib/apt/lists/* + +RUN curl -fsSL "https://github.com/premake/premake-core/releases/download/v${PREMAKE_VERSION}/premake-${PREMAKE_VERSION}-linux.tar.gz" \ + | tar -xz -C /usr/local/bin premake5 + +WORKDIR /hdass diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a178367 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + hdass: + build: . + image: hdass-dev + platform: linux/amd64 + working_dir: /hdass + volumes: + - .:/hdass + command: sleep infinity diff --git a/examples/fibonacci.hdasm b/examples/fibonacci.hdasm new file mode 100644 index 0000000..b044d84 --- /dev/null +++ b/examples/fibonacci.hdasm @@ -0,0 +1,60 @@ +const SYS_WRITE = 1 +const SYS_EXIT = 60 + +const STDOUT = 1 + +data newline = "\n" + +proc print_number(value: rdi) +{ + stack buffer[32] + + rax = value + rbx = 10 + rsi = buffer+31 + +convert: + rdx = 0 + rax /= rbx + rdx += '0' + + ^rsi = rdx + rsi -= 1 + + if rax != 0 + goto convert + rsi += 1 + + rax = SYS_WRITE + rdi = STDOUT + rdx = buffer+32-rsi + syscall + + rax = SYS_WRITE + rdi = STDOUT + rsi = newline + rdx = newline.len + syscall +} + +proc main +{ + r12 = 0 + r13 = 1 + rcx = 10 + +loop: + print_number(r12) + + rax = r12 + r12 = r13 + r13 += rax + + rcx -= 1 + if rcx != 0 + goto loop + + rax = SYS_EXIT + rdi = 0 + syscall +} diff --git a/examples/hello_world.hdass b/examples/hello_world.hdass new file mode 100644 index 0000000..59dac80 --- /dev/null +++ b/examples/hello_world.hdass @@ -0,0 +1,19 @@ +const SYS_WRITE = 1 +const SYS_EXIT = 60 + +const STDOUT = 1 + +data message = "Hello, World!\n" + +proc main +{ + rax = SYS_WRITE + rdi = STDOUT + rsi = message + rdx = message.len + syscall + + rax = SYS_EXIT + rdi = 0 + syscall +} diff --git a/premake5.lua b/premake5.lua new file mode 100644 index 0000000..710bf1c --- /dev/null +++ b/premake5.lua @@ -0,0 +1,92 @@ +output_dir = "%{cfg.buildcfg}-%{cfg.system}" + +function setup_target() + targetdir ("bin/" .. output_dir) + objdir ("bin-int/" .. output_dir .. "/%{prj.name}") + staticruntime "On" +end + +function setup_c_target() + setup_target() + + filter "configurations:debug" + runtime "Debug" + symbols "On" + filter { "configurations:release", "configurations:dist" } + runtime "Release" + optimize "Speed" + filter "configurations:dist" + symbols "Off" + filter {} +end + +newaction { + trigger = "clean", + description = "Remove build output and generated project files", + + execute = function() + os.rmdir("bin") + os.rmdir("bin-int") + os.remove("Makefile") + + for _, file in ipairs(os.matchfiles("*.make")) do + os.remove(file) + end + + print("Cleaned build output and generated project files") + end +} + +workspace "hdass" + architecture "x64" + startproject "hdass" + multiprocessorcompile "On" + + configurations { + "debug", + "release", + "dist", + } + + filter "system:windows" + defines "HDASS_WINDOWS" + filter "system:linux" + defines "HDASS_LINUX" + filter "system:macosx" + architecture "ARM64" + defines "HDASS_MACOS" + filter {} + +project "hdass" + kind "ConsoleApp" + language "C" + cdialect "C17" + + setup_c_target() + + files { + "src/**.h", + "src/**.c", + } + + includedirs "src" + + filter { "system:macosx or system:linux" } + buildoptions { + "-Wall", + "-Wextra", + "-Werror", + "-pedantic", + } + filter {} + + filter "system:windows" + systemversion "latest" + + filter "configurations:debug" + defines "HDASS_DEBUG" + filter "configurations:release" + defines "HDASS_RELEASE" + filter "configurations:dist" + defines "HDASS_DIST" + filter {} diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..902e18a --- /dev/null +++ b/src/main.c @@ -0,0 +1,6 @@ +#include + +int main(void) +{ + puts("type shi"); +} -- cgit v1.3