From 8f93a44cacd172de503dad1febab28aa3c5d343d Mon Sep 17 00:00:00 2001 From: Greg Shuflin Date: Mon, 1 Dec 2025 02:14:43 -0800 Subject: [PATCH] my local debugging --- c/sdl.c | 8 +++++++- justfile | 25 +++++++++++++++++++++++++ lakefile.lean | 17 +++++++++-------- 3 files changed, 41 insertions(+), 9 deletions(-) create mode 100644 justfile diff --git a/c/sdl.c b/c/sdl.c index e899ebd..c6da2ee 100644 --- a/c/sdl.c +++ b/c/sdl.c @@ -1,7 +1,9 @@ #include #include +#include #include #include +#include static SDL_Window* g_window = NULL; static SDL_Renderer* g_renderer = NULL; @@ -9,6 +11,10 @@ static SDL_Texture* g_wall_texture = NULL; lean_obj_res sdl_init(uint32_t flags, lean_obj_arg w) { int32_t result = SDL_Init(flags); + if (!result) { + const char* err = SDL_GetError(); + printf("Error initializing SDL %d : %s\n", result, err); + } return lean_io_result_mk_ok(lean_box_uint32(result)); } @@ -132,4 +138,4 @@ lean_obj_res sdl_render_texture_column(uint32_t dst_x, uint32_t dst_y, uint32_t SDL_FRect dst_rect = {(float)dst_x, (float)dst_y, 1.0f, (float)dst_height}; return lean_io_result_mk_ok(lean_box_uint32(SDL_RenderTexture(g_renderer, g_wall_texture, &src_rect, &dst_rect))); -} \ No newline at end of file +} diff --git a/justfile b/justfile new file mode 100644 index 0000000..4c5a051 --- /dev/null +++ b/justfile @@ -0,0 +1,25 @@ +# Build the project +build: + lake build + patchelf --set-interpreter /usr/lib/ld-linux-x86-64.so.2 .lake/build/bin/LeanDoomed + patchelf --set-rpath '$ORIGIN:/usr/lib' .lake/build/bin/LeanDoomed + +# Run LeanDoomed +run: build + .lake/build/bin/LeanDoomed + +# Run with X11 explicitly (for Wayland systems) +run-x11: build + SDL_VIDEODRIVER=x11 .lake/build/bin/LeanDoomed + +# Run with Wayland explicitly +run-wayland: build + SDL_VIDEODRIVER=wayland .lake/build/bin/LeanDoomed + +# Clean build artifacts +clean: + lake clean + rm -rf .lake/build/bin/*.so* + +# Rebuild from scratch +rebuild: clean build diff --git a/lakefile.lean b/lakefile.lean index 5035d38..bb2a178 100644 --- a/lakefile.lean +++ b/lakefile.lean @@ -115,13 +115,14 @@ target libleansdl pkg : FilePath := do if entry.path.extension == some "dll" then copyFile entry.path (".lake/build/bin/" / entry.path.fileName.get!) else - -- binaries for Lean/Lake itself, like libgmp are on a different place on Linux - let lakeBinariesDir := (← IO.appPath).parent.get!.parent.get! / "lib" - println! "Copying Lake binaries from {lakeBinariesDir}" - - for entry in (← lakeBinariesDir.readDir) do - if entry.path.extension != none then - copyFile entry.path (".lake/build/bin/" / entry.path.fileName.get!) + -- binaries for Lean/Lake itself - only copy Lean-specific libraries, not all Nix libs + let leanLibDir := (← IO.appPath).parent.get!.parent.get! / "lib" / "lean" + let leanLibDirExists ← System.FilePath.pathExists leanLibDir + if leanLibDirExists then + println! "Copying Lean libraries from {leanLibDir}" + for entry in (← leanLibDir.readDir) do + if entry.path.extension == some "so" then + copyFile entry.path (".lake/build/bin/" / entry.path.fileName.get!) buildStaticLib (pkg.staticLibDir / name) #[sdlO] @@ -138,4 +139,4 @@ lean_exe LeanDoomed where moreLinkArgs := if Platform.isWindows then #["vendor/SDL/build/SDL3.dll", "vendor/SDL_image/build/SDL3_image.dll"] else - #["vendor/SDL/build/libSDL3.so", "vendor/SDL_image/build/libSDL3_image.so", "-Wl,--allow-shlib-undefined", "-Wl,-rpath=$ORIGIN", "-Wl,-rpath=$ORIGIN"] + #["vendor/SDL/build/libSDL3.so", "vendor/SDL_image/build/libSDL3_image.so", "-Wl,--allow-shlib-undefined", "-Wl,-rpath=$ORIGIN"]