Skip to content

Commit 1191961

Browse files
committed
Create Swift package
1 parent 9ca45ba commit 1191961

File tree

4 files changed

+114
-0
lines changed

4 files changed

+114
-0
lines changed

Package.swift

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// swift-tools-version: 6.0
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import CompilerPluginSupport
5+
import PackageDescription
6+
7+
import class Foundation.FileManager
8+
import class Foundation.ProcessInfo
9+
10+
// Note: the JAVA_HOME environment variable must be set to point to where
11+
// Java is installed, e.g.,
12+
// Library/Java/JavaVirtualMachines/openjdk-21.jdk/Contents/Home.
13+
func findJavaHome() -> String {
14+
if let home = ProcessInfo.processInfo.environment["JAVA_HOME"] {
15+
return home
16+
}
17+
18+
// This is a workaround for envs (some IDEs) which have trouble with
19+
// picking up env variables during the build process
20+
let path = "\(FileManager.default.homeDirectoryForCurrentUser.path()).java_home"
21+
if let home = try? String(contentsOfFile: path, encoding: .utf8) {
22+
if let lastChar = home.last, lastChar.isNewline {
23+
return String(home.dropLast())
24+
}
25+
26+
return home
27+
}
28+
29+
fatalError("Please set the JAVA_HOME environment variable to point to where Java is installed.")
30+
}
31+
let javaHome = findJavaHome()
32+
33+
let javaIncludePath = "\(javaHome)/include"
34+
#if os(Linux)
35+
let javaPlatformIncludePath = "\(javaIncludePath)/linux"
36+
#elseif os(macOS)
37+
let javaPlatformIncludePath = "\(javaIncludePath)/darwin"
38+
#elseif os(Windows)
39+
let javaPlatformIncludePath = "\(javaIncludePath)/win32"
40+
#endif
41+
42+
let package = Package(
43+
name: "Kotlin",
44+
platforms: [
45+
.macOS(.v10_15)
46+
],
47+
products: [
48+
.library(
49+
name: "Kotlin",
50+
targets: ["Kotlin"]
51+
),
52+
.library(
53+
name: "KotlinJVM",
54+
targets: ["KotlinJVM"]
55+
),
56+
],
57+
dependencies: [
58+
.package(
59+
url: "https://github.com/PureSwift/swift-java.git",
60+
branch: "feature/android-shim"
61+
),
62+
.package(
63+
url: "https://github.com/apple/swift-log",
64+
from: "1.6.3"
65+
),
66+
.package(
67+
url: "https://github.com/apple/swift-system",
68+
from: "1.5.0"
69+
)
70+
],
71+
targets: [
72+
.target(
73+
name: "Kotlin"
74+
),
75+
.target(
76+
name: "KotlinJVM",
77+
dependencies: [
78+
.product(
79+
name: "JavaKit",
80+
package: "swift-java"
81+
),
82+
.product(
83+
name: "JavaKitCollection",
84+
package: "swift-java"
85+
)
86+
],
87+
exclude: ["swift-java.config"],
88+
swiftSettings: [
89+
.swiftLanguageMode(.v5),
90+
.unsafeFlags(["-I\(javaIncludePath)", "-I\(javaPlatformIncludePath)"]),
91+
]
92+
),
93+
.testTarget(
94+
name: "KotlinTests",
95+
dependencies: ["Kotlin"]
96+
),
97+
]
98+
)

Sources/Kotlin/Kotlin.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book

Sources/KotlinJVM/KotlinJVM.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
//
2+
// KotlinJVM.swift
3+
// Kotlin
4+
//
5+
// Created by Alsey Coleman Miller on 6/15/25.
6+
//
7+
8+
import JavaKit

Tests/KotlinTests/KotlinTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import Testing
2+
@testable import Kotlin
3+
4+
@Test func example() async throws {
5+
// Write your test here and use APIs like `#expect(...)` to check expected conditions.
6+
}

0 commit comments

Comments
 (0)