Skip to content

RPM build scripts for Amazon Linux 2023, x64, Swift 5.8 and 5.9 #278

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/Dockerfile-5.8
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# 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:2023
LABEL PURPOSE="This image is configured to build Swift for the version of Amazon Linux listed above"

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

# Compile ld.gold from the source and install it.
ADD install_ld.gold.sh /tmp/install_ld.gold.sh
RUN chmod u+x /tmp/install_ld.gold.sh
RUN cd tmp && ./install_ld.gold.sh

# Optimization: Install Swift build requirements listed in the spec file
ADD swiftlang.spec /tmp/swiftlang.spec

# rewrite a minimal spec with the build requirements
RUN echo -e "Name: optimization\nVersion: optimization\nRelease: optimization\nSummary: optimization\nLicense: optimization\n" > /tmp/optimization.spec
RUN cat /tmp/swiftlang.spec | grep BuildRequires >> /tmp/optimization.spec
RUN echo -e "\n%description" >> /tmp/optimization.spec
# install the build requirements
RUN cd /tmp && yum-builddep -y optimization.spec
34 changes: 34 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/Dockerfile-5.9
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# 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:2023
LABEL PURPOSE="This image is configured to build Swift for the version of Amazon Linux listed above"

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

# Compile ld.gold from the source and install it.
ADD install_ld.gold.sh /tmp/install_ld.gold.sh
RUN chmod u+x /tmp/install_ld.gold.sh
RUN cd tmp && ./install_ld.gold.sh

# Add Swift 5.8 (be sure to have the Swift tar.gz file)
# ADD a tar.gz files automatically decompresses and expands it
# TODO: replace with a download from Swift.org when it will be available
ADD swift-5.8-amazonlinux2023.tar.gz /
RUN swift --version

# Optimization: Install Swift build requirements listed in the spec file
ADD swiftlang.spec /tmp/swiftlang.spec

# rewrite a minimal spec with the build requirements
RUN echo -e "Name: optimization\nVersion: optimization\nRelease: optimization\nSummary: optimization\nLicense: optimization\n" > /tmp/optimization.spec
RUN cat /tmp/swiftlang.spec | grep BuildRequires >> /tmp/optimization.spec
RUN echo -e "\n%description" >> /tmp/optimization.spec
# install the build requirements
RUN cd /tmp && yum-builddep -y optimization.spec
59 changes: 59 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Building Swift on Amazon Linux 2023

## Install docker

```sh
sudo dnf install docker -y
sudo usermod -a -G docker ec2-user
sudo newgrp docker
sudo systemctl enable docker.service
sudo systemctl start docker.service
```

## Install docker compose v2

```sh
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
```

## Select the swift version to build

Create a symlink `swiftlang.spec -> swiftlang-VERSION.spec`

For example, to build Swift 5.9 :

```sh
SWIFT_VERSION=5.9
rm swiftlang.spec
ln -s swiftlang-${SWIFT)_VERSION}.spec swiftlang.spec
```

## Building with docker-compose

### run the build end-to-end

```sh
docker compose -f docker-compose-${SWIFT_VERSION}.yaml run build
```

### enter the docker env in shell mode

```sh
docker compose -f docker-compose-${SWIFT_VERSION}.yaml run shell
```

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

### rebuild the base image

