Skip to content

add amazon linux 2 RPM spec #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions platforms/Linux/amazonlinux/2/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.output
23 changes: 23 additions & 0 deletions platforms/Linux/amazonlinux/2/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

FROM amazonlinux:2
LABEL PURPOSE="This image is configured to build Swift for the version of Amazon Linux listed above"

RUN yum -y update

# RPM and yum development tools
RUN yum install -y rpmdevtools yum-utils

# Configure epel
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

# Optimization: Install all the dependencies needed to build Swift from the spec file itself
ADD swift-lang.spec /tmp/swift-lang.spec
RUN touch /tmp/metadata.inc # fake metadata is okay for this optimization
RUN cd /tmp && yum-builddep -y swift-lang.spec
31 changes: 31 additions & 0 deletions platforms/Linux/amazonlinux/2/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Building Swift on Amazon Linux


### building with docker-compose

* to run the build end-to-end

```
docker-compose run build
```

* to enter the docker env in shell mode

```
docker-compose run shell
```

then you can run `./build_rpm.sh` to run the build manually inside the docker


* to rebuild the base image

```
docker-compose build --pull
```

note this still uses the docker cache, so will rebuild only if the version of the underlying base image changed upstream


### Open Issues / TODO
* 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)
47 changes: 47 additions & 0 deletions platforms/Linux/amazonlinux/2/build_rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

#!/usr/bin/env bash

set -ex

OUTDIR=/output
if [[ ! -d "$OUTDIR" ]]; then
echo "$OUTDIR does not exist, so no place to copy the artifacts!"
exit 1
fi

# always make sure we're up to date
yum update -y

# prepare direcoties
mkdir -p $HOME/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}

