Skip to content

Commit d521787

Browse files
committed
update fedora setup to follow conventions of other RPM builders
motivation: consistentcy across RPM builders changes: * add docker-compose setup * update rpmspec to use share metadata * update Dockerfile to use updated rpmspec * update build script to use updated Dockerfile and rpmspec * add readme
1 parent 4663d92 commit d521787

File tree

15 files changed

+391
-184
lines changed

15 files changed

+391
-184
lines changed
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
FROM fedora:34
210
LABEL PURPOSE="This image is configured to build Swift for the version of Fedora listed above"
311

4-
WORKDIR /root
5-
612
RUN yum -y update
713

814
# RPM and yum development tools
9-
RUN yum install -y rpmdevtools yum-utils
10-
11-
# Add the spec
12-
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
13-
ADD swiftlang.spec /root/rpmbuild/SPECS/swiftlang.spec
14-
15-
16-
# Install all the dependencies needed to build Swift from the spec file itself
17-
RUN yum-builddep -y /root/rpmbuild/SPECS/swiftlang.spec
18-
19-
# Get the sources for Swift as defined in the spec file
20-
RUN spectool -g -R /root/rpmbuild/SPECS/swiftlang.spec
21-
22-
# Add the patches
23-
ADD patches/*.patch /root/rpmbuild/SOURCES/
24-
25-
# Add the driver script
26-
ADD build_rpm.sh /root/build_rpm.sh
27-
RUN chmod +x /root/build_rpm.sh
28-
15+
RUN yum install -y rpmdevtools yum-utils createrepo
2916

30-
CMD ["/root/build_rpm.sh"]
17+
# Optimization: Install all the dependencies needed to build Swift from the spec file itself
18+
ADD swiftlang.spec /tmp/swiftlang.spec
19+
RUN touch /tmp/metadata.inc # fake metadata is okay for this optimization
20+
RUN cd /tmp && yum-builddep -y swiftlang.spec
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Building Swift on Fedora Linux
2+
3+
4+
### building with docker-compose
5+
6+
* to run the build end-to-end
7+
8+
```
9+
docker-compose run build
10+
```
11+
12+
* to enter the docker env in shell mode
13+
14+
```
15+
docker-compose run shell
16+
```
17+
18+
then you can run `./build_rpm.sh` to run the build manually inside the docker
19+
20+
21+
* to rebuild the base image
22+
23+
```
24+
docker-compose build --pull
25+
```
26+
27+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
28+
29+
30+
### Open Issues / TODO
31+
* the list of build requirements (BuildRequires) and especially requirements (Requires) should come from an external file, likely one per swift release version (which we can use it to also drive documentation)

platforms/Linux/RPM/Fedora/34/build_rpm.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
#!/usr/bin/env bash
210

3-
# This script assumes it's running in a container as root
4-
# and that /out is mounted to a directory on the local
5-
# filesystem so the build output and artifacts can be
6-
# copied out and used
11+
set -ex
712

8-
OUTDIR=/out
9-
if [[ ! -d "$OUTDIR" ]]
10-
then
13+
OUTDIR=/output
14+
if [[ ! -d "$OUTDIR" ]]; then
1115
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
1216
exit 1
1317
fi
1418

15-
# Always make sure we're up to date
16-
yum -y update
19+
# always make sure we're up to date
20+
yum update -y
21+
22+
# prepare direcoties
23+
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
24+
25+
# Add the spec
26+
cp swiftlang.spec $HOME/rpmbuild/SPECS/
27+
# Add the metadata for this swift version
28+
cp /shared/metadata.inc $HOME/rpmbuild/SPECS/
29+
# Add any patches
30+
cp patches/*.patch $HOME/rpmbuild/SOURCES/
1731

32+
pushd $HOME/rpmbuild/SPECS
33+
# install all the dependencies needed to build Swift from the spec file itself
34+
yum-builddep -y ./swiftlang.spec
35+
# get the sources for Swift as defined in the spec file
36+
spectool -g -R ./swiftlang.spec
1837
# Now we proceed to build Swift. If this is successful, we
1938
# will have two files: a SRPM file which contains the source files
2039
# as well as a regular RPM file that can be installed via `dnf' or `yum'
21-
pushd $HOME/rpmbuild/SPECS
22-
rpmbuild -ba ./swiftlang.spec 2>&1 | tee $HOME/build-output.txt
40+
rpmbuild -ba ./swiftlang.spec 2>&1 | tee /root/build-output.txt
2341
popd
2442

2543
# Include the build log which can be used to determine what went
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
9+
# this setup is designed to build the RPM with docker
10+
# usage:
11+
# docker-compose -f platforms/Linux/fedora/34/docker-compose.yaml build
12+
# to shell into the container for debugging purposes:
13+
# docker-compose -f platforms/Linux/fedora/34/docker-compose.yaml run build
14+
15+
version: "2"
16+
17+
services:
18+
19+
docker-setup:
20+
image: fedora-34-rpm-builder
21+
build:
22+
context: .
23+
dockerfile: Dockerfile
24+
25+
common: &common
26+
image: fedora-34-rpm-builder
27+
depends_on: [docker-setup]
28+
volumes:
29+
- .:/code:z
30+
- ../../../RPM:/shared:ro
31+
- ./.output:/output:z
32+
working_dir: /code
33+
cap_drop:
34+
- CAP_NET_RAW
35+
- CAP_NET_BIND_SERVICE
36+
37+
build:
38+
<<: *common
39+
command: /bin/bash -cl "./build_rpm.sh"
40+
41+
createrepo:
42+
<<: *common
43+
command: /bin/bash -cl "../shared/createrepo_rpm.sh"
44+
45+
shell:
46+
<<: *common
47+
entrypoint: /bin/bash -l

platforms/Linux/RPM/Fedora/34/swiftlang.spec

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
1+
%include metadata.inc
2+
13
%global debug_package %{nil}
2-
%global linux_version fedora
3-
%global swift_version 5.6-RELEASE
4-
%global package_version 5.6.0
5-
%global swift_source_location swift-source
6-
%global icu_version 65-1
7-
%global yams_version 4.0.2
8-
%global swift_argument_parser_version 1.0.3
9-
%global swift_crypto_version 1.1.5
10-
%global ninja_version 1.10.2
11-
%global cmake_version 3.19.6
12-
%global swift_atomics_version 1.0.2
13-
%global swift_collections_version 1.0.1
14-
%global swift_numerics_version 1.0.1
15-
%global swift_system_version 1.1.1
16-
%global swift_nio_version 2.31.2
17-
%global swift_nio_ssl_version 2.15.0
18-
19-
Name: swiftlang
4+
5+
Name: %{package_name}
206
Version: %{package_version}
217
Release: 1%{?dist}
22-
Summary: The Swift programming language
23-
License: Apache 2.0
24-
URL: https://www.swift.org
8+
Summary: %{package_summary}
9+
License: %{package_license}
10+
URL: %{package_url}
2511

2612
Source0: https://github.com/apple/swift/archive/swift-%{swift_version}.tar.gz#/swift.tar.gz
2713
Source1: https://github.com/apple/swift-corelibs-libdispatch/archive/swift-%{swift_version}.tar.gz#/corelibs-libdispatch.tar.gz
@@ -91,8 +77,6 @@ Requires: ncurses-devel
9177

9278
ExclusiveArch: x86_64 aarch64
9379

94-
Provides: swiftlang = %{version}-%{release}
95-
9680
%description
9781
Swift is a general-purpose programming language built using
9882
a modern approach to safety, performance, and software design
@@ -106,6 +90,7 @@ correct programs easier for the developer.
10690

10791
%prep
10892
%setup -q -c -n %{swift_source_location} -a 0 -a 1 -a 2 -a 3 -a 4 -a 5 -a 6 -a 7 -a 8 -a 9 -a 10 -a 11 -a 12 -a 13 -a 14 -a 15 -a 16 -a 17 -a 18 -a 19 -a 20 -a 21 -a 22 -a 23 -a 24 -a 25 -a 26 -a 27 -a 28 -a 29 -a 30 -a 31 -a 32 -a 33
93+
10994
# The Swift build script requires directories to be named
11095
# in a specific way so renaming the source directories is
11196
# necessary
@@ -114,7 +99,6 @@ mv icu-release-%{icu_version} icu
11499
mv indexstore-db-swift-%{swift_version} indexstore-db
115100
mv llvm-project-swift-%{swift_version} llvm-project
116101
mv ninja-%{ninja_version} ninja
117-
mv ninja-%{ninja_version} ninja
118102
mv sourcekit-lsp-swift-%{swift_version} sourcekit-lsp
119103
mv swift-argument-parser-%{swift_argument_parser_version} swift-argument-parser
120104
mv swift-atomics-%{swift_atomics_version} swift-atomics
@@ -165,8 +149,8 @@ ln -s /usr/bin/python3 $PWD/binforpython/python
165149
export PATH=$PWD/binforpython:$PATH
166150
%endif
167151

168-
# Here we go!
169-
swift/utils/build-script --preset=buildbot_linux,no_assertions,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-%{linux_version}.tar.gz
152+
# Run the build
153+
swift/utils/build-script --preset=buildbot_linux,no_assertions,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-fedora-34.tar.gz
170154

171155
%install
172156
mkdir -p %{buildroot}%{_libexecdir}/swift/%{package_version}
Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,20 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
FROM fedora:35
210
LABEL PURPOSE="This image is configured to build Swift for the version of Fedora listed above"
311

4-
WORKDIR /root
5-
612
RUN yum -y update
713

814
# RPM and yum development tools
9-
RUN yum install -y rpmdevtools yum-utils
10-
11-
# Add the spec
12-
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
13-
ADD swiftlang.spec /root/rpmbuild/SPECS/swiftlang.spec
14-
15-
16-
# Install all the dependencies needed to build Swift from the spec file itself
17-
RUN yum-builddep -y /root/rpmbuild/SPECS/swiftlang.spec
18-
19-
# Get the sources for Swift as defined in the spec file
20-
RUN spectool -g -R /root/rpmbuild/SPECS/swiftlang.spec
21-
22-
# Add the patches
23-
ADD patches/*.patch /root/rpmbuild/SOURCES/
24-
25-
# Add the driver script
26-
ADD build_rpm.sh /root/build_rpm.sh
27-
RUN chmod +x /root/build_rpm.sh
28-
15+
RUN yum install -y rpmdevtools yum-utils createrepo
2916

30-
CMD ["/root/build_rpm.sh"]
17+
# Optimization: Install all the dependencies needed to build Swift from the spec file itself
18+
ADD swiftlang.spec /tmp/swiftlang.spec
19+
RUN touch /tmp/metadata.inc # fake metadata is okay for this optimization
20+
RUN cd /tmp && yum-builddep -y swiftlang.spec
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Building Swift on Fedora Linux
2+
3+
4+
### building with docker-compose
5+
6+
* to run the build end-to-end
7+
8+
```
9+
docker-compose run build
10+
```
11+
12+
* to enter the docker env in shell mode
13+
14+
```
15+
docker-compose run shell
16+
```
17+
18+
then you can run `./build_rpm.sh` to run the build manually inside the docker
19+
20+
21+
* to rebuild the base image
22+
23+
```
24+
docker-compose build --pull
25+
```
26+
27+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
28+
29+
30+
### Open Issues / TODO
31+
* the list of build requirements (BuildRequires) and especially requirements (Requires) should come from an external file, likely one per swift release version (which we can use it to also drive documentation)

platforms/Linux/RPM/Fedora/35/build_rpm.sh

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
# Licensed under Apache License v2.0 with Runtime Library Exception
5+
#
6+
# See http://swift.org/LICENSE.txt for license information
7+
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
8+
19
#!/usr/bin/env bash
210

3-
# This script assumes it's running in a container as root
4-
# and that /out is mounted to a directory on the local
5-
# filesystem so the build output and artifacts can be
6-
# copied out and used
11+
set -ex
712

8-
OUTDIR=/out
9-
if [[ ! -d "$OUTDIR" ]]
10-
then
13+
OUTDIR=/output
14+
if [[ ! -d "$OUTDIR" ]]; then
1115
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
1216
exit 1
1317
fi
1418

15-
# Always make sure we're up to date
16-
yum -y update
19+
# always make sure we're up to date
20+
yum update -y
21+
22+
# prepare direcoties
23+
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
24+
25+
# Add the spec
26+
cp swiftlang.spec $HOME/rpmbuild/SPECS/
27+
# Add the metadata for this swift version
28+
cp /shared/metadata.inc $HOME/rpmbuild/SPECS/
29+
# Add any patches
30+
cp patches/*.patch $HOME/rpmbuild/SOURCES/
1731

32+
pushd $HOME/rpmbuild/SPECS
33+
# install all the dependencies needed to build Swift from the spec file itself
34+
yum-builddep -y ./swiftlang.spec
35+
# get the sources for Swift as defined in the spec file
36+
spectool -g -R ./swiftlang.spec
1837
# Now we proceed to build Swift. If this is successful, we
1938
# will have two files: a SRPM file which contains the source files
2039
# as well as a regular RPM file that can be installed via `dnf' or `yum'
21-
pushd $HOME/rpmbuild/SPECS
22-
rpmbuild -ba ./swiftlang.spec 2>&1 | tee $HOME/build-output.txt
40+
rpmbuild -ba ./swiftlang.spec 2>&1 | tee /root/build-output.txt
2341
popd
2442

2543
# Include the build log which can be used to determine what went

0 commit comments

Comments
 (0)