From 35f7243b4d4ff347208ac5a9b3fa168fee9bd6ba Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Aug 2025 13:32:40 +0200 Subject: [PATCH 01/27] remove --- .github/workflows/CI-unixish.yml | 151 ------------------------------- .github/workflows/CI-windows.yml | 66 -------------- .github/workflows/clang-tidy.yml | 44 --------- .github/workflows/format.yml | 62 ------------- appveyor.yml | 21 ----- 5 files changed, 344 deletions(-) delete mode 100644 .github/workflows/CI-unixish.yml delete mode 100644 .github/workflows/CI-windows.yml delete mode 100644 .github/workflows/clang-tidy.yml delete mode 100644 .github/workflows/format.yml delete mode 100644 appveyor.yml diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml deleted file mode 100644 index adb91138..00000000 --- a/.github/workflows/CI-unixish.yml +++ /dev/null @@ -1,151 +0,0 @@ -name: CI-unixish - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - build: - - strategy: - matrix: - os: [ubuntu-22.04, ubuntu-24.04, macos-13, macos-14, macos-15] - compiler: [clang++] - include: - - os: ubuntu-22.04 - compiler: g++ - - os: ubuntu-24.04 - compiler: g++ - fail-fast: false - - runs-on: ${{ matrix.os }} - - env: - CXX: ${{ matrix.compiler }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software on ubuntu - if: matrix.os == 'ubuntu-24.04' - run: | - sudo apt-get update - sudo apt-get install valgrind - - - name: Install missing software on ubuntu (clang++) - if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' - run: | - sudo apt-get update - sudo apt-get install libc++-18-dev - - # coreutils contains "nproc" - - name: Install missing software on macos - if: contains(matrix.os, 'macos') - run: | - brew install coreutils - - - name: Install missing Python packages - run: | - python3 -m pip config set global.break-system-packages true - python3 -m pip install pytest - - - name: make simplecpp - run: make -j$(nproc) CXXOPTS="-Werror" - - - name: make test - run: make -j$(nproc) test CXXOPTS="-Werror" - - - name: selfcheck - run: | - make -j$(nproc) selfcheck - - - name: make testrunner (c++17) - run: | - make clean - make -j$(nproc) testrunner CXXOPTS="-std=c++17" - - - name: make testrunner (c++20) - run: | - make clean - make -j$(nproc) testrunner CXXOPTS="-std=c++20" - - - name: Run CMake - run: | - cmake -S . -B cmake.output -DCMAKE_COMPILE_WARNING_AS_ERROR=On - - - name: CMake simplecpp - run: | - cmake --build cmake.output --target simplecpp -- -j $(nproc) - - - name: CMake testrunner - run: | - cmake --build cmake.output --target testrunner -- -j $(nproc) - ./cmake.output/testrunner - # Re-run tests from within the build directory to validate that - # SIMPLECPP_TEST_SOURCE_DIR is correctly defined and resolved - (cd cmake.output && ./testrunner) - - - name: Run valgrind - if: matrix.os == 'ubuntu-24.04' - run: | - make clean - make -j$(nproc) - valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./testrunner - valgrind --leak-check=full --num-callers=50 --show-reachable=yes --track-origins=yes --gen-suppressions=all --error-exitcode=42 ./simplecpp simplecpp.cpp -e - - - name: Run with libstdc++ debug mode - if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'g++' - run: | - make clean - make -j$(nproc) test selfcheck CXXOPTS="-Werror -g3 -D_GLIBCXX_DEBUG" - - - name: Run with libc++ hardening mode - if: matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' - run: | - make clean - make -j$(nproc) test selfcheck CXXOPTS="-Werror -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDOPTS="-lc++" - - - name: Run AddressSanitizer - if: matrix.os == 'ubuntu-24.04' - run: | - make clean - make -j$(nproc) test selfcheck CXXOPTS="-Werror -O2 -g3 -fsanitize=address" LDOPTS="-fsanitize=address" - env: - ASAN_OPTIONS: detect_stack_use_after_return=1 - - - name: Run UndefinedBehaviorSanitizer - if: matrix.os == 'ubuntu-24.04' - run: | - make clean - make -j$(nproc) test selfcheck CXXOPTS="-Werror -O2 -g3 -fsanitize=undefined -fno-sanitize=signed-integer-overflow" LDOPTS="-fsanitize=undefined -fno-sanitize=signed-integer-overflow" - env: - UBSAN_OPTIONS: print_stacktrace=1:halt_on_error=1:report_error_type=1 - - # TODO: requires instrumented libc++ - - name: Run MemorySanitizer - if: false && matrix.os == 'ubuntu-24.04' && matrix.compiler == 'clang++' - run: | - make clean - make -j$(nproc) test selfcheck CXXOPTS="-Werror -O2 -g3 -stdlib=libc++ -fsanitize=memory" LDOPTS="-lc++ -fsanitize=memory" - - - name: Run callgrind - if: matrix.os == 'ubuntu-24.04' - run: | - wget https://github.com/danmar/simplecpp/archive/refs/tags/1.5.1.tar.gz - tar xvf 1.5.1.tar.gz - make clean - make -j$(nproc) CXXOPTS="-O2 -g3" - valgrind --tool=callgrind ./simplecpp -e simplecpp-1.5.1/simplecpp.cpp 2>callgrind.log || (cat callgrind.log && false) - cat callgrind.log - callgrind_annotate --auto=no > callgrind.annotated.log - head -50 callgrind.annotated.log - - - uses: actions/upload-artifact@v4 - if: matrix.os == 'ubuntu-24.04' - with: - name: Callgrind Output - ${{ matrix.compiler }} - path: | - ./callgrind.* diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml deleted file mode 100644 index 767bba6c..00000000 --- a/.github/workflows/CI-windows.yml +++ /dev/null @@ -1,66 +0,0 @@ -# Some convenient links: -# - https://github.com/actions/virtual-environments/blob/master/images/win/Windows2019-Readme.md -# - -name: CI-windows - -on: [push,pull_request] - -permissions: - contents: read - -defaults: - run: - shell: cmd - -jobs: - - build: - strategy: - matrix: - os: [windows-2022, windows-2025] - config: [Release, Debug] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Setup msbuild.exe - uses: microsoft/setup-msbuild@v2 - - - name: Set up Python 3.13 - uses: actions/setup-python@v5 - with: - python-version: '3.13' - check-latest: true - - - name: Install missing Python packages - run: | - python -m pip install pip --upgrade || exit /b !errorlevel! - python -m pip install pytest || exit /b !errorlevel! - - - name: Run CMake - run: | - cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_COMPILE_WARNING_AS_ERROR=On . || exit /b !errorlevel! - - - name: Build - run: | - msbuild -m simplecpp.sln /p:Configuration=${{ matrix.config }} /p:Platform=x64 || exit /b !errorlevel! - - - name: Test - run: | - .\${{ matrix.config }}\testrunner.exe || exit /b !errorlevel! - - - name: Selfcheck - run: | - .\${{ matrix.config }}\simplecpp.exe simplecpp.cpp -e || exit /b !errorlevel! - - - name: integration test - run: | - set SIMPLECPP_EXE_PATH=.\${{ matrix.config }}\simplecpp.exe - python -m pytest integration_test.py -vv || exit /b !errorlevel! - diff --git a/.github/workflows/clang-tidy.yml b/.github/workflows/clang-tidy.yml deleted file mode 100644 index fd71bdfe..00000000 --- a/.github/workflows/clang-tidy.yml +++ /dev/null @@ -1,44 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: clang-tidy - -on: [push, pull_request] - -permissions: - contents: read - -jobs: - build: - - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Install missing software - run: | - sudo apt-get update - sudo apt-get install -y cmake make - - - name: Install clang - run: | - wget https://apt.llvm.org/llvm.sh - chmod +x llvm.sh - sudo ./llvm.sh 20 - sudo apt-get install clang-tidy-20 - - - name: Verify clang-tidy configuration - run: | - clang-tidy-20 --verify-config - - - name: Prepare CMake - run: | - cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON - env: - CXX: clang-20 - - - name: Clang-Tidy - run: | - run-clang-tidy-20 -q -j $(nproc) -p=cmake.output diff --git a/.github/workflows/format.yml b/.github/workflows/format.yml deleted file mode 100644 index 4d5657f8..00000000 --- a/.github/workflows/format.yml +++ /dev/null @@ -1,62 +0,0 @@ -# Syntax reference https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions -# Environment reference https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners -name: format - -on: - push: - branches: - - 'master' - - 'releases/**' - - '1.*' - tags: - - '1.*' - pull_request: - -permissions: - contents: read - -jobs: - format: - - runs-on: ubuntu-22.04 - - defaults: - run: - shell: bash -euo pipefail {0} - - env: - UNCRUSTIFY_INSTALL_DIR: ${{ github.workspace }}/runformat-uncrustify - - steps: - - uses: actions/checkout@v5 - with: - persist-credentials: false - - - name: Determine uncrustify version - id: get-uncrustify-version - run: | - version="$(./runformat --expected-uncrustify-version)" - echo "Expected uncrustify version: $version" - echo "version=$version" >> "$GITHUB_OUTPUT" - - - name: Set UNCRUSTIFY_VERSION env variable - run: | - version=$(./runformat --expected-uncrustify-version) - echo "version [$version]" - echo "UNCRUSTIFY_VERSION=${version}" >> "$GITHUB_ENV" - - - name: Cache uncrustify - uses: actions/cache@v4 - id: cache-uncrustify - with: - path: ${{ env.UNCRUSTIFY_INSTALL_DIR }} - key: ${{ runner.os }}-uncrustify-${{ steps.get-uncrustify-version.outputs.version }} - - - name: Install uncrustify - if: steps.cache-uncrustify.outputs.cache-hit != 'true' - run: | - ./runformat --install --install-dir "${UNCRUSTIFY_INSTALL_DIR}" - - - name: Uncrustify check - run: | - ./runformat diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 09aa6cbe..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,21 +0,0 @@ -version: 1.{build} - -environment: - matrix: - - VisualStudioVersion: 14.0 - platform: "Win32" - configuration: "Debug" - vcvarsall_platform: "x86" - PlatformToolset: "v140" - -build_script: - - ECHO Building %configuration% %platform% with MSVC %VisualStudioVersion% using %PlatformToolset% PlatformToolset - - cmake -DCMAKE_COMPILE_WARNING_AS_ERROR=On -G "Visual Studio 14" . - - dir - - 'CALL "C:\Program Files (x86)\Microsoft Visual Studio %VisualStudioVersion%\VC\vcvarsall.bat" %vcvarsall_platform%' - - set _CL_=/WX - - msbuild "simplecpp.sln" /consoleloggerparameters:Verbosity=minimal /target:Build /property:Configuration="%configuration%";Platform=%platform% /p:PlatformToolset=%PlatformToolset% /maxcpucount /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" - -test_script: - - debug\testrunner.exe - - debug\simplecpp.exe simplecpp.cpp -e From 050fda76f1c2ba72902f5fceace318125dd22064 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 4 Aug 2025 13:32:53 +0200 Subject: [PATCH 02/27] added MinGW workflow Co-authored-by: glankk --- .github/workflows/CI-mingw.yml | 114 +++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 .github/workflows/CI-mingw.yml diff --git a/.github/workflows/CI-mingw.yml b/.github/workflows/CI-mingw.yml new file mode 100644 index 00000000..86ac42f9 --- /dev/null +++ b/.github/workflows/CI-mingw.yml @@ -0,0 +1,114 @@ +name: CI-mingw + +on: [push, pull_request] + +permissions: + contents: read + +defaults: + run: + shell: msys2 {0} + +jobs: + build: + + strategy: + matrix: + compiler: [g++, clang++] + msystem: [MSYS, MINGW32, MINGW64, CLANG64] + include: + - msystem: MSYS + pkg-prefix: '' + - msystem: MINGW32 + pkg-prefix: 'mingw-w64-i686-' + - msystem: MINGW64 + pkg-prefix: 'mingw-w64-x86_64-' + - msystem: CLANG64 + pkg-prefix: 'mingw-w64-clang-x86_64-' + - compiler: g++ + compiler-pkg: gcc + - compiler: clang++ + compiler-pkg: clang + exclude: + - msystem: CLANG64 + compiler: g++ + fail-fast: false + + runs-on: windows-2025 + + env: + CXX: ${{ matrix.compiler }} + + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Set up MSYS2 + uses: msys2/setup-msys2@v2 + with: + release: false # use pre-installed + cache: false + msystem: ${{ matrix.msystem }} + # TODO: install mingw-w64-x86_64-make and use mingw32.make instead - currently fails with "Windows Subsystem for Linux has no installed distributions." + # TODO: also run tests with non-prefixed Python? + install: >- + make + ${{ matrix.pkg-prefix }}cmake + ${{ matrix.pkg-prefix }}python + ${{ matrix.pkg-prefix }}python-pytest + + - name: install compiler + run: | + pacman -S --noconfirm ${{ matrix.pkg-prefix }}${{ matrix.compiler-pkg }} + ${CXX} -v + + - name: make simplecpp + run: make -j$(nproc) CXXOPTS="-Werror" + + # gcc *and* clang are required to run-tests.py + # install it at this point since it has gcc as dependency which might interfere with the build + - name: install compiler (test) + if: matrix.compiler == 'g++' + run: | + pacman -S --noconfirm clang + + - name: install compiler (test) + if: matrix.compiler == 'clang++' + run: | + pacman -S --noconfirm gcc + + - name: make test + run: make -j$(nproc) CXXOPTS="-Werror" test + + - name: selfcheck + run: | + make -j$(nproc) selfcheck + + - name: Run CMake + run: | + cmake -S . -B cmake.output -DCMAKE_COMPILE_WARNING_AS_ERROR=On + + - name: CMake simplecpp + run: | + cmake --build cmake.output --target simplecpp -- -j $(nproc) + + - name: CMake testrunner + run: | + cmake --build cmake.output --target testrunner -- -j $(nproc) + + - name: Run testrunner + run: | + ./cmake.output/testrunner + + - name: Run with libstdc++ debug mode + if: matrix.compiler == 'g++' + run: | + make clean + make -j$(nproc) test selfcheck CXXOPTS="-Werror -g3 -D_GLIBCXX_DEBUG" + + - name: Run with libc++ hardening mode + if: matrix.compiler == 'clang++' && matrix.msystem == 'CLANG64' + run: | + make clean + make -j$(nproc) test selfcheck CXXOPTS="-Werror -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDOPTS="-lc++" From db18ea8e046f9b85d2ac63561e30c74a8275e37f Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 11 Aug 2025 16:33:40 +0200 Subject: [PATCH 03/27] run-tests.py: improved output when test failed --- run-tests.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/run-tests.py b/run-tests.py index 8810bf2b..20f59a49 100644 --- a/run-tests.py +++ b/run-tests.py @@ -92,7 +92,7 @@ def cleanup(out: str) -> str: ] -def run(compiler_executable: str, compiler_args: list[str]) -> tuple[int, str, str]: +def run(compiler_executable: str, compiler_args: list[str]) -> tuple[int, str, str, str]: """Execute a compiler command and capture its exit code, stdout, and stderr.""" compiler_cmd = [compiler_executable] compiler_cmd.extend(compiler_args) @@ -103,7 +103,7 @@ def run(compiler_executable: str, compiler_args: list[str]) -> tuple[int, str, s output = cleanup(stdout) error = (stderr or "").strip() - return (exit_code, output, error) + return (exit_code, output, stdout, error) numberOfSkipped = 0 @@ -117,20 +117,32 @@ def run(compiler_executable: str, compiler_args: list[str]) -> tuple[int, str, s numberOfSkipped = numberOfSkipped + 1 continue - _, clang_output, _ = run(CLANG_EXE, cmd.split(' ')) + _, clang_output_c, clang_output, _ = run(CLANG_EXE, cmd.split(' ')) - _, gcc_output, _ = run(GCC_EXE, cmd.split(' ')) + _, gcc_output_c, gcc_output, _ = run(GCC_EXE, cmd.split(' ')) # -E is not supported and we bail out on unknown options - simplecpp_ec, simplecpp_output, simplecpp_err = run(SIMPLECPP_EXE, cmd.replace('-E ', '', 1).split(' ')) + simplecpp_ec, simplecpp_output_c, simplecpp_output, simplecpp_err = run(SIMPLECPP_EXE, cmd.replace('-E ', '', 1).split(' ')) - if simplecpp_output != clang_output and simplecpp_output != gcc_output: + if simplecpp_output_c != clang_output_c and simplecpp_output_c != gcc_output_c: filename = cmd[cmd.rfind('/')+1:] if filename in todo: print('TODO ' + cmd) usedTodos.append(filename) else: print('FAILED ' + cmd) + print('---expected (clang):') + print(clang_output_c) + print('---expected (gcc):') + print(gcc_output_c) + print('---actual:') + print(simplecpp_output_c) + print('---output (clang):') + print(clang_output) + print('---output (gcc):') + print(gcc_output) + print('---output (simplecpp):') + print(simplecpp_output) if simplecpp_ec: print('simplecpp failed - ' + simplecpp_err) numberOfFailed = numberOfFailed + 1 From 64f07b670c3c050da6b6a6c160919b77e50fa268 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 2 Sep 2025 09:22:14 +0200 Subject: [PATCH 04/27] simplecpp.cpp: fixed `-Wzero-as-null-pointer-constant` Clang warnings --- simplecpp.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index b1505cb6..33ae59c5 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3083,7 +3083,7 @@ std::pair simplecpp::FileDataCache::get(const std:: bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id) { #ifdef SIMPLECPP_WINDOWS - HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); + HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) return false; From 9ca053441f2376eab402fa7ea4201c6fdde1272a Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 2 Sep 2025 09:24:25 +0200 Subject: [PATCH 05/27] disabled some compiler warnings Co-authored-by: glankk --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8799b7a4..073ad3ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,7 +37,7 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class add_compile_options(-Wsuggest-attribute=noreturn) - add_compile_options_safe(-Wuseless-cast) + #add_compile_options_safe(-Wuseless-cast) # triggered by _WIN32 code elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC") add_compile_definitions(_CRT_SECURE_NO_WARNINGS) # TODO: bump warning level @@ -51,15 +51,20 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang") # these are not really fixable add_compile_options(-Wno-exit-time-destructors -Wno-global-constructors -Wno-weak-vtables) add_compile_options_safe(-Wno-unsafe-buffer-usage) + add_compile_options_safe(-Wno-nrvo) # we are not interested in these add_compile_options(-Wno-multichar -Wno-four-char-constants) # ignore C++11-specific warning add_compile_options(-Wno-suggest-override -Wno-suggest-destructor-override) # contradicts -Wcovered-switch-default add_compile_options(-Wno-switch-default) + # for _WIN32 + add_compile_options(-Wno-reserved-macro-identifier) + add_compile_options(-Wno-unused-macros) # TODO: fix these? add_compile_options(-Wno-padded -Wno-sign-conversion -Wno-implicit-int-conversion -Wno-shorten-64-to-32 -Wno-shadow-field-in-constructor) + if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14) # TODO: verify this regression still exists in clang-15 if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") From c74e586d144a3772e3200d7592cd064bffb233fc Mon Sep 17 00:00:00 2001 From: glank Date: Tue, 2 Sep 2025 16:45:48 +0200 Subject: [PATCH 06/27] fixed #524 - use `CreateFileA` for _WIN32 only (fixes includes not found on MinGW) Co-authored-by: firewave --- simplecpp.cpp | 13 ++++++++++--- simplecpp.h | 10 +++------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/simplecpp.cpp b/simplecpp.cpp index 33ae59c5..8339e3ba 100644 --- a/simplecpp.cpp +++ b/simplecpp.cpp @@ -3,13 +3,20 @@ * Copyright (C) 2016-2023 simplecpp team */ -#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) -# define _WIN32_WINNT 0x0602 +#if defined(_WIN32) +# ifndef _WIN32_WINNT +# define _WIN32_WINNT 0x0602 +# endif # define NOMINMAX +# define WIN32_LEAN_AND_MEAN # include # undef ERROR #endif +#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) +# define SIMPLECPP_WINDOWS +#endif + #include "simplecpp.h" #include @@ -3082,7 +3089,7 @@ std::pair simplecpp::FileDataCache::get(const std:: bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id) { -#ifdef SIMPLECPP_WINDOWS +#ifdef _WIN32 HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) diff --git a/simplecpp.h b/simplecpp.h index 43a03730..ef748b3e 100644 --- a/simplecpp.h +++ b/simplecpp.h @@ -6,10 +6,6 @@ #ifndef simplecppH #define simplecppH -#if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) -# define SIMPLECPP_WINDOWS -#endif - #include #include #include @@ -43,7 +39,7 @@ # define SIMPLECPP_LIB #endif -#ifdef SIMPLECPP_WINDOWS +#ifdef _WIN32 # include #else # include @@ -471,7 +467,7 @@ namespace simplecpp { private: struct FileID { -#ifdef SIMPLECPP_WINDOWS +#ifdef _WIN32 struct { std::uint64_t VolumeSerialNumber; struct { @@ -495,7 +491,7 @@ namespace simplecpp { #endif struct Hasher { std::size_t operator()(const FileID &id) const { -#ifdef SIMPLECPP_WINDOWS +#ifdef _WIN32 return static_cast(id.fileIdInfo.FileId.IdentifierHi ^ id.fileIdInfo.FileId.IdentifierLo ^ id.fileIdInfo.VolumeSerialNumber); #else From cf65a2f391ef621d8dfca59ec31c77cbb49c38e9 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Jun 2025 12:40:46 +0200 Subject: [PATCH 07/27] main.cpp: error out when file/path provided by `-I` or `-include=`, or the input do not exist main.cpp: replaced `std::exit()` with `return` --- main.cpp | 75 ++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 54 insertions(+), 21 deletions(-) diff --git a/main.cpp b/main.cpp index 2397e847..6ee8d7ca 100644 --- a/main.cpp +++ b/main.cpp @@ -9,9 +9,19 @@ #include #include #include +#include #include #include +static bool isDir(const std::string& path) +{ + struct stat file_stat; + if (stat(path.c_str(), &file_stat) == -1) + return false; + + return (file_stat.st_mode & S_IFMT) == S_IFDIR; +} + int main(int argc, char **argv) { bool error = false; @@ -21,6 +31,7 @@ int main(int argc, char **argv) // Settings.. simplecpp::DUI dui; + dui.removeComments = true; bool quiet = false; bool error_only = false; for (int i = 1; i < argc; i++) { @@ -81,18 +92,18 @@ int main(int argc, char **argv) } } else if (filename) { std::cout << "error: multiple filenames specified" << std::endl; - std::exit(1); + return 1; } else { filename = arg; } } if (error) - std::exit(1); + return 1; if (quiet && error_only) { std::cout << "error: -e cannot be used in conjunction with -q" << std::endl; - std::exit(1); + return 1; } if (!filename) { @@ -107,32 +118,54 @@ int main(int argc, char **argv) std::cout << " -is Use std::istream interface." << std::endl; std::cout << " -e Output errors only." << std::endl; std::cout << " -f Fail when errors were encountered (exitcode 1)." << std::endl; - std::exit(0); + return 0; } - dui.removeComments = true; + // TODO: move this logic into simplecpp + bool inp_missing = false; + + for (const std::string& inc : dui.includes) { + std::ifstream f(inc); + if (!f.is_open() || isDir(inc)) { + inp_missing = true; + std::cout << "error: could not open include '" << inc << "'" << std::endl; + } + } + + for (const std::string& inc : dui.includePaths) { + if (!isDir(inc)) { + inp_missing = true; + std::cout << "error: could not find include path '" << inc << "'" << std::endl; + } + } + + std::ifstream f(filename); + if (!f.is_open() || isDir(filename)) { + inp_missing = true; + std::cout << "error: could not open file '" << filename << "'" << std::endl; + } + + if (inp_missing) + return 1; // Perform preprocessing simplecpp::OutputList outputList; std::vector files; - simplecpp::TokenList *rawtokens; - if (use_istream) { - std::ifstream f(filename); - if (!f.is_open()) { - std::cout << "error: could not open file '" << filename << "'" << std::endl; - std::exit(1); + simplecpp::TokenList outputTokens(files); + { + simplecpp::TokenList *rawtokens; + if (use_istream) { + rawtokens = new simplecpp::TokenList(f, files,filename,&outputList); + } else { + f.close(); + rawtokens = new simplecpp::TokenList(filename,files,&outputList); } - rawtokens = new simplecpp::TokenList(f, files,filename,&outputList); - } else { - rawtokens = new simplecpp::TokenList(filename,files,&outputList); + rawtokens->removeComments(); + simplecpp::FileDataCache filedata; + simplecpp::preprocess(outputTokens, *rawtokens, files, filedata, dui, &outputList); + simplecpp::cleanup(filedata); + delete rawtokens; } - rawtokens->removeComments(); - simplecpp::TokenList outputTokens(files); - simplecpp::FileDataCache filedata; - simplecpp::preprocess(outputTokens, *rawtokens, files, filedata, dui, &outputList); - simplecpp::cleanup(filedata); - delete rawtokens; - rawtokens = nullptr; // Output if (!quiet) { From 96f2ec10717c943701e78aeef526e3636cf90fb3 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Jun 2025 12:54:09 +0200 Subject: [PATCH 08/27] selfcheck.sh: also run with system includes made available --- Makefile | 2 +- selfcheck.sh | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 112 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7489ec83..b6bc26da 100644 --- a/Makefile +++ b/Makefile @@ -22,7 +22,7 @@ test: testrunner simplecpp python3 -m pytest integration_test.py -vv selfcheck: simplecpp - ./selfcheck.sh + CXX=$(CXX) ./selfcheck.sh simplecpp: main.o simplecpp.o $(CXX) $(LDFLAGS) main.o simplecpp.o -o simplecpp diff --git a/selfcheck.sh b/selfcheck.sh index a43ef8c5..41980abe 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -4,8 +4,117 @@ output=$(./simplecpp simplecpp.cpp -e -f 2>&1) ec=$? errors=$(echo "$output" | grep -v 'Header not found: <') if [ $ec -ne 0 ]; then - # only fail if got errors which do not refer to missing system includes + # only fail if we got errors which do not refer to missing system includes if [ ! -z "$errors" ]; then exit $ec fi -fi \ No newline at end of file +fi + +if [ -z "$CXX" ]; then + exit 0 +fi + +cxx_type=$($CXX --version | head -1 | cut -d' ' -f1) +if [ "$cxx_type" = "Ubuntu" ]; then + cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) +fi +# TODO: how to get built-in include paths from compiler? +if [ "$cxx_type" = "g++" ]; then + gcc_ver=$($CXX -dumpversion) + defs= + defs="$defs -D__GNUC__" + defs="$defs -D__STDC__" + defs="$defs -D__STDC_HOSTED__" + defs="$defs -D__CHAR_BIT__=8" + defs="$defs -D__x86_64__" + defs="$defs -D__has_builtin(x)=(1)" + defs="$defs -D__has_cpp_attribute(x)=(1)" + defs="$defs -D__has_attribute(x)=(1)" + # some required include paths might differ per distro + inc= + inc="$inc -I/usr/include" + inc="$inc -I/usr/include/linux" + inc="$inc -I/usr/include/c++/$gcc_ver" + if [ -d "/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" ]; then + inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" + fi + if [ -d "/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" ]; then + inc="$inc -I/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" + fi + if [ -d "/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" ]; then + inc="$inc -I/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" + fi + if [ -d "/usr/include/x86_64-linux-gnu" ]; then + inc="$inc -I/usr/include/x86_64-linux-gnu" + inc="$inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver" + fi +elif [ "$cxx_type" = "clang" ]; then + clang_ver=$($CXX -dumpversion) + clang_ver=${clang_ver%%.*} + defs= + defs="$defs -D__BYTE_ORDER__" + defs="$defs -D__linux__" + defs="$defs -D__x86_64__" + defs="$defs -D__SIZEOF_SIZE_T__=8" + defs="$defs -D__has_feature(x)=(1)" + defs="$defs -D__has_extension(x)=(1)" + defs="$defs -D__has_attribute(x)=(0)" + defs="$defs -D__has_cpp_attribute(x)=(0)" + defs="$defs -D__has_include_next(x)=(0)" + defs="$defs -D__has_builtin(x)=(1)" + # some required include paths might differ per distro + inc= + if [ -d "/usr/include/c++/v1" ]; then + inc="$inc -I/usr/include/c++/v1" + fi + if [ -d "/usr/lib/llvm-$clang_ver/include/c++/v1" ]; then + inc="$inc -I/usr/lib/llvm-$clang_ver/include/c++/v1" + fi + inc="$inc -I/usr/include" + inc="$inc -I/usr/lib/clang/$clang_ver/include" + if [ -d "/usr/include/x86_64-linux-gnu" ]; then + inc="$inc -I/usr/include/x86_64-linux-gnu" + fi +elif [ "$cxx_type" = "Apple" ]; then + appleclang_ver=$($CXX -dumpversion) + appleclang_ver=${appleclang_ver%%.*} + xcode_path="/Applications/Xcode_16.4.app" + if [ ! -d "$xcode_path" ]; then + xcode_path="/Applications/Xcode_15.2.app" + fi + sdk_path="$xcode_path/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" + defs= + defs="$defs -D__BYTE_ORDER__" + defs="$defs -D__APPLE__" + defs="$defs -D__GNUC__=15" + defs="$defs -D__x86_64__" + defs="$defs -D__SIZEOF_SIZE_T__=8" + defs="$defs -D__has_feature(x)=(0)" + defs="$defs -D__has_extension(x)=(1)" + defs="$defs -D__has_attribute(x)=(0)" + defs="$defs -D__has_cpp_attribute(x)=(0)" + defs="$defs -D__has_include_next(x)=(0)" + defs="$defs -D__has_builtin(x)=(1)" + defs="$defs -D__is_target_os(x)=(0)" + defs="$defs -D__is_target_arch(x)=(0)" + defs="$defs -D__is_target_vendor(x)=(0)" + defs="$defs -D__is_target_environment(x)=(0)" + defs="$defs -D__is_target_variant_os(x)=(0)" + defs="$defs -D__is_target_variant_environment(x)=(0)" + inc= + inc="$inc -I$sdk_path/usr/include/c++/v1" + inc="$inc -I$sdk_path/usr/include" + inc="$inc -I$sdk_path/usr/include/i386" + if [ -d "$xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/$appleclang_ver/include" ]; then + inc="$inc -I$xcode_path/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/$appleclang_ver/include" + fi +else + echo "unknown compiler '$cxx_type'" + exit 1 +fi + +./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc +ec=$? +if [ $ec -ne 0 ]; then + exit $ec +fi From 319ba2f12d430e635c06faf06408538daded1d9e Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:15:44 +0200 Subject: [PATCH 09/27] mingw --- selfcheck.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 41980abe..54b658f3 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -33,8 +33,12 @@ if [ "$cxx_type" = "g++" ]; then # some required include paths might differ per distro inc= inc="$inc -I/usr/include" - inc="$inc -I/usr/include/linux" - inc="$inc -I/usr/include/c++/$gcc_ver" + if [ -d "/usr/include/linux" ]; then # Manjaro, ubuntu + inc="$inc -I/usr/include/linux" + fi + if [ -d "/usr/include/c++/$gcc_ver" ]; then # Manjaro, ubuntu + inc="$inc -I/usr/include/c++/$gcc_ver" + fi if [ -d "/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" ]; then inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" fi @@ -61,7 +65,8 @@ elif [ "$cxx_type" = "clang" ]; then defs="$defs -D__has_attribute(x)=(0)" defs="$defs -D__has_cpp_attribute(x)=(0)" defs="$defs -D__has_include_next(x)=(0)" - defs="$defs -D__has_builtin(x)=(1)" + defs="$defs -D__building_module(x)=(ß)" # MSYS + # some required include paths might differ per distro inc= if [ -d "/usr/include/c++/v1" ]; then From 5aeba8b0c85ec24bfead14fb17db1c9d6522313d Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:17:12 +0200 Subject: [PATCH 10/27] mingw --- selfcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index 54b658f3..3b5fd3e4 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -19,7 +19,7 @@ if [ "$cxx_type" = "Ubuntu" ]; then cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) fi # TODO: how to get built-in include paths from compiler? -if [ "$cxx_type" = "g++" ]; then +if [ [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ] ]; then gcc_ver=$($CXX -dumpversion) defs= defs="$defs -D__GNUC__" From 0942b492f016753b247bc5db2c184f839cc9fc6c Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:19:17 +0200 Subject: [PATCH 11/27] mingw --- selfcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index 3b5fd3e4..5358071c 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -19,7 +19,7 @@ if [ "$cxx_type" = "Ubuntu" ]; then cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) fi # TODO: how to get built-in include paths from compiler? -if [ [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ] ]; then +if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then gcc_ver=$($CXX -dumpversion) defs= defs="$defs -D__GNUC__" From 90ffe5c83ec460a10caa5644e10ccd9535953f91 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:24:53 +0200 Subject: [PATCH 12/27] mingw --- selfcheck.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 5358071c..b9ec6dda 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -30,6 +30,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" + find -name cctype /usr/include # some required include paths might differ per distro inc= inc="$inc -I/usr/include" @@ -65,7 +66,7 @@ elif [ "$cxx_type" = "clang" ]; then defs="$defs -D__has_attribute(x)=(0)" defs="$defs -D__has_cpp_attribute(x)=(0)" defs="$defs -D__has_include_next(x)=(0)" - defs="$defs -D__building_module(x)=(ß)" # MSYS + defs="$defs -D__building_module(x)=(0)" # MSYS # some required include paths might differ per distro inc= @@ -76,7 +77,9 @@ elif [ "$cxx_type" = "clang" ]; then inc="$inc -I/usr/lib/llvm-$clang_ver/include/c++/v1" fi inc="$inc -I/usr/include" - inc="$inc -I/usr/lib/clang/$clang_ver/include" + if [ -d "/usr/lib/clang/$clang_ver/include" ]; then # Manjaro, ubuntu + inc="$inc -I/usr/lib/clang/$clang_ver/include" + fi if [ -d "/usr/include/x86_64-linux-gnu" ]; then inc="$inc -I/usr/include/x86_64-linux-gnu" fi From dc48327d3b70842a15f60251d343b23b9cdeb6b6 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:29:21 +0200 Subject: [PATCH 13/27] mingw --- selfcheck.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index b9ec6dda..1abb73bb 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -30,7 +30,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" - find -name cctype /usr/include + find /usr/include -name cctype # some required include paths might differ per distro inc= inc="$inc -I/usr/include" @@ -68,6 +68,7 @@ elif [ "$cxx_type" = "clang" ]; then defs="$defs -D__has_include_next(x)=(0)" defs="$defs -D__building_module(x)=(0)" # MSYS + find /usr/include -name cctype # some required include paths might differ per distro inc= if [ -d "/usr/include/c++/v1" ]; then From 444a73e4330e7801b52c4a10cdfc0dd94c23e049 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:35:18 +0200 Subject: [PATCH 14/27] mingw --- selfcheck.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/selfcheck.sh b/selfcheck.sh index 1abb73bb..76cd1f49 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -30,7 +30,10 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" + find /usr -name cctype find /usr/include -name cctype + find /usr -name stddef.h + find /usr/include -name stddef.h # some required include paths might differ per distro inc= inc="$inc -I/usr/include" @@ -68,7 +71,10 @@ elif [ "$cxx_type" = "clang" ]; then defs="$defs -D__has_include_next(x)=(0)" defs="$defs -D__building_module(x)=(0)" # MSYS + find /usr -name cctype find /usr/include -name cctype + find /usr -name stddef.h + find /usr/include -name stddef.h # some required include paths might differ per distro inc= if [ -d "/usr/include/c++/v1" ]; then From d3a0acdde398937fdfbabeea7c66a5b703899a67 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:43:27 +0200 Subject: [PATCH 15/27] mingw --- selfcheck.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/selfcheck.sh b/selfcheck.sh index 76cd1f49..41c0048e 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -56,6 +56,12 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then inc="$inc -I/usr/include/x86_64-linux-gnu" inc="$inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver" fi + if [ -d "/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include" ]; then # MSYS + inc="$inc -I/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include" + fi + if [ -d "/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include/c++" ]; then # MSYS + inc="$inc -I/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include/c++" + fi elif [ "$cxx_type" = "clang" ]; then clang_ver=$($CXX -dumpversion) clang_ver=${clang_ver%%.*} From 910b9b41c274d4573f2ff3cc2607282dfa40a67b Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 11:50:43 +0200 Subject: [PATCH 16/27] mingw --- selfcheck.sh | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 41c0048e..94a749a6 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -21,6 +21,7 @@ fi # TODO: how to get built-in include paths from compiler? if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then gcc_ver=$($CXX -dumpversion) + gcc_target=$(gcc -v 2>&1 | grep Target: | cut -d' ' -f2) defs= defs="$defs -D__GNUC__" defs="$defs -D__STDC__" @@ -43,24 +44,18 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then if [ -d "/usr/include/c++/$gcc_ver" ]; then # Manjaro, ubuntu inc="$inc -I/usr/include/c++/$gcc_ver" fi - if [ -d "/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" ]; then - inc="$inc -I/usr/include/c++/$gcc_ver/x86_64-pc-linux-gnu" + if [ -d "/usr/include/c++/$gcc_ver/$gcc_target" ]; then + inc="$inc -I/usr/include/c++/$gcc_ver/$gcc_target" fi - if [ -d "/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" ]; then - inc="$inc -I/usr/lib/gcc/x86_64-pc-linux-gnu/$gcc_ver/include" + if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include" ]; then + inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include" fi - if [ -d "/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" ]; then - inc="$inc -I/usr/lib/gcc/x86_64-linux-gnu/$gcc_ver/include" + if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" ]; then # MSYS + inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" fi - if [ -d "/usr/include/x86_64-linux-gnu" ]; then - inc="$inc -I/usr/include/x86_64-linux-gnu" - inc="$inc -I/usr/include/x86_64-linux-gnu/c++/$gcc_ver" - fi - if [ -d "/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include" ]; then # MSYS - inc="$inc -I/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include" - fi - if [ -d "/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include/c++" ]; then # MSYS - inc="$inc -I/usr/lib/gcc/x86_64-pc-cygwin/$gcc_ver/include/c++" + if [ -d "/usr/include/$gcc_target" ]; then + inc="$inc -I/usr/include/$gcc_target" + inc="$inc -I/usr/include/$gcc_target/c++/$gcc_ver" fi elif [ "$cxx_type" = "clang" ]; then clang_ver=$($CXX -dumpversion) From b9803c6b6e333b4a9fe2916b9ce762bbcbb94e24 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:38:06 +0200 Subject: [PATCH 17/27] mingw --- selfcheck.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 94a749a6..ff2d83df 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -x + output=$(./simplecpp simplecpp.cpp -e -f 2>&1) ec=$? errors=$(echo "$output" | grep -v 'Header not found: <') @@ -21,7 +23,7 @@ fi # TODO: how to get built-in include paths from compiler? if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then gcc_ver=$($CXX -dumpversion) - gcc_target=$(gcc -v 2>&1 | grep Target: | cut -d' ' -f2) + gcc_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) defs= defs="$defs -D__GNUC__" defs="$defs -D__STDC__" @@ -35,6 +37,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then find /usr/include -name cctype find /usr -name stddef.h find /usr/include -name stddef.h + find /usr -name c++config.h # some required include paths might differ per distro inc= inc="$inc -I/usr/include" @@ -60,6 +63,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then elif [ "$cxx_type" = "clang" ]; then clang_ver=$($CXX -dumpversion) clang_ver=${clang_ver%%.*} + clang_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) defs= defs="$defs -D__BYTE_ORDER__" defs="$defs -D__linux__" @@ -88,8 +92,8 @@ elif [ "$cxx_type" = "clang" ]; then if [ -d "/usr/lib/clang/$clang_ver/include" ]; then # Manjaro, ubuntu inc="$inc -I/usr/lib/clang/$clang_ver/include" fi - if [ -d "/usr/include/x86_64-linux-gnu" ]; then - inc="$inc -I/usr/include/x86_64-linux-gnu" + if [ -d "/usr/include/$clang_target" ]; then + inc="$inc -I/usr/include/$clang_target" fi elif [ "$cxx_type" = "Apple" ]; then appleclang_ver=$($CXX -dumpversion) From 244c8033d47d626bbfd0408dab84b4265ea81d60 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:38:32 +0200 Subject: [PATCH 18/27] mingw --- selfcheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/selfcheck.sh b/selfcheck.sh index ff2d83df..15f57f67 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -38,6 +38,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then find /usr -name stddef.h find /usr/include -name stddef.h find /usr -name c++config.h + cat /usr/lib/gcc/x86_64-pc-cygwin/15.2.0/include/c++/bits/requires_hosted.h # some required include paths might differ per distro inc= inc="$inc -I/usr/include" From 191ad473f574c59f0ccda8d4eb620cab04abf899 Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:43:39 +0200 Subject: [PATCH 19/27] mingw --- selfcheck.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/selfcheck.sh b/selfcheck.sh index 15f57f67..247cdf68 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -33,6 +33,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" + find /usr -name cctype find /usr/include -name cctype find /usr -name stddef.h @@ -57,6 +58,9 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" ]; then # MSYS inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" fi + if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++/$gcc_target" ]; then # MSYS + inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++/$gcc_target" + fi if [ -d "/usr/include/$gcc_target" ]; then inc="$inc -I/usr/include/$gcc_target" inc="$inc -I/usr/include/$gcc_target/c++/$gcc_ver" From 3d1903e7b0eb94adcc312c04ffbb94ac9c722c8a Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:50:21 +0200 Subject: [PATCH 20/27] mingw --- selfcheck.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 247cdf68..9b2d53d4 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -20,7 +20,19 @@ cxx_type=$($CXX --version | head -1 | cut -d' ' -f1) if [ "$cxx_type" = "Ubuntu" ]; then cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) fi -# TODO: how to get built-in include paths from compiler? +# TODO: get built-in include paths from compiler +# $CXX -x c++ -v -c - < /dev/null +# ... +# include <...> search starts here: +# /usr/include/c++/14 +# /usr/include/x86_64-linux-gnu/c++/14 +# /usr/include/c++/14/backward +# /usr/lib/gcc/x86_64-linux-gnu/14/include +# /usr/local/include +# /usr/include/x86_64-linux-gnu +# /usr/include +# End of search list. +# if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then gcc_ver=$($CXX -dumpversion) gcc_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) @@ -39,7 +51,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then find /usr -name stddef.h find /usr/include -name stddef.h find /usr -name c++config.h - cat /usr/lib/gcc/x86_64-pc-cygwin/15.2.0/include/c++/bits/requires_hosted.h + cat /usr/include/sys/_intsup.h # some required include paths might differ per distro inc= inc="$inc -I/usr/include" From 91417fdde9eaf7d6c091f811a20d80f3d0caea8c Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:55:44 +0200 Subject: [PATCH 21/27] mingw --- selfcheck.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 9b2d53d4..3a96da57 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -1,7 +1,5 @@ #!/bin/sh -set -x - output=$(./simplecpp simplecpp.cpp -e -f 2>&1) ec=$? errors=$(echo "$output" | grep -v 'Header not found: <') @@ -20,28 +18,20 @@ cxx_type=$($CXX --version | head -1 | cut -d' ' -f1) if [ "$cxx_type" = "Ubuntu" ]; then cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) fi -# TODO: get built-in include paths from compiler -# $CXX -x c++ -v -c - < /dev/null -# ... -# include <...> search starts here: -# /usr/include/c++/14 -# /usr/include/x86_64-linux-gnu/c++/14 -# /usr/include/c++/14/backward -# /usr/lib/gcc/x86_64-linux-gnu/14/include -# /usr/local/include -# /usr/include/x86_64-linux-gnu -# /usr/include -# End of search list. -# + if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then gcc_ver=$($CXX -dumpversion) gcc_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) + # TODO: get built-in include paths from compiler + $CXX -x c++ -v -c - < /dev/null + defs= defs="$defs -D__GNUC__" defs="$defs -D__STDC__" defs="$defs -D__STDC_HOSTED__" defs="$defs -D__CHAR_BIT__=8" defs="$defs -D__x86_64__" + defs="$defs -D__INTPTR_TYPE__=long int" # MSYS defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" @@ -81,6 +71,9 @@ elif [ "$cxx_type" = "clang" ]; then clang_ver=$($CXX -dumpversion) clang_ver=${clang_ver%%.*} clang_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) + # TODO: get built-in include paths from compiler + $CXX -x c++ -v -c - < /dev/null + defs= defs="$defs -D__BYTE_ORDER__" defs="$defs -D__linux__" @@ -115,6 +108,7 @@ elif [ "$cxx_type" = "clang" ]; then elif [ "$cxx_type" = "Apple" ]; then appleclang_ver=$($CXX -dumpversion) appleclang_ver=${appleclang_ver%%.*} + # TODO: get include paths from compiler xcode_path="/Applications/Xcode_16.4.app" if [ ! -d "$xcode_path" ]; then xcode_path="/Applications/Xcode_15.2.app" From f7ca151b276fe085c9a5dea61abe81f24ad1551b Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 11 Sep 2025 19:58:35 +0200 Subject: [PATCH 22/27] mingw --- selfcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index 3a96da57..f1a4576c 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -31,7 +31,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then defs="$defs -D__STDC_HOSTED__" defs="$defs -D__CHAR_BIT__=8" defs="$defs -D__x86_64__" - defs="$defs -D__INTPTR_TYPE__=long int" # MSYS + defs="$defs -D__INTPTR_TYPE__='long int'" # MSYS defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" From 7be0fda9125fb4b9a046a98fcd418d3de06778a8 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 12 Sep 2025 08:40:18 +0200 Subject: [PATCH 23/27] mingw --- selfcheck.sh | 74 +++++++++------------------------------------------- 1 file changed, 13 insertions(+), 61 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index f1a4576c..54c5cb96 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -20,91 +20,43 @@ if [ "$cxx_type" = "Ubuntu" ]; then fi if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then - gcc_ver=$($CXX -dumpversion) - gcc_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) - # TODO: get built-in include paths from compiler - $CXX -x c++ -v -c - < /dev/null - defs= defs="$defs -D__GNUC__" defs="$defs -D__STDC__" defs="$defs -D__STDC_HOSTED__" defs="$defs -D__CHAR_BIT__=8" defs="$defs -D__x86_64__" - defs="$defs -D__INTPTR_TYPE__='long int'" # MSYS defs="$defs -D__has_builtin(x)=(1)" defs="$defs -D__has_cpp_attribute(x)=(1)" defs="$defs -D__has_attribute(x)=(1)" - find /usr -name cctype - find /usr/include -name cctype - find /usr -name stddef.h - find /usr/include -name stddef.h - find /usr -name c++config.h - cat /usr/include/sys/_intsup.h - # some required include paths might differ per distro inc= - inc="$inc -I/usr/include" - if [ -d "/usr/include/linux" ]; then # Manjaro, ubuntu - inc="$inc -I/usr/include/linux" - fi - if [ -d "/usr/include/c++/$gcc_ver" ]; then # Manjaro, ubuntu - inc="$inc -I/usr/include/c++/$gcc_ver" - fi - if [ -d "/usr/include/c++/$gcc_ver/$gcc_target" ]; then - inc="$inc -I/usr/include/c++/$gcc_ver/$gcc_target" - fi - if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include" ]; then - inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include" - fi - if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" ]; then # MSYS - inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++" - fi - if [ -d "/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++/$gcc_target" ]; then # MSYS - inc="$inc -I/usr/lib/gcc/$gcc_target/$gcc_ver/include/c++/$gcc_target" - fi - if [ -d "/usr/include/$gcc_target" ]; then - inc="$inc -I/usr/include/$gcc_target" - inc="$inc -I/usr/include/$gcc_target/c++/$gcc_ver" - fi + while read line + do + inc="$inc -I$line" + done <<< "$($CXX -x c++ -v -c - 2>&1 < /dev/null | grep -e'^ [/A-Z]' | grep -v /cc1plus | grep -v /as)" elif [ "$cxx_type" = "clang" ]; then - clang_ver=$($CXX -dumpversion) - clang_ver=${clang_ver%%.*} - clang_target=$($CXX -v 2>&1 | grep Target: | cut -d' ' -f2) - # TODO: get built-in include paths from compiler - $CXX -x c++ -v -c - < /dev/null - defs= defs="$defs -D__BYTE_ORDER__" defs="$defs -D__linux__" defs="$defs -D__x86_64__" defs="$defs -D__SIZEOF_SIZE_T__=8" + defs="$defs -D__STDC_HOSTED__" + defs="$defs -D__CHAR_BIT__=8" defs="$defs -D__has_feature(x)=(1)" defs="$defs -D__has_extension(x)=(1)" defs="$defs -D__has_attribute(x)=(0)" defs="$defs -D__has_cpp_attribute(x)=(0)" defs="$defs -D__has_include_next(x)=(0)" - defs="$defs -D__building_module(x)=(0)" # MSYS + defs="$defs -D__building_module(x)=(0)" + defs="$defs -D__has_builtin(x)=(1)" - find /usr -name cctype - find /usr/include -name cctype - find /usr -name stddef.h - find /usr/include -name stddef.h - # some required include paths might differ per distro + # TODO: use libc++ inc= - if [ -d "/usr/include/c++/v1" ]; then - inc="$inc -I/usr/include/c++/v1" - fi - if [ -d "/usr/lib/llvm-$clang_ver/include/c++/v1" ]; then - inc="$inc -I/usr/lib/llvm-$clang_ver/include/c++/v1" - fi - inc="$inc -I/usr/include" - if [ -d "/usr/lib/clang/$clang_ver/include" ]; then # Manjaro, ubuntu - inc="$inc -I/usr/lib/clang/$clang_ver/include" - fi - if [ -d "/usr/include/$clang_target" ]; then - inc="$inc -I/usr/include/$clang_target" - fi + while read line + do + inc="$inc -I$line" + done <<< "$($CXX -x c++ -v -c - 2>&1 < /dev/null | grep -e'^ [/A-Z]')" elif [ "$cxx_type" = "Apple" ]; then appleclang_ver=$($CXX -dumpversion) appleclang_ver=${appleclang_ver%%.*} From 294d320e1ff652560c3603a0adc007ac8ed94680 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 12 Sep 2025 08:55:15 +0200 Subject: [PATCH 24/27] mingw --- selfcheck.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfcheck.sh b/selfcheck.sh index 54c5cb96..715b1344 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash output=$(./simplecpp simplecpp.cpp -e -f 2>&1) ec=$? @@ -34,7 +34,7 @@ if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then while read line do inc="$inc -I$line" - done <<< "$($CXX -x c++ -v -c - 2>&1 < /dev/null | grep -e'^ [/A-Z]' | grep -v /cc1plus | grep -v /as)" + done <<< "$($CXX -x c++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]' | grep -v /cc1plus)" elif [ "$cxx_type" = "clang" ]; then defs= defs="$defs -D__BYTE_ORDER__" @@ -56,7 +56,7 @@ elif [ "$cxx_type" = "clang" ]; then while read line do inc="$inc -I$line" - done <<< "$($CXX -x c++ -v -c - 2>&1 < /dev/null | grep -e'^ [/A-Z]')" + done <<< "$($CXX -x c++ -v -c -S - 2>&1 < /dev/null | grep -e'^ [/A-Z]')" elif [ "$cxx_type" = "Apple" ]; then appleclang_ver=$($CXX -dumpversion) appleclang_ver=${appleclang_ver%%.*} From 61fdb94ec06cbd36caf86a7962b2d1d6c5dcf082 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 12 Sep 2025 08:57:34 +0200 Subject: [PATCH 25/27] mingw --- selfcheck.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/selfcheck.sh b/selfcheck.sh index 715b1344..4a324c9d 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -15,7 +15,7 @@ if [ -z "$CXX" ]; then fi cxx_type=$($CXX --version | head -1 | cut -d' ' -f1) -if [ "$cxx_type" = "Ubuntu" ]; then +if [ "$cxx_type" = "Ubuntu" ] || [ "$cxx_type" = "Debian" ]; then cxx_type=$($CXX --version | head -1 | cut -d' ' -f2) fi From 4caff6a5b854fe47084836fdb7071d7ab4a73ca0 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 12 Sep 2025 09:00:55 +0200 Subject: [PATCH 26/27] mingw --- selfcheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/selfcheck.sh b/selfcheck.sh index 4a324c9d..ec67201b 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -96,6 +96,7 @@ else exit 1 fi +# run with -std=gnuc++* so __has_include(...) is available ./simplecpp simplecpp.cpp -e -f -std=gnu++11 $defs $inc ec=$? if [ $ec -ne 0 ]; then From bc754ac622f5b46f45a65b0c20a746561f1d8b76 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 12 Sep 2025 09:02:39 +0200 Subject: [PATCH 27/27] mingw --- selfcheck.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/selfcheck.sh b/selfcheck.sh index ec67201b..14799675 100755 --- a/selfcheck.sh +++ b/selfcheck.sh @@ -20,6 +20,7 @@ if [ "$cxx_type" = "Ubuntu" ] || [ "$cxx_type" = "Debian" ]; then fi if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then + cat C:/msys64/mingw32/include/_mingw.h defs= defs="$defs -D__GNUC__" defs="$defs -D__STDC__"