Skip to content

Commit

Permalink
swift 6 updates across the board (#45)
Browse files Browse the repository at this point in the history
* swift 6 updates across the board
* macOS 15 runner for CI
* iOS version match for Xcode 16
  • Loading branch information
heckj authored Nov 15, 2024
1 parent 0f0248b commit 2dc2756
Show file tree
Hide file tree
Showing 54 changed files with 302 additions and 302 deletions.
11 changes: 3 additions & 8 deletions .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,16 @@ on:
jobs:
build:

runs-on: macos-14
runs-on: macos-15
strategy:
matrix:
run-config:
- { scheme: 'Lindenmayer-Package', destination: 'platform=iOS Simulator,OS=15.5,name=iPhone 8' }
# Xcode on Github Actions supports at best up to macOS 11.6.2 currently...
- { scheme: 'Lindenmayer-Package', destination: 'platform=macOS,arch=x86_64' }
- { scheme: 'Lindenmayer-Package', destination: 'platform=iOS Simulator,OS=18.1,name=iPhone 16' }
- { scheme: 'Lindenmayer-Package', destination: 'platform=macOS' }

steps:
- uses: actions/checkout@v4

# default Xcode for macOS 14 image is v15.0.1
- name: Select Xcode 15.3
run: sudo xcode-select -s /Applications/Xcode_15.3.app

- name: Show Build SDK
run: xcodebuild -showsdks

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Joseph Heck
Copyright (c) 2021-2024 Joseph Heck

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 12 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

import PackageDescription

var globalSwiftSettings: [PackageDescription.SwiftSetting] = [
.enableExperimentalFeature("StrictConcurrency"),
.enableUpcomingFeature("ExistentialAny"),
.enableExperimentalFeature("AccessLevelOnImport"),
.enableUpcomingFeature("InternalImportsByDefault"),
]

let package = Package(
name: "Lindenmayer",
platforms: [
Expand All @@ -19,22 +26,23 @@ let package = Package(
],
dependencies: [
.package(url: "https://github.com/heckj/SceneKitDebugTools.git", from: "0.1.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/swiftlang/swift-docc-plugin", from: "1.0.0"),
],
targets: [
.target(
name: "Lindenmayer",
dependencies: ["SceneKitDebugTools"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
swiftSettings: globalSwiftSettings
),
.target(
name: "LindenmayerViews",
dependencies: ["Lindenmayer", "SceneKitDebugTools"],
swiftSettings: [.enableExperimentalFeature("StrictConcurrency")]
swiftSettings: globalSwiftSettings
),
.testTarget(
name: "LindenmayerTests",
dependencies: ["Lindenmayer", "SceneKitDebugTools"]
),
]
],
swiftLanguageVersions: [.version("6"), .v5]
)
10 changes: 5 additions & 5 deletions Sources/Lindenmayer/Examples/Examples2D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum Examples2D {
struct Internode: Module {
// This is the kind of thing that I want external developers using the library to be able to create to represent elements within their L-system.
public var name = "I"
public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] // draws a line 10 units long
public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)] // draws a line 10 units long
public init() {}
}

Expand Down Expand Up @@ -48,7 +48,7 @@ public enum Examples2D {
struct Leaf: Module {
static let green = ColorRepresentation(r: 0.3, g: 0.56, b: 0.0)
public var name = "L"
public var render2D: [TwoDRenderCmd] = [
public var render2D: [any TwoDRenderCmd] = [
RenderCommand.SetLineWidth(width: 3),
RenderCommand.SetColor(representation: green),
RenderCommand.Draw(length: 5),
Expand All @@ -59,7 +59,7 @@ public enum Examples2D {

struct Stem: Module {
public var name = "I"
public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 5)] // would be neat to make this green...
public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 5)] // would be neat to make this green...
}

static let stem = Stem()
Expand Down Expand Up @@ -99,14 +99,14 @@ public enum Examples2D {

struct F: Module {
public var name = "F"
public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)]
public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)]
}

static let f = F()

struct G: Module {
public var name = "G"
public var render2D: [TwoDRenderCmd] = [RenderCommand.Draw(length: 10)]
public var render2D: [any TwoDRenderCmd] = [RenderCommand.Draw(length: 10)]
}