# Add the spec
cp swift-lang.spec $HOME/rpmbuild/SPECS/
# Add the metadata for this swift version
cp /shared/metadata.inc $HOME/rpmbuild/SPECS/
# Add any patches
cp patches/*.patch $HOME/rpmbuild/SOURCES/

pushd $HOME/rpmbuild/SPECS
# install all the dependencies needed to build Swift from the spec file itself
yum-builddep -y ./swift-lang.spec
# get the sources for Swift as defined in the spec file
spectool -g -R ./swift-lang.spec
# Now we proceed to build Swift. If this is successful, we
# will have two files: a SRPM file which contains the source files
# as well as a regular RPM file that can be installed via `dnf' or `yum'
rpmbuild -ba ./swift-lang.spec 2>&1 | tee /root/build-output.txt
popd

# Include the build log which can be used to determine what went
# wrong if there are no artifacts
cp $HOME/build-output.txt $OUTDIR
cp $HOME/rpmbuild/SRPMS/* $OUTDIR
cp $HOME/rpmbuild/RPMS/`uname -i`/* $OUTDIR
43 changes: 43 additions & 0 deletions platforms/Linux/amazonlinux/2/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2021 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See http://swift.org/LICENSE.txt for license information
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors

# this setup is designed to build the RPM with docker
# usage:
# docker-compose -f platforms/Linux/amazonlinux/2/docker-compose.yaml build
# to shell into the container for debugging purposes:
# docker-compose -f platforms/Linux/amazonlinux/2/docker-compose.yaml run build

version: "2"

services:

docker-setup:
image: amazonlinux2-rpm-builder
build:
context: .
dockerfile: Dockerfile

common: &common
image: amazonlinux2-rpm-builder
depends_on: [docker-setup]
volumes:
- .:/code:z
- ../../shared/RPM:/shared:ro
- ./.output:/output:z
working_dir: /code
cap_drop:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE

build:
<<: *common
command: /bin/bash -cl "./build_rpm.sh"

shell:
<<: *common
entrypoint: /bin/bash -l
10 changes: 10 additions & 0 deletions platforms/Linux/amazonlinux/2/patches/hwasan_symbolize.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
diff --git a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
index dd5f859561e1..21d18998cf31 100755
--- a/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
+++ b/llvm-project/compiler-rt/lib/hwasan/scripts/hwasan_symbolize
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
#===- lib/hwasan/scripts/hwasan_symbolize ----------------------------------===#
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
diff --git a/swift/utils/api_checker/swift-api-checker.py b/swift/utils/api_checker/swift-api-checker.py
index 8ed16b4abf7..0b11a4bb83a 100755
--- a/swift/utils/api_checker/swift-api-checker.py
+++ b/swift/utils/api_checker/swift-api-checker.py
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3

from __future__ import print_function
159 changes: 159 additions & 0 deletions platforms/Linux/amazonlinux/2/swift-lang.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
%include metadata.inc

%global debug_package %{nil}

Name: %{package_name}
Version: %{package_version}
Release: 1%{?dist}
Summary: %{package_summary}
License: %{package_license}
URL: %{package_url}

Source0: https://github.com/apple/swift/archive/swift-%{swift_version}.tar.gz#/swift.tar.gz
Source1: https://github.com/apple/swift-corelibs-libdispatch/archive/swift-%{swift_version}.tar.gz#/corelibs-libdispatch.tar.gz
Source2: https://github.com/apple/swift-corelibs-foundation/archive/swift-%{swift_version}.tar.gz#/corelibs-foundation.tar.gz
Source3: https://github.com/apple/swift-integration-tests/archive/swift-%{swift_version}.tar.gz#/swift-integration-tests.tar.gz
Source4: https://github.com/apple/swift-corelibs-xctest/archive/swift-%{swift_version}.tar.gz#/corelibs-xctest.tar.gz
Source5: https://github.com/apple/swift-package-manager/archive/swift-%{swift_version}.tar.gz#/package-manager.tar.gz
Source6: https://github.com/apple/swift-llbuild/archive/swift-%{swift_version}.tar.gz#/llbuild.tar.gz
Source7: https://github.com/apple/swift-cmark/archive/swift-%{swift_version}.tar.gz#/cmark.tar.gz
Source8: https://github.com/apple/swift-xcode-playground-support/archive/swift-%{swift_version}.tar.gz#/swift-xcode-playground-support.tar.gz
Source9: https://github.com/apple/sourcekit-lsp/archive/swift-%{swift_version}.tar.gz#/sourcekit-lsp.tar.gz
Source10: https://github.com/apple/indexstore-db/archive/swift-%{swift_version}.tar.gz#/indexstore-db.tar.gz
Source11: https://github.com/apple/llvm-project/archive/swift-%{swift_version}.tar.gz#/llvm-project.tar.gz
Source12: https://github.com/apple/swift-tools-support-core/archive/swift-%{swift_version}.tar.gz#/swift-tools-support-core.tar.gz
Source13: https://github.com/apple/swift-argument-parser/archive/%{swift_argument_parser_version}.tar.gz#/swift-argument-parser.tar.gz
Source14: https://github.com/apple/swift-driver/archive/swift-%{swift_version}.tar.gz#/swift-driver.tar.gz
Source15: https://github.com/unicode-org/icu/archive/release-%{icu_version}.tar.gz#/icu.tar.gz
Source16: https://github.com/apple/swift-syntax/archive/swift-%{swift_version}.zip#/swift-syntax.tar.gz
Source17: https://github.com/jpsim/Yams/archive/%{yams_version}.zip#/yams.tar.gz
Source18: https://github.com/apple/swift-crypto/archive/refs/tags/%{swift_crypto_version}.tar.gz#/swift-crypto.tar.gz
Source19: https://github.com/ninja-build/ninja/archive/refs/tags/v%{ninja_version}.tar.gz#/ninja.tar.gz

Patch0: patches/swift-api-checker.patch
Patch1: patches/hwasan_symbolize.patch

BuildRequires: clang
BuildRequires: cmake
BuildRequires: curl-devel
BuildRequires: gcc-c++
BuildRequires: git
BuildRequires: glibc-static
BuildRequires: libbsd-devel
BuildRequires: libedit-devel
BuildRequires: libicu-devel
BuildRequires: libuuid-devel
BuildRequires: libxml2-devel
BuildRequires: ncurses-devel
BuildRequires: pexpect
BuildRequires: pkgconfig
BuildRequires: procps-ng
BuildRequires: python
BuildRequires: python-devel
BuildRequires: python-pkgconfig
BuildRequires: python-six
BuildRequires: python3-devel
BuildRequires: rsync
BuildRequires: sqlite-devel
BuildRequires: swig
BuildRequires: tzdata
BuildRequires: uuid-devel
BuildRequires: wget
BuildRequires: which

Requires: binutils
Requires: gcc
Requires: git
Requires: glibc-static
Requires: gzip
Requires: libbsd
Requires: libcurl
Requires: libedit
Requires: libicu
Requires: libsqlite
Requires: libstdc++-static
Requires: libuuid
Requires: libxml2
Requires: tar
Requires: tzdata

ExclusiveArch: x86_64 aarch64

%description
Swift is a general-purpose programming language built using
a modern approach to safety, performance, and software design
patterns.

The goal of the Swift project is to create the best available
language for uses ranging from systems programming, to mobile
and desktop apps, scaling up to cloud services. Most
importantly, Swift is designed to make writing and maintaining
correct programs easier for the developer.

%prep
%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
# The Swift build script requires directories to be named
# in a specific way so renaming the source directories is
# necessary
mv swift-cmark-swift-%{swift_version} cmark
mv swift-corelibs-foundation-swift-%{swift_version} swift-corelibs-foundation
mv swift-corelibs-libdispatch-swift-%{swift_version} swift-corelibs-libdispatch
mv swift-corelibs-xctest-swift-%{swift_version} swift-corelibs-xctest
mv swift-integration-tests-swift-%{swift_version} swift-integration-tests
mv swift-llbuild-swift-%{swift_version} llbuild
mv swift-package-manager-swift-%{swift_version} swiftpm
mv swift-swift-%{swift_version} swift
mv swift-xcode-playground-support-swift-%{swift_version} swift-xcode-playground-support
mv sourcekit-lsp-swift-%{swift_version} sourcekit-lsp
mv indexstore-db-swift-%{swift_version} indexstore-db
mv llvm-project-swift-%{swift_version} llvm-project
mv swift-syntax-swift-%{swift_version} swift-syntax
mv swift-tools-support-core-swift-%{swift_version} swift-tools-support-core
mv swift-argument-parser-%{swift_argument_parser_version} swift-argument-parser
mv swift-driver-swift-%{swift_version} swift-driver
mv swift-crypto-%{swift_crypto_version} swift-crypto
mv ninja-%{ninja_version} ninja

# ICU
mv icu-release-%{icu_version} icu

# Yams
mv Yams-%{yams_version} yams

# Adjust python version swift-api-checker
%patch0 -p1

# Adjust python version hwasan_symbolize
%patch1 -p1

# Fix python to python3
ln -s /usr/bin/python3 /usr/bin/python

%build
export VERBOSE=1

# Run the build
swift/utils/build-script --preset=buildbot_linux,no_test install_destdir=%{_builddir} installable_package=%{_builddir}/swift-%{version}-centos8.tar.gz

%install
mkdir -p %{buildroot}%{_libexecdir}/swift/
cp -r %{_builddir}/usr/* %{buildroot}%{_libexecdir}/swift
mkdir -p %{buildroot}%{_bindir}
ln -fs %{_libexecdir}/swift/bin/swift %{buildroot}%{_bindir}/swift
ln -fs %{_libexecdir}/swift/bin/swiftc %{buildroot}%{_bindir}/swiftc
ln -fs %{_libexecdir}/swift/bin/sourcekit-lsp %{buildroot}%{_bindir}/sourcekit-lsp
mkdir -p %{buildroot}%{_mandir}/man1
cp %{_builddir}/usr/share/man/man1/swift.1 %{buildroot}%{_mandir}/man1/swift.1

%files
%license swift/LICENSE.txt
%{_bindir}/swift
%{_bindir}/swiftc
%{_bindir}/sourcekit-lsp
%{_mandir}/man1/swift.1.gz
%{_libexecdir}/swift/

%post -p /sbin/ldconfig
%postun -p /sbin/ldconfig

%changelog