From d83dd682f5fafd4426f804ee6ce483b569374955 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 28 Dec 2025 21:53:09 +0000 Subject: [PATCH] Remove src/ folder and update CMakeLists.txt to reference real interpreter - Removed src/ directory (accidental commit with minimal runtime) - Removed include/ and tests/ directories (part of minimal runtime) - Updated CMakeLists.txt to build Programs/python.c (real CPython entry point) - Added minimal pyconfig.h stub (NOTE: incomplete, proper build needs configure) The CMakeLists.txt now references the real Python interpreter source but requires additional work to properly build the full CPython interpreter with all dependencies. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- CMakeLists.txt | 68 ++++++++++++++++++--------------------- Include/pyconfig.h | 58 +++++++++++++++++++++++++++++++++ include/typthon/runtime.h | 15 --------- src/main.c | 40 ----------------------- src/runtime.c | 14 -------- tests/smoke.c | 16 --------- 6 files changed, 89 insertions(+), 122 deletions(-) create mode 100644 Include/pyconfig.h delete mode 100644 include/typthon/runtime.h delete mode 100644 src/main.c delete mode 100644 src/runtime.c delete mode 100644 tests/smoke.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 6205eb0..1a47729 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,51 +11,45 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/cmake/version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/generated/typthon/version.h - @ONLY -) +# NOTE: Building CPython requires proper configuration (./configure) +# This CMakeLists.txt is a work in progress to wire to the real interpreter -add_library(typthon_core STATIC src/runtime.c) -target_include_directories( - typthon_core - PUBLIC - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_BINARY_DIR}/generated -) -target_compile_features(typthon_core PUBLIC c_std_11) +# Platform detection +if(UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() -add_executable(typthon src/main.c) -target_link_libraries(typthon PRIVATE typthon_core) +# TODO: Collect and build Python core source files from: +# - Python/*.c (interpreter core) +# - Objects/*.c (built-in types) +# - Parser/*.c (parser) +# - Modules/*.c (built-in modules) + +# TODO: Generate or provide pyconfig.h +# CPython normally generates this via ./configure + +# Placeholder: Build Python executable +add_executable(typthon Programs/python.c) + +# TODO: Link against Python core library once built +# target_link_libraries(typthon PRIVATE python_core) + +if(UNIX) + target_link_libraries(typthon PRIVATE m dl pthread util) +endif() + +target_include_directories(typthon + PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/Include +) include(GNUInstallDirs) install( - TARGETS typthon_core typthon + TARGETS typthon RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} -) -install( - FILES ${CMAKE_CURRENT_BINARY_DIR}/generated/typthon/version.h - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/typthon ) include(CTest) if(BUILD_TESTING) - add_executable(typthon_smoketest tests/smoke.c) - target_include_directories( - typthon_smoketest - PRIVATE - ${CMAKE_CURRENT_SOURCE_DIR}/include - ${CMAKE_CURRENT_BINARY_DIR}/generated - ) - target_link_libraries(typthon_smoketest PRIVATE typthon_core) - - add_test(NAME typthon_cli COMMAND typthon --version) - add_test(NAME typthon_runtime_version COMMAND typthon_smoketest) + add_test(NAME typthon_version COMMAND typthon --version) endif() diff --git a/Include/pyconfig.h b/Include/pyconfig.h new file mode 100644 index 0000000..53fb3a0 --- /dev/null +++ b/Include/pyconfig.h @@ -0,0 +1,58 @@ +/* Minimal pyconfig.h for Typthon CMake build + * NOTE: This is a stub. A proper build requires running ./configure + * to generate a complete pyconfig.h with platform-specific settings. + */ + +#ifndef Py_PYCONFIG_H +#define Py_PYCONFIG_H + +/* Platform detection */ +#if defined(_WIN32) || defined(_WIN64) + #define MS_WINDOWS + #define MS_WIN32 +#elif defined(__linux__) + #define __linux__ 1 +#elif defined(__APPLE__) + #define __APPLE__ 1 +#endif + +/* Basic configuration - these are minimal stubs */ +#define SIZEOF_INT 4 +#define SIZEOF_LONG 8 +#define SIZEOF_VOID_P 8 +#define SIZEOF_SIZE_T 8 +#define SIZEOF_TIME_T 8 +#define SIZEOF_WCHAR_T 4 +#define SIZEOF_SHORT 2 +#define SIZEOF_FLOAT 4 +#define SIZEOF_DOUBLE 8 +#define SIZEOF_FPOS_T 16 +#define SIZEOF_LONG_LONG 8 + +/* Enable threading */ +#ifndef MS_WINDOWS + #define WITH_THREAD 1 + #define HAVE_PTHREAD_H 1 +#endif + +/* Common POSIX features */ +#ifndef MS_WINDOWS + #define HAVE_UNISTD_H 1 + #define HAVE_FCNTL_H 1 + #define HAVE_SYS_TYPES_H 1 + #define HAVE_SYS_STAT_H 1 + #define HAVE_DIRENT_H 1 + #define HAVE_DLFCN_H 1 +#endif + +/* Standard C features */ +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRING_H 1 +#define HAVE_ERRNO_H 1 +#define HAVE_STDIO_H 1 + +/* TODO: Add more platform-specific defines as needed */ +/* This stub is incomplete. For a full build, use CPython's configure script */ + +#endif /* Py_PYCONFIG_H */ diff --git a/include/typthon/runtime.h b/include/typthon/runtime.h deleted file mode 100644 index 8b1a3cf..0000000 --- a/include/typthon/runtime.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -const char *typthon_version(void); -void typthon_print_banner(FILE *output); - -#ifdef __cplusplus -} -#endif - diff --git a/src/main.c b/src/main.c deleted file mode 100644 index 007a21f..0000000 --- a/src/main.c +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include -#include - -#include "typthon/runtime.h" -#include "typthon/version.h" - -static void print_usage(void) { - printf("Typthon %s\n", typthon_version()); - printf("usage: typthon [--version] [--help]\n"); - printf("This is a lightweight bootstrap for the Typthon runtime.\n"); -} - -int main(int argc, char **argv) { - bool show_help = false; - bool show_version = false; - - for (int i = 1; i < argc; ++i) { - if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) { - show_help = true; - } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) { - show_version = true; - } else { - fprintf(stderr, "unknown option: %s\n", argv[i]); - return 1; - } - } - - if (show_help) { - print_usage(); - return 0; - } - - if (show_version || argc == 1) { - typthon_print_banner(stdout); - return 0; - } - - return 0; -} diff --git a/src/runtime.c b/src/runtime.c deleted file mode 100644 index aa9f40c..0000000 --- a/src/runtime.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "typthon/runtime.h" -#include "typthon/version.h" - -const char *typthon_version(void) { - return TYPTHON_VERSION; -} - -void typthon_print_banner(FILE *output) { - if (output == NULL) { - return; - } - - fprintf(output, "Typthon %s\n", typthon_version()); -} diff --git a/tests/smoke.c b/tests/smoke.c deleted file mode 100644 index 88efc0e..0000000 --- a/tests/smoke.c +++ /dev/null @@ -1,16 +0,0 @@ -#include -#include -#include - -#include "typthon/runtime.h" -#include "typthon/version.h" - -int main(void) { - const char *version = typthon_version(); - assert(version != NULL); - assert(strlen(version) > 0); - - printf("Typthon runtime version: %s\n", version); - typthon_print_banner(stdout); - return 0; -}