Swiftpack.co - Jomy10/SemverSwift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Jomy10.
Jomy10/SemverSwift v1.2.0
Parser and evaluator for Semantic Versioning.
⭐️ 0
🕓 8 weeks ago
.package(url: "https://github.com/Jomy10/SemverSwift.git", from: "v1.2.0")

Semver

version tests platforms

A package for parsing and evaluating semantic versioning in Swift.

This is a binding to semver, which uses Cargo's flavor of semantic versioning. See semver's README for more information.

Bridge between Rust and Swift is generated using Swift Bridge.

Installation

Swift Package Manager

In your Package.swift

dependencies: [
    .package(url: "https://github.com/jomy10/SemverSwift", from: "1.0.0")
],
targets: [
    .target(
        name: "YourTarget",
        dependencies: [
            .product(name: "Semver", package: "SemverSwift")
        ]
    )
]

XCode

Examples

Creating and parsing a new Version

let version = Version(major: 1, minor: 0, patch: 3)
let versionParsed = try Version.parse("1.0.3").get()

XCTAssertEqual(version, versionParsed)

Of course in an actual application, you might want to implement some bother error handling such as guard or switch;

let versionParsedResult = Version.parse("1.0.3")
guard case .success(let versionParsed) = versionParsedResult else {
    XCTFail()
}

Version requirements

You can test if a version matches a specific version requirement using the VersionReq.match method:

let versionReq = try VersionReq.parse(">=1.0.0").get()
let version = try Version.parse("1.0.0").get()
let lowerVersion = try Version.parse("0.9.8").get()

XCTAssert(
    versionReq.matches(version: version)
)

XCTAssertFalse(
    versionReq.matches(version: lowerVersion)
)

The * operator matches any version:

let versionReq = try VersionReq.parse("*").get()
let otherVersionReq = VersionReq.STAR

XCTAssertEqual(versionReq, otherVersionReq)

let version = Version(major: 1, minor: 50, patch: 69)

// Will always match
XCTAssert(versionReq.matches(version: version))

You can also define ranges:

let versionReq = try VersionReq.parse(">=1.2.3, <1.8").get()
let versionIn = try Version.parse("1.6.3").get()
let versionOut = try Version.parse("1.8.0").get()

XCTAssert(versionReq.matches(version: versionIn))
XCTAssertFalse(versionReq.matches(version: versionOut))

Platform support

The package currently supports macOS, iOS and iOS Simulator.

Support for Linux is possible if you compile your program using swiftc. More information can be found in the Swift Bridge documentation. In this case, it will boil down to copying the files in the generated folder (after building) and copying the semver.swift file in the Semver package to your project (and removing the import statements, except for Foundation). Then also copying the static library obtained using cargo build --target {linux-target}. After that, compile your program with swiftc according to the Swift Bridge documentation. If you need Linux support, feel free to open an issue and I will guide you through the process and write a more thorough documentation.

Support for other Apple platforms has not been tested, but we will probably need to compile Rust to those platforms, there is no official support for the other Apple platforms yet however.

Project structure

SemverRustBridge

This directory contains the Rust source files that bridge the Rust semver package to Swift using swift-bridge.

SemverSwiftBridge

This is the package generated by Swift Bridge.

SemverSwift

This is the package that further refines the generated package for Swift, providing a nicer public API.

Building from source

Clone this repository

git clone https://github.com/jomy10/SemverSwift

To create a Swift package from the Rust source files, you will need to have the swift-bridge-cli installed:

cargo install -f swift-bridge-cli

To build the project for macOS, iOS, and iOS Simulator, run the following:

If you use bash, or any other shell than zsh, you can change the interpreter at the top of the build.sh file.

If you would like the SwiftBridge package to be build somewhere else, go ahead and change that first (the default is the folder above the cloned repo)

cd SemverRustBridge
./build.sh RELEASE

This will build the SemverBridge package. In the Package.swift of this cloned repo, change the dependency to point to this generated file.

To build a debug version for macOS, run:

./build.sh
# or
./build.sh DEBUG

Running tests

To run the tests:

swift test

Roadmap

This project will follow updates of semver. The current version is 1.0.6.

Unimplemented features

A number of features are currently unimplemented and are planned to be implemented soon (help is appreciated).

  • BuildMetadata

Contributing

See CONTRIBUTING.md.

License

This package is dual licensed under Apache 2.0 and MIT licenses, just like the original crate.

See licenses.

GitHub

link
Stars: 0
Last commit: 3 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.2.0
8 weeks ago

Full Changelog: https://github.com/Jomy10/SemverSwift/compare/v1.1.0...v1.2.0

folow version 1.0.6 of semver

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics