Skip to content

Swiftexport #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ android.useAndroidX=true
# Increase memory for in-process compiler execution.
org.gradle.jvmargs=-Xmx3g
# https://kotlinlang.org/docs/migrating-multiplatform-project-to-14.html#migrate-to-the-hierarchical-project-structure
kotlin.experimental.swift-export.enabled=true
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.enableHierarchicalCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
kotlin.native.ignoreDisabledTargets=true
org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled
org.jetbrains.dokka.experimental.gradle.pluginMode.noWarn=true
3 changes: 3 additions & 0 deletions libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ ktorClientDarwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor"
ktorClientLogging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktorClientOkHttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktorClientWinHttp = { module = "io.ktor:ktor-client-winhttp", version.ref = "ktor" }
ktorEvents = { module = "io.ktor:ktor-events", version.ref = "ktor" }
ktorHttp = { module = "io.ktor:ktor-http", version.ref = "ktor" }
ktorIo = { module = "io.ktor:ktor-io", version.ref = "ktor" }
ktorSerializationKotlinxJson = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktorUtils = { module = "io.ktor:ktor-utils", version.ref = "ktor" }
okio = { module = "com.squareup.okio:okio", version.ref = "okio" }
Expand Down
45 changes: 22 additions & 23 deletions solana-kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import co.touchlab.skie.configuration.ClassInterop
import co.touchlab.skie.configuration.DefaultArgumentInterop
import org.jetbrains.kotlin.gradle.swiftexport.ExperimentalSwiftExportDsl

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand All @@ -8,14 +7,13 @@ plugins {
alias(libs.plugins.dokka)
signing
alias(libs.plugins.multiplatform.swiftpackage)
alias(libs.plugins.skie)
}

group = "net.avianlabs.solana"
version = properties["version"] as String

kotlin {
targetHierarchy.default()
applyDefaultHierarchyTemplate()
explicitApi()

jvm {
Expand All @@ -27,20 +25,29 @@ kotlin {
}
}

listOf(
iosArm64(),
iosSimulatorArm64(),
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "SolanaKotlin"
export(project(":tweetnacl-multiplatform"))
isStatic = true
}
}
iosArm64()
iosSimulatorArm64()

mingwX64()
linuxX64()

@OptIn(ExperimentalSwiftExportDsl::class)
swiftExport {
// Root module name
moduleName = "SolanaKotlin"

// Collapse rule
flattenPackage = "net.avianlabs.solana"

// // Export external modules
// export(project(":tweetnacl-multiplatform")) {
// // Exported module name
// moduleName = "TweetNaCl"
// // Collapse exported dependency rule
// flattenPackage = "net.avianlabs.solana.tweetnacl"
// }
}

