Skip to content

Commit 09e5f9e

Browse files
committed
Initial commit of build instructions for Swift under Fedora Linux
1 parent 32876ac commit 09e5f9e

File tree

8 files changed

+1150
-0
lines changed

8 files changed

+1150
-0
lines changed

platforms/Linux/Fedora/Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM fedora:35
2+
LABEL PURPOSE="This image is configured to build Swift for the version of Fedora listed above"
3+
4+
WORKDIR /root
5+
6+
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
7+
ADD swift-lang.spec /root/rpmbuild/SPECS/swift-lang.spec
8+
ADD *.patch /root/rpmbuild/SOURCES
9+
10+
ADD build_swift_rpm.sh /root/build_swift_rpm.sh
11+
RUN chmod +x /root/build_swift_rpm.sh
12+
13+
RUN dnf -y update
14+
15+
# Required for the "rpmbuild" command
16+
RUN dnf install -y fedora-packager fedora-review
17+
18+
# Install all the dependencies needed to build Swift from the
19+
# spec file itself
20+
RUN dnf builddep -y /root/rpmbuild/SPECS/swift-lang.spec
21+
# And now get the sources for Swift as defined in the spec file
22+
RUN spectool -g -R /root/rpmbuild/SPECS/swift-lang.spec
23+
24+
CMD ["/root/build_swift_rpm.sh"]

