Skip to content

Commit 616872d

Browse files
committed
Build Debian package for the LLVM backend
This commit instantiates a similar set of infrastructure to the main K repo for building a Debian package.
1 parent 8872d33 commit 616872d

File tree

13 files changed

+272
-1
lines changed

13 files changed

+272
-1
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/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: 'Set up 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: true

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.0) 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: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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 make lsof
13+
apt-get install --yes ./k-llvm-backend.deb

package/version.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ version_bump() {
2828
version_sub() {
2929
local version
3030
version="$(cat $version_file)"
31+
sed -i 's/^k-llvm-backend (.*) unstable; urgency=medium$/k-llvm-backend ('"$version"') unstable; urgency=medium/' package/debian/changelog
3132
}
3233

3334
version_command="$1" ; shift

0 commit comments

Comments
 (0)