From 5cac1677284ef48c8973bae26f08a9cc21fa07a8 Mon Sep 17 00:00:00 2001 From: Lawrence Forooghian Date: Tue, 10 Dec 2024 16:40:15 -0300 Subject: [PATCH] Check that the library builds in `release` configuration To catch anything that's incorrectly gated behind an `#if DEBUG`, for example. Resolves #68. --- .github/workflows/check.yaml | 49 ++++++++++++++++++++++++--- Sources/BuildTool/BuildTool.swift | 18 ++++++++++ Sources/BuildTool/Configuration.swift | 12 +++++++ Sources/BuildTool/XcodeRunner.swift | 6 +++- 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 Sources/BuildTool/Configuration.swift diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 1a5b09c5..15e16609 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -74,7 +74,7 @@ jobs: - id: generation-step run: swift run BuildTool generate-matrices >> $GITHUB_OUTPUT - check-spm: + build-and-test-spm: name: SPM (Xcode ${{ matrix.tooling.xcodeVersion }}) runs-on: macos-15 needs: generate-matrices @@ -94,7 +94,26 @@ jobs: - run: swift build -Xswiftc -warnings-as-errors - run: swift test -Xswiftc -warnings-as-errors - check-xcode: + build-release-configuration-spm: + name: SPM, `release` configuration (Xcode ${{ matrix.tooling.xcodeVersion }}) + runs-on: macos-15 + needs: generate-matrices + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix).withoutPlatform }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: ${{ matrix.tooling.xcodeVersion }} + + # https://forums.swift.org/t/warnings-as-errors-for-libraries-frameworks/58393/2 + - run: swift build -Xswiftc -warnings-as-errors --configuration release + + build-and-test-xcode: name: Xcode, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }}) runs-on: macos-15 needs: generate-matrices @@ -119,6 +138,26 @@ jobs: - name: Run tests run: swift run BuildTool test-library --platform ${{ matrix.platform }} + build-release-configuration-xcode: + name: Xcode, `release` configuration, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }}) + runs-on: macos-15 + needs: generate-matrices + + strategy: + fail-fast: false + matrix: ${{ fromJson(needs.generate-matrices.outputs.matrix).withPlatform }} + + steps: + - uses: actions/checkout@v4 + with: + submodules: true + - uses: maxim-lobanov/setup-xcode@v1 + with: + xcode-version: ${{ matrix.tooling.xcodeVersion }} + + - name: Build library + run: swift run BuildTool build-library --platform ${{ matrix.platform }} --configuration release + check-example-app: name: Example app, ${{matrix.platform}} (Xcode ${{ matrix.tooling.xcodeVersion }}) runs-on: macos-15 @@ -149,8 +188,10 @@ jobs: needs: - lint - spec-coverage - - check-spm - - check-xcode + - build-and-test-spm + - build-release-configuration-spm + - build-and-test-xcode + - build-release-configuration-xcode - check-example-app steps: diff --git a/Sources/BuildTool/BuildTool.swift b/Sources/BuildTool/BuildTool.swift index 6591e42e..e1a01903 100644 --- a/Sources/BuildTool/BuildTool.swift +++ b/Sources/BuildTool/BuildTool.swift @@ -8,6 +8,7 @@ import Table struct BuildTool: AsyncParsableCommand { static let configuration = CommandConfiguration( subcommands: [ + BuildLibrary.self, BuildLibraryForTesting.self, TestLibrary.self, BuildExampleApp.self, @@ -18,6 +19,23 @@ struct BuildTool: AsyncParsableCommand { ) } +@available(macOS 14, *) +struct BuildLibrary: AsyncParsableCommand { + static let configuration = CommandConfiguration( + abstract: "Build the AblyChat library" + ) + + @Option var configuration: Configuration? + @Option var platform: Platform + + mutating func run() async throws { + let destinationSpecifier = try await platform.resolve() + let scheme = "AblyChat" + + try await XcodeRunner.runXcodebuild(action: "build", configuration: configuration, scheme: scheme, destination: destinationSpecifier) + } +} + @available(macOS 14, *) struct BuildLibraryForTesting: AsyncParsableCommand { static let configuration = CommandConfiguration( diff --git a/Sources/BuildTool/Configuration.swift b/Sources/BuildTool/Configuration.swift new file mode 100644 index 00000000..48ddbc6b --- /dev/null +++ b/Sources/BuildTool/Configuration.swift @@ -0,0 +1,12 @@ +import ArgumentParser + +enum Configuration: String, CaseIterable { + case debug + case release +} + +extension Configuration: ExpressibleByArgument { + init?(argument: String) { + self.init(rawValue: argument) + } +} diff --git a/Sources/BuildTool/XcodeRunner.swift b/Sources/BuildTool/XcodeRunner.swift index e9a82930..359d3e48 100644 --- a/Sources/BuildTool/XcodeRunner.swift +++ b/Sources/BuildTool/XcodeRunner.swift @@ -2,13 +2,17 @@ import Foundation @available(macOS 14, *) enum XcodeRunner { - static func runXcodebuild(action: String?, scheme: String, destination: DestinationSpecifier) async throws { + static func runXcodebuild(action: String?, configuration: Configuration? = nil, scheme: String, destination: DestinationSpecifier) async throws { var arguments: [String] = [] if let action { arguments.append(action) } + if let configuration { + arguments.append(contentsOf: ["-configuration", configuration.rawValue]) + } + arguments.append(contentsOf: ["-scheme", scheme]) arguments.append(contentsOf: ["-destination", destination.xcodebuildArgument])