changeset 124:dbf14f84d51c

Refactor Seobeo and mrjunejune build files so it works.
author June Park <parkjune1995@gmail.com>
date Thu, 08 Jan 2026 07:31:32 -0800
parents 3f4ec30e42e0
children f236c895604e
files gara/BUILD mrjunejune/BUILD mrjunejune/main.c mrjunejune/server_entry.c seobeo/BUILD seobeo/examples/BUILD seobeo/s_logging.c seobeo/s_web.c seobeo/tests/BUILD
diffstat 9 files changed, 308 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/gara/BUILD	Thu Jan 08 06:46:10 2026 -0800
+++ b/gara/BUILD	Thu Jan 08 07:31:32 2026 -0800
@@ -3,7 +3,7 @@
 cc_binary(
   name = "gara_c",
   srcs = ["main.c"],
-  deps = ["//seobeo:seobeo"],
+  deps = ["//seobeo:seobeo_min"],
 )
 
 
--- a/mrjunejune/BUILD	Thu Jan 08 06:46:10 2026 -0800
+++ b/mrjunejune/BUILD	Thu Jan 08 07:31:32 2026 -0800
@@ -1,8 +1,8 @@
 load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:cc_library.bzl", "cc_library")
-# load("@rules_python//python:py_binary.bzl", "py_binary")
 load("//gui_ze:gui_ze.bzl", "move_files_into_dir", "bundle")
 
