Skip to content

Commit 3e5a6dd

Browse files
AndrewQuijanoRot127
authored andcommitted
Updating CI to create Debian package and version is assigned by tag
version. Also updating release CI to not use end-of-life workflows
1 parent 8455b3c commit 3e5a6dd

File tree

10 files changed

+276
-27
lines changed

10 files changed

+276
-27
lines changed

.dockerignore

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Ignore source control directories
2+
.git
3+
.svn
4+
5+
# Ignore build directories
6+
build
7+
dist
8+
9+
# Ignore dependency directories
10+
node_modules
11+
vendor
12+
13+
# Ignore temporary files
14+
*.log
15+
*.tmp
16+
17+
# Ignore environment files
18+
.env
19+
20+
# Ignore tests
21+
tests

.gitattributes

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
/arch/**/*.inc linguist-language=C
2+
3+
# Ensure shell scripts have LF line endings
4+
*.sh text eol=lf

.github/workflows/build_release.yml

+32-18
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,32 @@ jobs:
1111
name: build
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515
with:
1616
submodules: true
17+
18+
- name: Make setup.sh and check_capstone.sh are executable
19+
run: |
20+
chmod +x debian/setup.sh
21+
chmod +x debian/check_capstone.sh
22+
23+
- name: Build Debian Package
24+
working-directory: ./debian
25+
run: ./setup.sh ${{ github.event.release.tag_name }}
26+
27+
- name: Run sanity checks on the Debian package
28+
working-directory: ./debian
29+
run: |
30+
./check_capstone.sh ./libcapstone-dev.deb ${{ github.event.release.tag_name }}
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+
./debian/*.deb
1740
1841
- name: archive
1942
id: archive
@@ -27,24 +50,15 @@ jobs:
2750
TARBALL=$PKGNAME.tar.xz
2851
tar cJf $TARBALL $PKGNAME
2952
sha256sum $TARBALL > $SHASUM
30-
echo "::set-output name=tarball::$TARBALL"
31-
echo "::set-output name=shasum::$SHASUM"
32-
- name: upload tarball
33-
uses: actions/upload-release-asset@v1
34-
env:
35-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36-
with:
37-
upload_url: ${{ github.event.release.upload_url }}
38-
asset_path: ./${{ steps.archive.outputs.tarball }}
39-
asset_name: ${{ steps.archive.outputs.tarball }}
40-
asset_content_type: application/gzip
53+
echo "tarball=$TARBALL" >> $GITHUB_OUTPUT
54+
echo "shasum=$SHASUM" >> $GITHUB_OUTPUT
4155
42-
- name: upload shasum
43-
uses: actions/upload-release-asset@v1
56+
- name: Upload tarball and shasum to release
57+
uses: softprops/action-gh-release@v2
4458
env:
4559
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4660
with:
47-
upload_url: ${{ github.event.release.upload_url }}
48-
asset_path: ./${{ steps.archive.outputs.shasum }}
49-
asset_name: ${{ steps.archive.outputs.shasum }}
50-
asset_content_type: text/plain
61+
tag_name: ${{ github.event.release.tag_name }}
62+
files: |
63+
${{ steps.archive.outputs.tarball }}
64+
${{ steps.archive.outputs.shasum }}

CMakeLists.txt

+22-9
Original file line numberDiff line numberDiff line change
@@ -631,16 +631,23 @@ set(ALL_HEADERS
631631
set_property(GLOBAL PROPERTY VERSION ${PROJECT_VERSION})
632632

633633
## targets
634-
add_library(capstone ${ALL_SOURCES} ${ALL_HEADERS})
634+
add_library(capstone OBJECT ${ALL_SOURCES} ${ALL_HEADERS})
635635
add_library(capstone::capstone ALIAS capstone)
636+
add_library(capstone_static STATIC $<TARGET_OBJECTS:capstone>)
637+
# Use normal capstone name. Otherwise we get libcapstone_static.so
638+
set_target_properties(capstone_static PROPERTIES OUTPUT_NAME "capstone")
636639
target_include_directories(capstone PUBLIC
637640
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
638641
)
639642
set_property(TARGET capstone PROPERTY C_STANDARD 99)
640643

641644
if(BUILD_SHARED_LIBS)
642-
target_compile_definitions(capstone PUBLIC CAPSTONE_SHARED)
643-
set_target_properties(capstone PROPERTIES
645+
set_property(TARGET capstone PROPERTY POSITION_INDEPENDENT_CODE 1)
646+
add_library(capstone_shared SHARED $<TARGET_OBJECTS:capstone>)
647+
# Use normal capstone name. Otherwise we get libcapstone_shared.so
648+
set_target_properties(capstone_shared PROPERTIES OUTPUT_NAME "capstone")
649+
target_compile_definitions(capstone_shared PUBLIC CAPSTONE_SHARED)
650+
set_target_properties(capstone_shared PROPERTIES
644651
VERSION ${PROJECT_VERSION}
645652
SOVERSION ${PROJECT_VERSION_MAJOR}
646653
)
@@ -753,12 +760,18 @@ if(CAPSTONE_INSTALL)
753760
DESTINATION ${CAPSTONE_CMAKE_CONFIG_INSTALL_DIR}
754761
)
755762

756-
install(TARGETS capstone
757-
EXPORT capstone-targets
758-
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
759-
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
760-
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
761-
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
763+
if(BUILD_SHARED_LIBS)
764+
set(LIB_INSTALL_TARGETS capstone_static capstone_shared)
765+
else()
766+
set(LIB_INSTALL_TARGETS capstone_static)
767+
endif()
768+
769+
install(TARGETS ${LIB_INSTALL_TARGETS}
770+
EXPORT capstone-targets
771+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
772+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
773+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
774+
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
762775
)
763776

764777
install(EXPORT capstone-targets

debian/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.deb
2+
*.txt

debian/Dockerfile

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
ARG VERSION=""
2+
3+
# Assume this is run from capstone/debian directory
4+
# Run in the root of the repo
5+
# docker build -f ./debian/Dockerfile -t packager .
6+
FROM debian:bookworm-slim
7+
8+
# Install necessary tools for packaging
9+
RUN apt-get -qq update && \
10+
DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \
11+
fakeroot dpkg-dev dos2unix cmake
12+
13+
# Copy your project files into the container
14+
RUN mkdir /capstone
15+
COPY . /capstone
16+
WORKDIR /capstone/
17+
18+
# Using cmake, see BUILDING.md file
19+
# For debug build change "Release" to "Debug"
20+
RUN cmake -B build -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=1
21+
RUN cmake --build build
22+
23+
# List files before cmake install
24+
# RUN find / -type f > /before-install.txt
25+
26+
# Run cmake install, by default everything goes into /usr/local
27+
RUN cmake --install build
28+
29+
# List files after cmake install
30+
# RUN find / -type f > /after-install.txt
31+
32+
# Make directories as needed
33+
RUN mkdir -p /package-root/usr/local/include/capstone/
34+
RUN mkdir -p /package-root/usr/local/lib/pkgconfig/
35+
RUN mkdir -p /package-root/usr/local/bin/
36+
37+
# Copy /usr/local/include/capstone/ to /package-root/usr/local/include/capstone/ and all other cases
38+
RUN cp -r /usr/local/include/capstone/* /package-root/usr/local/include/capstone/
39+
RUN cp -r /usr/local/lib/libcapstone* /package-root/usr/local/lib/
40+
RUN cp -r /usr/local/lib/pkgconfig/capstone* /package-root/usr/local/lib/pkgconfig/
41+
RUN cp -r /usr/local/bin/cstool /package-root/usr/local/bin/
42+
43+
# Create DEBIAN directory and control file
44+
COPY ./debian/control /package-root/DEBIAN/control
45+
46+
# Update capstone.pc file with the correct version and remove archs field
47+
# Update control file with the correct version
48+
ARG VERSION
49+
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/DEBIAN/control
50+
RUN sed -i "s/^Version:.*/Version: ${VERSION}/" /package-root/usr/local/lib/pkgconfig/capstone.pc
51+
RUN sed -i "/^archs=/d" /package-root/usr/local/lib/pkgconfig/capstone.pc
52+
53+
# Add postinst script to run ldconfig after installation
54+
COPY ./debian/postinst /package-root/DEBIAN/postinst
55+
RUN chmod 755 /package-root/DEBIAN/postinst
56+
57+
# Build the package
58+
RUN fakeroot dpkg-deb --build /package-root /libcapstone-dev.deb
59+
60+
# The user can now extract the .deb file from the container with something like
61+
# docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"

