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.
Semver
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
XCode
Instructions on adding a package to your XCode project (brief)
https://github.com/jomy10/SemverSwift
Othernstructions on adding a package to your XCode project.
Examples
Creating and parsing a new Version
Of course in an actual application, you might want to implement some bother error handling such as
guard
orswitch
;Version requirements
You can test if a version matches a specific version requirement using the
VersionReq.match
method:The
*
operator matches any version:You can also define ranges:
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 theSwift Bridge
documentation. In this case, it will boil down to copying the files in thegenerated
folder (after building) and copying thesemver.swift
file in theSemver
package to your project (and removing the import statements, except for Foundation). Then also copying the static library obtained usingcargo build --target {linux-target}
. After that, compile your program withswiftc
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 usingswift-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
To create a Swift package from the Rust source files, you will need to have the
swift-bridge-cli
installed: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)This will build the
SemverBridge
package. In thePackage.swift
of this cloned repo, change the dependency to point to this generated file.To build a debug version for macOS, run:
Running tests
To run the tests:
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.