Skip to content

Commit 53f30c4

Browse files
CMake: Add packaging support (#486)
1 parent 19c11d6 commit 53f30c4

File tree

11 files changed

+189
-82
lines changed

11 files changed

+189
-82
lines changed

.github/workflows/vcpkg_ci.yml

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ jobs:
3131

3232
steps:
3333
- uses: actions/checkout@v2
34+
with:
35+
fetch-depth: 0
3436
- name: Install utility tools
3537
shell: bash
3638
run: |
3739
# TODO some of these should probably live in the Docker build image
3840
apt-get update
39-
apt-get install -y pixz xz-utils make
41+
apt-get install -y pixz xz-utils make rpm
4042
4143
- name: Build with build script
4244
shell: bash
@@ -54,6 +56,33 @@ jobs:
5456
remill-lift-${{ matrix.llvm }} --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000
5557
remill-lift-${{ matrix.llvm }} --arch aarch64 --ir_out /dev/stdout --address 0x400544 --bytes FD7BBFA90000009000601891FD030091B7FFFF97E0031F2AFD7BC1A8C0035FD6
5658
59+
- name: Locate the packages
60+
id: package_names
61+
shell: bash
62+
working-directory: remill-build
63+
run: |
64+
echo ::set-output name=DEB_PACKAGE_PATH::remill-build/$(ls *.deb)
65+
echo ::set-output name=RPM_PACKAGE_PATH::remill-build/$(ls *.rpm)
66+
echo ::set-output name=TGZ_PACKAGE_PATH::remill-build/$(ls *.tar.gz)
67+
68+
- name: Store the DEB package
69+
uses: actions/upload-artifact@v1
70+
with:
71+
name: ${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm${{ matrix.llvm }}_deb_package
72+
path: ${{ steps.package_names.outputs.DEB_PACKAGE_PATH }}
73+
74+
- name: Store the RPM package
75+
uses: actions/upload-artifact@v1
76+
with:
77+
name: ${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm${{ matrix.llvm }}_rpm_package
78+
path: ${{ steps.package_names.outputs.RPM_PACKAGE_PATH }}
79+
80+
- name: Store the TGZ package
81+
uses: actions/upload-artifact@v1
82+
with:
83+
name: ${{ matrix.image.name }}-${{ matrix.image.tag }}_llvm${{ matrix.llvm }}_tgz_package
84+
path: ${{ steps.package_names.outputs.TGZ_PACKAGE_PATH }}
85+
5786
build_mac:
5887
strategy:
5988
fail-fast: false
@@ -69,6 +98,8 @@ jobs:
6998

7099
steps:
71100
- uses: actions/checkout@v2
101+
with:
102+
fetch-depth: 0
72103
- name: Build with build script
73104
shell: bash
74105
run: ./scripts/build.sh --llvm-version ${{ matrix.llvm }}
@@ -84,3 +115,16 @@ jobs:
84115
run: |
85116
remill-lift-${{ matrix.llvm }} --arch amd64 --ir_out /dev/stdout --bytes c704ba01000000
86117
remill-lift-${{ matrix.llvm }} --arch aarch64 --ir_out /dev/stdout --address 0x400544 --bytes FD7BBFA90000009000601891FD030091B7FFFF97E0031F2AFD7BC1A8C0035FD6
118+
119+
- name: Locate the packages
120+
id: package_names
121+
shell: bash
122+
working-directory: remill-build
123+
run: |
124+
echo ::set-output name=TGZ_PACKAGE_PATH::remill-build/$(ls *.tar.gz)
125+
126+
- name: Store the TGZ package
127+
uses: actions/upload-artifact@v1
128+
with:
129+
name: macos-11.0_llvm${{ matrix.llvm }}_tgz_package
130+
path: ${{ steps.package_names.outputs.TGZ_PACKAGE_PATH }}

distro_packages/ArchLinux/.gitignore

Lines changed: 0 additions & 19 deletions
This file was deleted.

distro_packages/ArchLinux/PKGBUILD

Lines changed: 0 additions & 61 deletions
This file was deleted.

packaging/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# remill packaging scripts
2+
3+
## How to generate packages
4+
5+
1. Configure and build remill
6+
2. Set the **DESTDIR** variable to a new folder
7+
3. Run the packaging script, passing the **DESTDIR** folder
8+
9+
Example:
10+
11+
```sh
12+
remill_version=$(git describe --always)
13+
14+
cpack -D REMILL_DATA_PATH="/path/to/install/directory" \
15+
-R ${remill_version} \
16+
--config "packaging/main.cmake"
17+
```

packaging/cmake/dispatcher.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}")
10+
set(CPACK_INSTALLED_DIRECTORIES "${REMILL_DATA_PATH};.")
11+
12+
string(TOLOWER "${CMAKE_SYSTEM_NAME}" system_name)
13+
if(system_name STREQUAL "darwin")
14+
set(system_name "macos")
15+
endif()
16+
17+
set(common_include "${CMAKE_CURRENT_LIST_DIR}/system/${system_name}/common.cmake")
18+
if(EXISTS "${common_include}")
19+
include("${common_include}")
20+
endif()
21+
22+
string(TOLOWER "${CPACK_GENERATOR}" cpack_generator)
23+
include("${CMAKE_CURRENT_LIST_DIR}/system/${system_name}/generators/${cpack_generator}.cmake")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
set(CPACK_DEBIAN_PACKAGE_PRIORITY "extra")
10+
set(CPACK_DEBIAN_PACKAGE_SECTION "default")
11+
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_PACKAGE_HOMEPAGE_URL}")
12+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
set(CPACK_RPM_PACKAGE_RELEASE "${CPACK_PACKAGE_VERSION}")
10+
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
11+
set(CPACK_RPM_PACKAGE_DESCRIPTION "${CPACK_PACKAGE_DESCRIPTION}")
12+
set(CPACK_RPM_PACKAGE_GROUP "default")
13+
set(CPACK_RPM_PACKAGE_LICENSE "GNU Affero General Public License v3.0")
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
set(CPACK_SET_DESTDIR ON)
10+
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
set(CPACK_SET_DESTDIR ON)
10+
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)

