From 1b7e99a7ebd52de1e7dab4cee9a0f5af1e1b9842 Mon Sep 17 00:00:00 2001 From: Bruno Virlet Date: Wed, 11 Jan 2023 11:03:50 +0100 Subject: [PATCH] Add Swift Package Manager support --- Package.swift | 42 ++++++++++++++++++++++++++++++++++++++++++ test/swift/test.swift | 17 +++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 Package.swift create mode 100644 test/swift/test.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 00000000..4b1fa4df --- /dev/null +++ b/Package.swift @@ -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") + ] + ) + ] +) diff --git a/test/swift/test.swift b/test/swift/test.swift new file mode 100644 index 00000000..db2f19d2 --- /dev/null +++ b/test/swift/test.swift @@ -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) + } +} \ No newline at end of file