From 7141a342d9d0e782bd7c1a82ec289e00ef32126d Mon Sep 17 00:00:00 2001 From: TymianekPL Date: Fri, 22 Aug 2025 19:38:22 +0200 Subject: [PATCH] process Signed-off-by: TymianekPL --- CMakeLists.txt | 18 ++++++++++-------- starlib/CMakeLists.txt | 12 ++++++++++-- starlib/process.cpp | 17 +++++++++++++++++ starlib/process.ixx | 6 ++++++ starlib/starlib.cpp | 4 ++-- starlib/starlib.ixx | 5 +---- testing/CMakeLists.txt | 6 ++++++ testing/main.cpp | 7 ------- 8 files changed, 52 insertions(+), 23 deletions(-) create mode 100644 starlib/process.cpp create mode 100644 starlib/process.ixx diff --git a/CMakeLists.txt b/CMakeLists.txt index 43fb636..08fbe18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 3.29) +cmake_minimum_required (VERSION 3.29) project(StarProject LANGUAGES CXX) set(CMAKE_CXX_STANDARD 23) @@ -10,13 +10,15 @@ if (POLICY CMP0141) # MSVC hot-reload schenanigans set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$,$>,$<$:EditAndContinue>,$<$:ProgramDatabase>>") endif() -if (MSVC) - add_compile_options(/experimental:module /EHsc /utf-8) -elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-fmodules-ts -stdlib=libc++) -elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - add_compile_options(-fmodules-ts) +if(MSVC) + string(REPLACE "/RTC1" "" OLD_FLAGS "${CMAKE_CXX_FLAGS_DEBUG}") + set(CMAKE_CXX_FLAGS_DEBUG "${OLD_FLAGS}") + add_compile_options(/permissive- /Zc:preprocessor /JMC /std:c++latest /GR- /GS- /EHsc-) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_compile_options(-ffreestanding -nostdinc++ -fno-exceptions -fno-rtti) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options(-ffreestanding -nostdinc++ -fno-exceptions -fno-rtti) endif() add_subdirectory(starlib) -add_subdirectory(testing) \ No newline at end of file +add_subdirectory(testing) diff --git a/starlib/CMakeLists.txt b/starlib/CMakeLists.txt index 5426885..03e44d8 100644 --- a/starlib/CMakeLists.txt +++ b/starlib/CMakeLists.txt @@ -1,12 +1,20 @@ -add_library(starlib STATIC) +add_library(starlib STATIC) # Add module sources target_sources(starlib PUBLIC FILE_SET cxx_modules TYPE CXX_MODULES FILES starlib.ixx + process.ixx PRIVATE starlib.cpp -) + process.cpp + "process.ixx") target_include_directories(starlib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +if(MSVC) + target_link_options(starlib PRIVATE /NODEFAULTLIB) +else() + target_link_libraries(starlib PRIVATE -nostdlib++) +endif() diff --git a/starlib/process.cpp b/starlib/process.cpp new file mode 100644 index 0000000..6ea3b3e --- /dev/null +++ b/starlib/process.cpp @@ -0,0 +1,17 @@ +module; +#ifdef _WIN32 +#include +#else +#error Unsupported platform +#endif + +module process; + +void starlib::process::Exit(int code) +{ +#ifdef _WIN32 + ExitProcess(static_cast(code)); +#else +#error Unsupported platform +#endif +} diff --git a/starlib/process.ixx b/starlib/process.ixx new file mode 100644 index 0000000..618424b --- /dev/null +++ b/starlib/process.ixx @@ -0,0 +1,6 @@ +export module process; + +namespace starlib::process +{ + export [[noreturn]] void Exit(int code); +} diff --git a/starlib/starlib.cpp b/starlib/starlib.cpp index 1a6d113..d1214c9 100644 --- a/starlib/starlib.cpp +++ b/starlib/starlib.cpp @@ -1,6 +1,6 @@ module starlib; -int starlib::Meow(void) +extern "C" void DefaultMain(void) { - return 1234; + starlib::process::Exit(1); } diff --git a/starlib/starlib.ixx b/starlib/starlib.ixx index 9ce39e1..61d3048 100644 --- a/starlib/starlib.ixx +++ b/starlib/starlib.ixx @@ -1,6 +1,3 @@ export module starlib; -namespace starlib -{ - export int Meow(); -} +export import process; diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 4e001af..2a3ab99 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -6,3 +6,9 @@ target_sources(testing ) target_link_libraries(testing PRIVATE starlib) + +if(MSVC) + target_link_options(testing PRIVATE /NODEFAULTLIB /ENTRY:DefaultMain) +else() + target_link_libraries(testing PRIVATE -nostdlib++) +endif() diff --git a/testing/main.cpp b/testing/main.cpp index 054f807..44a7cb3 100644 --- a/testing/main.cpp +++ b/testing/main.cpp @@ -1,8 +1 @@ import starlib; - -#include - -int main(void) -{ - std::println("Meow() -> {}", starlib::Meow()); -}