|
| 1 | +// swift-tools-version: 6.0 |
| 2 | + |
| 3 | +import PackageDescription |
| 4 | + |
| 5 | +import class Foundation.FileManager |
| 6 | +import class Foundation.ProcessInfo |
| 7 | + |
| 8 | +// Note: the JAVA_HOME environment variable must be set to point to where |
| 9 | +// Java is installed, e.g., |
| 10 | +// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home. |
| 11 | +func findJavaHome() -> String { |
| 12 | + if let home = ProcessInfo.processInfo.environment["JAVA_HOME"] { |
| 13 | + return home |
| 14 | + } |
| 15 | + |
| 16 | + // This is a workaround for envs (some IDEs) which have trouble with |
| 17 | + // picking up env variables during the build process |
| 18 | + let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home" |
| 19 | + if let home = try? String(contentsOfFile: path, encoding: .utf8) { |
| 20 | + if let lastChar = home.last, lastChar.isNewline { |
| 21 | + return String(home.dropLast()) |
| 22 | + } |
| 23 | + |
| 24 | + return home |
| 25 | + } |
| 26 | + |
| 27 | + fatalError("Please set the JAVA_HOME environment variable to point to where Java is installed.") |
| 28 | +} |
| 29 | +let javaHome = findJavaHome() |
| 30 | + |
| 31 | +let javaIncludePath = "\(javaHome)/include" |
| 32 | +#if os(Linux) |
| 33 | + let javaPlatformIncludePath = "\(javaIncludePath)/linux" |
| 34 | +#elseif os(macOS) |
| 35 | + let javaPlatformIncludePath = "\(javaIncludePath)/darwin" |
| 36 | +#else |
| 37 | + // TODO: Handle windows as well |
| 38 | + #error("Currently only macOS and Linux platforms are supported, this may change in the future.") |
| 39 | +#endif |
| 40 | + |
| 41 | +let package = Package( |
| 42 | + name: "benchmarks", |
| 43 | + platforms: [ |
| 44 | + .macOS("15.03") |
| 45 | + ], |
| 46 | + dependencies: [ |
| 47 | + .package(path: "../"), |
| 48 | + .package(url: "https://github.com/ordo-one/package-benchmark", .upToNextMajor(from: "1.4.0")), |
| 49 | + ], |
| 50 | + targets: [ |
| 51 | + .executableTarget( |
| 52 | + name: "JavaApiCallBenchmarks", |
| 53 | + dependencies: [ |
| 54 | + .product(name: "JavaRuntime", package: "swift-java"), |
| 55 | + .product(name: "JavaKit", package: "swift-java"), |
| 56 | + .product(name: "JavaKitNetwork", package: "swift-java"), |
| 57 | + .product(name: "Benchmark", package: "package-benchmark"), |
| 58 | + ], |
| 59 | + path: "Benchmarks/JavaApiCallBenchmarks", |
| 60 | + swiftSettings: [ |
| 61 | + .unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]), |
| 62 | + .swiftLanguageMode(.v5), |
| 63 | + ], |
| 64 | + plugins: [ |
| 65 | + .plugin(name: "BenchmarkPlugin", package: "package-benchmark") |
| 66 | + ] |
| 67 | + ) |
| 68 | + ] |
| 69 | +) |
0 commit comments