Skip to content

Commit eea7a54

Browse files
CMake: Add packaging support (#96)
* CMake: Add packaging support * CI: Upload artifacts, auto-create releases from tags * Build: Lock the cxx-common version
1 parent de43af8 commit eea7a54

File tree

10 files changed

+298
-4
lines changed

10 files changed

+298
-4
lines changed

.github/workflows/vcpkg_ci.yml

+143-1
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
CLANG_BIN="$(find ../../pre-built-llvm-${{ matrix.llvm }} -name clang | grep "bin/clang")"
5557
../scripts/roundtrip.py "./tools/rellic-decomp-${{ matrix.llvm }}.0" ../tests/tools/decomp "${CLANG_BIN}"
5658
59+
- name: Locate the packages
60+
id: package_names
61+
shell: bash
62+
working-directory: rellic-build
63+
run: |
64+
echo ::set-output name=DEB_PACKAGE_PATH::rellic-build/$(ls *.deb)
65+
echo ::set-output name=RPM_PACKAGE_PATH::rellic-build/$(ls *.rpm)
66+
echo ::set-output name=TGZ_PACKAGE_PATH::rellic-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: |
@@ -84,3 +115,114 @@ jobs:
84115
# Run tests manually (kinda ugly, so use CMake way)
85116
CLANG_BIN="$(find ../../pre-built-llvm-${{ matrix.llvm }} -name clang | grep "bin/clang")"
86117
../scripts/roundtrip.py "./tools/rellic-decomp-${{ matrix.llvm }}.0" ../tests/tools/decomp "${CLANG_BIN}"
118+
- name: Locate the packages
119+
id: package_names
120+
shell: bash
121+
working-directory: rellic-build
122+
run: |
123+
echo ::set-output name=TGZ_PACKAGE_PATH::rellic-build/$(ls *.tar.gz)
124+
125+
- name: Store the TGZ package
126+
uses: actions/upload-artifact@v1
127+
with:
128+
name: macos-11.0_llvm${{ matrix.llvm }}_tgz_package
129+
path: ${{ steps.package_names.outputs.TGZ_PACKAGE_PATH }}
130+
131+
132+
release_linux:
133+
# Do not run the release procedure if any of the builds has failed
134+
needs: [ build_linux, build_mac ]
135+
runs-on: ubuntu-20.04
136+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
137+
138+
steps:
139+
- name: Download all artifacts
140+
uses: actions/download-artifact@v2
141+
142+
- name: Draft the new release
143+
id: create_release
144+
uses: actions/create-release@v1
145+
146+
env:
147+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
148+
149+
with:
150+
tag_name: ${{ github.ref }}
151+
release_name: Version ${{ github.ref }}
152+
draft: true
153+
prerelease: true
154+
155+
- name: Group the packages by platform
156+
run: |
157+
zip -r9 rellic_ubuntu-18.04_packages.zip \
158+
ubuntu-18.04*
159+
160+
zip -r9 rellic_ubuntu-20.04_packages.zip \
161+
ubuntu-20.04*
162+
163+
- name: Upload the Ubuntu 18.04 packages
164+
uses: actions/upload-release-asset@v1
165+
166+
env:
167+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
168+
169+
with:
170+
upload_url: ${{ steps.create_release.outputs.upload_url }}
171+
asset_path: rellic_ubuntu-18.04_packages.zip
172+
asset_name: rellic_ubuntu-18.04_packages.zip
173+
asset_content_type: application/gzip
174+
175+
- name: Upload the Ubuntu 20.04 packages
176+
uses: actions/upload-release-asset@v1
177+
178+
env:
179+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
180+
181+
with:
182+
upload_url: ${{ steps.create_release.outputs.upload_url }}
183+
asset_path: rellic_ubuntu-20.04_packages.zip
184+
asset_name: rellic_ubuntu-20.04_packages.zip
185+
asset_content_type: application/gzip
186+
187+
188+
189+
190+
release_macos:
191+
# Do not run the release procedure if any of the builds has failed
192+
needs: [ build_linux, build_mac ]
193+
runs-on: 'macos-11.0'
194+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
195+
196+
steps:
197+
- name: Download all artifacts
198+
uses: actions/download-artifact@v2
199+
200+
- name: Draft the new release
201+
id: create_release
202+
uses: actions/create-release@v1
203+
204+
env:
205+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
206+
207+
with:
208+
tag_name: ${{ github.ref }}
209+
release_name: Version ${{ github.ref }}
210+
draft: true
211+
prerelease: true
212+
213+
- name: Group the packages by platform
214+
run: |
215+
zip -r9 rellic_macos-11.0_packages.zip \
216+
macos-11.0*
217+
218+
- name: Upload the macOS 11.0 packages
219+
uses: actions/upload-release-asset@v1
220+
221+
env:
222+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
223+
224+
with:
225+
upload_url: ${{ steps.create_release.outputs.upload_url }}
226+
asset_path: rellic_macos-11.0_packages.zip
227+
asset_name: rellic_macos-11.0_packages.zip
228+
asset_content_type: application/gzip

packaging/README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# rellic packaging scripts
2+
3+
## How to generate packages
4+
5+
1. Configure and build rellic
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+
rellic_version=$(git describe --always)
13+
14+
cpack -D RELLIC_DATA_PATH="/path/to/install/directory" \
15+
-R ${rellic_version} \
16+
--config "packaging/main.cmake"
17+
```

packaging/cmake/dispatcher.cmake

+23
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 "${RELLIC_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")
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+
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")
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)
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

+30
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(RELLIC_DATA_PATH STREQUAL "")
17+
message(FATAL_ERROR "The RELLIC_DATA_PATH variable was not set")
18+
endif()
19+
20+
if(RELLIC_PACKAGE_VERSION STREQUAL "")
21+
message(FATAL_ERROR "The RELLIC_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 "Rellic produces goto-free C output from LLVM bitcode")
27+
set(CPACK_PACKAGE_NAME "rellic")
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/rellic")

scripts/build.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ARCH_VERSION=unknown
2828
BUILD_FLAGS=
2929
USE_HOST_COMPILER=0
3030
LIBRARIES="${BUILD_DIR}/libraries"
31+
CXX_COMMON_VERSION="v0.1.1"
3132

3233
Z3_ARCHIVE=z3-
3334
Z3_VERSION=4.7.1
@@ -102,7 +103,7 @@ function GetArchVersion
102103
function DownloadCxxCommon
103104
{
104105
local GITHUB_LIBS="${LIBRARY_VERSION}.tar.xz"
105-
local URL="https://github.com/trailofbits/cxx-common/releases/latest/download/${GITHUB_LIBS}"
106+
local URL="https://github.com/trailofbits/cxx-common/releases/download/${CXX_COMMON_VERSION}/${GITHUB_LIBS}"
106107

107108
echo "Fetching: ${URL}"
108109
if ! curl -LO "${URL}"; then

scripts/build_with_vcpkg.sh

+38-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ LLVM_VERSION=llvm-9
2828
OS_VERSION=unknown
2929
ARCH_VERSION=unknown
3030
BUILD_FLAGS=
31+
CXX_COMMON_VERSION="v0.1.1"
3132

3233
# There are pre-build versions of various libraries for specific
3334
# Ubuntu releases.
@@ -102,7 +103,7 @@ function GetArchVersion
102103
function DownloadVcpkgLibraries
103104
{
104105
local GITHUB_LIBS="${LIBRARY_VERSION}.tar.xz"
105-
local URL="https://github.com/trailofbits/cxx-common/releases/latest/download/${GITHUB_LIBS}"
106+
local URL="https://github.com/trailofbits/cxx-common/releases/download/${CXX_COMMON_VERSION}/${GITHUB_LIBS}"
106107

107108
mkdir -p "${DOWNLOAD_DIR}"
108109
pushd "${DOWNLOAD_DIR}" || return 1
@@ -264,6 +265,41 @@ function Build
264265
return $?
265266
}
266267

268+
# Create the packages
269+
function Package
270+
{
271+
tag_count=$(cd "${SRC_DIR}" && git tag | wc -l)
272+
if [[ ${tag_count} == 0 ]]; then
273+
echo "WARNING: No tag found, marking this release as 0.0.0"
274+
rellic_tag="v0.0.0"
275+
else
276+
rellic_tag=$(cd "${SRC_DIR}" && git describe --tags --always --abbrev=0)
277+
fi
278+
279+
rellic_commit=$(cd "${SRC_DIR}" && git rev-parse HEAD | cut -c1-7)
280+
rellic_version="${rellic_tag:1}.${rellic_commit}"
281+
282+
(
283+
set -x
284+
285+
if [[ -d "install" ]]; then
286+
rm -rf "install"
287+
fi
288+
289+
mkdir "install"
290+
export DESTDIR="$(pwd)/install"
291+
292+
cmake --build . \
293+
--target install
294+
295+
cpack -D RELLIC_DATA_PATH="${DESTDIR}" \
296+
-R ${rellic_version} \
297+
--config "${SRC_DIR}/packaging/main.cmake"
298+
) || return $?
299+
300+
return $?
301+
}
302+
267303
# Get a LLVM version name for the build. This is used to find the version of
268304
# cxx-common to download.
269305
function GetLLVMVersion
@@ -375,7 +411,7 @@ function main
375411
mkdir -p "${BUILD_DIR}"
376412
cd "${BUILD_DIR}" || exit 1
377413

378-
if ! (DownloadLibraries && Configure && Build); then
414+
if ! (DownloadLibraries && Configure && Build && Package); then
379415
echo "[x] Build aborted."
380416
exit 1
381417
fi

0 commit comments

Comments
 (0)