Skip to content
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

Globally exclude ObjC product and targets for Linux #66

Merged
merged 4 commits into from
Jan 8, 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
28 changes: 0 additions & 28 deletions .github/workflows/build-ios.yml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/build-linux.yml

This file was deleted.

38 changes: 36 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
name: Build macOS
name: Build Blocks

# 📜 https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows
on:
Expand All @@ -9,7 +9,8 @@ on:
- main

jobs:
build:
build_macOS:
name: Build macOS
runs-on: macos-13
steps:
- name: Checkout
Expand All @@ -23,3 +24,36 @@ jobs:
- name: Test debug version
run: |
make test

build_iOS:
name: Build iOS
runs-on: macos-13
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Output XCode version
run: |
xcodebuild -version
- name: Show destinations
run: xcrun xcodebuild -showdestinations -scheme Blocks
- name: Build debug version
run: |
make build-ios
# TODO: Find a way for tests without the following error:
#
# ```
# Error Domain=com.apple.dt.IDEContainerErrorDomain Code=6 "Cannot open "Documentation.docc" as a "Folder" because it is already open as a "Swift User Managed Package Folder"." UserInfo={NSLocalizedDescription=Cannot open "Documentation.docc" as a "Folder" because it is already open as a "Swift User Managed Package Folder".}
# ```

build_linux:
name: Build Linux
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build debug version
run: |
swift build
- name: Test debug version
run: |
swift test
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ WORKDIR /app
COPY . .

# Build the Swift project
RUN swift build --target Blocks
RUN swift build

# Run the tests
CMD ["swift", "test"]
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ cli:
swift build --package-path Examples/BlocksCLI/

build-ios:
xcodebuild -verbose -scheme Blocks -destination "platform=iOS Simulator,OS=17.0.1" -derivedDataPath "/tmp/" clean build
xcrun xcodebuild clean build -scheme Blocks -destination generic/platform=ios
xcrun xcodebuild clean build -scheme ObjectiveBlocks -destination generic/platform=ios

test-debug:
swift package clean
Expand All @@ -23,7 +24,7 @@ test:
set -o pipefail && swift test | xcpretty

test-ios:
xcodebuild -verbose -scheme Blocks -destination "platform=iOS Simulator,OS=17.0.1" -derivedDataPath "/tmp/" clean build test
xcrun xcodebuild clean test -scheme Blocks -destination "platform=iOS Simulator,OS=17.0.1"

release:
swift build -c release
Expand Down Expand Up @@ -57,3 +58,6 @@ dump-packages:

build-linux-dev:
docker build -t swift-blocks .

test-linux-dev:
docker run swift-blocks
79 changes: 53 additions & 26 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,57 @@
// 📜 https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageDescription.md
import PackageDescription

#if os(Linux)
let products: [Product] = [
.library(
name: "Blocks",
targets: ["Blocks"]
)
]
#else
let products: [Product] = [
.library(
name: "Blocks",
targets: ["Blocks"]
),
.library(
name: "ObjectiveBlocks",
targets: ["ObjectiveBlocks"]
)
]
#endif

#if os(Linux)
let targets: [Target] = [
.target(
name: "Blocks",
dependencies: []
),
.testTarget(
name: "BlocksTests",
dependencies: ["Blocks"],
resources: [.process("Resources")]
)
]
#else
let targets: [Target] = [
.target(
name: "Blocks",
dependencies: []
),
.testTarget(
name: "BlocksTests",
dependencies: ["Blocks"],
resources: [.process("Resources")]
),
.target(
name: "ObjectiveBlocks",
dependencies: [],
publicHeadersPath: "public"
)
]
#endif

let package = Package(
name: "swift-blocks",
platforms: [
Expand All @@ -11,31 +62,7 @@ let package = Package(
.tvOS(.v15),
.watchOS(.v8)
],
products: [
.library(
name: "Blocks",
targets: ["Blocks"]
),
.library(
name: "ObjectiveBlocks",
targets: ["ObjectiveBlocks"]
)
],
products: products,
dependencies: [],
targets: [
.target(
name: "Blocks",
dependencies: []
),
.testTarget(
name: "BlocksTests",
dependencies: ["Blocks"],
resources: [.process("Resources")]
),
.target(
name: "ObjectiveBlocks",
dependencies: [],
publicHeadersPath: "public"
)
]
targets: targets
)
11 changes: 0 additions & 11 deletions Tests/BlocksTests/JSONTests.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@testable import Blocks
import os
import XCTest

final class JSONTests: XCTestCase {
Expand Down Expand Up @@ -44,15 +43,5 @@ final class JSONTests: XCTestCase {
]
}
""")

// Test how things look with print and logger
JSON.print(sampleCodable)

if #available(iOS 14.0, *) {
let logger = Logger(subsystem: "swift-blocks", category: "JSON")
logger.info("JSON public: \(JSON.stringify(sampleCodable), privacy: .public)")
logger.info("JSON private: \(JSON.stringify(sampleCodable), privacy: .private)")
logger.info("JSON auto/hash: \(JSON.stringify(sampleCodable), privacy: .auto(mask: .hash))")
}
}
}
2 changes: 2 additions & 0 deletions Tests/BlocksTests/Security/PKCETests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if canImport(CryptoKit)
@testable import Blocks
import XCTest

Expand All @@ -12,3 +13,4 @@ final class PKCETests: XCTestCase {
XCTAssertEqual(try pkceSeeds.codeChallenge(), "E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM")
}
}
#endif
2 changes: 2 additions & 0 deletions Tests/BlocksTests/Security/SecurityErrorTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if canImport(Security)
@testable import Blocks
import XCTest

Expand All @@ -7,3 +8,4 @@ final class SecurityErrorTests: XCTestCase {
XCTAssertEqual(sut.localizedDescription, "A keychain with the same name already exists.")
}
}
#endif
4 changes: 3 additions & 1 deletion Tests/BlocksTests/Security/SecurityUtilsTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#if canImport(Security)
import Blocks
import XCTest

final class PKCEUtilsTests: XCTestCase {
final class SecurityUtilsTests: XCTestCase {
func testGenerateCryptographicallySecureRandomOctets() {
measure {
do {
Expand All @@ -17,3 +18,4 @@ final class PKCEUtilsTests: XCTestCase {
}
}
}
#endif
3 changes: 3 additions & 0 deletions Tests/BlocksTests/Transport/DummyURLRequest.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@testable import Blocks
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

struct DummyURLRequest {
func create() throws -> URLRequest {
Expand Down
2 changes: 2 additions & 0 deletions Tests/BlocksTests/Transport/LoggingTransportTests.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if canImport(os)
@testable import Blocks
import XCTest

Expand All @@ -18,3 +19,4 @@ final class LoggingTransportTests: XCTestCase {
XCTAssertEqual(data, "Hello".data(using: .utf8)!)
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@testable import Blocks
import XCTest

#if os(Linux)
// Cannot use this test as `HTTPURLResponse` has no accessible initializers
#else
@available(iOS 15.0.0, *)
@available(macOS 12.0, *)
final class StatusCodeCheckingTransportTests: XCTestCase {
Expand Down Expand Up @@ -47,3 +50,4 @@ final class StatusCodeCheckingTransportTests: XCTestCase {
XCTAssertEqual(sut.localizedDescription, "Unexpected HTTP status code: 200")
}
}
#endif
Loading
Loading