Skip to content

Add workflow for building on Windows #2675

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 40 additions & 3 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ jobs:
PKGNAME="capstone-$VERSION"
SHASUM=$PKGNAME.tar.xz.sha256
mkdir -p /tmp/$PKGNAME
mv * /tmp/$PKGNAME
mv /tmp/$PKGNAME .
rsync -a --exclude=build --exclude='.*' ./ /tmp/$PKGNAME/
TARBALL=$PKGNAME.tar.xz
tar cJf $TARBALL $PKGNAME
tar -C /tmp -cJf $TARBALL $PKGNAME
sha256sum $TARBALL > $SHASUM
echo "tarball=$TARBALL" >> $GITHUB_OUTPUT
echo "shasum=$SHASUM" >> $GITHUB_OUTPUT
Expand Down Expand Up @@ -64,3 +63,41 @@ jobs:
files: |
./build/*.deb
./build/*.rpm

build_windows:
name: build_windows
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true

- name: Win MSVC 64 dev cmd setup
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64

- name: Configure CMake and build the project
run: |
cmake -B build `
-T "ClangCL,host=x64" `
-A x64 `
-DPROJECT_VERSION="${{ github.event.release.tag_name }}" `
-DCMAKE_BUILD_TYPE=Release `
-DCAPSTONE_BUILD_SHARED_LIBS=1
cmake --build build --config Release
cmake --install build --config Release

- name: Package NSIS installer
run: |
cd build
cpack -G NSIS

- name: Upload NSIS installer to release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.release.tag_name }}
files: |
./build/*.exe
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ endif()
cmake_policy(SET CMP0042 NEW)

# Check if VERSION is provided externally, otherwise default to 6.0.0
if(NOT DEFINED PROJECT_VERSION)
if(NOT DEFINED PROJECT_VERSION OR PROJECT_VERSION STREQUAL "")
set(PROJECT_VERSION "6.0.0")
endif()

Expand Down
2 changes: 2 additions & 0 deletions CPackConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ foreach(generator ${CPACK_GENERATOR})
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_FILE_NAME})
elseif("${generator}" STREQUAL "RPM")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_PACKAGE_FILE_NAME})
elseif("${generator}" STREQUAL "NSIS")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_NSIS_PACKAGE_FILE_NAME})
elseif("${generator}" STREQUAL "DragNDrop")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DMG_PACKAGE_FILE_NAME})
else()
Expand Down
9 changes: 9 additions & 0 deletions CPackConfig.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ set(CPACK_RPM_CHANGELOG_FILE "${PROJECT_SOURCE_DIR}/ChangeLog")
set(CPACK_RPM_PACKAGE_LICENSE "BSD3, LLVM")
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")

# Windows package settings
if(WIN32)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "capstone")
set(CPACK_SYSTEM_NAME "Windows-x64")
set(CPACK_NSIS_MODIFY_PATH ON)
set(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
endif()

# Set package file name based on the generator
set(CPACK_DEBIAN_PACKAGE_FILE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
set(CPACK_RPM_PACKAGE_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_DMG_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_NSIS_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}")

include(CPack)
Loading