Skip to content

Commit d7fb8af

Browse files
Baltolirv-auditor
andauthored
Build debian package (#1036)
This PR sets up a Debian package build for the LLVM backend, such that we will be able to adapt the K CI testing process to download this released version rather than rebuilding the backend from scratch on every run. The package building step is tested in CI, and I have tested the part of the workflow that deals with _uploading_ the released package locally by creating and deleting releases on pushes to this branch. I'll make sure to babysit the release to ensure that the file is attached correctly when this PR is merged. The Debian packaging specifics in this PR have been largely adapted from the main K repo. --------- Co-authored-by: devops <[email protected]>
1 parent 6a6c288 commit d7fb8af

File tree

15 files changed

+341
-4
lines changed

15 files changed

+341
-4
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: 'Build Ubuntu Package'
2+
description: 'Build the package for a given distribution and test it.'
3+
4+
inputs:
5+
os:
6+
description: 'Release OS to build and test package for.'
7+
required: true
8+
distro:
9+
description: 'Distribution to build and test package for.'
10+
required: true
11+
llvm:
12+
description: 'LLVM version to use.'
13+
required: true
14+
dockerfile:
15+
description: 'Hardcode the path of the dockerfile to use.'
16+
required: false
17+
default: .github/workflows/Dockerfile
18+
build-package:
19+
description: 'Script which builds the given package.'
20+
required: true
21+
test-package:
22+
description: 'Script which tests the given package.'
23+
required: true
24+
pkg-name:
25+
description: 'Where to move the package.'
26+
required: false
27+
default: package.pkg
28+
29+
runs:
30+
using: 'composite'
31+
32+
steps:
33+
34+
- name: 'Check out code'
35+
uses: actions/checkout@v4
36+
with:
37+
path: k-${{ inputs.distro }}
38+
submodules: recursive
39+
40+
- name: 'Set up Docker'
41+
uses: ./.github/actions/with-docker
42+
with:
43+
tag: kllvm-package-build-${{ inputs.os }}-${{ inputs.distro }}-${{ github.sha }}
44+
subdir: k-${{ inputs.distro }}/
45+
os: ${{ inputs.os }}
46+
distro: ${{ inputs.distro }}
47+
llvm: ${{ inputs.llvm }}
48+
dockerfile: ${{ inputs.dockerfile }}
49+
50+
- name: 'Build Package: ${{ inputs.distro }}'
51+
shell: bash {0}
52+
env:
53+
BASE_DISTRO: ${{ inputs.distro }}
54+
BASE_OS: ${{ inputs.os }}
55+
BUILD_PACKAGE: ${{ inputs.build-package }}
56+
PKG_NAME: ${{ inputs.pkg-name }}
57+
run: |
58+
set -euxo pipefail
59+
docker exec -t kllvm-package-build-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA} /bin/bash -c "${BUILD_PACKAGE} ${PKG_NAME}"
60+
61+
- name: 'Tear down Docker'
62+
shell: bash {0}
63+
env:
64+
BASE_DISTRO: ${{ inputs.distro }}
65+
BASE_OS: ${{ inputs.os }}
66+
if: always()
67+
run: |
68+
docker stop --time=0 kllvm-package-build-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA}
69+
docker container rm --force kllvm-package-build-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA} || true
70+
71+
- name: 'Set up Docker Test Image: ${{ inputs.os }}:${{ inputs.distro }}'
72+
shell: bash {0}
73+
env:
74+
BASE_OS: ${{ inputs.os }}
75+
BASE_DISTRO: ${{ inputs.distro }}
76+
run: |
77+
set -euxo pipefail
78+
workspace=$(pwd)
79+
cd k-${BASE_DISTRO}
80+
docker run \
81+
--name kllvm-package-test-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA} \
82+
--rm -it \
83+
--detach \
84+
--workdir /opt/workspace \
85+
-v "${workspace}:/opt/workspace" \
86+
${BASE_OS}:${BASE_DISTRO}
87+
88+
- name: 'Test Package: ${{ inputs.os }}:${{ inputs.distro }}'
89+
shell: bash {0}
90+
env:
91+
BASE_OS: ${{ inputs.os }}
92+
BASE_DISTRO: ${{ inputs.distro }}
93+
TEST_PACKAGE: ${{ inputs.test-package }}
94+
PKG_NAME: ${{ inputs.pkg-name }}
95+
SUBDIR: k-${{ inputs.distro }}/
96+
run: |
97+
set -euxo pipefail
98+
mv ${SUBDIR}${PKG_NAME} ${PKG_NAME}
99+
docker exec -t kllvm-package-test-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA} /bin/bash -c "${TEST_PACKAGE} ${PKG_NAME}"
100+
101+
- name: 'Tear down Docker Test'
102+
shell: bash {0}
103+
env:
104+
BASE_OS: ${{ inputs.os }}
105+
BASE_DISTRO: ${{ inputs.distro }}
106+
if: always()
107+
run: |
108+
docker stop --time=0 k-package-test-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA}
109+
docker container rm --force k-package-test-${BASE_OS}-${BASE_DISTRO}-${GITHUB_SHA} || true

