Skip to content

Commit 9363e6b

Browse files
authored
Merge pull request swiftlang#38 from tomerd/amazonlinux2
add amazon linux 2 RPM spec
2 parents ff823a6 + ca79b9b commit 9363e6b

File tree

8 files changed

+323
-0
lines changed

8 files changed

+323
-0
lines changed

Diff for: platforms/Linux/amazonlinux/2/.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.output

Diff for: platforms/Linux/amazonlinux/2/Dockerfile

+23
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

Diff for: platforms/Linux/amazonlinux/2/README.md

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
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)

Diff for: platforms/Linux/amazonlinux/2/build_rpm.sh

+47
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) 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+
# 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 swift-lang.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/
31+
32+
pushd $HOME/rpmbuild/SPECS
33+
# install all the dependencies needed to build Swift from the spec file itself
34+
yum-builddep -y ./swift-lang.spec
35+
# get the sources for Swift as defined in the spec file
36+
spectool -g -R ./swift-lang.spec
37+
# Now we proceed to build Swift. If this is successful, we
38+
# will have two files: a SRPM file which contains the source files
39+
# as well as a regular RPM file that can be installed via `dnf' or `yum'
40+
rpmbuild -ba ./swift-lang.spec 2>&1 | tee /root/build-output.txt
41+
popd
42+
43+
# Include the build log which can be used to determine what went
44+
# wrong if there are no artifacts
45+
cp $HOME/build-output.txt $OUTDIR
46+
cp $HOME/rpmbuild/SRPMS/* $OUTDIR
47+
cp $HOME/rpmbuild/RPMS/`uname -i`/* $OUTDIR

Diff for: platforms/Linux/amazonlinux/2/docker-compose.yaml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
# this setup is designed to build the RPM with docker
10+
# usage:
11+
# docker-compose -f platforms/Linux/amazonlinux/2/docker-compose.yaml build
12+
# to shell into the container for debugging purposes:
13+
# docker-compose -f platforms/Linux/amazonlinux/2/docker-compose.yaml run build
14+
15+
version: "2"
16+
17+
services:
18+
19+
docker-setup:
20+
image: amazonlinux2-rpm-builder
21+
build:
22+
context: .
23+
dockerfile: Dockerfile
24+
25+
common: &common
26+
image: amazonlinux2-rpm-builder
27+
depends_on: [docker-setup]
28+
volumes:
29+
- .:/code:z
30+
- ../../shared/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+
shell:
42+
<<: *common
43+
entrypoint: /bin/bash -l
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.
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

Diff for: platforms/Linux/amazonlinux/2/swift-lang.spec

+159
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)