|
1 | 1 | #!/usr/bin/env bash
|
| 2 | +##===----------------------------------------------------------------------===## |
| 3 | +## |
| 4 | +## This source file is part of the SwiftContainerPlugin open source project |
| 5 | +## |
| 6 | +## Copyright (c) 2025 Apple Inc. and the SwiftContainerPlugin project authors |
| 7 | +## Licensed under Apache License v2.0 |
| 8 | +## |
| 9 | +## See LICENSE.txt for license information |
| 10 | +## See CONTRIBUTORS.txt for the list of SwiftContainerPlugin project authors |
| 11 | +## |
| 12 | +## SPDX-License-Identifier: Apache-2.0 |
| 13 | +## |
| 14 | +##===----------------------------------------------------------------------===## |
2 | 15 |
|
3 |
| -set -ex -o pipefail |
| 16 | +# |
| 17 | +# This script assumes that the Static Linux SDK has already been installed |
| 18 | +# |
4 | 19 |
|
| 20 | +log() { printf -- "** %s\n" "$*" >&2; } |
| 21 | +error() { printf -- "** ERROR: %s\n" "$*" >&2; } |
| 22 | +fatal() { error "$@"; exit 1; } |
| 23 | + |
| 24 | +set -euo pipefail |
| 25 | + |
| 26 | +RUNTIME=${RUNTIME-"docker"} |
| 27 | + |
| 28 | +# |
| 29 | +# Create a test package |
| 30 | +# |
5 | 31 | PKGPATH=$(mktemp -d)
|
6 | 32 | swift package --package-path "$PKGPATH" init --type executable --name hello
|
7 | 33 |
|
| 34 | +cleanup() { |
| 35 | + log "Deleting temporary package $PKGPATH" |
| 36 | + rm -rf "$PKGPATH" |
| 37 | +} |
| 38 | +trap cleanup EXIT |
| 39 | + |
| 40 | +# |
8 | 41 | # Build and package an x86_64 binary
|
| 42 | +# |
9 | 43 | swift build --package-path "$PKGPATH" --swift-sdk x86_64-swift-linux-musl
|
10 |
| -file "$PKGPATH/.build/x86_64-swift-linux-musl/debug/hello" |
| 44 | +FILETYPE=$(file "$PKGPATH/.build/x86_64-swift-linux-musl/debug/hello") |
| 45 | +log "Executable type: $FILETYPE" |
| 46 | + |
11 | 47 | IMGREF=$(swift run containertool --repository localhost:5000/elf_test "$PKGPATH/.build/x86_64-swift-linux-musl/debug/hello" --from scratch)
|
12 |
| -docker pull "$IMGREF" |
13 |
| -docker inspect "$IMGREF" --format "{{.Architecture}}" | grep amd64 |
14 |
| -echo x86_64 detection: PASSED |
| 48 | +$RUNTIME pull "$IMGREF" |
| 49 | +IMGARCH=$($RUNTIME inspect "$IMGREF" --format "{{.Architecture}}") |
| 50 | +if [ "$IMGARCH" = "amd64" ] ; then |
| 51 | + log "x86_64 detection: PASSED" |
| 52 | +else |
| 53 | + fatal "x86_64 detection: FAILED - image architecture was $IMGARCH; expected amd64" |
| 54 | +fi |
15 | 55 |
|
| 56 | +# |
16 | 57 | # Build and package an aarch64 binary
|
| 58 | +# |
17 | 59 | swift build --package-path "$PKGPATH" --swift-sdk aarch64-swift-linux-musl
|
18 |
| -file "$PKGPATH/.build/aarch64-swift-linux-musl/debug/hello" |
19 |
| -IMGREF=$(swift run containertool --repository localhost:5000/elf_test "$PKGPATH/.build/aarch64-swift-linux-musl/debug/hello" --from scratch) |
20 |
| -docker pull "$IMGREF" |
21 |
| -docker inspect "$IMGREF" --format "{{.Architecture}}" | grep arm64 |
| 60 | +FILETYPE=$(file "$PKGPATH/.build/x86_64-swift-linux-musl/debug/hello") |
| 61 | +log "Executable type: $FILETYPE" |
22 | 62 |
|
23 |
| -echo aarch64 detection: PASSED |
| 63 | +IMGREF=$(swift run containertool --repository localhost:5000/elf_test "$PKGPATH/.build/aarch64-swift-linux-musl/debug/hello" --from scratch) |
| 64 | +$RUNTIME pull "$IMGREF" |
| 65 | +IMGARCH=$($RUNTIME inspect "$IMGREF" --format "{{.Architecture}}") |
| 66 | +if [ "$IMGARCH" = "arm64" ] ; then |
| 67 | + log "aarch64 detection: PASSED" |
| 68 | +else |
| 69 | + fatal "aarch64 detection: FAILED - image architecture was $IMGARCH; expected arm64" |
| 70 | +fi |
0 commit comments