diff --git a/demos/swift/.gitignore b/demos/swift/.gitignore new file mode 100644 index 0000000..95c4320 --- /dev/null +++ b/demos/swift/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +/.build +/Packages +/*.xcodeproj +xcuserdata/ diff --git a/demos/swift/.vscode/launch.json b/demos/swift/.vscode/launch.json new file mode 100644 index 0000000..4de07ed --- /dev/null +++ b/demos/swift/.vscode/launch.json @@ -0,0 +1,16 @@ +// .vscode/launch.json +{ + "version": "0.2.0", + "configurations": [ + // Running executables + { + "type": "lldb", + "request": "launch", + "name": "Run your Executable", + "program": "${workspaceFolder}/.build/debug/swiftDemo", + "args": [], + "cwd": "${workspaceFolder}", + "preLaunchTask": "swift-build" + } + ] +} diff --git a/demos/swift/.vscode/settings.json b/demos/swift/.vscode/settings.json new file mode 100644 index 0000000..4cd3f84 --- /dev/null +++ b/demos/swift/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + // You need to adapt this path to your swift installation. + // See here for more info: + // https://github.com/vadimcn/vscode-lldb/issues/234 + "lldb.library": "/home/hediet/swift-5.1.5-RELEASE-ubuntu14.04/usr/lib/liblldb.so" +} diff --git a/demos/swift/.vscode/tasks.json b/demos/swift/.vscode/tasks.json new file mode 100644 index 0000000..9656016 --- /dev/null +++ b/demos/swift/.vscode/tasks.json @@ -0,0 +1,23 @@ +{ + "version": "2.0.0", + "tasks": [ + // compile your SPM project + { + "label": "swift-build", + "type": "shell", + "command": "swift build" // for TensorFlow add -Xlinker -ltensorflow + }, + // compile your SPM tests + { + "label": "swift-build-tests", + "type": "process", + "command": "swift", + "group": "build", + "args": [ + "build", + "--build-tests" + // for TensorFlow add "-Xlinker", "-ltensorflow" + ] + } + ] +} diff --git a/demos/swift/Package.swift b/demos/swift/Package.swift new file mode 100644 index 0000000..f4f94b2 --- /dev/null +++ b/demos/swift/Package.swift @@ -0,0 +1,22 @@ +// swift-tools-version:5.1 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "swiftDemo", + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages which this package depends on. + .target( + name: "swiftDemo", + dependencies: []), + .testTarget( + name: "swiftDemoTests", + dependencies: ["swiftDemo"]), + ] +) diff --git a/demos/swift/Sources/swiftDemo/main.swift b/demos/swift/Sources/swiftDemo/main.swift new file mode 100644 index 0000000..8551e0f --- /dev/null +++ b/demos/swift/Sources/swiftDemo/main.swift @@ -0,0 +1,5 @@ +let s = "{\"kind\":{\"graph\":true}," + + "\"nodes\":[{\"id\":\"1\"},{\"id\":\"2\"}]," + + "\"edges\":[{\"from\":\"1\",\"to\":\"2\"}]}"; + +print(s) diff --git a/demos/swift/Tests/LinuxMain.swift b/demos/swift/Tests/LinuxMain.swift new file mode 100644 index 0000000..ff054e8 --- /dev/null +++ b/demos/swift/Tests/LinuxMain.swift @@ -0,0 +1,7 @@ +import XCTest + +import swiftTests + +var tests = [XCTestCaseEntry]() +tests += swiftTests.allTests() +XCTMain(tests) diff --git a/demos/swift/Tests/swiftDemoTests/XCTestManifests.swift b/demos/swift/Tests/swiftDemoTests/XCTestManifests.swift new file mode 100644 index 0000000..f8cba90 --- /dev/null +++ b/demos/swift/Tests/swiftDemoTests/XCTestManifests.swift @@ -0,0 +1,9 @@ +import XCTest + +#if !canImport(ObjectiveC) +public func allTests() -> [XCTestCaseEntry] { + return [ + testCase(swiftTests.allTests), + ] +} +#endif diff --git a/demos/swift/Tests/swiftDemoTests/swiftDemoTests.swift b/demos/swift/Tests/swiftDemoTests/swiftDemoTests.swift new file mode 100644 index 0000000..da3bf09 --- /dev/null +++ b/demos/swift/Tests/swiftDemoTests/swiftDemoTests.swift @@ -0,0 +1,47 @@ +import XCTest +import class Foundation.Bundle + +final class swiftTests: XCTestCase { + func testExample() throws { + // This is an example of a functional test case. + // Use XCTAssert and related functions to verify your tests produce the correct + // results. + + // Some of the APIs that we use below are available in macOS 10.13 and above. + guard #available(macOS 10.13, *) else { + return + } + + let fooBinary = productsDirectory.appendingPathComponent("swift") + + let process = Process() + process.executableURL = fooBinary + + let pipe = Pipe() + process.standardOutput = pipe + + try process.run() + process.waitUntilExit() + + let data = pipe.fileHandleForReading.readDataToEndOfFile() + let output = String(data: data, encoding: .utf8) + + XCTAssertEqual(output, "Hello, world!\n") + } + + /// Returns path to the built products directory. + var productsDirectory: URL { + #if os(macOS) + for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") { + return bundle.bundleURL.deletingLastPathComponent() + } + fatalError("couldn't find the products directory") + #else + return Bundle.main.bundleURL + #endif + } + + static var allTests = [ + ("testExample", testExample), + ] +} diff --git a/demos/swift/main.swift b/demos/swift/main.swift new file mode 100644 index 0000000..2cf70bc --- /dev/null +++ b/demos/swift/main.swift @@ -0,0 +1,2 @@ +import Swift +print("Hello, World!") \ No newline at end of file