.github/workflows/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ RUN apt-get update \
1616
cmake \
1717
clang-${LLVM_VERSION} \
1818
clang-tidy-${LLVM_VERSION} \
19+
debhelper \
1920
llvm-${LLVM_VERSION}-tools \
2021
lld-${LLVM_VERSION} \
2122
zlib1g-dev \
2223
flex \
2324
locales \
25+
libboost-dev \
2426
libboost-test-dev \
2527
libfmt-dev \
2628
libgmp-dev \

.github/workflows/release.yml

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,88 @@ on:
55
- master
66

77
jobs:
8+
draft-release:
9+
name: 'Draft Release'
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: 'Check out code'
13+
uses: actions/checkout@v4
14+
- name: 'Make release'
15+
env:
16+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17+
run: |
18+
set -x
19+
VERSION=v$(cat package/version)
20+
gh release create ${VERSION} \
21+
--repo runtimeverification/llvm-backend \
22+
--draft \
23+
--title ${VERSION} \
24+
--target ${{ github.sha }}
25+
26+
27+
build-jammy-package:
28+
name: 'Build Ubuntu Jammy Package'
29+
runs-on: [self-hosted, linux, normal]
30+
needs: draft-release
31+
32+
steps:
33+
- uses: actions/checkout@v4
34+
- name: 'Check out code'
35+
uses: actions/checkout@v4
36+
with:
37+
path: k-llvm-jammy
38+
submodules: recursive
39+
40+
- name: 'Build package in Docker'
41+
uses: ./.github/actions/test-package
42+
with:
43+
os: ubuntu
44+
distro: jammy
45+
llvm: 15
46+
build-package: package/debian/build-package jammy
47+
test-package: package/debian/test-package
48+
pkg-name: k-llvm-backend_amd64_ubuntu_jammy.deb
49+
50+
- name: 'Upload to release'
51+
env:
52+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
53+
run: |
54+
set -x
55+
VERSION=v$(cat package/version)
56+
cp k-llvm-backend_amd64_ubuntu_jammy.deb k-llvm-backend_${VERSION}_amd64_ubuntu_jammy.deb
57+
gh release upload ${VERSION} \
58+
--repo runtimeverification/llvm-backend \
59+
--clobber \
60+
k-llvm-backend_${VERSION}_amd64_ubuntu_jammy.deb
61+
62+
- name: 'On failure, delete drafted release'
63+
if: failure()
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
run: |
67+
set -x
68+
VERSION=v$(cat package/version)
69+
gh release delete ${VERSION} \
70+
--repo runtimeverification/llvm-backend \
71+
--yes \
72+
--cleanup-tag
73+
874
975
release:
1076
name: 'Publish Release'
1177
runs-on: ubuntu-latest
1278
environment: production
79+
needs: build-jammy-package
1380
steps:
1481
- name: 'Check out code'
1582
uses: actions/checkout@v4
16-
- name: 'Make release'
83+
- name: 'Finalise release'
1784
env:
1885
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1986
run: |
2087
set -x
2188
VERSION=v$(cat package/version)
22-
gh release create ${VERSION} --target ${{ github.sha }}
89+
gh release edit ${VERSION} --draft=false
2390
- name: 'Update dependents'
2491
env:
2592
GITHUB_TOKEN: ${{ secrets.JENKINS_GITHUB_PAT }}

.github/workflows/test.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ concurrency:
66
cancel-in-progress: true
77

88
jobs:
9-
109
version-bump:
1110
name: 'Version Bump'
1211
runs-on: ubuntu-latest
@@ -108,3 +107,24 @@ jobs:
108107
run: |
109108
docker stop --time=0 llvm-backend-ci-${GITHUB_SHA}
110109
docker container rm --force llvm-backend-ci-${GITHUB_SHA} || true
110+
111+
build-jammy-package:
112+
name: 'Build Ubuntu Jammy package'
113+
runs-on: [self-hosted, linux, normal]
114+
115+
steps:
116+
- uses: actions/checkout@v4
117+
- name: 'Check out code'
118+
uses: actions/checkout@v4
119+
with:
120+
path: k-llvm-jammy
121+
submodules: recursive
122+
123+
- name: 'Build package in Docker'
124+
uses: ./.github/actions/test-package
125+
with:
126+
os: ubuntu
127+
distro: jammy
128+
llvm: 15
129+
build-package: package/debian/build-package jammy
130+
test-package: package/debian/test-package

package/debian/build-package

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
base_distro="$1" ; shift
6+
pkg_name="$1" ; shift
7+
8+
mkdir debian
9+
10+
mv package/debian/changelog debian/changelog
11+
mv package/debian/copyright debian/copyright
12+
mv package/debian/k-llvm-backend-docs.docs debian/k-llvm-backend-docs.docs
13+
mv package/debian/source debian/source
14+
15+
mv package/debian/compat.${base_distro} debian/compat
16+
mv package/debian/control.${base_distro} debian/control
17+
mv package/debian/rules.${base_distro} debian/rules
18+
19+
dpkg-buildpackage
20+
21+
mv ../k-llvm-backend_$(cat package/version)_amd64.deb ${pkg_name}