+# Files
 move_files_into_dir(
   name = "compiled_ts_games",
   srcs = [
@@ -25,6 +25,7 @@
   srcs = glob(["src/**"]) + [":compiled_ts", ":compiled_ts_games"],
 )
 
+# Server binary
 cc_binary(
   name = "mrjunejune_server",
   srcs = ["main.c"],
@@ -35,10 +36,11 @@
 cc_binary(
   name = "mrjunejune_server_dev",
   srcs = ["main.c"],
-  deps = ["//seobeo:seobeo_server_dev"],
+  deps = ["//seobeo:seobeo_server"],
   data = [":src_files"],
 )
 
+# Rlease bundle
 bundle(
   name = "mrjunejune_server_bundle",
   binary = ":mrjunejune_server",
@@ -49,10 +51,12 @@
   binary = ":mrjunejune_server_dev",
 )
 
+# Tests
+# TODO: Move this in a folder.
 cc_test(
   name = "integration_test",
   srcs = ["test/integration_test.c"],
-  deps = ["//seobeo:seobeo_client"],
+  deps = ["//seobeo:seobeo_min"],
   data = [
     "//mrjunejune:mrjunejune_server",
     "//mrjunejune:src_files",
@@ -67,7 +71,7 @@
 cc_binary(
   name = "create_snapshots",
   srcs = ["test/create_snapshots.c"],
-  deps = ["//seobeo:seobeo_client"],
+  deps = ["//seobeo:seobeo_tcp_client"],
   data = [
     "//mrjunejune:mrjunejune_server",
     "//mrjunejune:src_files",
@@ -88,6 +92,8 @@
   ],
 )
 
+# Experimenting with python to see if I can call it as ffi.
+# load("@rules_python//python:py_binary.bzl", "py_binary")
 # This was to use python ffi, but w/e
 # cc_library(
 #   name = "mrjunejune_server_lib",
--- a/mrjunejune/main.c	Thu Jan 08 06:46:10 2026 -0800
+++ b/mrjunejune/main.c	Thu Jan 08 07:31:32 2026 -0800
@@ -1,3 +1,4 @@
+#define SEOBEO_ENABLE_DEBUG
 #include "seobeo/seobeo.h"
 #include <time.h>
 
--- a/mrjunejune/server_entry.c	Thu Jan 08 06:46:10 2026 -0800
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#include "seobeo/seobeo.h"
-
-void start_server(void) {
-  Seobeo_Web_Server_Start("mrjunejune/pages", "6969", SEOBEO_MODE_EDGE, 2);
-}
--- a/seobeo/BUILD	Thu Jan 08 06:46:10 2026 -0800
+++ b/seobeo/BUILD	Thu Jan 08 07:31:32 2026 -0800
@@ -1,7 +1,6 @@
-load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
 load("@rules_cc//cc:cc_library.bzl", "cc_library")
-load("@rules_cc//cc:cc_test.bzl", "cc_test")
 
+# File group 
 filegroup(
   name = "seobeo_hdrs",
   srcs = [
@@ -12,31 +11,72 @@
   visibility = ["//visibility:public"],
 )
 
+# Minimal TCP/SSL handling only (no HTTP, no WebSocket)
 alias(
-  name = "seobeo_server",
+  name = "seobeo_min",
   actual = select({
-    "//config:macos":  ":seobeo_server_macos",
-    "//config:linux":  ":seobeo_server_linux",
-    "//conditions:default": ":seobeo_server_linux",
-  }),
-  visibility = ["//visibility:public"],
-)
-
-alias(
-  name = "seobeo_server_dev",
-  actual = select({
-    "//config:macos":  ":seobeo_server_macos_dev",
-    "//config:linux":  ":seobeo_server_linux_dev",
-    "//conditions:default": ":seobeo_server_linux_dev",
+    "//config:macos":  ":seobeo_min_macos",
+    "//config:linux":  ":seobeo_min_linux",
+    "//conditions:default": ":seobeo_min_linux",
   }),
   visibility = ["//visibility:public"],
 )
 
 cc_library(
-  name = "seobeo_server_macos",
+  name = "seobeo_min_macos",
+  srcs = [
+    "s_network.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "os/s_macos_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  target_compatible_with = [
+    "@platforms//os:osx",
+  ],
+  visibility = ["//visibility:public"],
+)
+
+cc_library(
+  name = "seobeo_min_linux",
   srcs = [
-    "s__network.c",
+    "s_network.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "os/s_linux_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  target_compatible_with = [
+    "@platforms//os:linux",
+  ],
+  visibility = ["//visibility:public"],
+)
+
+# TCP Server with HTTP (no WebSocket, no SSL)
+alias(
+  name = "seobeo_tcp_server",
+  actual = select({
+    "//config:macos":  ":seobeo_tcp_server_macos",
+    "//config:linux":  ":seobeo_tcp_server_linux",
+    "//conditions:default": ":seobeo_tcp_server_linux",
+  }),
+  visibility = ["//visibility:public"],
+)
+
+cc_library(
+  name = "seobeo_tcp_server_macos",
+  srcs = [
+    "s_network.c",
     "s_web.c",
+    "s_logging.c",
     "s_ssl.c",
     "os/s_macos_edge.c",
   ],
@@ -52,29 +92,11 @@
 )
 
 cc_library(
-  name = "seobeo_server_macos_dev",
+  name = "seobeo_tcp_server_linux",
   srcs = [
     "s_network.c",
     "s_web.c",
-    "s_ssl.c",
-    "os/s_macos_edge.c",
-  ],
-  hdrs = [":seobeo_hdrs"],
-  deps = [
-    "//dowa:dowa",
-  ],
-  defines = ["SEOBEO_NO_SSL", "SEOBEO_ENABLE_DEBUG"],
-  target_compatible_with = [
-    "@platforms//os:osx",
-  ],
-  visibility = ["//visibility:public"],
-)
-
-cc_library(
-  name = "seobeo_server_linux",
-  srcs = [
-    "s_network.c",
-    "s_web.c",
+    "s_logging.c",
     "s_ssl.c",
     "os/s_linux_edge.c",
   ],
@@ -89,45 +111,79 @@
   visibility = ["//visibility:public"],
 )
 
+# TCP Server with HTTP + WebSocket
+alias(
+  name = "seobeo_tcp_server_ws",
+  actual = select({
+    "//config:macos":  ":seobeo_tcp_server_ws_macos",
+    "//config:linux":  ":seobeo_tcp_server_ws_linux",
+    "//conditions:default": ":seobeo_tcp_server_ws_linux",
+  }),
+  visibility = ["//visibility:public"],
+)
+
 cc_library(
-  name = "seobeo_server_linux_dev",
+  name = "seobeo_tcp_server_ws_macos",
   srcs = [
     "s_network.c",
     "s_web.c",
+    "s_logging.c",
     "s_ssl.c",
+    "s_websocket_server.c",
+    "os/s_macos_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  defines = ["SEOBEO_WEBSOCKET_SERVER"],
+  target_compatible_with = [
+    "@platforms//os:osx",
+  ],
+  visibility = ["//visibility:public"],
+)
+
+cc_library(
+  name = "seobeo_tcp_server_ws_linux",
+  srcs = [
+    "s_network.c",
+    "s_web.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "s_websocket_server.c",
     "os/s_linux_edge.c",
   ],
   hdrs = [":seobeo_hdrs"],
   deps = [
     "//dowa:dowa",
+    "@openssl//:ssl",
   ],
-  defines = ["SEOBEO_NO_SSL", "SEOBEO_ENABLE_DEBUG"],
+  defines = ["SEOBEO_WEBSOCKET_SERVER"],
   target_compatible_with = [
     "@platforms//os:linux",
   ],
   visibility = ["//visibility:public"],
 )
 
-# Client target with SSL support (full functionality)
+# TCP Client with HTTP
 alias(
-  name = "seobeo_client",
+  name = "seobeo_tcp_client",
   actual = select({
-    "//config:macos":  ":seobeo_client_macos",
-    "//config:linux":  ":seobeo_client_linux",
-    "//conditions:default": ":seobeo_client_linux",
+    "//config:macos":  ":seobeo_tcp_client_macos",
+    "//config:linux":  ":seobeo_tcp_client_linux",
+    "//conditions:default": ":seobeo_tcp_client_linux",
   }),
   visibility = ["//visibility:public"],
 )
 
 cc_library(
-  name = "seobeo_client_macos",
+  name = "seobeo_tcp_client_macos",
   srcs = [
     "s_network.c",
-    "s_web.c",
+    "s_logging.c",
     "s_ssl.c",
     "s_http_client.c",
-    "s_websocket.c",
-    "s_websocket_server.c",
     "snapshot_creator.c",
     "os/s_macos_edge.c",
   ],
@@ -143,14 +199,12 @@
 )
 
 cc_library(
-  name = "seobeo_client_linux",
+  name = "seobeo_tcp_client_linux",
   srcs = [
     "s_network.c",
-    "s_web.c",
+    "s_logging.c",
     "s_ssl.c",
     "s_http_client.c",
-    "s_websocket.c",
-    "s_websocket_server.c",
     "snapshot_creator.c",
     "os/s_linux_edge.c",
   ],
@@ -165,46 +219,131 @@
   visibility = ["//visibility:public"],
 )
 
-# Default target for backward compatibility (points to client with SSL)
+# TCP Client with HTTP + WebSocket
 alias(
-  name = "seobeo",
-  actual = ":seobeo_client",
+  name = "seobeo_tcp_client_ws",
+  actual = select({
+    "//config:macos":  ":seobeo_tcp_client_ws_macos",
+    "//config:linux":  ":seobeo_tcp_client_ws_linux",
+    "//conditions:default": ":seobeo_tcp_client_ws_linux",
+  }),
   visibility = ["//visibility:public"],
 )
 
-# Examples
-cc_binary(
-  name = "websocket_server_example",
-  srcs = ["examples/websocket_server_example.c"],
-  deps = [":seobeo_client"],
+cc_library(
+  name = "seobeo_tcp_client_ws_macos",
+  srcs = [
+    "s_network.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "s_http_client.c",
+    "s_websocket.c",
+    "snapshot_creator.c",
+    "os/s_macos_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  target_compatible_with = [
+    "@platforms//os:osx",
+  ],
+  visibility = ["//visibility:public"],
+)
+
+cc_library(
+  name = "seobeo_tcp_client_ws_linux",
+  srcs = [
+    "s_network.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "s_http_client.c",
+    "s_websocket.c",
+    "snapshot_creator.c",
+    "os/s_linux_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  target_compatible_with = [
+    "@platforms//os:linux",
+  ],
   visibility = ["//visibility:public"],
 )
 
-# Tests
-cc_test(
-  name = "seobeo_client_test",
-  srcs = ["tests/seobeo_client_test.c"],
-  deps = [":seobeo_client"],
+# All combined  only used this if you don't want to deal with imports and what not...
+alias(
+  name = "seobeo",
+  actual = select({
+    "//config:macos":  ":seobeo_macos",
+    "//config:linux":  ":seobeo_linux",
+    "//conditions:default": ":seobeo_linux",
+  }),
+  visibility = ["//visibility:public"],
+)
+
+cc_library(
+  name = "seobeo_macos",
+  srcs = [
+    "s_network.c",
+    "s_web.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "s_http_client.c",
+    "s_websocket.c",
+    "s_websocket_server.c",
+    "snapshot_creator.c",
+    "os/s_macos_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  defines = ["SEOBEO_WEBSOCKET_SERVER"],
+  target_compatible_with = [
+    "@platforms//os:osx",
+  ],
   visibility = ["//visibility:public"],
 )
 
-cc_test(
-  name = "seobeo_websocket_test",
-  srcs = ["tests/seobeo_websocket_test.c"],
-  deps = [":seobeo_client"],
-  size = "small",
-  timeout = "short",
+cc_library(
+  name = "seobeo_linux",
+  srcs = [
+    "s_network.c",
+    "s_web.c",
+    "s_logging.c",
+    "s_ssl.c",
+    "s_http_client.c",
+    "s_websocket.c",
+    "s_websocket_server.c",
+    "snapshot_creator.c",
+    "os/s_linux_edge.c",
+  ],
+  hdrs = [":seobeo_hdrs"],
+  deps = [
+    "//dowa:dowa",
+    "@openssl//:ssl",
+  ],
+  defines = ["SEOBEO_WEBSOCKET_SERVER"],
+  target_compatible_with = [
+    "@platforms//os:linux",
+  ],
   visibility = ["//visibility:public"],
 )
 
-cc_test(
-  name = "seobeo_websocket_server_test",
-  srcs = ["tests/seobeo_web_server_test.c"],
-  deps = [":seobeo_client"],
-  data = [
-    ":websocket_server_example",
-  ],
-  size = "large",
-  timeout = "long",
-  args = ["$(location //seobeo:websocket_server_example)"],
+# Names I often use 
+alias(
+  name = "seobeo_server",
+  actual = ":seobeo_tcp_server",
+  visibility = ["//visibility:public"],
 )
+
+alias(
+  name = "seobeo_client",
+  actual = ":seobeo",
+  visibility = ["//visibility:public"],
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/seobeo/examples/BUILD	Thu Jan 08 07:31:32 2026 -0800
@@ -0,0 +1,8 @@
+load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
+
+cc_binary(
+  name = "websocket_server_example",
+  srcs = ["websocket_server_example.c"],
+  deps = ["//seobeo:seobeo"],
+  visibility = ["//visibility:public"],
+)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/seobeo/s_logging.c	Thu Jan 08 07:31:32 2026 -0800
@@ -0,0 +1,30 @@
+#include "seobeo/seobeo.h"
+
+static char *Seobeo_Log_Level_String(Seobeo_Log_Level level)
+{
+  switch(level)
+  {
+    case SEOBEO_DEBUG:   return "DEBUG";
+    case SEOBEO_INFO:    return "INFO";
+    case SEOBEO_WARNING: return "WARNING";
+    case SEOBEO_ERROR:   return "ERROR";
+    default:          return "INFO";
+  }
+}
+
+int Seobeo_Log(Seobeo_Log_Level level, const char * restrict format, ...)
+{
+  #ifndef SEOBEO_ENABLE_DEBUG
+  if (level == SEOBEO_DEBUG)
+    return 0;
+  #endif
+
+  int result;
+  va_list args;
+  printf("[%s] ", Seobeo_Log_Level_String(level));
+  va_start(args, format);
+  result = vprintf(format, args);
+  va_end(args);
+
+  return result;
+}
--- a/seobeo/s_web.c	Thu Jan 08 06:46:10 2026 -0800
+++ b/seobeo/s_web.c	Thu Jan 08 07:31:32 2026 -0800
@@ -65,13 +65,14 @@
 void Seobeo_Web_HandleClientRequest(Seobeo_Handle  *p_cli_handle,
                                     Seobeo_Cache_Entry *p_html_cache)
 {
-  Dowa_Arena *p_request_arena = Dowa_Arena_Create(1*1024*1024); // 1MB for request parsing
+  // TODO: This should be splitted up instead of handling up to 50 MB as it will fail more often... 
+  Dowa_Arena *p_request_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB because of files... 
   if (!p_request_arena) { perror("Dowa_Arena_Create request"); goto clean_up; }
 
-  Dowa_Arena *p_response_arena = Dowa_Arena_Create(5*1024*1024); // 5MB for response
+  Dowa_Arena *p_response_arena = Dowa_Arena_Create(50*1024*1024); // 50 MB for response
   if (!p_response_arena) { perror("Dowa_Arena_Create response"); goto clean_up; }
 
-  void *p_response_header = Dowa_Arena_Allocate(p_response_arena, (size_t)1024*5); // 5Kb
+  void *p_response_header = Dowa_Arena_Allocate(p_response_arena, 1024*5); // 5Kb
   if (!p_response_header) { perror("Dowa_Arena_Allocate"); goto clean_up; }
 
   Seobeo_Request_Entry *p_req_map = NULL;
@@ -135,6 +136,7 @@
   const char *path = p_path_kv ? ((Seobeo_Request_Entry*)p_path_kv)->value : "/";
 
   // --- Check for WebSocket upgrade request ---
+  #ifdef SEOBEO_WEBSOCKET_SERVER
   if (Seobeo_WebSocket_Server_Handle_Upgrade(p_cli_handle, p_req_map, path))
   {
     Seobeo_Log(SEOBEO_INFO, "WebSocket connection established\n");
@@ -144,6 +146,7 @@
       Dowa_Arena_Free(p_response_arena);
     return;
   }
+  #endif
 
   // --- Try to match API route first ---
   Seobeo_Route_Handler handler = Seobeo_Router_Find_Handler(method, path, &p_req_map, p_request_arena);
@@ -730,31 +733,5 @@
   g_routes = NULL;
 }
 
-static char *Seobeo_Log_Level_String(Seobeo_Log_Level level)
-{
-  switch(level) {
-    case SEOBEO_DEBUG:   return "DEBUG";
-    case SEOBEO_INFO:    return "INFO";
-    case SEOBEO_WARNING: return "WARNING";
-    case SEOBEO_ERROR:   return "ERROR";
-    default:          return "INFO";
-  }
-}
+// Logging functions moved to s_logging.c
 
-int Seobeo_Log(Seobeo_Log_Level level, const char * restrict format, ...)
-{
-  #ifndef SEOBEO_ENABLE_DEBUG
-  if (level == SEOBEO_DEBUG)
-    return 0;
-  #endif
-
-  int result;
-  va_list args;
-  printf("[%s] ", Seobeo_Log_Level_String(level));
-  va_start(args, format);
-  result = vprintf(format, args);
-  va_end(args);
-
-  return result;
-}
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/seobeo/tests/BUILD	Thu Jan 08 07:31:32 2026 -0800
@@ -0,0 +1,30 @@
+load("@rules_cc//cc:cc_test.bzl", "cc_test")
+
+cc_test(
+  name = "seobeo_client_test",
+  srcs = ["seobeo_client_test.c"],
+  deps = ["//seobeo:seobeo"],
+  visibility = ["//visibility:public"],
+)
+
+cc_test(
+  name = "seobeo_websocket_test",
+  srcs = ["seobeo_websocket_test.c"],
+  deps = ["//seobeo:seobeo"],
+  size = "small",
+  timeout = "short",
+  visibility = ["//visibility:public"],
+)
+
+cc_test(
+  name = "seobeo_websocket_server_test",
+  srcs = ["seobeo_web_server_test.c"],
+  deps = ["//seobeo:seobeo"],
+  data = [
+    "//seobeo/examples:websocket_server_example",
+  ],
+  size = "large",
+  timeout = "long",
+  args = ["$(location //seobeo/examples:websocket_server_example)"],
+  visibility = ["//visibility:public"],
+)