packaging/main.cmake

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Copyright (c) 2021-present, Trail of Bits, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed in accordance with the terms specified in
6+
# the LICENSE file found in the root directory of this source tree.
7+
#
8+
9+
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
10+
set(CPACK_GENERATOR "TGZ;DEB;RPM")
11+
12+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
13+
set(CPACK_GENERATOR "TGZ")
14+
endif()
15+
16+
if(REMILL_DATA_PATH STREQUAL "")
17+
message(FATAL_ERROR "The REMILL_DATA_PATH variable was not set")
18+
endif()
19+
20+
if(REMILL_PACKAGE_VERSION STREQUAL "")
21+
message(FATAL_ERROR "The REMILL_PACKAGE_VERSION variable was not set")
22+
endif()
23+
24+
set(CPACK_PROJECT_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/dispatcher.cmake")
25+
26+
set(CPACK_PACKAGE_DESCRIPTION "Library for lifting of x86, amd64, and aarch64 machine code to LLVM bitcode")
27+
set(CPACK_PACKAGE_NAME "remill")
28+
set(CPACK_PACKAGE_VENDOR "Trail of Bits")
29+
set(CPACK_PACKAGE_CONTACT "[email protected]")
30+
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/lifting-bits/remill")

scripts/build.sh

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,34 @@ function Build
257257
return $?
258258
}
259259

260+
# Create the packages
261+
function Package
262+
{
263+
remill_tag=$(cd "${SRC_DIR}" && git describe --tags --always --abbrev=0)
264+
remill_commit=$(cd "${SRC_DIR}" && git rev-parse HEAD | cut -c1-7)
265+
remill_version="${remill_tag:1}.${remill_commit}"
266+
267+
(
268+
set -x
269+
270+
if [[ -d "install" ]]; then
271+
rm -rf "install"
272+
fi
273+
274+
mkdir "install"
275+
export DESTDIR="$(pwd)/install"
276+
277+
cmake --build . \
278+
--target install
279+
280+
cpack -D REMILL_DATA_PATH="${DESTDIR}" \
281+
-R ${remill_version} \
282+
--config "${SRC_DIR}/packaging/main.cmake"
283+
) || return $?
284+
285+
return $?
286+
}
287+
260288
# Get a LLVM version name for the build. This is used to find the version of
261289
# cxx-common to download.
262290
function GetLLVMVersion
@@ -385,7 +413,7 @@ function main
385413
mkdir -p "${BUILD_DIR}"
386414
cd "${BUILD_DIR}" || exit 1
387415

388-
if ! (DownloadLibraries && Configure && Build); then
416+
if ! (DownloadLibraries && Configure && Build && Package); then
389417
echo "[x] Build aborted."
390418
exit 1
391419
fi

0 commit comments

Comments
 (0)