From f503a23586da360f68255f6391edfe1ca70ded63 Mon Sep 17 00:00:00 2001 From: David Gonzalez Martin Date: Wed, 23 Oct 2024 06:13:25 -0600 Subject: [PATCH] Fix Windows CI --- .github/workflows/ci.yml | 12 ++++-- CMakeLists.txt | 12 ++++++ bootstrap/include/std/base.h | 8 ++-- bootstrap/std/base.c | 36 ++++++++--------- fetch-llvm.ps1 | 22 +++++++++-- project.ps1 | 76 +++++++++++++++++++++++------------- 6 files changed, 109 insertions(+), 57 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 2333f70..ca90cdd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: runs-on: ${{ matrix.os}} timeout-minutes: 15 strategy: + fail-fast: false matrix: os: [ubuntu-24.04, macos-15, windows-2022] build_type: [Debug, MinSizeRel, RelWithDebInfo, Release] @@ -31,15 +32,18 @@ jobs: run: | uname -a lsb_release -a + df -h - name: System Info (macOS) if: matrix.os == env.MACOS_IMAGE run: | uname -a sw_vers -productVersion + df -h - name: System Info (Windows) - if: matrix.os == 'windows-2022' - run: + if: matrix.os == env.WINDOWS_IMAGE + run: | systeminfo + wmic logicaldisk get name, size, freespace - name: Install dependencies (Linux) if: matrix.os == env.LINUX_IMAGE @@ -49,7 +53,7 @@ jobs: run: brew install llvm ninja - name: Install dependencies (Windows) if: matrix.os == env.WINDOWS_IMAGE - run: choco install ninja && pwsh ./fetch-llvm.ps1 + run: choco install ninja && pwsh ./fetch-llvm.ps1 "${{ matrix.build_type }}" - name: Clang version run: clang -v @@ -59,4 +63,4 @@ jobs: run: ./project.sh "build_type=${{ matrix.build_type }}" test all - name: Build and test (Windows) if: matrix.os == env.WINDOWS_IMAGE - run: pwsh ./project.ps1 "-DCMAKE_PREFIX_PATH=clang+llvm-19.1.2-x86_64-pc-windows-msvc" "build_type=${{ matrix.build_type }}" test all + run: pwsh ./project.ps1 "build_type=${{ matrix.build_type }}" test all diff --git a/CMakeLists.txt b/CMakeLists.txt index c94758f..8011d8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,17 @@ cmake_minimum_required(VERSION 3.10) project(nest) +include(CMakePrintHelpers) +cmake_print_variables("Build type: ${CMAKE_BUILD_TYPE}") +cmake_print_variables("C flags Debug: ${CMAKE_C_FLAGS_DEBUG}") +cmake_print_variables("CXX flags Debug: ${CMAKE_CXX_FLAGS_DEBUG}") +cmake_print_variables("C flags MinSizeRel: ${CMAKE_C_FLAGS_MINSIZEREL}") +cmake_print_variables("CXX flags MinSizeRel: ${CMAKE_CXX_FLAGS_MINSIZEREL}") +cmake_print_variables("C flags RelWithDebInfo: ${CMAKE_C_FLAGS_RELWITHDEBINFO}") +cmake_print_variables("CXX flags RelWithDebInfo: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") +cmake_print_variables("C flags Release: ${CMAKE_C_FLAGS_RELEASE}") +cmake_print_variables("CXX flags Release: ${CMAKE_CXX_FLAGS_RELEASE}") + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_C_STANDARD 23) set(CMAKE_CXX_STANDARD 23) @@ -116,6 +127,7 @@ add_executable("${COMPILER_NAME}" ) target_compile_definitions(${COMPILER_NAME} PRIVATE ${LLVM_DEFINITIONS}) +cmake_print_variables("LLVM definitions: ${LLVM_DEFINITIONS}") target_include_directories(${COMPILER_NAME} PRIVATE ${LLVM_INCLUDE_DIRS}) target_link_directories(${COMPILER_NAME} PRIVATE ${LLVM_LIBRARY_DIRS}) target_link_libraries(${COMPILER_NAME} PRIVATE ${LIBRARY_NAME} ${LLVM_LIBRARIES}) diff --git a/bootstrap/include/std/base.h b/bootstrap/include/std/base.h index 47a9f80..ee04e6e 100644 --- a/bootstrap/include/std/base.h +++ b/bootstrap/include/std/base.h @@ -1,9 +1,9 @@ #pragma once #ifdef NDEBUG -#define _DEBUG 0 +#define NEST_DEBUG 0 #else -#define _DEBUG 1 +#define NEST_DEBUG 1 #endif #ifdef STATIC @@ -166,7 +166,7 @@ const may_be_unused global_variable u8 bracket_close = ']'; #define s_get_slice(T, s, start, end) (Slice(T)){ .pointer = ((s).pointer) + (start), .length = (end) - (start) } #define s_equal(a, b) ((a).length == (b).length && memcmp((a).pointer, (b).pointer, sizeof(*((a).pointer)) * (a).length) == 0) -#if _DEBUG +#if NEST_DEBUG #define assert(x) if (unlikely(!(x))) { bad_exit("Assert failed: \"" # x "\"", __FILE__, __LINE__); } #else #define assert(x) unlikely(!(x)) @@ -177,7 +177,7 @@ const may_be_unused global_variable u8 bracket_close = ']'; #ifdef unreachable #undef unreachable #endif -#if _DEBUG +#if NEST_DEBUG #define unreachable() bad_exit("Unreachable triggered", __FILE__, __LINE__) #else #define unreachable() __builtin_unreachable() diff --git a/bootstrap/std/base.c b/bootstrap/std/base.c index 3dd62e0..9ddb101 100644 --- a/bootstrap/std/base.c +++ b/bootstrap/std/base.c @@ -3,7 +3,7 @@ u8 cast_u32_to_u8(u32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > UINT8_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -19,7 +19,7 @@ u8 cast_u32_to_u8(u32 source, const char* name, int line) u16 cast_u32_to_u16(u32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > UINT16_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -35,7 +35,7 @@ u16 cast_u32_to_u16(u32 source, const char* name, int line) s16 cast_u32_to_s16(u32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > INT16_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -51,7 +51,7 @@ s16 cast_u32_to_s16(u32 source, const char* name, int line) s32 cast_u32_to_s32(u32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > INT32_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -67,7 +67,7 @@ s32 cast_u32_to_s32(u32 source, const char* name, int line) u8 cast_u64_to_u8(u64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > UINT8_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -83,7 +83,7 @@ u8 cast_u64_to_u8(u64 source, const char* name, int line) u16 cast_u64_to_u16(u64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > UINT16_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -99,7 +99,7 @@ u16 cast_u64_to_u16(u64 source, const char* name, int line) u32 cast_u64_to_u32(u64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > UINT32_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -115,7 +115,7 @@ u32 cast_u64_to_u32(u64 source, const char* name, int line) s32 cast_u64_to_s32(u64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > INT32_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -131,7 +131,7 @@ s32 cast_u64_to_s32(u64 source, const char* name, int line) s64 cast_u64_to_s64(u64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > INT64_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -147,7 +147,7 @@ s64 cast_u64_to_s64(u64 source, const char* name, int line) u8 cast_s32_to_u8(s32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -168,7 +168,7 @@ u8 cast_s32_to_u8(s32 source, const char* name, int line) u16 cast_s32_to_u16(s32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -189,7 +189,7 @@ u16 cast_s32_to_u16(s32 source, const char* name, int line) u32 cast_s32_to_u32(s32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -205,7 +205,7 @@ u32 cast_s32_to_u32(s32 source, const char* name, int line) u64 cast_s32_to_u64(s32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -221,7 +221,7 @@ u64 cast_s32_to_u64(s32 source, const char* name, int line) s16 cast_s32_to_s16(s32 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source > INT16_MAX) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -242,7 +242,7 @@ s16 cast_s32_to_s16(s32 source, const char* name, int line) u16 cast_s64_to_u16(s64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -263,7 +263,7 @@ u16 cast_s64_to_u16(s64 source, const char* name, int line) u32 cast_s64_to_u32(s64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -279,7 +279,7 @@ u32 cast_s64_to_u32(s64 source, const char* name, int line) u64 cast_s64_to_u64(s64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < 0) { print("Cast failed at {cstr}:{u32}\n", name, line); @@ -295,7 +295,7 @@ u64 cast_s64_to_u64(s64 source, const char* name, int line) s32 cast_s64_to_s32(s64 source, const char* name, int line) { -#if _DEBUG +#if NEST_DEBUG if (source < INT32_MIN) { print("Cast failed at {cstr}:{u32}\n", name, line); diff --git a/fetch-llvm.ps1 b/fetch-llvm.ps1 index f760428..727fe97 100644 --- a/fetch-llvm.ps1 +++ b/fetch-llvm.ps1 @@ -2,13 +2,27 @@ Set-StrictMode -Version Latest Set-PSDebug -Trace 2 $LLVM_VERSION="19.1.2" -$BASE_DOWNLOAD_URL="https://github.com/llvm/llvm-project/releases/download/llvmorg-$LLVM_VERSION" +$BASE_DOWNLOAD_URL="https://github.com/birth-software/build-llvm/releases/download/llvm-$LLVM_VERSION" -$LLVM_DOWNLOAD_FILE_BASENAME="clang+llvm-$LLVM_VERSION-x86_64-pc-windows-msvc" -$LLVM_DOWNLOAD_FILE="$LLVM_DOWNLOAD_FILE_BASENAME.tar.xz" +$LLVM_DOWNLOAD_FILE_BASENAME="llvm-$LLVM_VERSION-windows-amd64-msvc17-msvcrt" +if ($args[0].Equals("Debug")) +{ + $LLVM_DOWNLOAD_FILE_BASENAME="$LLVM_DOWNLOAD_FILE_BASENAME-dbg" +} + +$LLVM_DOWNLOAD_FILE="$LLVM_DOWNLOAD_FILE_BASENAME.7z" $LLVM_DOWNLOAD_URL="$BASE_DOWNLOAD_URL/$LLVM_DOWNLOAD_FILE" +Write-Output "URL: $LLVM_DOWNLOAD_URL" + Invoke-WebRequest -Uri "$LLVM_DOWNLOAD_URL" -OutFile "$LLVM_DOWNLOAD_FILE" +if ($LastExitCode -ne 0) +{ + exit $LastExitCode +} 7z x $LLVM_DOWNLOAD_FILE -7z x "$LLVM_DOWNLOAD_FILE_BASENAME.tar" +if ($LastExitCode -ne 0) +{ + exit $LastExitCode +} dir diff --git a/project.ps1 b/project.ps1 index 6aaa0d4..edc3dd3 100644 --- a/project.ps1 +++ b/project.ps1 @@ -7,42 +7,64 @@ $build_dir="build" $release_mode="Debug" $build_type_prefix="build_type=" $cmake_prefix_path_prefix="-DCMAKE_PREFIX_PATH=" -$cmake_prefix_path="" -& { - try +try +{ + $cmake_prefix_path="" + foreach ($arg in $myargs) { - foreach ($arg in $myargs) + if ($arg.StartsWith($build_type_prefix)) { - if ($arg.StartsWith($build_type_prefix)) - { - $release_mode = $arg.Substring($build_type_prefix.Length) - } - if ($arg.StartsWith($cmake_prefix_path_prefix)) - { - $cmake_prefix_path = $arg.Substring($cmake_prefix_path_prefix.Length); - } + $release_mode = $arg.Substring($build_type_prefix.Length) } - - Write-Output "Build type: $release_mode" - - New-Item -Path $build_dir -ItemType Directory -Force - cmake . "-B$build_dir" -G Ninja "-DCMAKE_BUILD_TYPE=$release_mode" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" "-DCMAKE_PREFIX_PATH=$cmake_prefix_path" - pushd $build_dir - ninja - popd - - if ($($myargs.Length) -ne 0) + if ($arg.StartsWith($cmake_prefix_path_prefix)) { - & ".\$build_dir\runner" $myargs + $cmake_prefix_path = $arg.Substring($cmake_prefix_path_prefix.Length); } } - catch + + if ($cmake_prefix_path.Equals("")) { - throw + if ($release_mode.Equals("Debug")) + { + $cmake_prefix_path="llvm-19.1.2-windows-amd64-msvc17-msvcrt-dbg" + } + else + { + $cmake_prefix_path="llvm-19.1.2-windows-amd64-msvc17-msvcrt" + } } - finally + + Write-Output "Build type: $release_mode. Prefix $cmake_prefix_path" + + New-Item -Path $build_dir -ItemType Directory -Force + cmake . "-B$build_dir" -G Ninja "-DCMAKE_BUILD_TYPE=$release_mode" -DCMAKE_C_COMPILER="clang" -DCMAKE_CXX_COMPILER="clang++" "-DCMAKE_PREFIX_PATH=$cmake_prefix_path" "-DCMAKE_VERBOSE_MAKEFILE=ON" + if ($LastExitCode -ne 0) { - $global:ErrorActionPreference = $previous_error_action_preference + exit $LastExitCode + } + pushd $build_dir + ninja -v + if ($LastExitCode -ne 0) + { + exit $LastExitCode + } + popd + + if ($($myargs.Length) -ne 0) + { + & ".\$build_dir\runner" $myargs + if ($LastExitCode -ne 0) + { + exit $LastExitCode + } } } +catch +{ + throw +} +finally +{ + $global:ErrorActionPreference = $previous_error_action_preference +}