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

Add global RuntimeConfiguration #6

Merged
merged 2 commits into from
Feb 27, 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
3 changes: 3 additions & 0 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ authors:
- family-names: "Bauer"
given-names: "Andreas"
orcid: "https://orcid.org/0000-0002-1680-237X"
- family-names: "Zagar"
given-names: "Philipp"
orcid: "https://orcid.org/0009-0001-5934-2078"
title: "SpeziFoundation"
doi: 10.5281/zenodo.10077558
url: "https://github.com/StanfordSpezi/SpeziFoundation"
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ SpeziFoundation contributors

* [Paul Schmiedmayer](https://github.com/PSchmiedmayer)
* [Andreas Bauer](https://github.com/Supereg)
* [Philipp Zagar](https://github.com/philippzagar)
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ let package = Package(
],
targets: [
.target(
name: "SpeziFoundation"
name: "SpeziFoundation",
swiftSettings: [
.enableExperimentalFeature("StrictConcurrency")
]
),
.testTarget(
name: "SpeziFoundationTests",
Expand Down
42 changes: 42 additions & 0 deletions Sources/SpeziFoundation/RuntimeConfig/RuntimeConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// This source file is part of the Stanford Spezi open-source project
//
// SPDX-FileCopyrightText: 2023 Stanford University and the project authors (see CONTRIBUTORS.md)
//
// SPDX-License-Identifier: MIT
//

import Foundation


/// Holds globally accessible runtime testing support configurations.
///
/// The ``RuntimeConfig`` stores configurations of the current runtime environment for testing support.
///
/// - Important: ``RuntimeConfig`` is only exposed as the [System Programming Interface (SPI)](https://blog.eidinger.info/system-programming-interfaces-spi-in-swift-explained)
/// target `TestingSupport`, therefore requiring to state the SPI target upon importing the `SpeziFoundation` target via `@_spi(TestingSupport)`.
///
/// ### Usage
///
/// One is able to access the ``RuntimeConfig`` from the `TestingSupport` SPI target as shown below.
///
/// ```swift
/// // Import the entire target, including the `TestingSupport` SPI target.
/// @_spi(TestingSupport) import SpeziFoundation
///
/// if RuntimeConfig.testMode { /* ... */ }
/// ```
///
/// As of Swift 5.8, one is able to only import the SPI target, without any other parts of the overall SPM target,
/// by setting the `-experimental-spi-only-imports` Swift compiler flag and using the `@_spiOnly` notation upon target import.
///
/// ```swift
/// // Import only the `TestingSupport` SPI target.
/// @_spiOnly import SpeziFoundation
///
/// if RuntimeConfig.testMode { /* ... */ }
/// ```
@_spi(TestingSupport)
public struct RuntimeConfig: Sendable {
public static let testMode: Bool = ProcessInfo.processInfo.arguments.contains("--testMode")
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ Spezi Foundation provides a base layer of functionality useful in many applicati

- ``AnyArray``
- ``AnyOptional``

### Runtime Configuration

- `RuntimeConfig` (exposed via the `TestingSupport` SPI target)
Loading