Skip to content

Commit da76aee

Browse files
committed
update fedora setup to use docke copose and follow conventions of other RPM builders
motivation: consistentcy across RPM builders changes: * add docker-compose setup * update rpmspec to use share metadata * update rpmspec to download cmake and not rely on the one that ships with the distro * other minor formatting adjustments to make rpmspec consistent with other rpmspecs * update Dockerfil to use updated rpmspec * update build script to use updated docker file and rpmspect * add readme
1 parent 6fded1b commit da76aee

File tree

15 files changed

+545
-343
lines changed

15 files changed

+545
-343
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
Lines changed: 60 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,39 @@
1+
%include metadata.inc
2+
13
%global debug_package %{nil}
2-
%global linux_version fedora
3-
%global swifttag 5.5.3-RELEASE
4-
%global swiftbuild swift-source
5-
%global icu_version 65-1
6-
%global yams_version 4.0.2
7-
%global sap_version 0.4.3
8-
%global swift_crypto_version 1.1.5
9-
%global ninja_version 1.10.2
10-
%global package_version 5.5.3
11-
12-
Name: swiftlang
13-
Version: 5.5.3
4+
5+
Name: %{package_name}
6+
Version: %{package_version}
147
Release: 1%{?dist}
15-
Summary: The Swift programming language
16-
License: Apache 2.0
17-
URL: https://www.swift.org
18-
19-
Source0: https://github.com/apple/swift/archive/swift-%{swifttag}.tar.gz#/swift.tar.gz
20-
Source1: https://github.com/apple/swift-corelibs-libdispatch/archive/swift-%{swifttag}.tar.gz#/corelibs-libdispatch.tar.gz
21-
Source2: https://github.com/apple/swift-corelibs-foundation/archive/swift-%{swifttag}.tar.gz#/corelibs-foundation.tar.gz
22-
Source3: https://github.com/apple/swift-integration-tests/archive/swift-%{swifttag}.tar.gz#/swift-integration-tests.tar.gz
23-
Source4: https://github.com/apple/swift-corelibs-xctest/archive/swift-%{swifttag}.tar.gz#/corelibs-xctest.tar.gz
24-
Source5: https://github.com/apple/swift-package-manager/archive/swift-%{swifttag}.tar.gz#/package-manager.tar.gz
25-
Source6: https://github.com/apple/swift-llbuild/archive/swift-%{swifttag}.tar.gz#/llbuild.tar.gz
26-
Source7: https://github.com/apple/swift-cmark/archive/swift-%{swifttag}.tar.gz#/cmark.tar.gz
27-
Source8: https://github.com/apple/swift-xcode-playground-support/archive/swift-%{swifttag}.tar.gz#/swift-xcode-playground-support.tar.gz
28-
Source9: https://github.com/apple/sourcekit-lsp/archive/swift-%{swifttag}.tar.gz#/sourcekit-lsp.tar.gz
29-
Source10: https://github.com/apple/indexstore-db/archive/swift-%{swifttag}.tar.gz#/indexstore-db.tar.gz
30-
Source11: https://github.com/apple/llvm-project/archive/swift-%{swifttag}.tar.gz#/llvm-project.tar.gz
31-
Source12: https://github.com/apple/swift-tools-support-core/archive/swift-%{swifttag}.tar.gz#/swift-tools-support-core.tar.gz
32-
Source13: https://github.com/apple/swift-argument-parser/archive/%{sap_version}.tar.gz
33-
Source14: https://github.com/apple/swift-driver/archive/swift-%{swifttag}.tar.gz#/swift-driver.tar.gz
8+
Summary: %{package_summary}
9+
License: %{package_license}
10+
URL: %{package_url}
11+
12+
Source0: https://github.com/apple/swift/archive/swift-%{swift_version}.tar.gz#/swift.tar.gz
13+
Source1: https://github.com/apple/swift-corelibs-libdispatch/archive/swift-%{swift_version}.tar.gz#/corelibs-libdispatch.tar.gz
14+
Source2: https://github.com/apple/swift-corelibs-foundation/archive/swift-%{swift_version}.tar.gz#/corelibs-foundation.tar.gz
15+
Source3: https://github.com/apple/swift-integration-tests/archive/swift-%{swift_version}.tar.gz#/swift-integration-tests.tar.gz
16+
Source4: https://github.com/apple/swift-corelibs-xctest/archive/swift-%{swift_version}.tar.gz#/corelibs-xctest.tar.gz
17+
Source5: https://github.com/apple/swift-package-manager/archive/swift-%{swift_version}.tar.gz#/package-manager.tar.gz
18+
Source6: https://github.com/apple/swift-llbuild/archive/swift-%{swift_version}.tar.gz#/llbuild.tar.gz
19+
Source7: https://github.com/apple/swift-cmark/archive/swift-%{swift_version}.tar.gz#/cmark.tar.gz
20+
Source8: https://github.com/apple/swift-xcode-playground-support/archive/swift-%{swift_version}.tar.gz#/swift-xcode-playground-support.tar.gz
21+
Source9: https://github.com/apple/sourcekit-lsp/archive/swift-%{swift_version}.tar.gz#/sourcekit-lsp.tar.gz
22+
Source10: https://github.com/apple/indexstore-db/archive/swift-%{swift_version}.tar.gz#/indexstore-db.tar.gz
23+
Source11: https://github.com/apple/llvm-project/archive/swift-%{swift_version}.tar.gz#/llvm-project.tar.gz
24+
Source12: https://github.com/apple/swift-tools-support-core/archive/swift-%{swift_version}.tar.gz#/swift-tools-support-core.tar.gz
25+
Source13: https://github.com/apple/swift-argument-parser/archive/%{swift_argument_parser_version}.tar.gz
26+
Source14: https://github.com/apple/swift-driver/archive/swift-%{swift_version}.tar.gz#/swift-driver.tar.gz
3427
Source15: https://github.com/unicode-org/icu/archive/release-%{icu_version}.tar.gz
35-
Source16: https://github.com/apple/swift-syntax/archive/swift-%{swifttag}.zip#/swift-syntax.tar.gz
36-
Source17: https://github.com/jpsim/Yams/archive/%{yams_version}.zip
28+
Source16: https://github.com/apple/swift-syntax/archive/swift-%{swift_version}.zip#/swift-syntax.tar.gz
29+
Source17: https://github.com/jpsim/Yams/archive/%{yams_version}.zip#/yams.tar.gz
3730
Source18: https://github.com/apple/swift-crypto/archive/refs/tags/%{swift_crypto_version}.tar.gz
3831
Source19: https://github.com/ninja-build/ninja/archive/refs/tags/v%{ninja_version}.tar.gz#/ninja.tar.gz
32+
Source20: https://github.com/KitWare/CMake/archive/refs/tags/v%{cmake_version}.tar.gz#/cmake.tar.gz
3933

