Skip to content

Commit

Permalink
fix: macOS build
Browse files Browse the repository at this point in the history
  • Loading branch information
surpher committed May 13, 2024
1 parent 338457a commit 7ec591e
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
destination: "platform=iOS Simulator,name=iPhone 15 Pro"
- platform: macos
scheme: "PactSwift-macOS"
destination: "arch=aarm64"
destination: "arch=arm64"
- host: macos-13
xcode: 14.3.1
- host: macos-14
Expand Down
8 changes: 5 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ opt_in_rules:
- static_operator
- toggle_bool
- unneeded_parentheses_in_closure_argument
- unused_declaration
- unused_import
- yoda_condition
- xct_specific_matcher

analyzer_rules:
- unused_declaration
- unused_import

attributes:
always_on_same_line: ["@IBAction", "@objc"]
always_on_same_line: []

line_length:
warning: 180
Expand Down
2 changes: 2 additions & 0 deletions PactSwift.xcfilelist
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
$(SRCROOT)/Sources/Extensions/Bundle+PactSwift.swift
$(SRCROOT)/Sources/Extensions/Task+Timeout.swift
$(SRCROOT)/Sources/Extensions/Date+PactSwift.swift
$(SRCROOT)/Sources/Extensions/UUID+PactSwift.swift
$(SRCROOT)/Sources/Extensions/MockServer+Async.swift
$(SRCROOT)/Sources/Extensions/String+PactSwift.swift
$(SRCROOT)/Sources/Extensions/Dictionary+PactSwift.swift
$(SRCROOT)/Sources/Extensions/Sequence+PactSwift.swift
Expand Down
6 changes: 3 additions & 3 deletions Scripts/BuildPhases/lint-target
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ errors=()

#### Script steps

if [[ ! -z "${INFOPLIST_FILE}" && ! -f "${INFOPLIST_FILE}" ]]; then
errors+=("error: Could not find Info.plist file "${INFOPLIST_FILE}" for target '${TARGET_NAME}'.")
if [[ -n "${INFOPLIST_FILE}" && ! -f "${INFOPLIST_FILE}" ]]; then
errors+=("error: Could not find Info.plist file ${INFOPLIST_FILE}\ for target '${TARGET_NAME}'.")
fi

if [[ ! -d "${TARGET_SRCROOT}" ]]; then
Expand All @@ -40,7 +40,7 @@ fi