debian/check_capstone.sh

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
# Usage: ./check_capstone_pc.sh <path_to_deb_file> <expected_version>
4+
5+
DEB_FILE=$1
6+
EXPECTED_VERSION=$2
7+
8+
# Check if the deb file exists
9+
if [[ ! -f "$DEB_FILE" ]]; then
10+
echo "Debian package file not found!"
11+
exit 1
12+
fi
13+
14+
# Create a temporary directory to extract the deb file
15+
TEMP_DIR=$(mktemp -d)
16+
17+
# Extract the deb file
18+
dpkg-deb -x "$DEB_FILE" "$TEMP_DIR"
19+
20+
# Path to the capstone.pc file
21+
CAPSTONE_PC="$TEMP_DIR/usr/local/lib/pkgconfig/capstone.pc"
22+
23+
# Check if the capstone.pc file exists
24+
if [[ ! -f "$CAPSTONE_PC" ]]; then
25+
echo "capstone.pc file not found in the package!"
26+
rm -rf "$TEMP_DIR"
27+
exit 1
28+
fi
29+
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+
50+
# Check if libcapstone.a is included in the package
51+
LIBCAPSTONE_A="$TEMP_DIR/usr/local/lib/libcapstone.a"
52+
if [[ ! -f "$LIBCAPSTONE_A" ]]; then
53+
echo "libcapstone.a not found in the package!"
54+
rm -rf "$TEMP_DIR"
55+
exit 1
56+
fi
57+
58+
# Check if libcapstone.so is included in the package
59+
LIBCAPSTONE_SO="$TEMP_DIR/usr/local/lib/libcapstone.so"
60+
if [[ ! -f "$LIBCAPSTONE_SO" ]]; then
61+
echo "libcapstone.so not found in the package!"
62+
rm -rf "$TEMP_DIR"
63+
exit 1
64+
fi
65+
66+
echo "libcapstone-dev.deb file is correct."
67+
rm -rf "$TEMP_DIR"
68+
exit 0

