Skip to content

Commit

Permalink
Merge pull request swiftlang#27 from tomerd/centos8
Browse files Browse the repository at this point in the history
centos8 rpm spec
  • Loading branch information
shahmishal authored Oct 1, 2021
2 parents bc72365 + 7793556 commit 55a6039
Show file tree
Hide file tree
Showing 8 changed files with 294 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.out
32 changes: 32 additions & 0 deletions platforms/Linux/centos/8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM centos:8
LABEL PURPOSE="This image is configured to build Swift for the version of CentOS listed above"

WORKDIR /root

RUN yum -y update

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

# Configure powertools
RUN yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
RUN yum config-manager --set-enabled powertools

# Add the spec
RUN mkdir -p /root/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
ADD swift-lang.spec /root/rpmbuild/SPECS/swift-lang.spec

# Install all the dependencies needed to build Swift from the spec file itself
RUN yum-builddep -y /root/rpmbuild/SPECS/swift-lang.spec

# Get the sources for Swift as defined in the spec file
RUN spectool -g -R /root/rpmbuild/SPECS/swift-lang.spec

# Add the patches
ADD patches/*.patch /root/rpmbuild/SOURCES/

# Add the driver script
ADD build_rpm.sh /root/build_rpm.sh
RUN chmod +x /root/build_rpm.sh

CMD ["/root/build_rpm.sh"]
29 changes: 29 additions & 0 deletions platforms/Linux/centos/8/build_rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash

# This script assumes it's running in a container as root
# and that /out is mounted to a directory on the local
# filesystem so the build output and artifacts can be
# copied out and used

OUTDIR=/out
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

# 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'
pushd $HOME/rpmbuild/SPECS
rpmbuild -ba ./swift-lang.spec 2>&1 | tee $HOME/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
23 changes: 23 additions & 0 deletions platforms/Linux/centos/8/patches/build-presets.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

diff -Naur swift-orig/utils/build-presets.ini swift/utils/build-presets.ini
--- swift-orig/utils/build-presets.ini 2021-01-11 09:24:03.000000000 -0600
+++ swift/utils/build-presets.ini 2021-01-14 15:42:31.063141040 -0600
@@ -771,7 +771,6 @@
libicu
libcxx

-build-ninja
install-llvm
install-swift
install-lldb
@@ -787,10 +786,6 @@
build-swift-static-sdk-overlay
build-swift-stdlib-unittest-extra

-# Executes the lit tests for the installable package that is created
-# Assumes the swift-integration-tests repo is checked out
-
-test-installable-package

# Build the benchmarks against the toolchain.
toolchain-benchmarks
10 changes: 10 additions & 0 deletions platforms/Linux/centos/8/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.
9 changes: 9 additions & 0 deletions platforms/Linux/centos/8/patches/swift-api-checker.patch
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
23 changes: 23 additions & 0 deletions platforms/Linux/centos/8/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Building Swift on CentOS Linux


### building with docker


Build the builder docker image, this will download the sources

```
docker build . -t rpm-builder
```

Run the builder, this will run the build

```
docker run -v `pwd`/.out:/out rpm-builder
```


Open Issues / Introduction
* the swift release version should be an argument
* the versions of source packages are no pinned to the swift release version (eg yams) should come from an external file, likely one per swift release version
* 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)
167 changes: 167 additions & 0 deletions platforms/Linux/centos/8/swift-lang.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
%global debug_package %{nil}
%global swifttag 5.5-RELEASE
%global swiftbuild swift-source
%global icu_version 65-1
%global yams_version 4.0.2
%global sap_version 0.4.3
%global swift_crypto_version 1.1.5

Name: swift-lang
Version: 5.5
Release: 1%{?dist}
Summary: Apple's Swift programming language
License: ASL 2.0 and Unicode
URL: https://swift.org

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

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

BuildRequires: autoconf
BuildRequires: clang
BuildRequires: cmake
BuildRequires: diffutils
BuildRequires: git
BuildRequires: glibc-static
BuildRequires: libbsd-devel
BuildRequires: libcurl-devel
BuildRequires: libedit-devel
BuildRequires: libicu-devel
BuildRequires: libstdc++-static
BuildRequires: libtool
BuildRequires: libuuid-devel
BuildRequires: libxml2-devel
BuildRequires: make
BuildRequires: ncurses-devel
BuildRequires: ninja-build
BuildRequires: pcre-devel
BuildRequires: python2
BuildRequires: python2-devel
BuildRequires: python2-six
BuildRequires: python3
BuildRequires: python3-six
BuildRequires: python3-pexpect
BuildRequires: platform-python-devel
BuildRequires: sqlite-devel
BuildRequires: swig
BuildRequires: rsync
BuildRequires: tar
BuildRequires: which

Requires: binutils
Requires: gcc
Requires: git
Requires: glibc-static
Requires: libbsd-devel
Requires: libedit
Requires: libedit-devel
Requires: libicu-devel
Requires: libstdc++-static
Requires: pkg-config
Requires: python3
Requires: sqlite
Requires: zlib-devel

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

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

# Yams
mv Yams-%{yams_version} yams

# Adjust presets
%patch0 -p0

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

# Adjust python version hwasan_symbolize
%patch2 -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

0 comments on commit 55a6039

Please sign in to comment.