package/debian/changelog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
k-llvm-backend (0.1.3) unstable; urgency=medium
2+
3+
* Initial release
4+
5+
-- Bruce Collie <[email protected]> Fri, 26 Apr 2024 15:43:00 +0100

package/debian/compat.jammy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
10

package/debian/control.jammy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Source: k-llvm-backend
2+
Section: devel
3+
Priority: optional
4+
Maintainer: Bruce Collie <[email protected]>
5+
Build-Depends: clang-15 , cmake , debhelper (>=10) , flex , libboost-dev , libboost-test-dev , libfmt-dev , libgmp-dev , libjemalloc-dev , libmpfr-dev , libyaml-dev , llvm-15-tools , pkg-config , python3 , python3-dev , xxd
6+
Standards-Version: 3.9.6
7+
Homepage: https://github.com/runtimeverification/llvm-backend
8+
9+
Package: k-llvm-backend
10+
Architecture: any
11+
Section: devel
12+
Priority: optional
13+
Depends: clang-15 , flex , libboost-dev , libffi-dev , libfmt-dev , libgmp-dev , libjemalloc-dev , libmpfr-dev , libyaml-0-2 , lld-15 , llvm-15 , pkg-config
14+
Description: K Framework LLVM backend
15+
Fast concrete execution backend for programming language semantics implemented using the K Framework.
16+
Homepage: https://github.com/runtimeverification/llvm-backend

package/debian/copyright

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
2+
Upstream-Name: k-llvm-backend
3+
Upstream-Contact: Bruce Collie <[email protected]>
4+
Source: https://github.com/runtimeverification/llvm-backend
5+
6+
Files: *
7+
Copyright: 2018-2024 K Team <[email protected]>
8+
License: BSD-3-Clause
9+
10+
License: BSD-3-Clause
11+
Redistribution and use in source and binary forms, with or without
12+
modification, are permitted provided that the following conditions are met:
13+
14+
1. Redistributions of source code must retain the above copyright notice, this
15+
list of conditions and the following disclaimer.
16+
17+
2. Redistributions in binary form must reproduce the above copyright notice,
18+
this list of conditions and the following disclaimer in the documentation
19+
and/or other materials provided with the distribution.
20+
21+
3. Neither the name of the copyright holder nor the names of its
22+
contributors may be used to endorse or promote products derived from
23+
this software without specific prior written permission.
24+
25+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
29+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

package/debian/k-llvm-backend-docs.docs

Whitespace-only changes.

package/debian/rules.jammy

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/make -f
2+
# See debhelper(7) (uncomment to enable)
3+
# output every command that modifies files on the build system.
4+
#export DH_VERBOSE = 1
5+
6+
7+
# see FEATURE AREAS in dpkg-buildflags(1)
8+
9+
# The LLVM backend is built using Clang, which is incompatible with LTO flags
10+
# added by default in newer versions of dpkg.
11+
# https://wiki.debian.org/ToolChain/LTO
12+
export DEB_BUILD_MAINT_OPTIONS=hardening=-stackprotector optimize=-lto
13+
14+
# see ENVIRONMENT in dpkg-buildflags(1)
15+
# package maintainers to append CFLAGS
16+
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
17+
# package maintainers to append LDFLAGS
18+
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed
19+
20+
DESTDIR=$(shell pwd)/debian/k-llvm-backend
21+
PREFIX=/usr
22+
PYTHON_VERSION=python3.10
23+
PYTHON_DEB_VERSION=python3
24+
export DESTDIR
25+
export PREFIX
26+
27+
%:
28+
dh $@
29+
30+
override_dh_auto_build:
31+
mkdir build
32+
cmake \
33+
-S . \
34+
-B build \
35+
-DCMAKE_BUILD_TYPE=Release \
36+
-DCMAKE_INSTALL_PREFIX=$(PREFIX)
37+
cmake --build build
38+
39+
override_dh_auto_install:
40+
cmake --install build
41+
42+
override_dh_strip:
43+
dh_strip -Xliballoc.a -Xlibarithmetic.a -XlibAST.a -Xlibutil.a -XlibParser.a -Xlibcollect.a -Xlibcollections.a -Xlibjson.a -Xlibstrings.a -Xlibmeta.a -Xlibio.a
44+
45+
# dh_make generated override targets
46+
# This is example for Cmake (See https://bugs.debian.org/641051 )
47+
#override_dh_auto_configure:
48+
# dh_auto_configure -- # -DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

package/debian/source/format

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.0 (native)

package/debian/test-package

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
pkg="$1" ; shift
6+
7+
cp "${pkg}" k-llvm-backend.deb
8+
9+
export DEBIAN_FRONTEND=noninteractive
10+
apt-get update
11+
apt-get upgrade --yes
12+
apt-get install --yes ./k-llvm-backend.deb

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.2
1+
0.1.3

0 commit comments

Comments
 (0)