diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 902b636fb..3b4e38de5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,9 +55,52 @@ jobs: with: name: libgpuocelot-${{ runner.os }} path: ocelot/build/libgpuocelot.${{ runner.os == 'Linux' && 'so' || 'dylib' }} + build-win: + runs-on: windows-2025 + strategy: + fail-fast: false + name: Windows + timeout-minutes: 15 + defaults: + run: + shell: msys2 {0} + steps: + + - name: 'Checkout' + uses: actions/checkout@v4 + with: + fetch-depth: 1 + persist-credentials: false + submodules: recursive + + - name: 'Setup MSYS2' + uses: msys2/setup-msys2@v2 + with: + msystem: ucrt64 + install: >- + git + make + bison + flex + pacboy: >- + toolchain:p + cmake:p + ninja:p + boost:p + + - name: 'Configure GPUOcelot' + run: | + cmake -S ocelot -G Ninja -B ocelot/build -DCMAKE_BUILD_TYPE=Release -DBUILD_TOOLS=OFF -DBUILD_TESTS_CUDA=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DMINGW_CROSS_BUILD_FOR_WINDOWS=1 + - name: 'Build GPUOcelot' + run: | + cmake --build ocelot/build + - uses: actions/upload-artifact@v7 + with: + name: libgpuocelot-${{ runner.os }} + path: ocelot/build/libgpuocelot.${{ runner.os == 'Linux' && 'so' || runner.os == 'Windows' && 'dll' || 'dylib' }} release: - needs: test + needs: [test, build-win] runs-on: ubuntu-24.04 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') permissions: diff --git a/ocelot/CMakeLists.txt b/ocelot/CMakeLists.txt index 2662d58f0..6df39d272 100644 --- a/ocelot/CMakeLists.txt +++ b/ocelot/CMakeLists.txt @@ -46,12 +46,20 @@ endif() if (ENABLE_LLVM) find_package(ZLIB REQUIRED) find_library(ZSTD_LIB NAMES zstd libzstd) -find_package(Curses REQUIRED) +if(MINGW_CROSS_BUILD_FOR_WINDOWS) + find_library(CURSES_LIBRARY pdcurses) +else() + find_package(Curses REQUIRED) +endif() if ("x${BUILD_LLVM}" STREQUAL "xOFF") find_package(LLVM REQUIRED CONFIG) -file(GLOB LLVM_LIBRARIES ${LLVM_LIBRARY_DIR}/*.a) +if(MINGW_CROSS_BUILD_FOR_WINDOWS) + file(GLOB LLVM_LIBRARIES ${LLVM_LIBRARY_DIR}/libLLVM*.a) +else() + file(GLOB LLVM_LIBRARIES ${LLVM_LIBRARY_DIR}/*.a) +endif() else() include(ExternalProject) @@ -263,6 +271,10 @@ else() list(APPEND ${PROJECT_NAME}_DEFINITIONS ENABLE_OPENGL=0) endif() +if(MINGW_CROSS_BUILD_FOR_WINDOWS) + list(APPEND ${PROJECT_NAME}_LINK_LIBRARIES ws2_32) +endif() + if (ENABLE_LLVM) list(APPEND ${PROJECT_NAME}_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS}) list(APPEND ${PROJECT_NAME}_LINK_LIBRARIES ZLIB::ZLIB ${CURSES_LIBRARIES} ${ZSTD_LIB}) @@ -485,6 +497,11 @@ target_compile_definitions(${PROJECT_NAME}_parser PRIVATE ${${PROJECT_NAME}_DEFI target_compile_options(${PROJECT_NAME}_parser PRIVATE PRIVATE ${${PROJECT_NAME}_CXXFLAGS}) target_include_directories(${PROJECT_NAME}_parser PRIVATE ${${PROJECT_NAME}_INCLUDE_DIRS}) target_include_directories(${PROJECT_NAME}_parser PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) +if(MSYS OR MINGW) +target_include_directories(${PROJECT_NAME}_parser PRIVATE + "${CMAKE_SOURCE_DIR}/ThirdParty/flex" +) +endif() target_link_libraries(${PROJECT_NAME}_parser PUBLIC ${${PROJECT_NAME}_LINK_LIBRARIES}) target_link_directories(${PROJECT_NAME}_parser PUBLIC ${${PROJECT_NAME}_LIBRARY_DIRS}) @@ -625,6 +642,23 @@ endif() endif() target_link_directories(${PROJECT_NAME} PUBLIC ${${PROJECT_NAME}_LIBRARY_DIRS}) +if(MINGW_CROSS_BUILD_FOR_WINDOWS) + execute_process( + COMMAND "${CMAKE_CXX_COMPILER}" -print-file-name=libwinpthread.a + OUTPUT_VARIABLE WINPTHREAD_STATIC + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(NOT EXISTS "${WINPTHREAD_STATIC}") + message(FATAL_ERROR "libwinpthread.a not found: ${WINPTHREAD_STATIC}") + endif() + target_link_options(${PROJECT_NAME} PRIVATE + -static-libgcc + -static-libstdc++ + ) + target_link_libraries(${PROJECT_NAME} PRIVATE + "${WINPTHREAD_STATIC}" + ) +endif() install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION $,/usr/local/lib,/usr/lib>) install(CODE "execute_process(COMMAND ldconfig)") diff --git a/ocelot/ThirdParty/flex/FlexLexer.h b/ocelot/ThirdParty/flex/FlexLexer.h new file mode 100644 index 000000000..c4dad2b14 --- /dev/null +++ b/ocelot/ThirdParty/flex/FlexLexer.h @@ -0,0 +1,220 @@ +// -*-C++-*- +// FlexLexer.h -- define interfaces for lexical analyzer classes generated +// by flex + +// Copyright (c) 1993 The Regents of the University of California. +// All rights reserved. +// +// This code is derived from software contributed to Berkeley by +// Kent Williams and Tom Epperly. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: + +// 1. Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. + +// Neither the name of the University nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. + +// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR +// IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +// PURPOSE. + +// This file defines FlexLexer, an abstract class which specifies the +// external interface provided to flex C++ lexer objects, and yyFlexLexer, +// which defines a particular lexer class. +// +// If you want to create multiple lexer classes, you use the -P flag +// to rename each yyFlexLexer to some other xxFlexLexer. You then +// include in your other sources once per lexer class: +// +// #undef yyFlexLexer +// #define yyFlexLexer xxFlexLexer +// #include +// +// #undef yyFlexLexer +// #define yyFlexLexer zzFlexLexer +// #include +// ... + +#ifndef __FLEX_LEXER_H +// Never included before - need to define base class. +#define __FLEX_LEXER_H + +#include + +extern "C++" { + +struct yy_buffer_state; +typedef int yy_state_type; + +class FlexLexer +{ +public: + virtual ~FlexLexer() { } + + const char* YYText() const { return yytext; } + int YYLeng() const { return yyleng; } + + virtual void + yy_switch_to_buffer( yy_buffer_state* new_buffer ) = 0; + virtual yy_buffer_state* yy_create_buffer( std::istream* s, int size ) = 0; + virtual yy_buffer_state* yy_create_buffer( std::istream& s, int size ) = 0; + virtual void yy_delete_buffer( yy_buffer_state* b ) = 0; + virtual void yyrestart( std::istream* s ) = 0; + virtual void yyrestart( std::istream& s ) = 0; + + virtual int yylex() = 0; + + // Call yylex with new input/output sources. + int yylex( std::istream& new_in, std::ostream& new_out ) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + int yylex( std::istream* new_in, std::ostream* new_out = 0) + { + switch_streams( new_in, new_out ); + return yylex(); + } + + // Switch to new input/output streams. A nil stream pointer + // indicates "keep the current one". + virtual void switch_streams( std::istream* new_in, + std::ostream* new_out ) = 0; + virtual void switch_streams( std::istream& new_in, + std::ostream& new_out ) = 0; + + int lineno() const { return yylineno; } + + int debug() const { return yy_flex_debug; } + void set_debug( int flag ) { yy_flex_debug = flag; } + +protected: + char* yytext; + int yyleng; + int yylineno; // only maintained if you use %option yylineno + int yy_flex_debug; // only has effect with -d or "%option debug" +}; + +} +#endif // FLEXLEXER_H + +#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) +// Either this is the first time through (yyFlexLexerOnce not defined), +// or this is a repeated include to define a different flavor of +// yyFlexLexer, as discussed in the flex manual. +# define yyFlexLexerOnce + +extern "C++" { + +class yyFlexLexer : public FlexLexer { +public: + // arg_yyin and arg_yyout default to the cin and cout, but we + // only make that assignment when initializing in yylex(). + yyFlexLexer( std::istream& arg_yyin, std::ostream& arg_yyout ); + yyFlexLexer( std::istream* arg_yyin = 0, std::ostream* arg_yyout = 0 ); +private: + void ctor_common(); + +public: + + virtual ~yyFlexLexer(); + + void yy_switch_to_buffer( yy_buffer_state* new_buffer ); + yy_buffer_state* yy_create_buffer( std::istream* s, int size ); + yy_buffer_state* yy_create_buffer( std::istream& s, int size ); + void yy_delete_buffer( yy_buffer_state* b ); + void yyrestart( std::istream* s ); + void yyrestart( std::istream& s ); + + void yypush_buffer_state( yy_buffer_state* new_buffer ); + void yypop_buffer_state(); + + virtual int yylex(); + virtual void switch_streams( std::istream& new_in, std::ostream& new_out ); + virtual void switch_streams( std::istream* new_in = 0, std::ostream* new_out = 0 ); + virtual int yywrap(); + +protected: + virtual int LexerInput( char* buf, int max_size ); + virtual void LexerOutput( const char* buf, int size ); + virtual void LexerError( const char* msg ); + + void yyunput( int c, char* buf_ptr ); + int yyinput(); + + void yy_load_buffer_state(); + void yy_init_buffer( yy_buffer_state* b, std::istream& s ); + void yy_flush_buffer( yy_buffer_state* b ); + + int yy_start_stack_ptr; + int yy_start_stack_depth; + int* yy_start_stack; + + void yy_push_state( int new_state ); + void yy_pop_state(); + int yy_top_state(); + + yy_state_type yy_get_previous_state(); + yy_state_type yy_try_NUL_trans( yy_state_type current_state ); + int yy_get_next_buffer(); + + std::istream yyin; // input source for default LexerInput + std::ostream yyout; // output sink for default LexerOutput + + // yy_hold_char holds the character lost when yytext is formed. + char yy_hold_char; + + // Number of characters read into yy_ch_buf. + int yy_n_chars; + + // Points to current character in buffer. + char* yy_c_buf_p; + + int yy_init; // whether we need to initialize + int yy_start; // start state number + + // Flag which is used to allow yywrap()'s to do buffer switches + // instead of setting up a fresh yyin. A bit of a hack ... + int yy_did_buffer_switch_on_eof; + + + size_t yy_buffer_stack_top; /**< index of top of stack. */ + size_t yy_buffer_stack_max; /**< capacity of stack. */ + yy_buffer_state ** yy_buffer_stack; /**< Stack as an array. */ + void yyensure_buffer_stack(void); + + // The following are not always needed, but may be depending + // on use of certain flex features (like REJECT or yymore()). + + yy_state_type yy_last_accepting_state; + char* yy_last_accepting_cpos; + + yy_state_type* yy_state_buf; + yy_state_type* yy_state_ptr; + + char* yy_full_match; + int* yy_full_state; + int yy_full_lp; + + int yy_lp; + int yy_looking_for_trail_begin; + + int yy_more_flag; + int yy_more_len; + int yy_more_offset; + int yy_prev_more_offset; +}; + +} + +#endif // yyFlexLexer || ! yyFlexLexerOnce diff --git a/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp b/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp index e611ff198..48c3fea19 100644 --- a/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp +++ b/ocelot/ThirdParty/hydrazine/src/SystemCompatibility.cpp @@ -14,15 +14,19 @@ #if __APPLE__ #include #include -#elif __GNUC__ +#elif _WIN32 + // Windows / MinGW + #include + // Optional: for demangling if you really need it + // #include // UnDecorateSymbolName +#else + // Linux / other Unix #if ENABLE_OPENGL #include #endif #include #include #include -#else - #error "Unknown system/compiler (APPLE and GNUC are supported)." #endif namespace hydrazine @@ -48,7 +52,11 @@ namespace hydrazine } } return count; - #elif __GNUC__ + #elif _WIN32 + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + return sysinfo.dwNumberOfProcessors; + #else return sysconf(_SC_NPROCESSORS_ONLN); #endif } @@ -70,7 +78,12 @@ namespace hydrazine length = sizeof(uint64_t); sysctl(mib, 2, &physical_memory, &length, NULL, 0); return physical_memory; - #elif __GNUC__ + #elif _WIN32 + MEMORYSTATUSEX status; + status.dwLength = sizeof(status); + GlobalMemoryStatusEx(&status); + return status.ullAvailPhys; + #else return get_avphys_pages() * getpagesize(); #endif } @@ -81,7 +94,9 @@ namespace hydrazine #if __APPLE__ // TODO fill this in return false; - #elif __GNUC__ + #elif _WIN32 + return wglGetCurrentContext() != nullptr; + #else GLXContext openglContext = glXGetCurrentContext(); return (openglContext != 0); #endif @@ -100,7 +115,10 @@ namespace hydrazine #if __APPLE__ // TODO fill this in return string; - #elif __GNUC__ + #elif _WIN32 + // Simple stub - real demangling on Windows needs DbgHelp + return string; + #else int status = 0; std::string name = abi::__cxa_demangle(string.c_str(), 0, 0, &status); diff --git a/ocelot/ThirdParty/hydrazine/src/compression.cpp b/ocelot/ThirdParty/hydrazine/src/compression.cpp index 2fba91e37..1ec8d848f 100644 --- a/ocelot/ThirdParty/hydrazine/src/compression.cpp +++ b/ocelot/ThirdParty/hydrazine/src/compression.cpp @@ -9,7 +9,7 @@ #include // System Includes -#if __GNUC__ +#if __unix__ #include #else // TODO Add dynamic loading support on windows diff --git a/ocelot/src/cal/CalDriver.cpp b/ocelot/src/cal/CalDriver.cpp index c95e6df0c..9ffd0e485 100644 --- a/ocelot/src/cal/CalDriver.cpp +++ b/ocelot/src/cal/CalDriver.cpp @@ -13,7 +13,7 @@ #include // Linux system headers -#if __GNUC__ +#if __unix__ #include #else // TODO Add dynamic loading support on windows diff --git a/ocelot/src/cuda/CudaDriver.cpp b/ocelot/src/cuda/CudaDriver.cpp index d0b1c808b..a7d8705eb 100644 --- a/ocelot/src/cuda/CudaDriver.cpp +++ b/ocelot/src/cuda/CudaDriver.cpp @@ -14,7 +14,7 @@ #include // Linux system headers -#if __GNUC__ +#if __unix__ #include #else // TODO Add dynamic loading support on windows diff --git a/ocelot/toolchains/mingw64.cmake b/ocelot/toolchains/mingw64.cmake new file mode 100644 index 000000000..217cd3b05 --- /dev/null +++ b/ocelot/toolchains/mingw64.cmake @@ -0,0 +1,17 @@ +set(CMAKE_SYSTEM_NAME Windows) +set(CMAKE_SYSTEM_PROCESSOR x86_64) + +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) + +set(BUILD_SHARED_LIBS ON) \ No newline at end of file