Skip to content

Commit aafbf38

Browse files
committed
add amazon linux 2 spec
motivation: support amazon linux 2 changes: add RPM spec file and supporting machinary for amazon linux 2
1 parent 2f62ecc commit aafbf38

File tree

10 files changed

+345
-0
lines changed

10 files changed

+345
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.output
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 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+
FROM amazonlinux:2
10+
LABEL PURPOSE="This image is configured to build Swift for the version of Amazon Linux listed above"
11+
12+
RUN yum -y update
13+
14+
# RPM and yum development tools
15+
RUN yum install -y rpmdevtools yum-utils
16+
17+
# Configure epel
18+
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
19+
20+
# Optimization: Install all the dependencies needed to build Swift from the spec file itself
21+
ADD swift-lang.spec /tmp/swift-lang.spec
22+
RUN touch /tmp/metadata.inc # fake metadata is okay for this optimization
23+
RUN cd /tmp && yum-builddep -y swift-lang.spec
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 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+
#!/usr/bin/env bash
10+
11+
set -ex
12+
13+
OUTDIR=/output
14+
if [[ ! -d "$OUTDIR" ]]; then
15+
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
16+
exit 1
17+
fi
18+
19+
SWIFT_VERSION=$1
20+
if [[ ! -n "$SWIFT_VERSION" ]]; then
21+
echo "unknown swift version, please pass as argument to the script"
22+
exit 1
23+
fi
24+
25+
# always make sure we're up to date
26+
yum update -y
27+
28+
# prepare direcoties
29+
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
30+
31+
# Add the spec
32+
cp swift-lang.spec $HOME/rpmbuild/SPECS/
33+
# Add the metadata for this swift version
34+
cp /metadata/$SWIFT_VERSION/metadata.inc $HOME/rpmbuild/SPECS/
35+
# Add any patches
36+
cp patches/*.patch $HOME/rpmbuild/SOURCES/
37+
38+
pushd $HOME/rpmbuild/SPECS
39+
# install all the dependencies needed to build Swift from the spec file itself
40+
yum-builddep -y ./swift-lang.spec
41+
# get the sources for Swift as defined in the spec file
42+
spectool -g -R ./swift-lang.spec
43+
# Now we proceed to build Swift. If this is successful, we
44+
# will have two files: a SRPM file which contains the source files
45+
# as well as a regular RPM file that can be installed via `dnf' or `yum'
46+
rpmbuild -ba ./swift-lang.spec 2>&1 | tee /root/build-output.txt
47+
popd
48+
49+
# Include the build log which can be used to determine what went
50+
# wrong if there are no artifacts
51+
cp $HOME/build-output.txt $OUTDIR
52+
cp $HOME/rpmbuild/SRPMS/* $OUTDIR
53+
cp $HOME/rpmbuild/RPMS/`uname -i`/* $OUTDIR
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This source file is part of the Swift.org open source project
2+
#
3+
# Copyright (c) 2021 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+
version: "3"
10+
11+
services:
12+
13+
docker-setup:
14+
image: amazonlinux2-rpm-builder
15+
build:
16+
context: .
17+
dockerfile: Dockerfile
18+
19+
common: &common
20+
image: amazonlinux2-rpm-builder
21+
depends_on: [docker-setup]
22+
volumes:
23+
- .:/code:z
24+
- ../../shared/metadata:/metadata:ro
25+
- ./.output:/output:z
26+
working_dir: /code
27+
cap_drop:
28+
- CAP_NET_RAW
29+
- CAP_NET_BIND_SERVICE
30+
environment:
31+
- SWIFT_VERSION # override this with environment variable
32+
33+
build:
34+
<<: *common
35+
command: /bin/bash -cl "./build_rpm.sh ${SWIFT_VERSION}"
36+
37+
shell:
38+
<<: *common
39+
entrypoint: /bin/bash -l
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
2+
index dd5f859561e1..21d18998cf31 100755
3+
--- a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
4+
+++ b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
5+
@@ -1,4 +1,4 @@
6+
-#!/usr/bin/env python
7+
+#!/usr/bin/env python3
8+
#===- lib/hwasan/scripts/hwasan_symbolize ----------------------------------===#
9+
#
10+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
diff --git a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
2+
index dd5f859561e1..21d18998cf31 100755
3+
--- a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
4+
+++ b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
5+
@@ -1,4 +1,4 @@
6+
-#!/usr/bin/env python
7+
+#!/usr/bin/env python3
8+
#===- lib/hwasan/scripts/hwasan_symbolize ----------------------------------===#
9+
#
10+
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/swift/utils/api_checker/swift-api-checker.py b/swift/utils/api_checker/swift-api-checker.py
2+
index 8ed16b4abf7..0b11a4bb83a 100755
3+
--- a/swift/utils/api_checker/swift-api-checker.py
4+
+++ b/swift/utils/api_checker/swift-api-checker.py
5+
@@ -1,4 +1,4 @@
6+
-#!/usr/bin/env python
7+
+#!/usr/bin/env python3
8+
9+
from __future__ import print_function
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Building Swift on Amazon Linux
2+
3+
4+
### building with docker-compose
5+
6+
* to run the build end-to-end
7+
8+
```
9+
export SWIFT_VERSION=...
10+
docker-compose run build
11+
```
12+
13+
* to enter the docker env in shell mode
14+
15+
```
16+
docker-compose run shell
17+
```
18+
19+
then you can run `./build_rpm.sh` to run the build manually inside the docker
20+
21+
22+
* to rebuild the base image
23+
24+
```
25+
docker-compose build --pull
26+
```
27+
28+
note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream
29+
30+
31+
### Open Issues / TODO
32+
* 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)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
diff --git a/swift/utils/api_checker/swift-api-checker.py b/swift/utils/api_checker/swift-api-checker.py
2+
index 8ed16b4abf7..0b11a4bb83a 100755
3+
--- a/swift/utils/api_checker/swift-api-checker.py
4+
+++ b/swift/utils/api_checker/swift-api-checker.py
5+
@@ -1,4 +1,4 @@
6+
-#!/usr/bin/env python
7+
+#!/usr/bin/env python3
8+
9+
from __future__ import print_function
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
%include metadata.inc
2+
3+
%global debug_package %{nil}
4+
5+
Name: %{package_name}
6+
Version: %{package_version}
7+
Release: 1%{?dist}
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#/swift-argument-parser.tar.gz
26+
Source14: https://github.com/apple/swift-driver/archive/swift-%{swift_version}.tar.gz#/swift-driver.tar.gz
27+
Source15: https://github.com/unicode-org/icu/archive/release-%{icu_version}.tar.gz#/icu.tar.gz
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
30+
Source18: https://github.com/apple/swift-crypto/archive/refs/tags/%{swift_crypto_version}.tar.gz#/swift-crypto.tar.gz
31+
Source19: https://github.com/ninja-build/ninja/archive/refs/tags/v%{ninja_version}.tar.gz#/ninja.tar.gz
32+
33+
Patch0: patches/swift-api-checker.patch
34+
Patch1: patches/hwasan_symbolize.patch
35+
36+
BuildRequires: clang
37+
BuildRequires: cmake
38+
BuildRequires: curl-devel
39+
BuildRequires: gcc-c++
40+
BuildRequires: git
41+
BuildRequires: glibc-static
42+
BuildRequires: libbsd-devel
43+
BuildRequires: libedit-devel
44+
BuildRequires: libicu-devel
45+
BuildRequires: libuuid-devel
46+
BuildRequires: libxml2-devel
47+
BuildRequires: ncurses-devel
48+
BuildRequires: pexpect
49+
BuildRequires: pkgconfig
50+
BuildRequires: procps-ng
51+
BuildRequires: python
52+
BuildRequires: python-devel
53+
BuildRequires: python-pkgconfig
54+
BuildRequires: python-six
55+
BuildRequires: python3-devel
56+
BuildRequires: rsync
57+
BuildRequires: sqlite-devel
58+
BuildRequires: swig
59+
BuildRequires: tzdata
60+
BuildRequires: uuid-devel
61+
BuildRequires: wget
62+
BuildRequires: which
63+
64+
Requires: binutils
65+
Requires: gcc
66+
Requires: git
67+
Requires: glibc-static
68+
Requires: gzip
69+
Requires: libbsd
70+
Requires: libcurl
71+
Requires: libedit
72+
Requires: libicu
73+
Requires: libsqlite
74+
Requires: libstdc++-static
75+
Requires: libuuid
76+
Requires: libxml2
77+
Requires: tar
78+
Requires: tzdata
79+
80+
ExclusiveArch: x86_64 aarch64
81+
82+
%description
83+
Swift is a general-purpose programming language built using
84+
a modern approach to safety, performance, and software design
85+
patterns.
86+
87+
The goal of the Swift project is to create the best available
88+
language for uses ranging from systems programming, to mobile
89+
and desktop apps, scaling up to cloud services. Most
90+
importantly, Swift is designed to make writing and maintaining
91+
correct programs easier for the developer.
92+
93+
%prep
94+
%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
95+
# The Swift build script requires directories to be named
96+
# in a specific way so renaming the source directories is
97+
# necessary
98+
mv swift-cmark-swift-%{swift_version} cmark
99+
mv swift-corelibs-foundation-swift-%{swift_version} swift-corelibs-foundation
100+
mv swift-corelibs-libdispatch-swift-%{swift_version} swift-corelibs-libdispatch
101+
mv swift-corelibs-xctest-swift-%{swift_version} swift-corelibs-xctest
102+
mv swift-integration-tests-swift-%{swift_version} swift-integration-tests
103+
mv swift-llbuild-swift-%{swift_version} llbuild
104+
mv swift-package-manager-swift-%{swift_version} swiftpm
105+
mv swift-swift-%{swift_version} swift
106+
mv swift-xcode-playground-support-swift-%{swift_version} swift-xcode-playground-support
107+
mv sourcekit-lsp-swift-%{swift_version} sourcekit-lsp
108+
mv indexstore-db-swift-%{swift_version} indexstore-db
109+
mv llvm-project-swift-%{swift_version} llvm-project
110+
mv swift-syntax-swift-%{swift_version} swift-syntax
111+
mv swift-tools-support-core-swift-%{swift_version} swift-tools-support-core
112+
mv swift-argument-parser-%{swift_argument_parser_version} swift-argument-parser
113+
mv swift-driver-swift-%{swift_version} swift-driver
114+
mv swift-crypto-%{swift_crypto_version} swift-crypto
115+
mv ninja-%{ninja_version} ninja
116+
117+
# ICU
118+
mv icu-release-%{icu_version} icu
119+
120+
# Yams
121+
mv Yams-%{yams_version} yams
122+
123+
# Adjust python version swift-api-checker
124+
%patch0 -p1
125+
126+
# Adjust python version hwasan_symbolize
127+
%patch1 -p1
128+
129+
# Fix python to python3
130+
ln -s /usr/bin/python3 /usr/bin/python
131+
132+
%build
133+
export VERBOSE=1
134+
135+
# Run the build
136+
swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-centos8.tar.gz
137+
138+
%install
139+
mkdir -p %{buildroot}%{_libexecdir}/swift/
140+
cp -r %{_builddir}/usr/* %{buildroot}%{_libexecdir}/swift
141+
mkdir -p %{buildroot}%{_bindir}
142+
ln -fs %{_libexecdir}/swift/bin/swift %{buildroot}%{_bindir}/swift
143+
ln -fs %{_libexecdir}/swift/bin/swiftc %{buildroot}%{_bindir}/swiftc
144+
ln -fs %{_libexecdir}/swift/bin/sourcekit-lsp %{buildroot}%{_bindir}/sourcekit-lsp
145+
mkdir -p %{buildroot}%{_mandir}/man1
146+
cp %{_builddir}/usr/share/man/man1/swift.1 %{buildroot}%{_mandir}/man1/swift.1
147+
148+
%files
149+
%license swift/LICENSE.txt
150+
%{_bindir}/swift
151+
%{_bindir}/swiftc
152+
%{_bindir}/sourcekit-lsp
153+
%{_mandir}/man1/swift.1.gz
154+
%{_libexecdir}/swift/
155+
156+
%post -p /sbin/ldconfig
157+
%postun -p /sbin/ldconfig
158+
159+
%changelog

0 commit comments

Comments
 (0)