Skip to content

Commit 9907b22

Browse files
Update v6 to have Debian Packages (capstone-engine#2579)
1 parent efbbc3b commit 9907b22

10 files changed

+131
-81
lines changed

.github/workflows/build_deb.yml

-26
This file was deleted.

.github/workflows/build_release.yml

+23
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,29 @@ jobs:
1515
with:
1616
submodules: true
1717

18+
- name: Make setup.sh and check_capstone.sh are executable
19+
run: |
20+
chmod +x ./packages/deb/setup.sh
21+
chmod +x ./packages/deb/check_capstone.sh
22+
23+
- name: Build Debian Package
24+
working-directory: ./packages/deb
25+
run: ./setup.sh ${{ github.event.release.tag_name }}
26+
27+
- name: Run sanity checks on the Debian package
28+
working-directory: ./packages/deb
29+
run: |
30+
./check_capstone.sh ./libcapstone-dev_${{ github.event.release.tag_name }}_amd64.deb
31+
32+
- name: Upload debian package to release
33+
uses: softprops/action-gh-release@v2
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
with:
37+
tag_name: ${{ github.event.release.tag_name }}
38+
files: |
39+
./packages/deb/*.deb
40+
1841
- name: Create archive
1942
id: archive
2043
run: |

CMakeLists.txt

+10-4
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,16 @@ endif()
1919
# https://cmake.org/cmake/help/latest/policy/CMP0042.html
2020
cmake_policy(SET CMP0042 NEW)
2121

22-
project(capstone
23-
VERSION 6.0
24-
)
22+
# Check if VERSION is provided externally, otherwise default to 6.0.0
23+
if(NOT DEFINED PROJECT_VERSION)
24+
set(PROJECT_VERSION "6.0.0")
25+
endif()
26+
27+
# Extract the major, minor, and patch versions
28+
string(REGEX MATCH "^[0-9]+\\.[0-9]+\\.[0-9]+" PROJECT_VERSION_BASE ${PROJECT_VERSION})
29+
30+
# Set the project version without the pre-release identifier
31+
project(capstone VERSION ${PROJECT_VERSION_BASE})
2532

2633
set(UNIX_COMPILER_OPTIONS -Werror -Wall -Warray-bounds -Wshift-negative-value -Wreturn-type -Wformat -Wmissing-braces -Wunused-function -Warray-bounds -Wunused-variable -Wparentheses -Wint-in-bool-context -Wmisleading-indentation)
2734

@@ -855,7 +862,6 @@ source_group("Include\\Xtensa" FILES ${HEADERS_XTENSA})
855862
## installation
856863
if(CAPSTONE_INSTALL)
857864
include(GNUInstallDirs)
858-
859865
install(FILES ${HEADERS_COMMON} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone)
860866
install(FILES ${HEADERS_INC} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/capstone/inc)
861867

LICENSES/LICENSE_DEB_PACKAGE.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
MIT License
2+
3+
The scope of this license is the `packages/deb` directory
4+
5+
Copyright (c) 2024 Andrew Quijano
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8+
9+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

capstone.pc.in

-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,3 @@ archive=${libdir}/libcapstone.a
1111
Libs: -L${libdir} -lcapstone
1212
Libs.private: -L${libdir} -l:libcapstone.a
1313
Cflags: -I${includedir} -I${includedir}/capstone
14-
archs=@CAPSTONE_ARCHITECTURES@

packages/deb/Dockerfile

+21-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (C) 2024 Andrew Quijano
3+
14
ARG VERSION=""
25

36
# Run in the root of the repo
@@ -16,7 +19,8 @@ WORKDIR /capstone/
1619

1720
# Using cmake, see BUILDING.md file
1821
# For debug build change "Release" to "Debug"
19-
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1
22+
ARG VERSION
23+
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DCAPSTONE_BUILD_SHARED_LIBS=1 -DPROJECT_VERSION=${VERSION} -DCMAKE_INSTALL_PREFIX=/usr
2024
RUN cmake --build build
2125

2226
# List files before cmake install
@@ -26,6 +30,7 @@ RUN cmake --build build
2630
RUN mkdir -p /package-root/usr/include/capstone/
2731
RUN mkdir -p /package-root/usr/lib/pkgconfig/
2832
RUN mkdir -p /package-root/usr/bin/
33+
RUN mkdir -p /package-root/usr/share/doc/libcapstone-dev
2934

3035
# Run cmake install
3136
RUN cmake --install build --prefix /package-root/usr/
@@ -36,18 +41,28 @@ RUN cmake --install build --prefix /package-root/usr/
3641
# Create DEBIAN directory and control file
3742
COPY ./packages/deb/control /package-root/DEBIAN/control
3843

39-
# Update capstone.pc file with the correct version and remove archs field
40-
# Update control file with the correct version
44+
# Copy documentation over
45+
COPY ./LICENSES/ /package-root/usr/share/doc/libcapstone-dev/LICENSES/
46+
COPY ./ChangeLog /package-root/usr/share/doc/libcapstone-dev
47+
COPY ./CREDITS.TXT /package-root/usr/share/doc/libcapstone-dev
48+
COPY ./README.md /package-root/usr/share/doc/libcapstone-dev
49+
COPY ./SPONSORS.TXT /package-root/usr/share/doc/libcapstone-dev
50+
51+
# Generate MD5 checksums for all files and save to DEBIAN/md5sums
52+
RUN cd /package-root && \
53+
find . -type f ! -path './DEBIAN/*' -exec md5sum {} + | sed 's| \./| |' > /package-root/DEBIAN/md5sums
54+
55+
# Update control file with the correct information
4156
ARG VERSION
57+
RUN INSTALLED_SIZE=$(du -sk /package-root | cut -f1) && \
58+
sed -i "s/^Installed-Size:.*/Installed-Size: ${INSTALLED_SIZE}/" /package-root/DEBIAN/control
4259
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control
43-
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/lib/pkgconfig/capstone.pc
44-
RUN sed -i "/^archs=/d" /package-root/usr/lib/pkgconfig/capstone.pc
4560

4661
# Add triggers script to run ldconfig after installation
4762
COPY ./packages/deb/triggers /package-root/DEBIAN/triggers
4863

4964
# Build the package
50-
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb
65+
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev_${VERSION}_amd64.deb
5166

5267
# The user can now extract the .deb file from the container with something like
5368
# docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"

packages/deb/README.md

+25-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
1-
Incomplete Debian package implementation.
2-
It can be used to generate an easily installable Capstone, but misses a lot of
3-
mandatory things to add it in the Debian repos (`debian/control` is incomplete, no dependencies added etc.).
1+
# Capstone Docker packaging
42

5-
You can build the package by dispatching the `Build Debian Package` workflow or executing the commands in the `Dockerfile`.
6-
It assumes the current commit is tagged and `"$(git describe --tags --abbrev=0)"` returns a valid version number.
7-
The package is uploaded as artifact.
3+
This assumes your working directory is in the `packages/deb/` directory.
4+
To build a Debian package for Capstone, run the script, where `<tag-name>` is going to be the version
5+
attached to both the `capstone.pc` file and the Debian package itself. The version is expected to be compliant with Debian versioning (a major/minor/patch), e. g. `5.0.4`. Debian versions can also support values to indicate pre-release, e. g. `6.0.0-Alpha1`.
6+
7+
**Note**: if a value such as `6.0.0-Alpha1` is provided, the major/minor/patch number is extracted for `capstone.pc`, which would have version `6.0.0`, but the Debian package would have the full version name on the control file.
8+
9+
**Note**: Currently the package is hard coded to the `amd64` architecture. Independently on what machine you built it. Also see [issue #2537](https://github.com/capstone-engine/capstone/issues/2537).
10+
11+
```bash
12+
./setup.sh <tag-name>
13+
```
14+
15+
The output Debian file would be in the form `libcapstone-dev_<tag-version>_amd64.deb`, as to match what would be expected in a standard Debian library package.
16+
17+
To confirm the necessary libraries and `capstone.pc` is filled correctly, there exists a `check_capstone.sh` script to confirm `libcapstone-dev` was built correctly.
18+
19+
If you want to check the contents of the Debian package, use the following:
20+
```bash
21+
# Check the DEBIAN/ folder
22+
dpkg-deb -e libcapstone-dev_<tag-version>_amd64.deb ./unpacked
23+
24+
# Check the content of the package, EXCEPT the DEBIAN/ folder
25+
dpkg-deb -x libcapstone-dev_<tag-version>_amd64.deb ./unpacked
26+
```

packages/deb/check_capstone.sh

+9-27
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (C) 2024 Andrew Quijano
3+
4+
15
#!/bin/bash
6+
set -eu
27

3-
# Usage: ./check_capstone_pc.sh <path_to_deb_file> <expected_version>
8+
# Usage: ./check_capstone_pc.sh <path_to_deb_file>
49

510
DEB_FILE=$1
6-
EXPECTED_VERSION=$2
711

812
# Check if the deb file exists
913
if [[ ! -f "$DEB_FILE" ]]; then
@@ -17,46 +21,24 @@ TEMP_DIR=$(mktemp -d)
1721
# Extract the deb file
1822
dpkg-deb -x "$DEB_FILE" "$TEMP_DIR"
1923

20-
# Path to the capstone.pc file
21-
CAPSTONE_PC="$TEMP_DIR/usr/lib/pkgconfig/capstone.pc"
22-
2324
# Check if the capstone.pc file exists
25+
CAPSTONE_PC="$TEMP_DIR/usr/lib/x86_64-linux-gnu/pkgconfig/capstone.pc"
2426
if [[ ! -f "$CAPSTONE_PC" ]]; then
2527
echo "capstone.pc file not found in the package!"
2628
rm -rf "$TEMP_DIR"
2729
exit 1
2830
fi
2931

30-
# Remove leading 'v' if present, e. g. v1.5.1 -> 1.5.1
31-
if [[ "$EXPECTED_VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
32-
EXPECTED_VERSION=${EXPECTED_VERSION:1}
33-
fi
34-
35-
# Check if the version follows the format X.Y.Z, e. g. 1.5.1 or 1.9.1
36-
if [[ ! "$EXPECTED_VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
37-
echo "ERROR: Version must be in the format X.Y.Z"
38-
exit 1
39-
fi
40-
41-
42-
# Check the version in the capstone.pc file
43-
ACTUAL_VERSION=$(grep "^Version:" "$CAPSTONE_PC" | awk '{print $2}')
44-
if [[ "$ACTUAL_VERSION" != "$EXPECTED_VERSION" ]]; then
45-
echo "Version mismatch! Expected: $EXPECTED_VERSION, Found: $ACTUAL_VERSION"
46-
rm -rf "$TEMP_DIR"
47-
exit 1
48-
fi
49-
5032
# Check if libcapstone.a is included in the package
51-
LIBCAPSTONE_A="$TEMP_DIR/usr/lib/libcapstone.a"
33+
LIBCAPSTONE_A="$TEMP_DIR/usr/lib/x86_64-linux-gnu/libcapstone.a"
5234
if [[ ! -f "$LIBCAPSTONE_A" ]]; then
5335
echo "libcapstone.a not found in the package!"
5436
rm -rf "$TEMP_DIR"
5537
exit 1
5638
fi
5739

5840
# Check if libcapstone.so is included in the package
59-
LIBCAPSTONE_SO="$TEMP_DIR/usr/lib/libcapstone.so"
41+
LIBCAPSTONE_SO="$TEMP_DIR/usr/lib/x86_64-linux-gnu/libcapstone.so"
6042
if [[ ! -f "$LIBCAPSTONE_SO" ]]; then
6143
echo "libcapstone.so not found in the package!"
6244
rm -rf "$TEMP_DIR"

packages/deb/control

+23-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1-
Package: capstone
1+
Package: libcapstone-dev
2+
Source: capstone
23
Version: <version-placeholder>
3-
Architecture: all
4+
Architecture: amd64
45
Maintainer: Rot127 <[email protected]>
5-
Description: Capstone is a lightweight multi-platform, multi-architecture disassembly framework.
6-
Capstone supports the following frameworks;
7-
Alpha, BPF, Ethereum VM, HPPA, LoongArch, M68K, M680X, Mips, MOS65XX, PPC, RISC-V(rv32G/rv64G),
8-
SH, Sparc, SystemZ, TMS320C64X, TriCore, Webassembly, XCore and X86.
6+
Original-Maintainer: Debian Security Tools <[email protected]>
7+
Installed-Size: <size-in-kb>
8+
Depends: libc6 (>= 2.2.5)
9+
Section: libdevel
10+
Priority: optional
11+
Multi-Arch: same
12+
Homepage: https://www.capstone-engine.org/
13+
Description: lightweight multi-architecture disassembly framework - devel files
14+
Capstone is a lightweight multi-platform, multi-architecture disassembly
15+
framework. These are the development headers and libraries.
16+
Features:
17+
- 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.
18+
- Clean/simple/lightweight/intuitive architecture-neutral API.
19+
- Provide details on disassembled instructions (called "decomposer" by some
20+
others).
21+
- Provide some semantics of the disassembled instruction, such as list of
22+
implicit registers read & written.
23+
- Thread-safe by design.
24+
- Special support for embedding into firmware or OS kernel.
25+
- Distributed under the open source BSD license.

packages/deb/setup.sh

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# SPDX-License-Identifier: MIT
2+
# Copyright (C) 2024 Andrew Quijano
3+
4+
15
# !/bin/bash
26
set -eu
37

@@ -33,10 +37,10 @@ if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
3337
version=${version:1}
3438
fi
3539

36-
# Check if the version follows the format X.Y.Z, e. g. 1.5.1 or 1.9.1
37-
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
38-
echo "ERROR: Version must be in the format X.Y.Z"
39-
exit 1
40+
# Check if the version follows the format for Debian Packages
41+
if [[ ! "$version" =~ ^[0-9]+(.[0-9]+)*(-[A-Za-z0-9]+)?$ ]]; then
42+
echo "ERROR: Version must be in a valid Debian package format"
43+
exit 1
4044
fi
4145

4246
# Now build the packager container from that
@@ -45,7 +49,7 @@ docker build -f ./packages/deb/Dockerfile -t packager --build-arg VERSION="${ver
4549
popd
4650

4751
# Copy deb file out of container to host
48-
docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"
52+
docker run --rm -v $(pwd):/out packager bash -c "cp /*.deb /out"
4953

5054
# Check which files existed before and after 'make install' was executed.
5155
# docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out"

0 commit comments

Comments
 (0)