From 6039446e602862e2b5a78e7cb3a678ee88f55576 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Fri, 22 May 2026 19:54:19 +0200 Subject: [PATCH] Visual Studio build --- .github/workflows/extra-builds.yml | 72 +++++++++++++++--------------- CMakeLists.txt | 12 ++++- cmake/FindDlfcn.cmake | 5 ++- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/.github/workflows/extra-builds.yml b/.github/workflows/extra-builds.yml index 47d65cb9a..cdf0c7fd5 100644 --- a/.github/workflows/extra-builds.yml +++ b/.github/workflows/extra-builds.yml @@ -31,41 +31,41 @@ jobs: echo "should_skip=${{ steps.skip_check.outputs.should_skip }}" >> $GITHUB_OUTPUT fi -# vs-prep: -# name: Prepare Visual Studio build -# runs-on: ubuntu-latest -# needs: [pre_job] -# if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true' -# steps: -# - uses: actions/checkout@v5 -# with: -# submodules: true -# persist-credentials: false -# - run: sudo apt-get install libfl-dev -# - name: Build -# run: make vcxsrc YOSYS_COMPILER="Visual Studio" VCX_DIR_NAME=yosys-win32-vcxsrc-latest -# - uses: actions/upload-artifact@v7 -# with: -# name: vcxsrc -# path: yosys-win32-vcxsrc-latest.zip -# -# vs-build: -# name: Visual Studio build -# runs-on: windows-latest -# needs: [vs-prep, pre_job] -# if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true' -# steps: -# - uses: actions/download-artifact@v8 -# with: -# name: vcxsrc -# path: . -# - name: unzip -# run: unzip yosys-win32-vcxsrc-latest.zip -# - name: setup-msbuild -# uses: microsoft/setup-msbuild@v2 -# - name: MSBuild -# working-directory: yosys-win32-vcxsrc-latest -# run: msbuild YosysVS.sln /p:PlatformToolset=v142 /p:Configuration=Release /p:WindowsTargetPlatformVersion=10.0.26100.0 + vs-build: + name: Visual Studio build + runs-on: windows-latest + needs: [pre_job] + if: (github.event_name == 'merge_group' || github.event_name == 'workflow_dispatch') && needs.pre_job.outputs.should_skip != 'true' + steps: + - uses: actions/checkout@v5 + with: + submodules: true + persist-credentials: false + + - name: Setup MSVC + uses: ilammy/msvc-dev-cmd@v1 + + - name: Install flex/bison + shell: pwsh + run: | + choco install winflexbison3 --no-progress + + # Make tools visible to CMake + echo "C:\Program Files (x86)\GnuWin32\bin" | Out-File -Append -FilePath $env:GITHUB_PATH + echo "C:\ProgramData\chocolatey\lib\winflexbison3\tools" | Out-File -Append -FilePath $env:GITHUB_PATH + + - name: Configure CMake + run: > + cmake -S . -B build + -A x64 + -DCMAKE_BUILD_TYPE=Release + -DYOSYS_WITHOUT_ABC=ON + + - name: Build + run: > + cmake --build build + --config Release + --parallel wasi-build: name: WASI build @@ -121,7 +121,7 @@ jobs: extra-builds-result: runs-on: ubuntu-latest needs: -# - vs-build + - vs-build - wasi-build - nix-build if: always() diff --git a/CMakeLists.txt b/CMakeLists.txt index d91440266..a9570e836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,7 +99,14 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") set(CMAKE_CXX_FLAGS_RELEASE "/O2") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/O2 /DEBUG") set(CMAKE_CXX_FLAGS_MINSIZEREL "/Os") - add_definitions(_CRT_SECURE_NO_WARNINGS) + add_compile_definitions( + _CRT_NONSTDC_NO_DEPRECATE + _CRT_SECURE_NO_WARNINGS + NOMINMAX + UNICODE + _UNICODE + ) + add_compile_options(/Zc:__cplusplus) else() # We have to do this because CMake adds `-DNDEBUG` in release builds by default, and there's # no particularly good way to prevent this without also erasing optimization flags. @@ -289,6 +296,9 @@ condition(YOSYS_ENABLE_EDITLINE editline_FOUND AND NOT YOSYS_WITHOUT_EDITLINE AN condition(YOSYS_ENABLE_TCL tcl_FOUND AND libtommath_FOUND AND NOT YOSYS_WITHOUT_TCL) condition(YOSYS_ENABLE_PYTHON Python3Embed_FOUND AND PyosysEnv_FOUND AND YOSYS_WITH_PYTHON) condition(YOSYS_ENABLE_VERIFIC YOSYS_VERIFIC_DIR AND zlib_FOUND) +if (MSVC) + set(YOSYS_ENABLE_SPAWN ON) +endif() # Describe dependencies and features # CMake 4.0 would let us use proper conditions, but that's too new for now. diff --git a/cmake/FindDlfcn.cmake b/cmake/FindDlfcn.cmake index 201745a3f..8ef21616a 100644 --- a/cmake/FindDlfcn.cmake +++ b/cmake/FindDlfcn.cmake @@ -2,7 +2,10 @@ include(CMakePushCheckState) include(CheckCXXSymbolExists) include(FindPackageHandleStandardArgs) -if (WIN32 OR MSYS) +if (MSVC) + set(Dlfcn_FOUND FALSE) + unset(Dlfcn_LIBRARIES CACHE) +elseif (WIN32 OR MSYS) # Windows; dlopen is available via a polyfill `libs/dlfcn-win32`. set(Dlfcn_LIBRARIES dlfcn) else()