Skip to content

Commit 4b4f3fd

Browse files
authored
update fedora setup to follow conventions of other RPM builders (swiftlang#82)
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 01e4f7b commit 4b4f3fd

27 files changed

+322
-277
lines changed
+18-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
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-
29-
30-
CMD ["/root/build_rpm.sh"]
15+
RUN yum install -y rpmdevtools yum-utils createrepo
16+
17+
# Optimization: Install Swift build requirements listed in the spec file
18+
ADD swiftlang.spec /tmp/swiftlang.spec
19+
# rewrite a minimal spec with the build requirements
20+
RUN echo -e "Name: optimization\nVersion: optimization\nRelease: optimization\nSummary: optimization\nLicense: optimization\n" > /tmp/optimization.spec
21+
RUN cat /tmp/swiftlang.spec | grep BuildRequires >> /tmp/optimization.spec
22+
RUN echo -e "\n%description" >> /tmp/optimization.spec
23+
# install the build requirements
24+
RUN cd /tmp && yum-builddep -y optimization.spec
+31
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

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/scripts/build_rpm.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/scripts/createrepo_rpm.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/metadata/description.inc
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+
- ../../Fedora/34:/code/Fedora/34:z
30+
- ../../Shared:/code/Shared:z
31+
- ./.output:/output:z
32+
working_dir: /code/Fedora/34
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 "./createrepo_rpm.sh"
44+
45+
shell:
46+
<<: *common
47+
entrypoint: /bin/bash -l
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/metadata/global.inc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/metadata/metadata.inc

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

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,5 @@
1-
%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
20-
Version: %{package_version}
21-
Release: 1%{?dist}
22-
Summary: The Swift programming language
23-
License: Apache 2.0
24-
URL: https://www.swift.org
1+
%include global.inc
2+
%include metadata.inc
253

264
Source0: https://github.com/apple/swift/archive/swift-%{swift_version}.tar.gz#/swift.tar.gz
275
Source1: https://github.com/apple/swift-corelibs-libdispatch/archive/swift-%{swift_version}.tar.gz#/corelibs-libdispatch.tar.gz
@@ -91,21 +69,12 @@ Requires: ncurses-devel
9169

9270
ExclusiveArch: x86_64 aarch64
9371

94-
Provides: swiftlang = %{version}-%{release}
95-
9672
%description
97-
Swift is a general-purpose programming language built using
98-
a modern approach to safety, performance, and software design
99-
patterns.
100-
101-
The goal of the Swift project is to create the best available
102-
language for uses ranging from systems programming, to mobile
103-
and desktop apps, scaling up to cloud services. Most
104-
importantly, Swift is designed to make writing and maintaining
105-
correct programs easier for the developer.
73+
%include description.inc
10674

10775
%prep
10876
%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
77+
10978
# The Swift build script requires directories to be named
11079
# in a specific way so renaming the source directories is
11180
# necessary
@@ -114,7 +83,6 @@ mv icu-release-%{icu_version} icu
11483
mv indexstore-db-swift-%{swift_version} indexstore-db
11584
mv llvm-project-swift-%{swift_version} llvm-project
11685
mv ninja-%{ninja_version} ninja
117-
mv ninja-%{ninja_version} ninja
11886
mv sourcekit-lsp-swift-%{swift_version} sourcekit-lsp
11987
mv swift-argument-parser-%{swift_argument_parser_version} swift-argument-parser
12088
mv swift-atomics-%{swift_atomics_version} swift-atomics
@@ -165,8 +133,8 @@ ln -s /usr/bin/python3 $PWD/binforpython/python
165133
export PATH=$PWD/binforpython:$PATH
166134
%endif
167135

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
136+
# Run the build
137+
swift/utils/build-script --preset=buildbot_linux,no_assertions,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-fedora-34.tar.gz
170138

171139
%install
172140
mkdir -p %{buildroot}%{_libexecdir}/swift/%{package_version}
+18-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,24 @@
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-
29-
30-
CMD ["/root/build_rpm.sh"]
15+
RUN yum install -y rpmdevtools yum-utils createrepo
16+
17+
# Optimization: Install Swift build requirements listed in the spec file
18+
ADD swiftlang.spec /tmp/swiftlang.spec
19+
# rewrite a minimal spec with the build requirements
20+
RUN echo -e "Name: optimization\nVersion: optimization\nRelease: optimization\nSummary: optimization\nLicense: optimization\n" > /tmp/optimization.spec
21+
RUN cat /tmp/swiftlang.spec | grep BuildRequires >> /tmp/optimization.spec
22+
RUN echo -e "\n%description" >> /tmp/optimization.spec
23+
# install the build requirements
24+
RUN cd /tmp && yum-builddep -y optimization.spec
+31
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

-29
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/scripts/build_rpm.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/scripts/createrepo_rpm.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../Shared/metadata/description.inc

0 commit comments

Comments
 (0)