debian/control

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Package: capstone
2+
Version: <version-placeholder>
3+
Architecture: all
4+
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.

debian/postinst

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
# postinst script for capstone package
3+
set -e
4+
5+
# Update the shared library cache
6+
ldconfig

debian/setup.sh

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# !/bin/bash
2+
set -eu
3+
4+
# Function to get the current Ubuntu version
5+
get_os_version() {
6+
lsb_release -i -s 2>/dev/null
7+
}
8+
9+
# Check if the script is running in the ./debian folder
10+
if [[ $(basename "$PWD") != "debian" ]]; then
11+
echo "ERROR: Script must be run from the ./debian directory"
12+
exit 1
13+
fi
14+
15+
OS_VERSION=$(get_os_version)
16+
if [[ "$OS_VERSION" != "Ubuntu" && "$OS_VERSION" != "Debian" ]]; then
17+
echo "ERROR: OS is not Ubuntu or Debian and unsupported"
18+
exit 1
19+
fi
20+
21+
# Get the version number as an input
22+
# Check if version argument is provided
23+
if [[ $# -ne 1 ]]; then
24+
echo "ERROR: Version argument is required"
25+
exit 1
26+
fi
27+
28+
# Get the version number as an input
29+
version=$1
30+
31+
# Remove leading 'v' if present, e. g. v1.5.1 -> 1.5.1
32+
if [[ "$version" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
33+
version=${version:1}
34+
fi
35+
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+
fi
41+
42+
# Now build the packager container from that
43+
pushd ../
44+
docker build -f ./debian/Dockerfile -t packager --build-arg VERSION="${version}" .
45+
popd
46+
47+
# Copy deb file out of container to host
48+
docker run --rm -v $(pwd):/out packager bash -c "cp /libcapstone-dev.deb /out"
49+
50+
# Check which files existed before and after 'make install' was executed.
51+
# docker run --rm -v $(pwd):/out packager bash -c "cp /before-install.txt /out"
52+
# docker run --rm -v $(pwd):/out packager bash -c "cp /after-install.txt /out"
53+
# diff before-install.txt after-install.txt

0 commit comments

Comments
 (0)