sourceSets {
val jvmMain by getting {
dependencies {
Expand Down Expand Up @@ -97,15 +104,6 @@ kotlin {
}
}

skie {
features {
group("net.avianlabs.solana.tweetnacl") {
ClassInterop.CInteropFrameworkName("TweetNaClMultiplatform")
DefaultArgumentInterop.Enabled(true)
}
}
}

multiplatformSwiftPackage {
swiftToolsVersion("5.9")
targetPlatforms {
Expand Down Expand Up @@ -140,6 +138,7 @@ publishing {
}
}
}

publications {
withType<MavenPublication> {
pom {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class SolanaClient(
) : this(
client = RpcKtorClient(
url = url,
httpClient = HttpClient(),
),
headerProviders = mapOf(
HttpHeaders.Authorization to {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@ import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.*
import kotlin.collections.set

public class RpcKtorClient(
public class RpcKtorClient internal constructor(
internal val url: Url,
httpClient: HttpClient = HttpClient(),
) {

public constructor(
url: String,
httpClient: HttpClient = HttpClient(),
) : this(
url = Url(url),
httpClient = httpClient,
httpClient = HttpClient(),
)

internal val requestIdGenerator: RequestIdGenerator = RequestIdGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class RPCIntegrationTest {
private val client = SolanaClient(
client = RpcKtorClient(
"http://localhost:8899",
httpClient = HttpClient {}
),
)

Expand Down
103 changes: 103 additions & 0 deletions swiftexport.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#!/bin/bash

set -e # Exit on error

# Function to check if xcodebuild is available
check_xcode() {
if ! command -v xcodebuild >/dev/null 2>&1; then
echo "Error: xcodebuild not found. Please install Xcode Command Line Tools."
exit 1
fi
}

# Function to get the active Xcode developer directory
get_developer_dir() {
local developer_dir
developer_dir=$(xcode-select -p)
echo "$developer_dir"
}

# Function to get SDK information
get_sdk_info() {
local sdk_type="$1" # iphoneos or iphonesimulator
xcodebuild -version -sdk "$sdk_type" Path
}

# Function to get default architecture for SDK
get_sdk_archs() {
local sdk_type="$1"
if [[ "$sdk_type" == "iphonesimulator" ]]; then
echo "arm64 x86_64"
else
echo "arm64"
fi
}

# Main script
echo "Detecting Xcode environment..."

# Check for Xcode installation
check_xcode

# Get developer directory
DEVELOPER_DIR=$(get_developer_dir)
echo "Developer Directory: $DEVELOPER_DIR"

# Determine SDK (preferring physical device SDK, falling back to simulator)
if xcodebuild -version -sdk iphoneos >/dev/null 2>&1; then
SDK_NAME="iphoneos"
PLATFORM_NAME="iphoneos"
EFFECTIVE_PLATFORM_NAME="-iphoneos"
else
SDK_NAME="iphonesimulator"
PLATFORM_NAME="iphonesimulator"
EFFECTIVE_PLATFORM_NAME="-iphonesimulator"
fi

# Read SDK information
IFS=$'\n' read -r -d '' SDKROOT SDK_PLATFORM_VERSION SDK_VERSION < <(get_sdk_info "$SDK_NAME" && printf '\0')

# Get architecture
ARCHS=$(get_sdk_archs "$SDK_NAME")
VALID_ARCHS=${ARCHS:-"arm64"} # Fallback to arm64 if detection fails

# Set up build directories
BASE_DIR="$(pwd)/build/xcode-env"
CONFIGURATION="Debug" # Can be parameterized if needed
KOTLIN_FRAMEWORK_BUILD_TYPE="debug" # Matches CONFIGURATION in lowercase
TARGET_BUILD_DIR="$BASE_DIR/Products"
BUILT_PRODUCTS_DIR="$TARGET_BUILD_DIR" # Required by Kotlin plugin
FRAMEWORKS_FOLDER_PATH="$BASE_DIR/Frameworks"

# Create required directories
mkdir -p "$TARGET_BUILD_DIR"
mkdir -p "$FRAMEWORKS_FOLDER_PATH"

# Export all required variables
export SDK_NAME
export SDKROOT
export CONFIGURATION
export KOTLIN_FRAMEWORK_BUILD_TYPE
export TARGET_BUILD_DIR
export BUILT_PRODUCTS_DIR
export ARCHS="$VALID_ARCHS"
export FRAMEWORKS_FOLDER_PATH
export PLATFORM_NAME
export EFFECTIVE_PLATFORM_NAME

# Print environment setup
echo "Environment variables set:"
echo "SDK_NAME=$SDK_NAME"
echo "SDKROOT=$SDKROOT"
echo "CONFIGURATION=$CONFIGURATION"
echo "KOTLIN_FRAMEWORK_BUILD_TYPE=$KOTLIN_FRAMEWORK_BUILD_TYPE"
echo "TARGET_BUILD_DIR=$TARGET_BUILD_DIR"
echo "BUILT_PRODUCTS_DIR=$BUILT_PRODUCTS_DIR"
echo "ARCHS=$ARCHS"
echo "FRAMEWORKS_FOLDER_PATH=$FRAMEWORKS_FOLDER_PATH"
echo "PLATFORM_NAME=$PLATFORM_NAME"
echo "EFFECTIVE_PLATFORM_NAME=$EFFECTIVE_PLATFORM_NAME"

# Run the gradle task
echo "Running gradle task..."
./gradlew :tweetnacl-multiplatform:embedSwiftExportForXcode
24 changes: 13 additions & 11 deletions tweetnacl-multiplatform/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import co.touchlab.cklib.gradle.CompileToBitcode.Language
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
import org.jetbrains.kotlin.gradle.swiftexport.ExperimentalSwiftExportDsl

plugins {
alias(libs.plugins.kotlinMultiplatform)
Expand All @@ -8,14 +9,13 @@ plugins {
alias(libs.plugins.dokka)
signing
alias(libs.plugins.multiplatform.swiftpackage)
alias(libs.plugins.skie)
}

group = "net.avianlabs.solana"
version = properties["version"] as String

kotlin {
targetHierarchy.default()
applyDefaultHierarchyTemplate()
explicitApi()

jvm {
Expand All @@ -27,16 +27,18 @@ kotlin {
}
}

listOf(
iosArm64(),
iosSimulatorArm64(),
).forEach { iosTarget ->
iosTarget.binaries.framework {
baseName = "TweetNaClMultiplatform"
isStatic = true
}
}
iosArm64()
iosSimulatorArm64()

@OptIn(ExperimentalSwiftExportDsl::class)
swiftExport {
// Root module name
moduleName = "TweetNaCl"

// Collapse rule
flattenPackage = "net.avianlabs.solana.tweetnacl"
}

mingwX64()
linuxX64()

Expand Down

This file was deleted.

This file was deleted.

Loading