Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ugocottin committed Apr 25, 2022
0 parents commit c9ba86a
Show file tree
Hide file tree
Showing 7 changed files with 244 additions and 0 deletions.
102 changes: 102 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
xcuserdata/
DerivedData/
.swiftpm/

# Created by https://www.toptal.com/developers/gitignore/api/swiftpm,swift
# Edit at https://www.toptal.com/developers/gitignore?templates=swiftpm,swift

### Swift ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore

## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
# Package.resolved
# *.xcodeproj
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
# .swiftpm

.build/

# CocoaPods
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
# Pods/
# Add this line if you want to avoid checking in source code from the Xcode workspace
# *.xcworkspace

# Carthage
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build/

# Accio dependency management
Dependencies/
.accio/

# fastlane
# It is recommended to not store the screenshots in the git repo.
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

# Code Injection
# After new code Injection tools there's a generated folder /iOSInjectionProject
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

### SwiftPM ###
Packages
xcuserdata
*.xcodeproj


# End of https://www.toptal.com/developers/gitignore/api/swiftpm,swift
22 changes: 22 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "CFirebird",
platforms: [
.macOS(.v10_10)
],
products: [
.library(
name: "CFirebird",
targets: ["CFirebird"]),
],
targets: [
.systemLibrary(name: "CFirebird", pkgConfig: "libfbclient"),
.testTarget(
name: "CFirebirdTests",
dependencies: ["CFirebird"]),
]
)
68 changes: 68 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# CFirebird

Modulemap to use fbclient library on linux and macOS.
The Firebird library is not provided, you have to install it yourself.

## Linux
Download the firebird library and install it on your system.

## macOS
Download the firebird library and install it on your system.

### Link on macOS

#### Using linkerSettings

```swift
let package = Package(
name: "YourLibrary",
...
targets: [
.target(name: "your-target", linkerSettings: [.unsafeFlags(["-L/usr/local/lib"])])
]
)
```
The drawback of this is that SwiftPM disable compilation for remote package dependencies that contains unsafe flags.

#### Using pkg-config

Put the following configuration to `/usr/local/lib/pkgconfig/libfbclient.pc`:

```pc
prefix=/Library/Frameworks/Firebird.framework
include_dir=${prefix}/Headers
lib_dir=${prefix}/Libraries
Name: libfbclient
Description: none
Version: <YOUR FIREBIRD VERSION>
Cflags: -I${include_dir}
Libs: -L${lib_dir}
```

Please set your Firebird version in the `Version` field of the pkgconfig file.

## Validate the installation

To ensure that the library if working, execute the tests!

```bash
$ swift test
```

## Usage

In `Package.swift`, add the following depedency

```swift
# package.swift
.package(url: "https://github.com/ugocottin/CFirebird.git", from: "0.0.0")
```

In your swift files, import the Firebird system library

```swift
import CFirebird
```

Enjoy!
3 changes: 3 additions & 0 deletions Sources/CFirebird/cfirebird.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "cfirebird.h"

// nothing here yet...
7 changes: 7 additions & 0 deletions Sources/CFirebird/cfirebird.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef C_FIREBIRD_H
#define C_FIREBIRD_H

#include <ibase.h>
#include <iberror.h>

#endif /* C_FIREBIRD_H */
5 changes: 5 additions & 0 deletions Sources/CFirebird/module.modulemap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CFirebird [system] {
header "cfirebird.h"
link "fbclient"
export *
}
37 changes: 37 additions & 0 deletions Tests/CFirebirdTests/CFirebirdTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import XCTest
@testable import CFirebird

final class CFirebirdTests: XCTestCase {

func testFunctionCall() {
var status: [ISC_STATUS] = Array(repeating: 0, count: Int(ISC_STATUS_LENGTH))
isc_print_status(&status)
let sqlCode = isc_sqlcode(&status)
print(sqlCode)
}

func testCodingTimestamp() {
var rawTime: time_t = 0
withUnsafeMutablePointer(to: &rawTime) {
time($0)
return
}

guard let unsafeTimeInfo = gmtime(&rawTime) else {
return XCTFail()
}

var encodedTimestamp: ISC_TIMESTAMP = .init()
withUnsafeMutablePointer(to: &encodedTimestamp) {
isc_encode_timestamp(unsafeTimeInfo, $0)
}

var decodedTimeInfo: tm = .init()
withUnsafeMutablePointer(to: &decodedTimeInfo) {
isc_decode_timestamp(&encodedTimestamp, $0)
}

let rawTime2 = timegm(&decodedTimeInfo)
XCTAssertEqual(rawTime, rawTime2)
}
}

0 comments on commit c9ba86a

Please sign in to comment.