Skip to content

[Static Linux] Add build scripts. #389

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 1 commit into from
Jun 4, 2024
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
97 changes: 97 additions & 0 deletions swift-ci/sdks/static-linux/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# ===----------------------------------------------------------------------===
#
# Swift Static SDK for Linux: Docker-based build
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

FROM ubuntu:22.04

# Versions to fetch

ARG SWIFT_VERSION=scheme:release/6.0
ARG MUSL_VERSION=1.2.5
ARG LIBXML2_VERSION=2.12.7
ARG CURL_VERSION=8.7.1
ARG BORINGSSL_VERSION=fips-20220613
ARG ICU_VERSION=maint/maint-69
ARG ZLIB_VERSION=1.3.1

# ............................................................................

# Install development tools
RUN apt-get -q update \
&& DEBIAN_FRONTEND=noninteractive apt-get -q install -y \
build-essential \
cmake \
ninja-build \
python3 \
golang \
git \
gnupg2 \
libsqlite3-dev \
libcurl4-openssl-dev \
libedit-dev \
libicu-dev \
libncurses5-dev \
libpython3-dev \
libsqlite3-dev \
libxml2-dev \
uuid-dev \
uuid-runtime \
tzdata \
curl \
&& rm -rf /var/lib/apt-lists/*

# Install Swift
ARG SWIFT_SIGNING_KEY=E813C892820A6FA13755B268F167DF1ACF9CE069
ARG SWIFT_PLATFORM=ubuntu
ARG OS_MAJOR_VER=22
ARG OS_MINOR_VER=04
ARG SWIFT_WEBROOT=https://download.swift.org/swift-6.0-branch

ENV SWIFT_SIGNING_KEY=$SWIFT_SIGNING_KEY \
SWIFT_PLATFORM=$SWIFT_PLATFORM \
OS_MAJOR_VER=$OS_MAJOR_VER \
OS_MINOR_VER=$OS_MINOR_VER \
OS_VER=$SWIFT_PLATFORM$OS_MAJOR_VER.$OS_MINOR_VER \
SWIFT_WEBROOT="$SWIFT_WEBROOT/$SWIFT_PLATFORM$OS_MAJOR_VER$OS_MINOR_VER"

COPY scripts/install-swift.sh /scripts/install-swift.sh
RUN chmod ugo+x /scripts/install-swift.sh

RUN /scripts/install-swift.sh

ENV PATH="/usr/local/swift/bin:${PATH}"

ENV SWIFT_VERSION=$SWIFT_VERSION \
MUSL_VERSION=$MUSL_VERSION \
LIBXML2_VERSION=$LIBXML2_VERSION \
CURL_VERSION=$CURL_VERSION \
BORINGSSL_VERSION=$BORINGSSL_VERSION \
ICU_VERSION=$ICU_VERSION \
ZLIB_VERSION=$ZLIB_VERSION

COPY scripts /scripts
RUN chmod ugo+x /scripts/*

COPY resources /resources

# Create a user
RUN groupadd -g 998 build-user && \
useradd -m -r -u 998 -g build-user build-user

USER build-user

WORKDIR /home/build-user




33 changes: 33 additions & 0 deletions swift-ci/sdks/static-linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Dockerfile-based build for Swift Static Linux SDK

## What is this?

This is a Dockerfile-based build set-up for the Swift Static Linux SDK.

To use it, you need to build the Docker image with

```shell
$ docker build -t static-swift-linux .
```

then you can check-out the sources somewhere using

```shell
$ scripts/fetch-source.sh --clone-with-ssh --source-dir /path/to/source
```

and finally use the Docker image to do your build

```shell
$ mkdir /path/to/products
$ docker run -it --rm \
-v /path/to/source:/source \
-v /path/to/products:/products \
static-swift-linux \
/scripts/build.sh --source-dir /source --products-dir /products
```

The artifact bundle should appear at `/path/to/products`.

The `scripts/build.sh` script has a number of options you may wish to
investigate. Similarly with the `scripts/fetch-source.sh` script.
32 changes: 32 additions & 0 deletions swift-ci/sdks/static-linux/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
#
# ===----------------------------------------------------------------------===
#
# Swift Static SDK for Linux: Top-level Build Script
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

DOCKER=docker

# Build the Docker image
$(DOCKER) build -t static-swift-linux .

# Check-out the sources
scripts/fetch-source.sh --clone-with-ssh --source-dir source

mkdir -p products

# Run the build
$(DOCKER) run -it --rm \
-v ./source:/source \
-v ./products:/products \
static-swift-linux \
/scripts/build.sh --source-dir /source --products-dir /products
25 changes: 25 additions & 0 deletions swift-ci/sdks/static-linux/resources/fts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# ===----------------------------------------------------------------------===
#
# Swift Static SDK for Linux: Build libfts
#
# This source file is part of the Swift.org open source project
#
# Copyright (c) 2024 Apple Inc. and the Swift project authors
# Licensed under Apache License v2.0 with Runtime Library Exception
#
# See https://swift.org/LICENSE.txt for license information
# See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
#
# ===----------------------------------------------------------------------===

cmake_minimum_required(VERSION 3.22.1)

project(fts)

add_library(fts STATIC fts.c)
set_target_properties(fts PROPERTIES PUBLIC_HEADER fts.h)
target_include_directories(fts PRIVATE SYSTEM ${CMAKE_CURRENT_SOURCE_DIR})

install(TARGETS fts
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
48 changes: 48 additions & 0 deletions swift-ci/sdks/static-linux/resources/fts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
What is this?
=============

Musl doesn't have fts in its libc. Alpine and other Musl-based
distributions typically provide an fts implementation separately,
using a derivative of NetBSD's fts, which is what you'll find in this
directory.

Typically they use the one from https://github.com/void-linux/musl-fts
but that uses GNU autotools and annoyingly they haven't checked in the
generated configure script. Not that it actually *needs* a configure
script, because they know what C library they're using already.

Anyway, I grabbed the fts sources from there and chucked them in this
directory along with a CMakeLists.txt that lets us build them with
CMake.

What's the license?
===================

Being from NetBSD, it's the BSD license:

Copyright (c) 1990, 1993, 1994
The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
1 change: 1 addition & 0 deletions swift-ci/sdks/static-linux/resources/fts/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.7
22 changes: 22 additions & 0 deletions swift-ci/sdks/static-linux/resources/fts/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Configure definitions for Musl */

#ifndef FTS_CONFIG_H_
#define FTS_CONFIG_H_

// We have dirfd(), in <dirent.h>
#define HAVE_DIRFD 1

// MAX is defined in <sys/param.h>
#define HAVE_DECL_MAX 1

// UINTMAX_MAX is in <stdint.h>
#define HAVE_DECL_UINTMAX_MAX 1

// We don't have d_namlen
//#undef HAVE_STRUCT_DIRENT_D_NAMLEN

// DIR is opaque
//#undef HAVE_DIR_DD_FD
//#undef HAVE_DIR_D_FD

#endif /* FTS_CONFIG_H_ */
Loading