if [ ${#errors[@]} -ne 0 ]; then
for i in "${errors[@]}"; do
echo $i
echo "$i"
done
exit 1
fi
Expand Down
8 changes: 4 additions & 4 deletions Scripts/BuildPhases/validate-build-settings
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ set -eu
echo "--- 🤖 Ensuring there are no build settings in Xcode project file."

PBXPROJ_FILE_PATH="${PROJECT_FILE_PATH}/project.pbxproj"
NUMBER_OF_BUILD_SETTINGS=`grep "buildSettings" "$PBXPROJ_FILE_PATH" | wc -l`
NUMBER_OF_EMPTY_BUILD_SETTINGS=`grep -B 0 -A 1 "buildSettings" "$PBXPROJ_FILE_PATH" | grep "};" | wc -l`
NUMBER_OF_BUILD_SETTINGS="$(grep -c "buildSettings" "$PBXPROJ_FILE_PATH")"
NUMBER_OF_EMPTY_BUILD_SETTINGS="$(grep -B 0 -A 1 "buildSettings" "$PBXPROJ_FILE_PATH" | grep "};" | wc -l)"

if [ $NUMBER_OF_BUILD_SETTINGS != $NUMBER_OF_EMPTY_BUILD_SETTINGS ]; then
NUMBER_WITH_SETTINGS=`expr $NUMBER_OF_BUILD_SETTINGS - $NUMBER_OF_EMPTY_BUILD_SETTINGS`
if [ "$NUMBER_OF_BUILD_SETTINGS" != "$NUMBER_OF_EMPTY_BUILD_SETTINGS" ]; then
NUMBER_WITH_SETTINGS=$(("$NUMBER_OF_BUILD_SETTINGS" - "$NUMBER_OF_EMPTY_BUILD_SETTINGS"))

echo "error: Found ${NUMBER_WITH_SETTINGS} build settings in Xcode project file! Build settings should only be defined in ./Configurations/*.xcconfig files."
exit 1
Expand Down
30 changes: 8 additions & 22 deletions Scripts/build_file_list_and_swiftlint
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,22 @@

set -eu

# Adds support for Apple Silicon brew directory
export PATH="$PATH:/opt/homebrew/bin"

SRCROOT=${SRCROOT:-"."}
DERIVED_FILE_DIR=${DERIVED_FILE_DIR:-"."}

if [ $# -ne 2 ]; then
echo "usage: build_file_list_and_swiftlint project_name swiftlint_yml"
exit 1
echo "usage: build_file_list_and_swiftlint project_name swiftlint_yml"
exit 1
fi

echo "--- 🤖 Linting $SRCROOT/Sources/*.swift"

if which swiftlint >/dev/null; then
# Build a list of Swift files in the Sources directory
find Sources -name \*.swift -exec echo "\$(SRCROOT)/"{} \; > $DERIVED_FILE_DIR/$1.xcfilelist

# Update the xcfilelist if the list of Swift files has changed
cmp --silent $SRCROOT/$1.xcfilelist $DERIVED_FILE_DIR/$1.xcfilelist || cp -f $DERIVED_FILE_DIR/$1.xcfilelist $SRCROOT/$1.xcfilelist

# Run swiftlint (TODO: - swiftlint by iterating through the $1.xcfilelist)
# swiftlint --config $2 -- #filename0 #filename1 #filename2 ...
swiftlint --path Sources --config $2

# Output an empty derived file
touch $DERIVED_FILE_DIR/swiftlint.txt
# Run swiftlint (TODO: - swiftlint by iterating through the $1.xcfilelist)
swiftlint lint "$SRCROOT/Sources"

# All hunky dory
echo "--- 👍 .swift files linted"
# All hunky dory
echo "--- 👍 .swift files in ./Sources linted"
else
echo "--- ⚠️ Swiftlint"
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
echo "--- ⚠️ Swiftlint"
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
54 changes: 27 additions & 27 deletions Scripts/build_rust_dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ PACT_FOUNDATION_REPO="https://github.com/pact-foundation/pact-reference.git"

if [ ! -d "$PWD/$PRODUCT_NAME.xcodeproj" ]
then
echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives."
echo "⚠️ You are runing it in $PWD"
exit 1
echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives."
echo "⚠️ You are runing it in $PWD"
exit 1
fi

#######################
Expand All @@ -27,20 +27,20 @@ fi
echo "👮‍♀️ Verifying project and dependencies' folder setup..."

if [[ "$CI" == true ]]; then
echo "ℹ️ Adding submodule ${PACT_FOUNDATION_REPO}"
if [ ! -d "$PWD/pact-reference"]; then
git submodule add $PACT_FOUNDATION_REPO
fi
git submodule update --init
cd pact-reference/rust/pact_ffi
echo "ℹ️ Adding submodule ${PACT_FOUNDATION_REPO}"
if [ ! -d "$PWD/pact-reference" ]; then
git submodule add $PACT_FOUNDATION_REPO
fi
git submodule update --init
cd pact-reference/rust/pact_ffi
elif [ ! -d "$PWD/../pact-reference" ]; then
echo "🚨 Missing pact-foundation/pact-reference repo."
echo "⚠️ Make sure you 'git clone ${PACT_FOUNDATION_REPO}' at the same folder level as your $PRODUCT_NAME."
exit 1
echo "🚨 Missing pact-foundation/pact-reference repo."
echo "⚠️ Make sure you 'git clone ${PACT_FOUNDATION_REPO}' at the same folder level as your $PRODUCT_NAME."
exit 1
else
echo "👍 Project setup seems to be in order."
echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd $LIBPACT_FFI_DIR
echo "👍 Project setup seems to be in order."
echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd "$LIBPACT_FFI_DIR"
fi

#######################
Expand All @@ -51,13 +51,13 @@ fi

echo "👮‍♀️ Checking if Rust is installed..."
if which cargo >/dev/null; then
echo "👍 cargo installed"
echo "👍 cargo installed"
elif command -v ~/.cargo/bin/cargo &> /dev/null; then
echo "👍 cargo installed in ~/.cargo/bin/"
echo "👍 cargo installed in ~/.cargo/bin/"
else
echo "🚨 Rust/Cargo not installed"
echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install"
exit 1
echo "🚨 Rust/Cargo not installed"
echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install"
exit 1
fi

##############################################
Expand All @@ -71,31 +71,31 @@ echo "✅ libpact_ffi built"

echo "ℹ️ Setting LD_LIBRARY_PATH to include $LIBPACT_PRODUCT_DIR"
if [[ "$CI" == true ]]; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${WORKSPACE}/pact-reference/rust/target/debug"
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${WORKSPACE}/pact-reference/rust/target/debug"
else
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LIBPACT_PRODUCT_DIR}"
export LD_LIBRARY_PATH="${LD_LIBRARY_PATH}:${LIBPACT_PRODUCT_DIR}"
fi

#######################
# Cleanup #
#######################

echo "ℹ️ Changing directory back to ${WORKSPACE}"
cd ${WORKSPACE}
cd "${WORKSPACE}"

##############################################################################################################
# Run Swift buld and test #
# https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#requiring-system-libraries #
##############################################################################################################

echo "ℹ️ Running swift build:"
swift build -Xlinker -L$LIBPACT_PRODUCT_DIR
swift build -Xlinker -L"$LIBPACT_PRODUCT_DIR"

echo "ℹ️ Running swift test with -Xlinker -L$LIBPACT_PRODUCT_DIR"

if [[ "$CI" == true ]]; then
BIN_PATH="${WORKSPACE}/pact-reference/rust/target/debug"
swift test -Xlinker -L$BIN_PATH
BIN_PATH="${WORKSPACE}/pact-reference/rust/target/debug"
swift test -Xlinker -L"$BIN_PATH"
else
swift test -Xlinker -L$LIBPACT_PRODUCT_DIR
swift test -Xlinker -L"$LIBPACT_PRODUCT_DIR"
fi
54 changes: 27 additions & 27 deletions Scripts/build_test_linux
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ PACT_FOUNDATION_REPO="https://github.com/pact-foundation/pact-reference.git"

if [ ! -d "$PWD/$PRODUCT_NAME.xcodeproj" ]
then
echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives."
echo "⚠️ You are runing it in $PWD"
exit 1
echo "🚨 Run this from the same folder where your '$PRODUCT_NAME.xcodeproj' lives."
echo "⚠️ You are runing it in $PWD"
exit 1
fi

#######################
Expand All @@ -46,30 +46,30 @@ fi
echo "👮‍♀️ Verifying project and dependencies' folder setup..."

if [[ "$CI" == true ]]; then
echo "ℹ️ Adding submodule ${PACT_FOUNDATION_REPO}"
if [ ! -d "$PWD/pact-reference" ]; then
git submodule add $PACT_FOUNDATION_REPO
git submodule update --init
echo "ℹ️ Adding submodule ${PACT_FOUNDATION_REPO}"
if [ ! -d "$PWD/pact-reference" ]; then
git submodule add $PACT_FOUNDATION_REPO
git submodule update --init

echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd $LIBPACT_FFI_DIR
git fetch --all --tags
git checkout tags/libpact_ffi-v0.3.11
fi
echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd "$LIBPACT_FFI_DIR"
git fetch --all --tags
git checkout tags/libpact_ffi-v0.3.11
fi

export LD_LIBRARY_PATH="/usr/local/lib"
export LD_LIBRARY_PATH="/usr/local/lib"

elif [ ! -d "$PWD/../pact-reference" ]; then
# TODO: fix this for running locally
echo "🚨 Missing pact-foundation/pact-reference repo."
echo "⚠️ Make sure you 'git clone ${PACT_FOUNDATION_REPO}' at the same folder level as your $PRODUCT_NAME."
exit 1
# TODO: fix this for running locally
echo "🚨 Missing pact-foundation/pact-reference repo."
echo "⚠️ Make sure you 'git clone ${PACT_FOUNDATION_REPO}' at the same folder level as your $PRODUCT_NAME."
exit 1
else
echo "👍 Project setup seems to be in order."
echo "👍 Project setup seems to be in order."
fi

echo "ℹ️ Changing location to ${LIBPACT_FFI_DIR}"
cd $LIBPACT_FFI_DIR
cd "$LIBPACT_FFI_DIR"

#######################
# Setup #
Expand All @@ -79,13 +79,13 @@ cd $LIBPACT_FFI_DIR

echo "👮‍♀️ Checking if Rust is installed..."
if which cargo >/dev/null; then
echo "👍 cargo installed"
echo "👍 cargo installed"
elif command -v ~/.cargo/bin/cargo &> /dev/null; then
echo "👍 cargo installed in ~/.cargo/bin/"
echo "👍 cargo installed in ~/.cargo/bin/"
else
echo "🚨 Rust/Cargo not installed"
echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install"
exit 1
echo "🚨 Rust/Cargo not installed"
echo "ERROR: cargo is required and is was found on this machine. See https://www.rust-lang.org/tools/install"
exit 1
fi

##############################################
Expand All @@ -105,15 +105,15 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBPACT_PRODUCT_DIR
#######################

echo "ℹ️ Changing directory back to ${WORKSPACE}"
cd ${WORKSPACE}
cd "${WORKSPACE}"

##############################################################################################################
# Run Swift buld and test #
# https://github.com/apple/swift-package-manager/blob/main/Documentation/Usage.md#requiring-system-libraries #
##############################################################################################################

echo "ℹ️ Running swift build:"
swift build -Xlinker -L$LIBPACT_PRODUCT_DIR
swift build -Xlinker -L"$LIBPACT_PRODUCT_DIR"

echo "ℹ️ Running swift test with -Xlinker -L$LIBPACT_PRODUCT_DIR"
swift test -Xlinker -L$LIBPACT_PRODUCT_DIR
swift test -Xlinker -L"$LIBPACT_PRODUCT_DIR"
33 changes: 16 additions & 17 deletions Scripts/carthage
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,31 @@ ACTIVE_ARCH=$(uname -m)

if [[ $ACTIVE_ARCH == "x86_64" ]]; then

# If running on Intel machine, do the excluded architectures dance 💃🕺
# If running on Intel machine, do the excluded architectures dance 💃🕺

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT
xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

echo "⚠️ NOTE: Using Carthage workaround script..."
echo "⚠️ NOTE: Using Carthage workaround script..."

# For Xcode 12 and 13 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.
# For Xcode 12 and 13 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.

CURRENT_XCODE_VERSION="$(xcodebuild -version | grep "Xcode" | cut -d' ' -f2 | cut -d'.' -f1)00"
CURRENT_XCODE_BUILD=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)
CURRENT_XCODE_VERSION="$(xcodebuild -version | grep "Xcode" | cut -d' ' -f2 | cut -d'.' -f1)00"
CURRENT_XCODE_BUILD=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)

echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_${CURRENT_XCODE_VERSION}__BUILD_${CURRENT_XCODE_BUILD} = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig
echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_${CURRENT_XCODE_VERSION}__BUILD_${CURRENT_XCODE_BUILD} = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig

echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_'${CURRENT_XCODE_VERSION}' = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_$(XCODE_VERSION_MAJOR)__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig
echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_'${CURRENT_XCODE_VERSION}' = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_$(XCODE_VERSION_MAJOR)__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage "$@"
export XCODE_XCCONFIG_FILE="$xcconfig"
carthage "$@"

else

# Running on arm64 machine so just use the plain carthage
echo "⚠️ NOTE: Using plain vanilla Carthage..."
carthage "$@"
# Running on arm64 machine so just use the plain carthage
echo "⚠️ NOTE: Using plain vanilla Carthage..."
carthage "$@"

fi

Loading

0 comments on commit 7ec591e

Please sign in to comment.