static let g = G()
Expand Down
18 changes: 9 additions & 9 deletions Sources/Lindenmayer/Examples/Examples3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum Examples3D: Sendable {

struct Cyl: Module {
public var name = "C"
public var render3D: ThreeDRenderCmd = RenderCommand.Cylinder(
public var render3D: any ThreeDRenderCmd = RenderCommand.Cylinder(
length: 10,
radius: 1,
color: ColorRepresentation(red: 1.0, green: 0.1, blue: 0.1, alpha: 1.0)
Expand All @@ -50,7 +50,7 @@ public enum Examples3D: Sendable {

struct S: Module {
public var name = "S"
public var render3D: ThreeDRenderCmd = RenderCommand.Cylinder(
public var render3D: any ThreeDRenderCmd = RenderCommand.Cylinder(
length: 5,
radius: 2,
color: ColorRepresentation(red: 0.1, green: 1.0, blue: 0.1, alpha: 1.0)
Expand Down Expand Up @@ -146,7 +146,7 @@ public enum Examples3D: Sendable {

struct StaticTrunk: Module {
public var name = ""
public var render3D: ThreeDRenderCmd {
public var render3D: any ThreeDRenderCmd {
RenderCommand.Cylinder(
length: growthDistance,
radius: diameter / 2,
Expand Down Expand Up @@ -395,7 +395,7 @@ public enum Examples3D: Sendable {
struct Stem2: Module {
public var name = "i"
let length: Double // start at 10
public var render3D: ThreeDRenderCmd {
public var render3D: any ThreeDRenderCmd {
RenderCommand.Cylinder(
length: length,
radius: length / 10,
Expand All @@ -407,7 +407,7 @@ public enum Examples3D: Sendable {
struct StaticStem2: Module {
public var name = "I"
let length: Double // start at 10
public var render3D: ThreeDRenderCmd {
public var render3D: any ThreeDRenderCmd {
RenderCommand.Cylinder(
length: length,
radius: length / 10,
Expand All @@ -417,19 +417,19 @@ public enum Examples3D: Sendable {
}

public static let randomBush = LSystem.create(Stem2(length: 1), with: Xoshiro(seed: 42))
.rewriteWithRNG(directContext: Stem2.self) { stem, rng async -> [Module] in
.rewriteWithRNG(directContext: Stem2.self) { stem, rng async -> [any Module] in

let upper: Float = 45.0
let lower: Float = 15.0

if await rng.p(0.5) {
return await [
if rng.p(0.5) {
return [
StaticStem2(length: 2),
Modules.PitchDown(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))),
Stem2(length: stem.length),
]
} else {
return await [
return [
StaticStem2(length: 2),
Modules.PitchUp(angle: Angle(degrees: Double(rng.randomFloat(in: lower ... upper)))),
Stem2(length: stem.length),
Expand Down
12 changes: 6 additions & 6 deletions Sources/Lindenmayer/LSystem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ public enum LSystem: Sendable {
/// Creates a new Lindenmayer system from an initial state.
/// - Parameters:
/// - axiom: An initial module that represents the initial state of the Lindenmayer system..
public static func create(_ axiom: Module) -> ContextualLSystem {
public static func create(_ axiom: some Module) -> ContextualLSystem {
ContextualLSystem([axiom], state: nil, newStateIndicators: nil)
}

/// Creates a new Lindenmayer system from an initial state.
/// - Parameters:
/// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system..
public static func create(_ axiom: [Module]) -> ContextualLSystem {
public static func create(_ axiom: [any Module]) -> ContextualLSystem {
ContextualLSystem(axiom, state: nil, newStateIndicators: nil)
}

/// Creates a new Lindenmayer system from an initial state and using the random number generator you provide.
/// - Parameters:
/// - axiom: An initial module that represents the initial state of the Lindenmayer system..
/// - prng: An optional psuedo-random number generator to use for randomness in rule productions.
public static func create<RNGType: Sendable>(_ axiom: Module, with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
public static func create<RNGType: Sendable>(_ axiom: some Module, with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
if let prng {
return RandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, prng: RNGWrapper(prng))
}
Expand All @@ -66,7 +66,7 @@ public enum LSystem: Sendable {
/// - Parameters:
/// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system..
/// - prng: An optional psuedo-random number generator to use for for randomness in rule productions.
public static func create<RNGType: Sendable>(_ axiom: [Module], with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
public static func create<RNGType: Sendable>(_ axiom: [any Module], with prng: RNGType?) -> RandomContextualLSystem<RNGType> {
if let prng {
return RandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, prng: RNGWrapper(prng))
}
Expand All @@ -78,7 +78,7 @@ public enum LSystem: Sendable {
/// - axiom: An initial module that represents the initial state of the Lindenmayer system.
/// - prng: An optional psuedo-random number generator to use for for randomness in rule productions.
/// - parameters: An instance of type you provide that the L-system provides to the rules you create for use as parameters.
public static func create<PType: Sendable, RNGType: Sendable>(_ axiom: Module, with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
public static func create<PType: Sendable, RNGType: Sendable>(_ axiom: some Module, with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
if let prng {
return ParameterizedRandomContextualLSystem(axiom: [axiom], state: nil, newStateIndicators: nil, parameters: parameters, prng: RNGWrapper(prng), rules: [])
}
Expand All @@ -90,7 +90,7 @@ public enum LSystem: Sendable {
/// - axiom: A sequence of modules that represents the initial state of the Lindenmayer system..
/// - prng: An optional psuedo-random number generator to use for for randomness in rule productions.
/// - parameters: An instance of type you provide that the L-system provides to the rules you create for use as parameters.
public static func create<PType: Sendable, RNGType: Sendable>(_ axiom: [Module], with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
public static func create<PType: Sendable, RNGType: Sendable>(_ axiom: [any Module], with prng: RNGType?, using parameters: PType) -> ParameterizedRandomContextualLSystem<PType, RNGType> {
if let prng {
return ParameterizedRandomContextualLSystem(axiom: axiom, state: nil, newStateIndicators: nil, parameters: parameters, prng: RNGWrapper(prng), rules: [])
}
Expand Down
Loading

0 comments on commit 2dc2756

Please sign in to comment.