Skip to content
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
9 changes: 9 additions & 0 deletions .buildkite/download-xcframework.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

set -euo pipefail

echo "--- :arrow_down: Downloading xcframework"
buildkite-agent artifact download target/libwordpressFFI.xcframework.zip . --step "xcframework"
buildkite-agent artifact download native/swift/Sources/wordpress-api-wrapper/wp_api.swift . --step "xcframework"
unzip target/libwordpressFFI.xcframework.zip -d .
rm target/libwordpressFFI.xcframework.zip
6 changes: 6 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,14 @@ steps:
make test-swift-linux
- label: ":swift: Lint"
command: |
.buildkite/download-xcframework.sh
echo "--- :swift: Swiftlint"
make lint-swift
depends_on: xcframework
env:
IMAGE_ID: xcode-15.3
agents:
queue: mac
#
# Kotlin Group
- group: ":kotlin: Kotlin Wrapper"
Expand Down
8 changes: 3 additions & 5 deletions .buildkite/swift-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

set -euo pipefail

echo "--- :arrow_down: Downloading xcframework"
buildkite-agent artifact download target/libwordpressFFI.xcframework.zip . --step "xcframework"
buildkite-agent artifact download native/swift/Sources/wordpress-api-wrapper/wp_api.swift . --step "xcframework"
unzip target/libwordpressFFI.xcframework.zip -d .
rm target/libwordpressFFI.xcframework.zip
.buildkite/download-xcframework.sh

export SKIP_PACKAGE_WP_API=true

function run_tests() {
Expand All @@ -23,6 +20,7 @@ function build_for_real_device() {
xcodebuild -destination "generic/platform=$platform" \
-scheme WordPress \
-derivedDataPath DerivedData \
-skipPackagePluginValidation \
build | xcbeautify
}

Expand Down
7 changes: 2 additions & 5 deletions .buildkite/validate-cocoapods.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,8 @@ Pod::Spec.new do |spec|
end
EOT

echo "--- :arrow_down: Downloading xcframework"
buildkite-agent artifact download target/libwordpressFFI.xcframework.zip . --step "xcframework"
buildkite-agent artifact download native/swift/Sources/wordpress-api-wrapper/wp_api.swift . --step "xcframework"
unzip target/libwordpressFFI.xcframework.zip -d .
rm target/libwordpressFFI.xcframework.zip
.buildkite/download-xcframework.sh

export SKIP_PACKAGE_WP_API=true

echo "--- :rubygems: Setting up Gems"
Expand Down
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
swiftlint_version: 0.53.0
swiftlint_version: 0.55.1
strict: true
included:
- native/swift
Expand Down
5 changes: 2 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ docker_container_repo_dir=/app

# Common docker options
rust_docker_container := public.ecr.aws/docker/library/rust:1.76
swiftlint_container := ghcr.io/realm/swiftlint:0.53.0

docker_opts_shared := --rm -v "$(PWD)":$(docker_container_repo_dir) -w $(docker_container_repo_dir)
rust_docker_run := docker run -v $(PWD):/$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it -e CARGO_HOME=/app/.cargo $(rust_docker_container)
Expand Down Expand Up @@ -181,10 +180,10 @@ lint-rust:
$(rust_docker_run) /bin/bash -c "rustup component add clippy && cargo clippy --all -- -D warnings && cargo clippy --tests --all -- -D warnings"

lint-swift:
docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint
swift package plugin swiftlint

lintfix-swift:
docker run -v $(PWD):$(docker_container_repo_dir) -w $(docker_container_repo_dir) -it $(swiftlint_container) swiftlint --autocorrect
swift package plugin swiftlint --autocorrect

fmt-rust:
$(rust_docker_run) /bin/bash -c "rustup component add rustfmt && cargo fmt"
Expand Down
86 changes: 86 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 66 additions & 17 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
// swift-tools-version:5.10

import Foundation
import PackageDescription

enum WordPressRSVersion {
case local
case release(version: String, checksum: String)
}

let libwordpressFFIVersion: WordPressRSVersion = .local

#if os(Linux)
Expand All @@ -15,20 +11,10 @@ let libwordpressFFI: Target = .systemLibrary(
path: "target/swift-bindings/libwordpressFFI-linux/"
)
#elseif os(macOS)
let libwordpressFFI: Target
switch libwordpressFFIVersion {
case .local:
libwordpressFFI = .binaryTarget(name: "libwordpressFFI", path: "target/libwordpressFFI.xcframework")
case let .release(version, checksum):
libwordpressFFI = .binaryTarget(
name: "libwordpressFFI",
url: "https://github.com/Automattic/wordpress-rs/releases/download/\(version)/libwordpressFFI.xcframework.zip",
checksum: checksum
)
}
let libwordpressFFI: Target = libwordpressFFIVersion.target
#endif

let package = Package(
var package = Package(
name: "WordPress",
platforms: [
.iOS(.v13),
Expand Down Expand Up @@ -75,3 +61,66 @@ let package = Package(
)
]
)

// MARK: - Enable local development toolings

let localDevelopment = libwordpressFFIVersion.isLocal

if localDevelopment {
try enableSwiftLint()
}

// MARK: - Helpers

enum WordPressRSVersion {
case local
case release(version: String, checksum: String)

var isLocal: Bool {
if case .local = self {
return true
}
return false
}

var target: Target {
switch libwordpressFFIVersion {
case .local:
return .binaryTarget(name: "libwordpressFFI", path: "target/libwordpressFFI.xcframework")
case let .release(version, checksum):
return .binaryTarget(
name: "libwordpressFFI",
url: "https://github.com/Automattic/wordpress-rs/releases/download/\(version)/libwordpressFFI.xcframework.zip",
checksum: checksum
)
}
}
}

// Add SwiftLint to the package so that we can see linting issues directly from Xcode.
func enableSwiftLint() throws {
#if os(macOS)
let version = try String(contentsOf: URL(string:"./.swiftlint.yml", relativeTo: URL(filePath: #filePath))!)
.split(separator: "\n")
.first(where: { $0.starts(with: "swiftlint_version") })?
.split(separator: ":")
.last?
.trimmingCharacters(in: .whitespaces)
guard let version else {
fatalError("Can't find swiftlint_version in .swiftlint.yml")
}

package.dependencies.append(.package(url: "https://github.com/realm/SwiftLint", exact: .init(version)!))

var platforms = package.platforms ?? []
if let mac = platforms.firstIndex(where: { $0 == .macOS(.v11) }) {
platforms.remove(at: mac)
platforms.append(.macOS(.v12))
}
package.platforms = platforms

if let target = package.targets.first(where: { $0.name == "WordPressAPI" }) {
target.plugins = (target.plugins ?? []) + [.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")]
}
#endif
}
1 change: 1 addition & 0 deletions scripts/xcodebuild-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ xcodebuild \
-scheme WordPress \
-derivedDataPath DerivedData \
-destination "id=${device_id}" \
-skipPackagePluginValidation \
test \
| xcbeautify