Add Swift Package Manager support

This commit is contained in:
Bruno Virlet 2023-01-11 11:03:50 +01:00 committed by John McNamara
parent 052d70ff95
commit 1b7e99a7eb
2 changed files with 59 additions and 0 deletions

42
Package.swift Normal file
View File

@ -0,0 +1,42 @@
// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
let package = Package(
name: "libxlsxwriter",
products: [
.library(
name: "libxlsxwriter",
targets: ["libxlsxwriter"]),
],
targets: [
.target(
name: "libxlsxwriter",
path: ".",
exclude: [
"src/Makefile",
],
sources: [
"include",
"src",
"third_party/minizip/zip.c",
"third_party/minizip/ioapi.c",
"third_party/tmpfileplus/tmpfileplus.c",
"third_party/md5/md5.c"
],
publicHeadersPath: "include",
linkerSettings: [
.linkedLibrary("z")
]),
.testTarget(
name: "libxlsxwritertests",
dependencies: ["libxlsxwriter"],
path: ".",
sources: ["test/swift"],
linkerSettings: [
.linkedLibrary("z")
]
)
]
)

17
test/swift/test.swift Normal file
View File

@ -0,0 +1,17 @@
import XCTest
@testable import libxlsxwriter
final class LibXlsxWriterTests: XCTestCase {
func testExample() throws {
let documentDirectory = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor:nil, create:false)
let fileURL = documentDirectory.appendingPathComponent("hello_world.xlsx")
let workbook = workbook_new((fileURL.absoluteString.dropFirst(6) as NSString).fileSystemRepresentation)
let worksheet = workbook_add_worksheet(workbook, nil)
worksheet_write_string(worksheet, 0, 0, "Hello", nil)
worksheet_write_number(worksheet, 1, 0, 123, nil)
workbook_close(workbook)
print(fileURL)
}
}