4034
Patch0: nocyclades.patch
41-
Patch1: unusedvariable.patch
42-
35+
Patch1: unusedvariable.patch
36+
4337
BuildRequires: clang
4438
BuildRequires: swig
4539
BuildRequires: rsync
@@ -69,78 +63,68 @@ Requires: gcc
6963
Requires: ncurses-devel
7064
Requires: ncurses-compat-libs
7165

72-
ExclusiveArch: x86_64 aarch64
73-
74-
Provides: swiftlang = %{version}-%{release}
66+
ExclusiveArch: x86_64 aarch64
7567

7668
%description
77-
Swift is a general-purpose programming language built using
78-
a modern approach to safety, performance, and software design
69+
Swift is a general-purpose programming language built using
70+
a modern approach to safety, performance, and software design
7971
patterns.
8072

81-
The goal of the Swift project is to create the best available
82-
language for uses ranging from systems programming, to mobile
83-
and desktop apps, scaling up to cloud services. Most
84-
importantly, Swift is designed to make writing and maintaining
85-
correct programs easier for the developer.
86-
73+
The goal of the Swift project is to create the best available
74+
language for uses ranging from systems programming, to mobile
75+
and desktop apps, scaling up to cloud services. Most
76+
importantly, Swift is designed to make writing and maintaining
77+
correct programs easier for the developer.
8778

