Skip to content

Commit

Permalink
Add global RuntimeConfiguration (#6)
Browse files Browse the repository at this point in the history
# Add global RuntimeConfiguration

## ♻️ Current situation & Problem
Within the `SpeziChat` project, we discovered the need for a global
runtime configuration object that holds certain testing support
variables (e.g. about the debug mode).


## ⚙️ Release Notes 
- Add global `RuntimeConfiguration` accessible via the `TestingSupport`
SPI target.


## 📚 Documentation
Added proper documentation


## ✅ Testing
No new test cases written


## 📝 Code of Conduct & Contributing Guidelines 

By submitting creating this pull request, you agree to follow our [Code
of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md):
- [x] I agree to follow the [Code of
Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md)
and [Contributing
Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
  • Loading branch information
philippzagar authored Feb 27, 2024
1 parent 0346857 commit 662f25d
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 1 deletion.
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)

0 comments on commit 662f25d

Please sign in to comment.