diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 5b27b6c6..5ccc91cf 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -2,39 +2,61 @@ name: tests on: push: - branches: [ master ] + branches: [master] pull_request: - branches: [ master ] + branches: [master] jobs: linux: runs-on: ubuntu-24.04 name: Ubuntu 24.04 steps: - - name: Install Swift - uses: tayloraswift/swift-install-action@master - with: - swift-prefix: "swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE" - swift-id: "swift-6.0.3-RELEASE-ubuntu24.04" + - name: Install Swift + uses: tayloraswift/swift-install-action@master + with: + swift-prefix: "swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE" + swift-id: "swift-6.0.3-RELEASE-ubuntu24.04" - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Install imagemagick - run: sudo apt install -y imagemagick + - name: Install imagemagick + run: sudo apt install -y imagemagick - - name: Run tests - run: Scripts/TestAll + - name: Run tests + run: Scripts/TestAll + + linux-musl: + runs-on: ubuntu-24.04 + name: Ubuntu 24.04 + steps: + - name: Install Swift + uses: tayloraswift/swift-install-action@master + with: + swift-prefix: "swift-6.0.3-release/ubuntu2404/swift-6.0.3-RELEASE" + swift-id: "swift-6.0.3-RELEASE-ubuntu24.04" + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install imagemagick + run: sudo apt install -y imagemagick + + - name: Install linux SDK + run: swift sdk install https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz --checksum 67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd + + - name: Run tests + run: Scripts/TestAll -b "--swift-sdk x86_64-swift-linux-musl" macos: runs-on: macos-15 name: macOS steps: - - name: Checkout repository - uses: actions/checkout@v3 + - name: Checkout repository + uses: actions/checkout@v3 - - name: Install imagemagick - run: brew install imagemagick + - name: Install imagemagick + run: brew install imagemagick - - name: Run tests - run: Scripts/TestAll + - name: Run tests + run: Scripts/TestAll diff --git a/Scripts/TestAll b/Scripts/TestAll index 93e6063d..e42b6da0 100755 --- a/Scripts/TestAll +++ b/Scripts/TestAll @@ -2,5 +2,28 @@ set -e swift --version -utils/tests -utils/examples -c release +DEFAULT_BUILD_FLAGS="" + +usage() +{ + echo "usage: Scripts/TestAll [OPTION...] + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS'" +} + +build_flags=$DEFAULT_BUILD_FLAGS + +while [ "$1" != "" ] ; do + case $1 in + -b | --build-flags ) + shift + build_flags=$1 + ;; + * ) + usage + exit 1 + esac + shift +done + +utils/tests -b "$build_flags" +utils/examples -c release -b "$build_flags" diff --git a/Sources/JPEGSystem/os.swift b/Sources/JPEGSystem/os.swift index dc2940b2..e4c688d1 100644 --- a/Sources/JPEGSystem/os.swift +++ b/Sources/JPEGSystem/os.swift @@ -6,8 +6,10 @@ import JPEG #if os(macOS) import Darwin -#elseif os(Linux) +#elseif canImport(Glibc) import Glibc +#elseif canImport(Musl) + import Musl #elseif os(Android) import Android #else diff --git a/utils/examples b/utils/examples index a000c6e2..1a1b8dba 100755 --- a/utils/examples +++ b/utils/examples @@ -1,11 +1,13 @@ #!/bin/bash DEFAULT_BUILD_CONFIGURATION="debug" SCRIPT_NAME="examples" +DEFAULT_BUILD_FLAGS="" usage() { echo "usage: utils/$SCRIPT_NAME [OPTION...] - -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION'" + -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION' + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS'" } error() @@ -23,6 +25,7 @@ check() } build_configuration=$DEFAULT_BUILD_CONFIGURATION +build_flags=$DEFAULT_BUILD_FLAGS while [ "$1" != "" ] ; do case $1 in @@ -30,6 +33,10 @@ while [ "$1" != "" ] ; do shift build_configuration=$1 ;; + -b | --build-flags ) + shift + build_flags=$1 + ;; * ) usage exit 1 @@ -37,7 +44,7 @@ while [ "$1" != "" ] ; do shift done -swift build -c $build_configuration +swift build -c $build_configuration $build_flags # run `DecodeBasic` example check "error: runtime error" \ diff --git a/utils/fuzz-test b/utils/fuzz-test index 7939d41b..2f7bd6bf 100755 --- a/utils/fuzz-test +++ b/utils/fuzz-test @@ -2,11 +2,13 @@ DEFAULT_BUILD_CONFIGURATION="debug" DEFAULT_COUNT="16" DEFAULT_PREFIX="tests/fuzz/data" +DEFAULT_BUILD_FLAGS="" usage() { echo "usage: utils/fuzz-test [OPTION...] -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION' + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS' -n, --count number of 8x8 test jpegs to generate, default $DEFAULT_COUNT -p, --prefix directory to write test images to, default '$DEFAULT_PREFIX'" } @@ -36,6 +38,7 @@ fi prefix=$DEFAULT_PREFIX count=$DEFAULT_COUNT build_configuration=$DEFAULT_BUILD_CONFIGURATION +build_flags=$DEFAULT_BUILD_FLAGS JPEG_DIRECTORY_NAME="jpeg" YCC_DIRECTORY_NAME="ycc" @@ -48,6 +51,10 @@ while [ "$1" != "" ] ; do shift build_configuration=$1 ;; + -b | --build-flags ) + shift + build_flags=$1 + ;; -n | --count ) shift count=$1 @@ -67,9 +74,9 @@ jpeg_pattern=$prefix/*.$JPEG_EXTENSION ycc_pattern=$prefix/*.$YCC_EXTENSION check "error: swift build failed" \ - swift build -c $build_configuration --product JPEGFuzzer + swift build -c $build_configuration --product JPEGFuzzer $build_flags check "error: swift build failed" \ - swift build -c $build_configuration --product JPEGComparator + swift build -c $build_configuration --product JPEGComparator $build_flags binaries=".build/$build_configuration" if ! [ -f $binaries/JPEGFuzzer ]; then diff --git a/utils/integration-test b/utils/integration-test index 2a218018..00f8aa5d 100755 --- a/utils/integration-test +++ b/utils/integration-test @@ -1,11 +1,13 @@ #!/bin/bash DEFAULT_BUILD_CONFIGURATION="debug" TOOL_NAME="JPEGIntegrationTests" +DEFAULT_BUILD_FLAGS="" usage() { echo "usage: utils/$TOOL_NAME [OPTION...] - -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION'" + -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION' + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS'" } error() @@ -23,6 +25,7 @@ check() } build_configuration=$DEFAULT_BUILD_CONFIGURATION +build_flags=$DEFAULT_BUILD_FLAGS while [ "$1" != "" ] ; do case $1 in @@ -30,6 +33,10 @@ while [ "$1" != "" ] ; do shift build_configuration=$1 ;; + -b | --build-flags ) + shift + build_flags=$1 + ;; * ) usage exit 1 @@ -38,7 +45,7 @@ while [ "$1" != "" ] ; do done check "error: swift build failed" \ - swift build -c $build_configuration --product $TOOL_NAME + swift build -c $build_configuration --product $TOOL_NAME $build_flags binaries=".build/$build_configuration" if ! [ -f $binaries/$TOOL_NAME ]; then diff --git a/utils/regression-test b/utils/regression-test index 1c2221a0..46b5e7ec 100755 --- a/utils/regression-test +++ b/utils/regression-test @@ -1,11 +1,13 @@ #!/bin/bash DEFAULT_BUILD_CONFIGURATION="debug" TOOL_NAME="JPEGRegressionTests" +DEFAULT_BUILD_FLAGS="" usage() { echo "usage: utils/$TOOL_NAME [OPTION...] -c, --configuration swift build configuration mode, default '$DEFAULT_BUILD_CONFIGURATION' + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS' -u, --update remove and regenerate golden outputs (tests will fail)" } @@ -24,6 +26,7 @@ check() } build_configuration=$DEFAULT_BUILD_CONFIGURATION +build_flags=$DEFAULT_BUILD_FLAGS while [ "$1" != "" ] ; do case $1 in @@ -31,6 +34,10 @@ while [ "$1" != "" ] ; do shift build_configuration=$1 ;; + -b | --build-flags ) + shift + build_flags=$1 + ;; -u | --update ) shift gold=(tests/regression/gold/*.jpg.ycc) @@ -51,7 +58,7 @@ while [ "$1" != "" ] ; do done check "error: swift build failed" \ - swift build -c $build_configuration --product $TOOL_NAME + swift build -c $build_configuration --product $TOOL_NAME $build_flags binaries=".build/$build_configuration" if ! [ -f $binaries/$TOOL_NAME ]; then diff --git a/utils/tests b/utils/tests index d3cc4a5b..a9563de7 100755 --- a/utils/tests +++ b/utils/tests @@ -1,6 +1,29 @@ #!/bin/bash +SCRIPT_NAME="tests" +DEFAULT_BUILD_FLAGS="" -utils/unit-test || exit 1 -utils/integration-test -c release || exit 1 -utils/regression-test -c release || exit 1 -utils/fuzz-test -c release -n 16 || exit 1 +usage() +{ + echo "usage: utils/$SCRIPT_NAME [OPTION...] + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS'" +} + +build_flags=$DEFAULT_BUILD_FLAGS + +while [ "$1" != "" ] ; do + case $1 in + -b | --build-flags ) + shift + build_flags=$1 + ;; + * ) + usage + exit 1 + esac + shift +done + +utils/unit-test -b "$build_flags" || exit 1 +utils/integration-test -c release -b "$build_flags" || exit 1 +utils/regression-test -c release -b "$build_flags" || exit 1 +utils/fuzz-test -c release -n 16 -b "$build_flags" || exit 1 diff --git a/utils/unit-test b/utils/unit-test index 4024f13f..10bafe43 100755 --- a/utils/unit-test +++ b/utils/unit-test @@ -1,5 +1,8 @@ #!/bin/bash TOOL_NAME="JPEGUnitTests" +SCRIPT_NAME="unit-test" +DEFAULT_BUILD_FLAGS="" + error() { echo $1 @@ -14,8 +17,29 @@ check() "$@" || error "$message" } +usage() +{ + echo "usage: utils/$SCRIPT_NAME [OPTION...] + -b, --build-flags swift build additional command flags, default '$DEFAULT_BUILD_FLAGS'" +} + +build_flags=$DEFAULT_BUILD_FLAGS + +while [ "$1" != "" ] ; do + case $1 in + -b | --build-flags ) + shift + build_flags=$1 + ;; + * ) + usage + exit 1 + esac + shift +done + check "error: swift build failed" \ - swift build -c release --product $TOOL_NAME + swift build -c release --product $TOOL_NAME $build_flags binaries=".build/release" if ! [ -f $binaries/$TOOL_NAME ]; then