Переглянути джерело

Add glfw, window test, Alpine to Debian container

Kajetan Johannes Hammerle 2 днів тому
батько
коміт
db32bdb35f
8 змінених файлів з 78 додано та 5 видалено
  1. 3 0
      .gitmodules
  2. 11 2
      CMakeLists.txt
  3. 10 2
      Dockerfile
  4. 2 1
      build_container.sh
  5. 4 0
      src/Main.c
  6. 41 0
      src/Window.c
  7. 6 0
      src/Window.h
  8. 1 0
      thirdparty/glfw

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "thirdparty/glfw"]
+	path = thirdparty/glfw
+	url = https://github.com/glfw/glfw.git

+ 11 - 2
CMakeLists.txt

@@ -13,6 +13,7 @@ set(SRC
     "src/Memory.c"
     "src/SystemFunctions.c"
     "src/Utils.c"
+    "src/Window.c"
 )
 
 set(COMPILER_ARGUMENTS
@@ -32,13 +33,18 @@ set(COMPILER_ARGUMENTS
     -Winfinite-recursion     -Wmissing-prototypes    -Woverlength-strings
     -Wimplicit-fallthrough   -Wmissing-declarations  -Wmissing-include-dirs
     -Wold-style-definition   -Wdisabled-optimization -Wunused-const-variable
-    -Wlarger-than=1073741824    -Wdeprecated-non-prototype
+    -Wlarger-than=1073741824
     -Wframe-larger-than=8388608 -Wmissing-variable-declarations
-    -Wzero-as-null-pointer-constant
     -fdiagnostics-color=always  -fstrict-flex-arrays=3
     -pedantic                   -pedantic-errors
 )
 if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
+    if(CMAKE_C_COMPILER_VERSION VERSION_GREATER 15.0)
+        set(COMPILER_ARGUMENTS ${COMPILER_ARGUMENTS}
+            -Wdeprecated-non-prototype
+            -Wzero-as-null-pointer-constant
+        )
+    endif()
     set(COMPILER_ARGUMENTS ${COMPILER_ARGUMENTS}
         -Walloc-zero          -Wlogical-op           -Wtrampolines
         -Wbidi-chars=any      -Wduplicated-cond      -Wnormalized=nfkc
@@ -54,10 +60,13 @@ elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
         -Wstrict-prototypes             -Wbad-function-cast
         -Wmissing-noreturn              -Wextra-semi-stmt
         -Wnested-externs                -Wnarrowing
+        -Wdeprecated-non-prototype      -Wzero-as-null-pointer-constant
     )
 endif()
 
 add_executable(${PROJECT_NAME} ${SRC})
+add_subdirectory(thirdparty/glfw)
+target_link_libraries(${PROJECT_NAME} PRIVATE glfw GL)
 target_compile_options(${PROJECT_NAME} PUBLIC ${COMPILER_ARGUMENTS})
 
 add_executable(test test/Test.c)

+ 10 - 2
Dockerfile

@@ -1,3 +1,11 @@
-FROM alpine:latest
+FROM debian:trixie-backports
 
-RUN apk add gcc musl-dev cmake samurai
+RUN apt update
+RUN apt install -y --no-install-recommends \
+        gcc \
+        ninja-build \
+        cmake=4.3.2-1~bpo13+1 \
+        libc-dev \
+        libwayland-dev \
+        libxkbcommon-dev \
+        xorg-dev

+ 2 - 1
build_container.sh

@@ -1,12 +1,13 @@
 #!/bin/sh
 
+set -e
 cd "$(dirname "$0")"
 
 podman build . -t builder:latest
 
 podman run -v $PWD:$PWD builder:latest sh -c " \
     cd $PWD
-    cmake -S . -B build_docker -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS=\"-static\"
+    cmake -S . -B build_docker -G Ninja -DCMAKE_BUILD_TYPE=Release
     ninja -C build_docker
     strip build_docker/basic
     "

+ 4 - 0
src/Main.c

@@ -1,15 +1,19 @@
 #include <stdint.h>
 #include <stdio.h>
+#include <string.h>
 
 #include "Code.h"
 #include "Compiler.h"
 #include "Memory.h"
 #include "SystemFunctions.h"
 #include "Tokenizer.h"
+#include "Window.h"
 
 int main(int argCount, const char** args) {
     if(argCount < 2) {
         return 0;
+    } else if(strcmp(args[1], "w") == 0 && windowTest()) {
+        return 0;
     }
 
     static char heap[2500];

+ 41 - 0
src/Window.c

@@ -0,0 +1,41 @@
+#include "Window.h"
+
+#include <GLFW/glfw3.h>
+#include <stdio.h>
+
+bool windowTest() {
+    GLFWwindow* window;
+
+    /* Initialize the library */
+    if(!glfwInit()) {
+        printf("init failed\n");
+        return true;
+    }
+
+    /* Create a windowed mode window and its OpenGL context */
+    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
+    if(!window) {
+        glfwTerminate();
+        printf("create window failed\n");
+        return true;
+    }
+
+    /* Make the window's context current */
+    glfwMakeContextCurrent(window);
+
+    /* Loop until the user closes the window */
+    while(!glfwWindowShouldClose(window)) {
+        /* Render here */
+        glClear(GL_COLOR_BUFFER_BIT);
+
+        /* Swap front and back buffers */
+        glfwSwapBuffers(window);
+
+        /* Poll for and process events */
+        glfwPollEvents();
+    }
+    printf("YES\n");
+
+    glfwTerminate();
+    return true;
+}

+ 6 - 0
src/Window.h

@@ -0,0 +1,6 @@
+#ifndef BASIC_WINDOW_H
+#define BASIC_WINDOW_H
+
+bool windowTest();
+
+#endif

+ 1 - 0
thirdparty/glfw

@@ -0,0 +1 @@
+Subproject commit 7b6aead9fb88b3623e3b3725ebb42670cbe4c579