platforms/Linux/Fedora/README.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
# Building Swift on Fedora Linux
3+
4+
## Introduction
5+
Fedora uses the [RPM package format](https://en.wikipedia.org/wiki/RPM_Package_Manager)
6+
to install software packages. The Swift RPM package can be built either by creating
7+
a Linux container image or manually.
8+
9+
## Files
10+
### `build_swift_rpm.sh`
11+
Builds the Swift RPM within a running container.
12+
### `Dockerfile`
13+
Builds the container image
14+
### `*.patch`
15+
Any post-release patches that have not yet been merged upstream that are
16+
temporarily necessary to build Swift.
17+
### `swift-lang.spec`
18+
The "recipe" the Fedora tools use to build Swift.
19+
20+
## Building Swift Via Linux Containers
21+
To build swift using containers, there are two steps, preparing the container image,
22+
and running the container.
23+
### Preparing the Container Image
24+
**Note**: These instructions assume you have either Docker or `podman` with
25+
`podman-docker` and `podman-compose` installed.
26+
1. Run `docker build -f ./Dockerfile -t swift-builder:5.5` This will create
27+
a new image with the name `swift-builder` and the tag `5.5`. Note that if
28+
using Docker, it may be necessary to prepend the command with `sudo`.
29+
2. Run `docker run -d -v$PWD:/out:Z swift-builder:5.5` The container will be
30+
created and automatically run `build_swift_rpm.sh`. After the container finishes
31+
building Swift, the artifacts will be placed in the current directory, along
32+
with `build-output.txt` which can be used for troubleshooting any build issues.
33+
34+
## Building Swift Locally
35+
Building Swift locally requires additional software to be installed in the local
36+
Fedora environment, requiring `sudo` permissions.
37+
### Installing the RPM tools on the local machine
38+
The following commands must be run to install the necessary software to build Swift
39+
locally
40+
1. `sudo dnf -y update`
41+
2. `sudo dnf install -y fedora-packager fedora-review`
42+
### Preparing to build Swift
43+
RPMs are built in the `$HOME/rpmbuild` directory, which has several subdirectories
44+
for specific purposes.
45+
1. `mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}`
46+
2. `cp swift-lang.spec $HOME/rpmbuild/SPECS`
47+
3. `cp *.patch $HOME/rpmbuild/SOURCES`
48+
#### Install all the dependencies necessary to build Swift:
49+
4. `sudo dnf builddep -y $HOME/rpmbuild/SPECS/swift-lang.spec`
50+
#### Download the Swift source tarballs:
51+
5. `spectool -g -R $HOME/rpmbuild/SPECS/swift-lang.spec`
52+
### Building Swift
53+
The RPM tools perform both building and packaging. _This process may take several
54+
hours depending on the hardware Fedora is running on._
55+
56+
`rpmbuild -ba $HOME/rpmbuild/SPECS/swift-lang.spec 2>&1 | tee $HOME/build-output.txt`
57+
58+
If there were no errors, the resulting Swift RPM file will be located in
59+
`$HOME/rpmbuild/RPMS/` in a subdirectory for the current processor architecture
60+
(e.g., `x86_64`).
61+
62+
## Installing Swift
63+
### Name format
64+
If Swift was built successfully there should
65+
be a file with the name format similar to `swift-lang-5.5-1.fc34.x86_64.rpm` where
66+
`5.5` is the version of Swift specified in `swift-lang.spec`, `fc34` is the version
67+
of Fedora that was used to build Swift, and `x86_64` is the processor architecture.
68+
69+
### Note about Fedora versions
70+
The Fedora version _must_ be the same as the one in the RPM file. In other words,
71+
a Swift RPM built for Fedora 34 can only be installed on Fedora 34.
72+
73+
### Installation
74+
To install the Swift RPM, change to the directory that contains the RPM file and
75+
run `sudo dnf install` _the Swift RPM file_ e.g.
76+
77+
`sudo dnf install ./swift-lang-5.5-1.fc34.x86_64.rpm`
78+
79+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
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
7+
8+
OUTDIR=/out
9+
if [[ ! -d "$OUTDIR" ]]
10+
then
11+
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
12+
exit 1
13+
fi
14+
15+
# Always make sure we're up to date
16+
dnf -y update
17+
18+
# Now we proceed to build Swift. If this is successful, we
19+
# will have two files: a SRPM file which contains the source files
20+
# as well as a regular RPM file that can be installed via `dnf' or `yum'
21+
pushd $HOME/rpmbuild/SPECS
22+
rpmbuild -ba ./swift-lang.spec 2>&1 | tee $HOME/build-output.txt
23+
popd
24+
25+
# Include the build log which can be used to determine what went
26+
# wrong if there are no artifacts
27+
cp $HOME/build-output.txt $OUTDIR
28+
cp $HOME/rpmbuild/SRPMS/* $OUTDIR
29+
cp $HOME/rpmbuild/RPMS/`uname -i`/* $OUTDIR
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
diff -Naur llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc
2+
--- llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 2021-05-28 10:17:04.000000000 -0500
3+
+++ llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors_ioctl.inc 2021-05-31 08:19:34.794058378 -0500
4+
@@ -370,15 +370,6 @@
5+
6+
#if SANITIZER_GLIBC
7+
// _(SIOCDEVPLIP, WRITE, struct_ifreq_sz); // the same as EQL_ENSLAVE
8+
- _(CYGETDEFTHRESH, WRITE, sizeof(int));
9+
- _(CYGETDEFTIMEOUT, WRITE, sizeof(int));
10+
- _(CYGETMON, WRITE, struct_cyclades_monitor_sz);
11+
- _(CYGETTHRESH, WRITE, sizeof(int));
12+
- _(CYGETTIMEOUT, WRITE, sizeof(int));
13+
- _(CYSETDEFTHRESH, NONE, 0);
14+
- _(CYSETDEFTIMEOUT, NONE, 0);
15+
- _(CYSETTHRESH, NONE, 0);
16+
- _(CYSETTIMEOUT, NONE, 0);
17+
_(EQL_EMANCIPATE, WRITE, struct_ifreq_sz);
18+
_(EQL_ENSLAVE, WRITE, struct_ifreq_sz);
19+
_(EQL_GETMASTRCFG, WRITE, struct_ifreq_sz);
20+
diff -Naur llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp
21+
--- llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp 2021-05-28 10:17:04.000000000 -0500
22+
+++ llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.cpp 2021-05-31 12:30:07.414710413 -0500
23+
@@ -143,7 +143,6 @@
24+
# include <sys/procfs.h>
25+
#endif
26+
#include <sys/user.h>
27+
-#include <linux/cyclades.h>
28+
#include <linux/if_eql.h>
29+
#include <linux/if_plip.h>
30+
#include <linux/lp.h>
31+
@@ -459,7 +458,6 @@
32+
33+
#if SANITIZER_GLIBC
34+
unsigned struct_ax25_parms_struct_sz = sizeof(struct ax25_parms_struct);
35+
- unsigned struct_cyclades_monitor_sz = sizeof(struct cyclades_monitor);
36+
#if EV_VERSION > (0x010000)
37+
unsigned struct_input_keymap_entry_sz = sizeof(struct input_keymap_entry);
38+
#else
39+
@@ -823,15 +821,6 @@
40+
#endif // SANITIZER_LINUX
41+
42+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
43+
- unsigned IOCTL_CYGETDEFTHRESH = CYGETDEFTHRESH;
44+
- unsigned IOCTL_CYGETDEFTIMEOUT = CYGETDEFTIMEOUT;
45+
- unsigned IOCTL_CYGETMON = CYGETMON;
46+
- unsigned IOCTL_CYGETTHRESH = CYGETTHRESH;
47+
- unsigned IOCTL_CYGETTIMEOUT = CYGETTIMEOUT;
48+
- unsigned IOCTL_CYSETDEFTHRESH = CYSETDEFTHRESH;
49+
- unsigned IOCTL_CYSETDEFTIMEOUT = CYSETDEFTIMEOUT;
50+
- unsigned IOCTL_CYSETTHRESH = CYSETTHRESH;
51+
- unsigned IOCTL_CYSETTIMEOUT = CYSETTIMEOUT;
52+
unsigned IOCTL_EQL_EMANCIPATE = EQL_EMANCIPATE;
53+
unsigned IOCTL_EQL_ENSLAVE = EQL_ENSLAVE;
54+
unsigned IOCTL_EQL_GETMASTRCFG = EQL_GETMASTRCFG;
55+
diff -Naur llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
56+
--- llvm-project-orig/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 2021-05-28 10:17:04.000000000 -0500
57+
+++ llvm-project/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h 2021-05-31 12:30:40.568693281 -0500
58+
@@ -983,7 +983,6 @@
59+
60+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
61+
extern unsigned struct_ax25_parms_struct_sz;
62+
-extern unsigned struct_cyclades_monitor_sz;
63+
extern unsigned struct_input_keymap_entry_sz;
64+
extern unsigned struct_ipx_config_data_sz;
65+
extern unsigned struct_kbdiacrs_sz;
66+
@@ -1328,15 +1327,6 @@
67+
#endif // SANITIZER_LINUX
68+
69+
#if SANITIZER_LINUX && !SANITIZER_ANDROID
70+
-extern unsigned IOCTL_CYGETDEFTHRESH;
71+
-extern unsigned IOCTL_CYGETDEFTIMEOUT;
72+
-extern unsigned IOCTL_CYGETMON;
73+
-extern unsigned IOCTL_CYGETTHRESH;
74+
-extern unsigned IOCTL_CYGETTIMEOUT;
75+
-extern unsigned IOCTL_CYSETDEFTHRESH;
76+
-extern unsigned IOCTL_CYSETDEFTIMEOUT;
77+
-extern unsigned IOCTL_CYSETTHRESH;
78+
-extern unsigned IOCTL_CYSETTIMEOUT;
79+
extern unsigned IOCTL_EQL_EMANCIPATE;
80+
extern unsigned IOCTL_EQL_ENSLAVE;
81+
extern unsigned IOCTL_EQL_GETMASTRCFG;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
From 14983644da3b8bbb32aa2823602e4161bf3e2ec9 Mon Sep 17 00:00:00 2001
2+
From: Dadoum <[email protected]>
3+
Date: Tue, 4 May 2021 01:06:34 +0200
4+
Subject: [PATCH] [PkgConfig] Cache PkgConfig and avoid reparsing multiple time
5+
the same file.
6+
7+
---
8+
swift-tools-support-core/Sources/TSCUtility/PkgConfig.swift | 31 ++++++++++++++++++------------
9+
1 file changed, 19 insertions(+), 12 deletions(-)
10+
11+
diff --git a/swift-tools-support-core/Sources/TSCUtility/PkgConfig.swift b/swift-tools-support-core/Sources/TSCUtility/PkgConfig.swift
12+
index 45d80995..558c81e7 100644
13+
--- a/swift-tools-support-core/Sources/TSCUtility/PkgConfig.swift
14+
+++ b/swift-tools-support-core/Sources/TSCUtility/PkgConfig.swift
15+
@@ -115,6 +115,8 @@ public class LoadingContext {
16+
17+
/// Information on an individual `pkg-config` supported package.
18+
public struct PkgConfig {
19+
+ public static var pkgConfigCache: [String: PkgConfig] = [String: PkgConfig]()
20+
+
21+
/// The name of the package.
22+
public let name: String
23+
24+
@@ -179,18 +181,23 @@ public struct PkgConfig {
25+
continue
26+
}
27+
28+
- // FIXME: This is wasteful, we should be caching the PkgConfig result.
29+
- let pkg = try PkgConfig(
30+
- name: dep,
31+
- additionalSearchPaths: additionalSearchPaths,
32+
- diagnostics: diagnostics,
33+
- fileSystem: fileSystem,
34+
- brewPrefix: brewPrefix,
35+
- loadingContext: loadingContext
36+
- )
37+
-
38+
- cFlags += pkg.cFlags
39+
- libs += pkg.libs
40+
+ if !PkgConfig.pkgConfigCache.keys.contains(dep) {
41+
+ PkgConfig.pkgConfigCache[dep] = try PkgConfig(
42+
+ name: dep,
43+
+ additionalSearchPaths: additionalSearchPaths,
44+
+ diagnostics: diagnostics,
45+
+ fileSystem: fileSystem,
46+
+ brewPrefix: brewPrefix,
47+
+ loadingContext: loadingContext
48+
+ )
49+
+ }
50+
+
51+
+ guard let cachedPkg = PkgConfig.pkgConfigCache[dep] else {
52+
+ fatalError("Cannot retrieve cached pkgConfig result")
53+
+ }
54+
+
55+
+ cFlags += cachedPkg.cFlags
56+
+ libs += cachedPkg.libs
57+
}
58+
59+
return (cFlags: cFlags, libs: libs)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff -Naur swift-orig/cmake/modules/AddSwift.cmake swift/cmake/modules/AddSwift.cmake
2+
--- swift-orig/cmake/modules/AddSwift.cmake 2021-01-11 09:24:03.000000000 -0600
3+
+++ swift/cmake/modules/AddSwift.cmake 2021-01-14 16:07:26.118061686 -0600
4+
@@ -288,7 +288,7 @@
5+
if(SWIFT_HOST_VARIANT_ARCH STREQUAL x86_64)
6+
# this is the minimum architecture that supports 16 byte CAS, which is
7+
# necessary to avoid a dependency to libatomic
8+
- target_compile_options(${target} PRIVATE -march=core2)
9+
+ target_compile_options(${target} PRIVATE -mcx16)
10+
endif()
11+
endif()
12+
13+
diff -Naur swift-orig/stdlib/cmake/modules/AddSwiftStdlib.cmake swift/stdlib/cmake/modules/AddSwiftStdlib.cmake
14+
--- swift-orig/stdlib/cmake/modules/AddSwiftStdlib.cmake 2021-01-11 09:24:03.000000000 -0600
15+
+++ swift/stdlib/cmake/modules/AddSwiftStdlib.cmake 2021-01-14 16:06:49.905752127 -0600
16+
@@ -306,7 +306,7 @@
17+
if("${CFLAGS_SDK}" STREQUAL "LINUX")
18+
if(${CFLAGS_ARCH} STREQUAL x86_64)
19+
# this is the minimum architecture that supports 16 byte CAS, which is necessary to avoid a dependency to libatomic
20+
- list(APPEND result "-march=core2")
21+
+ list(APPEND result "-mcx16")
22+
endif()
23+
endif()
24+
25+
diff -Naur swift-orig/utils/build-presets.ini swift/utils/build-presets.ini
26+
--- swift-orig/utils/build-presets.ini 2021-01-11 09:24:03.000000000 -0600
27+
+++ swift/utils/build-presets.ini 2021-01-14 15:42:31.063141040 -0600
28+
@@ -771,7 +771,6 @@
29+
libicu
30+
libcxx
31+
32+
-build-ninja
33+
install-llvm
34+
install-swift
35+
install-lldb
36+
@@ -787,10 +786,6 @@
37+
build-swift-static-sdk-overlay
38+
build-swift-stdlib-unittest-extra
39+
40+
-# Executes the lit tests for the installable package that is created
41+
-# Assumes the swift-integration-tests repo is checked out
42+
-
43+
-test-installable-package
44+
45+
# Build the benchmarks against the toolchain.
46+
toolchain-benchmarks

0 commit comments

Comments
 (0)