diff --git a/platforms/Linux/centos/7/.dockerignore b/platforms/Linux/centos/7/.dockerignore new file mode 100644 index 00000000..16ff3c79 --- /dev/null +++ b/platforms/Linux/centos/7/.dockerignore @@ -0,0 +1 @@ +.output diff --git a/platforms/Linux/centos/7/Dockerfile b/platforms/Linux/centos/7/Dockerfile new file mode 100644 index 00000000..7b368bb8 --- /dev/null +++ b/platforms/Linux/centos/7/Dockerfile @@ -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 centos:7 +LABEL PURPOSE="This image is configured to build Swift for the version of CentOS listed above" + +RUN yum -y update + +# RPM and yum development tools +RUN yum install -y rpmdevtools yum-utils + +# Configure epel +RUN yum install -y epel-release centos-release-scl + +# 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 diff --git a/platforms/Linux/centos/7/README.md b/platforms/Linux/centos/7/README.md new file mode 100644 index 00000000..c658e2d5 --- /dev/null +++ b/platforms/Linux/centos/7/README.md @@ -0,0 +1,31 @@ +# Building Swift on CentOS 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) diff --git a/platforms/Linux/centos/7/build_rpm.sh b/platforms/Linux/centos/7/build_rpm.sh new file mode 100755 index 00000000..beec9ab2 --- /dev/null +++ b/platforms/Linux/centos/7/build_rpm.sh @@ -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 diff --git a/platforms/Linux/centos/7/docker-compose.yaml b/platforms/Linux/centos/7/docker-compose.yaml new file mode 100644 index 00000000..0c85651b --- /dev/null +++ b/platforms/Linux/centos/7/docker-compose.yaml @@ -0,0 +1,46 @@ +# 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/centos/7/docker-compose.yaml build +# to shell into the container for debugging purposes: +# docker-compose -f platforms/Linux/centos/7/docker-compose.yaml run build + +version: "2" + +services: + + docker-setup: + image: centos7-rpm-builder + build: + context: . + dockerfile: Dockerfile + + common: &common + image: centos7-rpm-builder + depends_on: [docker-setup] + # https://bugs.swift.org/browse/SR-15343 + security_opt: + - seccomp:unconfined + 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 diff --git a/platforms/Linux/centos/7/patches/hwasan_symbolize.patch b/platforms/Linux/centos/7/patches/hwasan_symbolize.patch new file mode 100644 index 00000000..3f323825 --- /dev/null +++ b/platforms/Linux/centos/7/patches/hwasan_symbolize.patch @@ -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. diff --git a/platforms/Linux/centos/7/patches/swift-api-checker.patch b/platforms/Linux/centos/7/patches/swift-api-checker.patch new file mode 100644 index 00000000..b087ef09 --- /dev/null +++ b/platforms/Linux/centos/7/patches/swift-api-checker.patch @@ -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 diff --git a/platforms/Linux/centos/7/swift-lang.spec b/platforms/Linux/centos/7/swift-lang.spec new file mode 100644 index 00000000..bfdcae70 --- /dev/null +++ b/platforms/Linux/centos/7/swift-lang.spec @@ -0,0 +1,160 @@ +%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: autoconf +BuildRequires: cmake +BuildRequires: devtoolset-8 +BuildRequires: glibc-static +BuildRequires: libatomic +BuildRequires: libcurl-devel +BuildRequires: libedit-devel +BuildRequires: libstdc++-static +BuildRequires: libtool +BuildRequires: libuuid-devel +BuildRequires: libxml2-devel +BuildRequires: llvm-toolset-7 +BuildRequires: make +BuildRequires: ncurses-devel +BuildRequires: ninja-build +BuildRequires: openssl-devel +BuildRequires: pexpect +BuildRequires: python-devel +BuildRequires: python3-devel +BuildRequires: python-pygments +BuildRequires: python-six +BuildRequires: python36-pexpect +BuildRequires: python36-six +BuildRequires: PyYAML +BuildRequires: rsync +BuildRequires: sclo-git25-git +BuildRequires: sqlite-devel +BuildRequires: swig3 +BuildRequires: which +BuildRequires: zlib-devel + +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 %{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