```sh
docker compose -f docker-compose-${SWIFT_VERSION}.yaml 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)
1 change: 1 addition & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/build_rpm.sh
1 change: 1 addition & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/createrepo_rpm.sh
1 change: 1 addition & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/description.inc
47 changes: 47 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/docker-compose-5.8.yaml
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

# 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: "3"

services:

docker-setup:
image: amazonlinux-2023-rpm-builder-5.8
build:
context: .
dockerfile: Dockerfile-5.8

common: &common
image: amazonlinux-2023-rpm-builder-5.8
depends_on: [docker-setup]
volumes:
- ../../Amazonlinux/2023:/code/Amazonlinux/2023:z
- ../../Shared:/code/Shared:z
- ./.output:/output:z
working_dir: /code/Amazonlinux/2023
cap_drop:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE

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

createrepo:
<<: *common
command: /bin/bash -cl "./createrepo_rpm.sh"

shell:
<<: *common
entrypoint: /bin/bash -l
47 changes: 47 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/docker-compose-5.9.yaml
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

# 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: "3"

services:

docker-setup:
image: amazonlinux-2023-rpm-builder-5.9
build:
context: .
dockerfile: Dockerfile-5.9

common: &common
image: amazonlinux-2023-rpm-builder-5.9
depends_on: [docker-setup]
volumes:
- ../../Amazonlinux/2023:/code/Amazonlinux/2023:z
- ../../Shared:/code/Shared:z
- ./.output:/output:z
working_dir: /code/Amazonlinux/2023
cap_drop:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE

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

createrepo:
<<: *common
command: /bin/bash -cl "./createrepo_rpm.sh"

shell:
<<: *common
entrypoint: /bin/bash -l
25 changes: 25 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/global-5.8.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# versions

%global package_version 5.8
%global swift_version 5.8-RELEASE

%global cmake_version 3.19.6
%global icu_version 65-1
%global ninja_version 1.10.2
%global swift_argument_parser_version 1.0.3
%global swift_atomics_version 1.0.2
%global swift_collections_version 1.0.1
%global swift_crypto_version 2.2.3
%global swift_nio_ssl_version 2.15.0
%global swift_nio_version 2.31.2
%global swift_numerics_version 1.0.1
%global swift_system_version 1.1.1
%global yams_version 5.0.1

# locations

%global swift_source_location swift-source

# other

%global debug_package %{nil}
27 changes: 27 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/global-5.9.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# versions

%global package_version 5.9.1
%global swift_version 5.9.1-RELEASE

%global cmake_version 3.19.6
%global icu_version 65-1
%global ninja_version 1.10.2
%global swift_argument_parser_version 1.2.2
%global swift_atomics_version 1.0.2
%global swift_collections_version 1.0.1
%global swift_crypto_version 2.5.0
%global swift_nio_ssl_version 2.15.0
%global swift_nio_version 2.31.2
%global swift_numerics_version 1.0.1
%global swift_system_version 1.1.1
%global swift_asn1_version 0.7.0
%global swift_certificates_version 0.4.1
%global yams_version 5.0.1

# locations

%global swift_source_location swift-source

# other

%global debug_package %{nil}
1 change: 1 addition & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/global.inc
26 changes: 26 additions & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/install_ld.gold.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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

dnf install gmp-devel mpfr-devel texinfo bison git gcc-c++ -y

mkdir ld.gold && cd ld.gold
git clone --depth 1 git://sourceware.org/git/binutils-gdb.git binutils

mkdir build && cd build
../binutils/configure --enable-gold --enable-plugins --disable-werror
make all-gold
cd gold
make all-am
cd ..

cp gold/ld-new /usr/bin/ld.gold
cd ../..

/usr/bin/ld.gold -v
1 change: 1 addition & 0 deletions platforms/Linux/RPM/Amazonlinux/2023/metadata.inc
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,13 @@
diff --git a/llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp b/llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp
index 750b3c386753..fbf312908476 100644
--- a/llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/llvm-project/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -2143,7 +2143,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
static const char *const AArch64LibDirs[] = {"/lib64", "/lib"};
static const char *const AArch64Triples[] = {
"aarch64-none-linux-gnu", "aarch64-linux-gnu", "aarch64-redhat-linux",
- "aarch64-suse-linux"};
+ "aarch64-suse-linux", "aarch64-amazon-linux"};
static const char *const AArch64beLibDirs[] = {"/lib"};
static const char *const AArch64beTriples[] = {"aarch64_be-none-linux-gnu",
"aarch64_be-linux-gnu"};
Loading