8879
%prep
89-
%setup -q -c -n %{swiftbuild} -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
80+
%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
9081
# The Swift build script requires directories to be named
9182
# in a specific way so renaming the source directories is
9283
# necessary
93-
mv swift-cmark-swift-%{swifttag} cmark
94-
mv swift-corelibs-foundation-swift-%{swifttag} swift-corelibs-foundation
95-
mv swift-corelibs-libdispatch-swift-%{swifttag} swift-corelibs-libdispatch
96-
mv swift-corelibs-xctest-swift-%{swifttag} swift-corelibs-xctest
97-
mv swift-integration-tests-swift-%{swifttag} swift-integration-tests
98-
mv swift-llbuild-swift-%{swifttag} llbuild
99-
mv swift-package-manager-swift-%{swifttag} swiftpm
100-
mv swift-swift-%{swifttag} swift
101-
mv swift-xcode-playground-support-swift-%{swifttag} swift-xcode-playground-support
102-
mv sourcekit-lsp-swift-%{swifttag} sourcekit-lsp
103-
mv indexstore-db-swift-%{swifttag} indexstore-db
104-
mv llvm-project-swift-%{swifttag} llvm-project
105-
mv swift-syntax-swift-%{swifttag} swift-syntax
106-
mv swift-tools-support-core-swift-%{swifttag} swift-tools-support-core
107-
mv swift-argument-parser-%{sap_version} swift-argument-parser
108-
mv swift-driver-swift-%{swifttag} swift-driver
84+
mv swift-cmark-swift-%{swift_version} cmark
85+
mv swift-corelibs-foundation-swift-%{swift_version} swift-corelibs-foundation
86+
mv swift-corelibs-libdispatch-swift-%{swift_version} swift-corelibs-libdispatch
87+
mv swift-corelibs-xctest-swift-%{swift_version} swift-corelibs-xctest
88+
mv swift-integration-tests-swift-%{swift_version} swift-integration-tests
89+
mv swift-llbuild-swift-%{swift_version} llbuild
90+
mv swift-package-manager-swift-%{swift_version} swiftpm
91+
mv swift-swift-%{swift_version} swift
92+
mv swift-xcode-playground-support-swift-%{swift_version} swift-xcode-playground-support
93+
mv sourcekit-lsp-swift-%{swift_version} sourcekit-lsp
94+
mv indexstore-db-swift-%{swift_version} indexstore-db
95+
mv llvm-project-swift-%{swift_version} llvm-project
96+
mv swift-syntax-swift-%{swift_version} swift-syntax
97+
mv swift-tools-support-core-swift-%{swift_version} swift-tools-support-core
98+
mv swift-argument-parser-%{swift_argument_parser_version} swift-argument-parser
99+
mv swift-driver-swift-%{swift_version} swift-driver
109100
mv swift-crypto-%{swift_crypto_version} swift-crypto
110-
111-
# ICU
101+
mv ninja-%{ninja_version} ninja
102+
mv CMake-%{cmake_version} cmake
112103
mv icu-release-%{icu_version} icu
113-
114-
# Yams
115104
mv Yams-%{yams_version} yams
116105

117-
# Ninja
118-
mv ninja-%{ninja_version} ninja
119-
120106
# Remove Cyclades as it has been removed from the Linux kernel
121107
%patch0 -p0
122108

123109
# Temp patch to test libdispatch issue with clang 13
124110
%patch1 -p0
125111

126-
# Fix python to python3
112+
# Fix python to python3
127113
pathfix.py -pni "%{__python3} %{py3_shbang_opts}" swift/utils/api_checker/swift-api-checker.py
128114
pathfix.py -pni "%{__python3} %{py3_shbang_opts}" llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
129115

130-
131116
%build
132117
export VERBOSE=1
133-
# Before Fedora 34, we may not have /usr/bin/python, so we
118+
# Before Fedora 34, we may not have /usr/bin/python, so we
134119
# roll our own because the build script expects there to be one.
135120
%if 0%{?fedora} < 34 || 0%{?el8}
136121
mkdir $PWD/binforpython
137122
ln -s /usr/bin/python3 $PWD/binforpython/python
138123
export PATH=$PWD/binforpython:$PATH
139124
%endif
140125

141-
# Here we go!
142-
swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-%{linux_version}.tar.gz
143-
126+
# Run the build
127+
swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-fedora-34.tar.gz
144128

145129
%install
146130
mkdir -p %{buildroot}%{_libexecdir}/swift/%{package_version}
@@ -156,7 +140,6 @@ cp %{_builddir}/usr/share/man/man1/swift.1 %{buildroot}%{_mandir}/man1/swift.1
156140
# how the Swift binaries use RPATH
157141
export QA_SKIP_RPATHS=1
158142

159-
160143
%files
161144
%license swift/LICENSE.txt
162145
%{_bindir}/swift
@@ -165,9 +148,7 @@ export QA_SKIP_RPATHS=1
165148
%{_mandir}/man1/swift.1.gz
166149
%{_libexecdir}/swift/
167150

168-
169151
%post -p /sbin/ldconfig
170152
%postun -p /sbin/ldconfig
171153

172-
173154
%changelog

0 commit comments

Comments
 (0)