From 5ead9118b3707ddc1e9dc8868d49d419717ec330 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Tue, 5 May 2026 21:30:32 +0100 Subject: [PATCH] build: add module to handle querying platform details --- CMakeLists.txt | 13 ++++--- cmake/Platform.cmake | 36 +++++++++++++++++++ fx.io/sys/{darwin => apple}/directory.c | 0 fx.io/sys/{darwin => apple}/file.c | 0 fx.io/sys/{darwin => apple}/misc.c | 0 fx.io/sys/{darwin => apple}/misc.h | 0 fx.io/sys/{darwin => apple}/path.c | 0 fx.io/sys/{darwin => apple}/posix.c | 0 fx.io/sys/{darwin => apple}/posix.h | 0 fx.io/sys/{windows => win32}/directory.c | 0 fx.io/sys/{windows => win32}/path.c | 0 .../{darwin/arm64 => apple/aarch64}/callvm.S | 0 .../{darwin/arm64 => apple/aarch64}/callvm.c | 0 .../aarch64}/include/platform/callvm.h | 0 .../sys/linux/{x86_64 => amd64}/callvm.S | 0 .../sys/linux/{x86_64 => amd64}/callvm.c | 0 .../include/platform/callvm.h | 0 fx.term/sys/{darwin => apple}/print.c | 0 fx.term/sys/{darwin => apple}/tty.c | 0 fx.term/sys/{windows => win32}/print.c | 0 fx.term/sys/{windows => win32}/tty.c | 0 fx/sys/{darwin => apple}/bitop.c | 0 fx/sys/{darwin => apple}/random.c | 0 fx/sys/{darwin => apple}/thread.c | 0 fx/sys/{windows => win32}/bitop.c | 0 fx/sys/{windows => win32}/random.c | 0 fx/vector.c | 2 +- 27 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 cmake/Platform.cmake rename fx.io/sys/{darwin => apple}/directory.c (100%) rename fx.io/sys/{darwin => apple}/file.c (100%) rename fx.io/sys/{darwin => apple}/misc.c (100%) rename fx.io/sys/{darwin => apple}/misc.h (100%) rename fx.io/sys/{darwin => apple}/path.c (100%) rename fx.io/sys/{darwin => apple}/posix.c (100%) rename fx.io/sys/{darwin => apple}/posix.h (100%) rename fx.io/sys/{windows => win32}/directory.c (100%) rename fx.io/sys/{windows => win32}/path.c (100%) rename fx.reflection/sys/{darwin/arm64 => apple/aarch64}/callvm.S (100%) rename fx.reflection/sys/{darwin/arm64 => apple/aarch64}/callvm.c (100%) rename fx.reflection/sys/{darwin/arm64 => apple/aarch64}/include/platform/callvm.h (100%) rename fx.reflection/sys/linux/{x86_64 => amd64}/callvm.S (100%) rename fx.reflection/sys/linux/{x86_64 => amd64}/callvm.c (100%) rename fx.reflection/sys/linux/{x86_64 => amd64}/include/platform/callvm.h (100%) rename fx.term/sys/{darwin => apple}/print.c (100%) rename fx.term/sys/{darwin => apple}/tty.c (100%) rename fx.term/sys/{windows => win32}/print.c (100%) rename fx.term/sys/{windows => win32}/tty.c (100%) rename fx/sys/{darwin => apple}/bitop.c (100%) rename fx/sys/{darwin => apple}/random.c (100%) rename fx/sys/{darwin => apple}/thread.c (100%) rename fx/sys/{windows => win32}/bitop.c (100%) rename fx/sys/{windows => win32}/random.c (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4890a41..720ef55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,14 @@ cmake_minimum_required(VERSION 3.25) project(fx C ASM) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) include (TestBigEndian) +include(Templates) +include(Platform) set(CMAKE_C_STANDARD 99) set(CMAKE_C_EXTENSIONS OFF) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake) set_property(GLOBAL PROPERTY USE_FOLDERS ON) set(fx_source_root ${CMAKE_CURRENT_SOURCE_DIR}) @@ -33,10 +35,9 @@ endif () message(STATUS "Floating point support: ${fx_enable_floating_point}") -set(fx_system_name ${CMAKE_SYSTEM_NAME}) -string(TOLOWER ${fx_system_name} fx_system_name) -set(fx_system_arch ${CMAKE_SYSTEM_PROCESSOR}) -string(TOLOWER ${fx_system_arch} fx_system_arch) +get_platform_details( + SYSTEM fx_system_name + PROCESSOR fx_system_arch) message(STATUS "Target system: ${fx_system_name}-${fx_system_arch}") @@ -44,8 +45,6 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin) -include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates.cmake) - foreach (assembly ${fx_assemblies}) add_subdirectory(assemblies/${assembly}) endforeach (assembly) diff --git a/cmake/Platform.cmake b/cmake/Platform.cmake new file mode 100644 index 0000000..6646191 --- /dev/null +++ b/cmake/Platform.cmake @@ -0,0 +1,36 @@ +function(get_platform_details) + set(options) + set(one_value_args SYSTEM PROCESSOR) + set(multi_value_args + NAMESPACES + DEPENDENCIES + LIBS) + cmake_parse_arguments(PARSE_ARGV 0 arg + "${options}" + "${one_value_args}" + "${multi_value_args}") + + set(system_name "") + + if ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux") + set(system_name "linux") + elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(system_name "apple") + elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows") + set(system_name "win32") + else () + message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}") + endif () + + if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") + set(system_arch "amd64") + elseif ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") + set(system_arch "aarch64") + else () + message(FATAL_ERROR "Unsupported architecture: ${CMAKE_SYSTEM_PROCESSOR}") + endif () + + set(${arg_SYSTEM} ${system_name} PARENT_SCOPE) + set(${arg_PROCESSOR} ${system_arch} PARENT_SCOPE) +endfunction (get_platform_details) + diff --git a/fx.io/sys/darwin/directory.c b/fx.io/sys/apple/directory.c similarity index 100% rename from fx.io/sys/darwin/directory.c rename to fx.io/sys/apple/directory.c diff --git a/fx.io/sys/darwin/file.c b/fx.io/sys/apple/file.c similarity index 100% rename from fx.io/sys/darwin/file.c rename to fx.io/sys/apple/file.c diff --git a/fx.io/sys/darwin/misc.c b/fx.io/sys/apple/misc.c similarity index 100% rename from fx.io/sys/darwin/misc.c rename to fx.io/sys/apple/misc.c diff --git a/fx.io/sys/darwin/misc.h b/fx.io/sys/apple/misc.h similarity index 100% rename from fx.io/sys/darwin/misc.h rename to fx.io/sys/apple/misc.h diff --git a/fx.io/sys/darwin/path.c b/fx.io/sys/apple/path.c similarity index 100% rename from fx.io/sys/darwin/path.c rename to fx.io/sys/apple/path.c diff --git a/fx.io/sys/darwin/posix.c b/fx.io/sys/apple/posix.c similarity index 100% rename from fx.io/sys/darwin/posix.c rename to fx.io/sys/apple/posix.c diff --git a/fx.io/sys/darwin/posix.h b/fx.io/sys/apple/posix.h similarity index 100% rename from fx.io/sys/darwin/posix.h rename to fx.io/sys/apple/posix.h diff --git a/fx.io/sys/windows/directory.c b/fx.io/sys/win32/directory.c similarity index 100% rename from fx.io/sys/windows/directory.c rename to fx.io/sys/win32/directory.c diff --git a/fx.io/sys/windows/path.c b/fx.io/sys/win32/path.c similarity index 100% rename from fx.io/sys/windows/path.c rename to fx.io/sys/win32/path.c diff --git a/fx.reflection/sys/darwin/arm64/callvm.S b/fx.reflection/sys/apple/aarch64/callvm.S similarity index 100% rename from fx.reflection/sys/darwin/arm64/callvm.S rename to fx.reflection/sys/apple/aarch64/callvm.S diff --git a/fx.reflection/sys/darwin/arm64/callvm.c b/fx.reflection/sys/apple/aarch64/callvm.c similarity index 100% rename from fx.reflection/sys/darwin/arm64/callvm.c rename to fx.reflection/sys/apple/aarch64/callvm.c diff --git a/fx.reflection/sys/darwin/arm64/include/platform/callvm.h b/fx.reflection/sys/apple/aarch64/include/platform/callvm.h similarity index 100% rename from fx.reflection/sys/darwin/arm64/include/platform/callvm.h rename to fx.reflection/sys/apple/aarch64/include/platform/callvm.h diff --git a/fx.reflection/sys/linux/x86_64/callvm.S b/fx.reflection/sys/linux/amd64/callvm.S similarity index 100% rename from fx.reflection/sys/linux/x86_64/callvm.S rename to fx.reflection/sys/linux/amd64/callvm.S diff --git a/fx.reflection/sys/linux/x86_64/callvm.c b/fx.reflection/sys/linux/amd64/callvm.c similarity index 100% rename from fx.reflection/sys/linux/x86_64/callvm.c rename to fx.reflection/sys/linux/amd64/callvm.c diff --git a/fx.reflection/sys/linux/x86_64/include/platform/callvm.h b/fx.reflection/sys/linux/amd64/include/platform/callvm.h similarity index 100% rename from fx.reflection/sys/linux/x86_64/include/platform/callvm.h rename to fx.reflection/sys/linux/amd64/include/platform/callvm.h diff --git a/fx.term/sys/darwin/print.c b/fx.term/sys/apple/print.c similarity index 100% rename from fx.term/sys/darwin/print.c rename to fx.term/sys/apple/print.c diff --git a/fx.term/sys/darwin/tty.c b/fx.term/sys/apple/tty.c similarity index 100% rename from fx.term/sys/darwin/tty.c rename to fx.term/sys/apple/tty.c diff --git a/fx.term/sys/windows/print.c b/fx.term/sys/win32/print.c similarity index 100% rename from fx.term/sys/windows/print.c rename to fx.term/sys/win32/print.c diff --git a/fx.term/sys/windows/tty.c b/fx.term/sys/win32/tty.c similarity index 100% rename from fx.term/sys/windows/tty.c rename to fx.term/sys/win32/tty.c diff --git a/fx/sys/darwin/bitop.c b/fx/sys/apple/bitop.c similarity index 100% rename from fx/sys/darwin/bitop.c rename to fx/sys/apple/bitop.c diff --git a/fx/sys/darwin/random.c b/fx/sys/apple/random.c similarity index 100% rename from fx/sys/darwin/random.c rename to fx/sys/apple/random.c diff --git a/fx/sys/darwin/thread.c b/fx/sys/apple/thread.c similarity index 100% rename from fx/sys/darwin/thread.c rename to fx/sys/apple/thread.c diff --git a/fx/sys/windows/bitop.c b/fx/sys/win32/bitop.c similarity index 100% rename from fx/sys/windows/bitop.c rename to fx/sys/win32/bitop.c diff --git a/fx/sys/windows/random.c b/fx/sys/win32/random.c similarity index 100% rename from fx/sys/windows/random.c rename to fx/sys/win32/random.c diff --git a/fx/vector.c b/fx/vector.c index 3130b7d..a7c7001 100644 --- a/fx/vector.c +++ b/fx/vector.c @@ -73,7 +73,7 @@ static int trim_excess_items( { size_t to_trim = v->v_count - new_capacity; size_t start = new_capacity; - char *item = &v->v_buf[start]; + char *item = (char *)v->v_buf + start; for (size_t i = start; i < v->v_count; i++) { ops->v_destroy(item);