Skip to content

Commit

Permalink
Create debian and rpm package on releases
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewQuijano committed Jan 5, 2025
1 parent 97fc31b commit 9406e36
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 181 deletions.
30 changes: 16 additions & 14 deletions .github/workflows/build_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@ jobs:
with:
submodules: true

- name: Make setup.sh and check_capstone.sh are executable
- name: Configure CMake and build the project
run: |
chmod +x ./packages/deb/setup.sh
chmod +x ./packages/deb/check_capstone.sh
- name: Build Debian Package
working-directory: ./packages/deb
run: ./setup.sh ${{ github.event.release.tag_name }}

- name: Run sanity checks on the Debian package
working-directory: ./packages/deb
cmake -B build \
-DPROJECT_VERSION=${{ github.event.release.tag_name }} \
-DCMAKE_BUILD_TYPE=Release \
-DCAPSTONE_BUILD_SHARED_LIBS=1 \
-DCMAKE_INSTALL_PREFIX=/usr \
-DCPACK_GENERATOR="DEB;RPM"
cmake --build build
- name: Package DEB and RPM package
run: |
./check_capstone.sh ./libcapstone-dev_${{ github.event.release.tag_name }}_amd64.deb
cd build
cpack --config CPackConfig.cmake
- name: Upload debian package to release
uses: softprops/action-gh-release@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.event.release.tag_name }}
files: |
./packages/deb/*.deb
./build/*.deb
./build/*.rpm
- name: Create archive
id: archive
run: |
Expand Down
10 changes: 10 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ cmake --build build
cmake --install build --prefix "<install-prefix>"
```

To create rpm, debian and OSX packages, run the following
```bash
cmake -B build -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1 -DCMAKE_INSTALL_PREFIX=/usr
cmake --build build
cd build
cpack -G DEB
cpack -G RPM
cpack -G DragNDrop
```

**Windows**

```bash
Expand Down
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ endif()
# Extract the major, minor, and patch versions
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PROJECT_VERSION_BASE ${PROJECT_VERSION})

# Use PROJECT_VERSION directly for CPack
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})

# Set the project version without the pre-release identifier
project(capstone VERSION ${PROJECT_VERSION_BASE})

Expand Down Expand Up @@ -959,3 +962,6 @@ if(CAPSTONE_BUILD_CSTEST)
set(TESTS_UNIT_DIR ${PROJECT_SOURCE_DIR}/tests/unit)
add_subdirectory(${TESTS_UNIT_DIR})
endif()

# Include CPack
include(CPackConfig.txt)
100 changes: 100 additions & 0 deletions CPackConfig.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
set(CPACK_PACKAGE_NAME "libcapstone-dev")
set(CPACK_PACKAGE_VENDOR "Rot127")
set(CPACK_PACKAGE_CONTACT "Rot127 <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION "Capstone is a lightweight multi-platform, multi-architecture disassembly framework. These are the development headers and libraries.\n Features:\n - Support hardware architectures: AArch64, ARM, Alpha, BPF, EVM, HPPA, LongArch, M680X, M68K, MOS65XX, Mips, PowerPC, RISCV, SH, Sparc, SystemZ, TMS320C64x, TriCore, WASM, x86, XCore, Xtensa.\n - Clean/simple/lightweight/intuitive architecture-neutral API.\n - Provide details on disassembled instructions (called \\\"decomposer\\\" by some others).\n - Provide some semantics of the disassembled instruction, such as list of implicit registers read & written.\n - Thread-safe by design.\n - Special support for embedding into firmware or OS kernel.\n - Distributed under the open source BSD license.")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Lightweight multi-architecture disassembly framework - devel files")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.capstone-engine.org/")
set(CPACK_STRIP_FILES false)

# Set Debian-specific package variables
set(CPACK_DEBIAN_PACKAGE_SOURCE "capstone")
set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}")
set(CPACK_DEBIAN_PACKAGE_ORIGINAL_MAINTAINER "Debian Security Tools <[email protected]>")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.2.5)")
set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel")
set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
set(CPACK_DEBIAN_PACKAGE_MULTIARCH "same")

# Determine architecture
if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "amd64")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i386" OR ${CMAKE_SYSTEM_PROCESSOR} STREQUAL "i686")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386")
elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm")
if(CMAKE_SIZE_OF_VOID_P EQUAL 4)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "armhf")
else()
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "arm64")
endif()
else()
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
endif()

# Include additional file to run 'ldconfig' after install
set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_SOURCE_DIR}/packages/deb/triggers")

# RPM package settings
set(CPACK_RPM_PACKAGE_NAME "capstone-devel")
set(CPACK_RPM_PACKAGE_VERSION "${PROJECT_VERSION}")
# set(CPACK_RPM_PACKAGE_RELEASE "6.fc42")
set(CPACK_RPM_PACKAGE_ARCHITECTURE ${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_PACKAGE_REQUIRES "libc6 >= 2.2.5")
set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_SOURCE_DIR}/packages/rpm/postinstall.sh")
set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_SOURCE_DIR}/ChangeLog")
set(CPACK_RPM_PACKAGE_LICENSE "BSD3, LLVM")
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")

# TODO: Do you have a script to run tests after installing the RPM/Debian package?
# Add %check section to RPM spec file
# set(CPACK_RPM_SPEC_MORE_DEFINE "${CPACK_RPM_SPEC_MORE_DEFINE}\n%check\ntrue")

# TODO: Please help get CPack working for Mac OSX packages too
# OSX package settings
# set(CPACK_BUNDLE_NAME "Capstone")
# set(CPACK_BUNDLE_PLIST "xcode/CapstoneFramework/Info.plist")

# Set package file name based on the generator
message(STATUS "CPACK_GENERATOR: ${CPACK_GENERATOR}")
message(STATUS "PROJECT VERSION: ${PROJECT_VERSION}")

# Set the final package file name
if("DEB" IN_LIST CPACK_GENERATOR)
set(CPACK_DEB_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
message(STATUS "DEB generator detected: ${CPACK_DEB_PACKAGE_FILE_NAME}")
# Copy over documentation for Debian Packages
install(FILES "${CMAKE_SOURCE_DIR}/ChangeLog" DESTINATION "/usr/share/doc/libcapstone-dev")
install(FILES "${CMAKE_SOURCE_DIR}/CREDITS.TXT" DESTINATION "/usr/share/doc/libcapstone-dev")
install(FILES "${CMAKE_SOURCE_DIR}/README.md" DESTINATION "/usr/share/doc/libcapstone-dev")
install(FILES "${CMAKE_SOURCE_DIR}/SPONSORS.TXT" DESTINATION "/usr/share/doc/libcapstone-dev")
install(DIRECTORY "${CMAKE_SOURCE_DIR}/LICENSES" DESTINATION "/usr/share/doc/libcapstone-dev")
endif()

if("RPM" IN_LIST CPACK_GENERATOR)
set(CPACK_RPM_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "RPM generator detected: ${CPACK_RPM_PACKAGE_FILE_NAME}")
endif()

if("DragNDrop" IN_LIST CPACK_GENERATOR)
set(CPACK_DMG_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
message(STATUS "DragNDrop generator detected: ${CPACK_DMG_PACKAGE_FILE_NAME}")
endif()

if(NOT "DEB" IN_LIST CPACK_GENERATOR AND NOT "RPM" IN_LIST CPACK_GENERATOR AND NOT "DragNDrop" IN_LIST CPACK_GENERATOR)
message(STATUS "No matching generator detected")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-unknown")
endif()

foreach(generator ${CPACK_GENERATOR})
if("${generator}" STREQUAL "DEB")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEB_PACKAGE_FILE_NAME})
elseif("${generator}" STREQUAL "RPM")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_RPM_PACKAGE_FILE_NAME})
elseif("${generator}" STREQUAL "DragNDrop")
set(CPACK_PACKAGE_FILE_NAME ${CPACK_DMG_PACKAGE_FILE_NAME})
endif()
endforeach()

# Include CPack
include(CPack)
167 changes: 0 additions & 167 deletions packages/rpm/capstone.spec

This file was deleted.

2 changes: 2 additions & 0 deletions packages/rpm/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
/sbin/ldconfig

0 comments on commit 9406e36

Please sign in to comment.