├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── gradle.properties ├── gradle ├── libs.versions.toml └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── iosApp ├── Configuration │ └── Config.xcconfig ├── Tests │ └── Tests.swift ├── iosApp.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── iosApp │ ├── Assets.xcassets │ ├── AccentColor.colorset │ │ └── Contents.json │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── ContentView.swift │ ├── Info.plist │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ └── iOSApp.swift ├── module-a ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── com │ │ └── github │ │ └── jetbrains │ │ └── modulea │ │ └── ACommon.kt │ └── iosMain │ └── kotlin │ └── com │ └── github │ └── jetbrains │ └── modulea │ └── IOSASource.kt ├── module-b ├── build.gradle.kts └── src │ ├── commonMain │ └── kotlin │ │ └── com │ │ └── github │ │ └── jetbrains │ │ └── moduleb │ │ └── BCommon.kt │ └── iosMain │ └── kotlin │ └── com │ └── github │ └── jetbrains │ └── moduleb │ └── IOSBSource.kt ├── settings.gradle.kts └── shared ├── build.gradle.kts └── src ├── commonMain └── kotlin │ └── com │ └── github │ └── jetbrains │ └── swiftexport │ └── Common.kt └── iosMain └── kotlin └── com └── github └── jetbrains └── swiftexport └── IOSSource.kt /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | .kotlin 4 | .fleet 5 | **/build/ 6 | xcuserdata 7 | !src/**/build/ 8 | local.properties 9 | .idea 10 | .DS_Store 11 | captures 12 | .externalNativeBuild 13 | .cxx 14 | *.xcodeproj/* 15 | !*.xcodeproj/project.pbxproj 16 | !*.xcodeproj/xcshareddata/ 17 | !*.xcodeproj/project.xcworkspace/ 18 | !*.xcworkspace/contents.xcworkspacedata 19 | **/xcshareddata/WorkspaceSettings.xcsettings 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 JetBrains s.r.o. and Kotlin Programming Language contributors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![official project](http://jb.gg/badges/official.svg)](https://confluence.jetbrains.com/display/ALL/JetBrains+on+GitHub) 2 | 3 | # Kotlin Swift Export Sample 4 | 5 | This project demonstrates how to export Kotlin code as native Swift modules using JetBrains' Kotlin Multiplatform. The sample consists of three modules: `:shared`, `:module-a`, and `:module-b`, showcasing how to configure the DSL to export these Kotlin modules into Swift with custom configurations. 6 | 7 | ## ⚠️ Experimental Feature Notice 8 | 9 | **Swift Export is an experimental feature and subject to change in any future releases.** It may not function as expected, and you may encounter bugs. This project serves as an early technology demonstration and is **not production-ready**. Use it at your own risk. 10 | 11 | ## Project Structure 12 | 13 | - `:shared` - The main shared module that aggregates and exports the other modules (`:module-a` and `:module-b`) as native Swift modules. 14 | - `:module-a` - A sample Kotlin module to be exported as `ModuleA` in Swift. 15 | - `:module-b` - Another sample Kotlin module to be exported as `ModuleB` in Swift. 16 | 17 | ## Swift Export Configuration 18 | 19 | The export process is configured in the `build.gradle.kts` file within the `kotlin {}` block. Below is the configuration: 20 | 21 | ```kotlin 22 | kotlin { 23 | iosX64() 24 | iosArm64() 25 | iosSimulatorArm64() 26 | 27 | @OptIn(ExperimentalSwiftExportDsl::class) 28 | swiftExport { 29 | // Root module name 30 | moduleName = "Shared" 31 | 32 | // Collapse rule 33 | flattenPackage = "com.github.jetbrains.swiftexport" 34 | 35 | // Export external modules 36 | export(project(":module-a")) { 37 | // Exported module name 38 | moduleName = "ModuleA" 39 | // Collapse exported dependency rule 40 | flattenPackage = "com.github.jetbrains.modulea" 41 | } 42 | 43 | export(project(":module-b")) { 44 | // Exported module name 45 | moduleName = "ModuleB" 46 | // Collapse exported dependency rule 47 | flattenPackage = "com.github.jetbrains.moduleb" 48 | } 49 | } 50 | 51 | sourceSets.commonMain.dependencies { 52 | api(project(":module-a")) 53 | api(project(":module-b")) 54 | } 55 | } 56 | ``` 57 | 58 | ## Getting Started 59 | 60 | ### Prerequisites 61 | 62 | - Enable Swift Export by adding `kotlin.experimental.swift-export.enabled=true` to your `local.properties` or `gradle.properties`. 63 | 64 | ### Running the Project 65 | 66 | 1. Clone this repository. 67 | 2. Open the project `iosApp/iosApp.xcodeproj` with Xcode (tested with version 16.0). 68 | 3. Ensure you have the following command in your Run Script build phase: `./gradlew :shared:embedSwiftExportForXcode`. 69 | 4. Build the project. The Swift modules will be generated and can be found in the build output directory. 70 | 71 | ## Key Features 72 | 73 | - **moduleName:** Allows setting a custom module name for the exported Kotlin module. For instance, the `:module-a` module is exported as `ModuleA` in Swift. 74 | - **flattenPackage:** A package collapsing rule that simplifies package usage in Swift. In Kotlin, modules are typically organized within packages (e.g., `com.github.jetbrains.modulea`). Using `flattenPackage`, you can omit the package name and directly use classes from the module in Swift. 75 | 76 | ## Learn More 77 | 78 | - For more information on Kotlin Multiplatform, check out the [Kotlin Multiplatform Documentation](https://www.jetbrains.com/help/kotlin-multiplatform-dev/get-started.html). 79 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | // this is necessary to avoid the plugins to be loaded multiple times 3 | // in each subproject's classloader 4 | alias(libs.plugins.kotlinMultiplatform) apply false 5 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | kotlin.code.style=official 2 | 3 | #Gradle 4 | org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\="-Xmx2048M" 5 | 6 | 7 | #MPP 8 | kotlin.mpp.enableCInteropCommonization=true 9 | kotlin.experimental.swift-export.enabled=true 10 | kotlin.apple.xcodeCompatibility.nowarn=true -------------------------------------------------------------------------------- /gradle/libs.versions.toml: -------------------------------------------------------------------------------- 1 | [versions] 2 | kotlin = "2.2.0-Beta1" 3 | 4 | [plugins] 5 | kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kotlin/swift-export-sample/78876274e730e9a9d44a64094a8d3aa4c632f366/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 48 | echo. 49 | echo Please set the JAVA_HOME variable in your environment to match the 50 | echo location of your Java installation. 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 62 | echo. 63 | echo Please set the JAVA_HOME variable in your environment to match the 64 | echo location of your Java installation. 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /iosApp/Configuration/Config.xcconfig: -------------------------------------------------------------------------------- 1 | TEAM_ID= 2 | BUNDLE_ID=com.github.jetbrains.swiftexport.swift-export-sample 3 | APP_NAME=swift-export-sample -------------------------------------------------------------------------------- /iosApp/Tests/Tests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // swift_export_sampleTests.swift 3 | // swift-export-sampleTests 4 | // 5 | // Created by Andrey.Yastrebov on 29.02.24. 6 | // Copyright © 2024 orgName. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Shared 11 | @testable import ModuleA 12 | @testable import ModuleB 13 | 14 | final class SharedTests: XCTestCase { 15 | 16 | func testSharedFunction() { 17 | let result = sharedFunction() 18 | XCTAssertEqual(result, 15, "sharedFunction() should return the expected result") 19 | } 20 | 21 | func testClassFromA() { 22 | let result = useClassFromA() 23 | XCTAssertEqual(result.hello(), "Hello from class_A", "useClassFromA() should return the expected result") 24 | } 25 | 26 | func testClassFromB() { 27 | let result = useClassFromB() 28 | XCTAssertEqual(result.hello(), "Hello from class_B", "useClassFromB() should return the expected result for the given parameter") 29 | } 30 | 31 | func testBar() { 32 | let result = iosBar() 33 | XCTAssertEqual(result, 125, "iosBar() should return the expected result for the given parameter") 34 | } 35 | } 36 | 37 | final class ModuleATests: XCTestCase { 38 | 39 | func testModuleAClass() { 40 | let instance = ClassFromA(name: "A") 41 | XCTAssertEqual(instance.hello(), "Hello from A", "hello() should return the expected result") 42 | } 43 | 44 | func testBar() { 45 | let result = iosModuleABar() 46 | XCTAssertEqual(result, 54321, "iosModuleABar() should return the expected result for the given parameter") 47 | } 48 | } 49 | 50 | final class ModuleBTests: XCTestCase { 51 | 52 | func testModuleBClass() { 53 | let instance = ClassFromB(name: "B") 54 | XCTAssertEqual(instance.hello(), "Hello from B", "hello() should return the expected result") 55 | } 56 | 57 | func testBar() { 58 | let result = iosModuleBBar() 59 | XCTAssertEqual(result, 12345, "iosModuleBBar() should return the expected result for the given parameter") 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /iosApp/iosApp.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 54; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557BA273AAA24004C7B11 /* Assets.xcassets */; }; 11 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */; }; 12 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2152FB032600AC8F00CF470E /* iOSApp.swift */; }; 13 | 7555FF83242A565900829871 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7555FF82242A565900829871 /* ContentView.swift */; }; 14 | BDF814C82B90BF7200BACB2F /* Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDF814C72B90BF7200BACB2F /* Tests.swift */; }; 15 | /* End PBXBuildFile section */ 16 | 17 | /* Begin PBXContainerItemProxy section */ 18 | BDF814C92B90BF7200BACB2F /* PBXContainerItemProxy */ = { 19 | isa = PBXContainerItemProxy; 20 | containerPortal = 7555FF73242A565900829871 /* Project object */; 21 | proxyType = 1; 22 | remoteGlobalIDString = 7555FF7A242A565900829871; 23 | remoteInfo = iosApp; 24 | }; 25 | /* End PBXContainerItemProxy section */ 26 | 27 | /* Begin PBXFileReference section */ 28 | 058557BA273AAA24004C7B11 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 29 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 30 | 2152FB032600AC8F00CF470E /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; }; 31 | 7555FF7B242A565900829871 /* swift-export-sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "swift-export-sample.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 32 | 7555FF82242A565900829871 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 33 | 7555FF8C242A565B00829871 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 34 | AB3632DC29227652001CCB65 /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; 35 | BDF814C52B90BF7200BACB2F /* Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = Tests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 36 | BDF814C72B90BF7200BACB2F /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = ""; }; 37 | /* End PBXFileReference section */ 38 | 39 | /* Begin PBXFrameworksBuildPhase section */ 40 | B92378962B6B1156000C7307 /* Frameworks */ = { 41 | isa = PBXFrameworksBuildPhase; 42 | buildActionMask = 2147483647; 43 | files = ( 44 | ); 45 | runOnlyForDeploymentPostprocessing = 0; 46 | }; 47 | BDF814C22B90BF7200BACB2F /* Frameworks */ = { 48 | isa = PBXFrameworksBuildPhase; 49 | buildActionMask = 2147483647; 50 | files = ( 51 | ); 52 | runOnlyForDeploymentPostprocessing = 0; 53 | }; 54 | /* End PBXFrameworksBuildPhase section */ 55 | 56 | /* Begin PBXGroup section */ 57 | 058557D7273AAEEB004C7B11 /* Preview Content */ = { 58 | isa = PBXGroup; 59 | children = ( 60 | 058557D8273AAEEB004C7B11 /* Preview Assets.xcassets */, 61 | ); 62 | path = "Preview Content"; 63 | sourceTree = ""; 64 | }; 65 | 42799AB246E5F90AF97AA0EF /* Frameworks */ = { 66 | isa = PBXGroup; 67 | children = ( 68 | ); 69 | name = Frameworks; 70 | sourceTree = ""; 71 | }; 72 | 7555FF72242A565900829871 = { 73 | isa = PBXGroup; 74 | children = ( 75 | AB1DB47929225F7C00F7AF9C /* Configuration */, 76 | 7555FF7D242A565900829871 /* iosApp */, 77 | BDF814C62B90BF7200BACB2F /* Tests */, 78 | 7555FF7C242A565900829871 /* Products */, 79 | 42799AB246E5F90AF97AA0EF /* Frameworks */, 80 | ); 81 | sourceTree = ""; 82 | }; 83 | 7555FF7C242A565900829871 /* Products */ = { 84 | isa = PBXGroup; 85 | children = ( 86 | 7555FF7B242A565900829871 /* swift-export-sample.app */, 87 | BDF814C52B90BF7200BACB2F /* Tests.xctest */, 88 | ); 89 | name = Products; 90 | sourceTree = ""; 91 | }; 92 | 7555FF7D242A565900829871 /* iosApp */ = { 93 | isa = PBXGroup; 94 | children = ( 95 | 058557BA273AAA24004C7B11 /* Assets.xcassets */, 96 | 7555FF82242A565900829871 /* ContentView.swift */, 97 | 7555FF8C242A565B00829871 /* Info.plist */, 98 | 2152FB032600AC8F00CF470E /* iOSApp.swift */, 99 | 058557D7273AAEEB004C7B11 /* Preview Content */, 100 | ); 101 | path = iosApp; 102 | sourceTree = ""; 103 | }; 104 | AB1DB47929225F7C00F7AF9C /* Configuration */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | AB3632DC29227652001CCB65 /* Config.xcconfig */, 108 | ); 109 | path = Configuration; 110 | sourceTree = ""; 111 | }; 112 | BDF814C62B90BF7200BACB2F /* Tests */ = { 113 | isa = PBXGroup; 114 | children = ( 115 | BDF814C72B90BF7200BACB2F /* Tests.swift */, 116 | ); 117 | path = Tests; 118 | sourceTree = ""; 119 | }; 120 | /* End PBXGroup section */ 121 | 122 | /* Begin PBXNativeTarget section */ 123 | 7555FF7A242A565900829871 /* iosApp */ = { 124 | isa = PBXNativeTarget; 125 | buildConfigurationList = 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */; 126 | buildPhases = ( 127 | F36B1CEA2AD836FC00CB74D5 /* Compile Kotlin Framework */, 128 | 7555FF77242A565900829871 /* Sources */, 129 | B92378962B6B1156000C7307 /* Frameworks */, 130 | 7555FF79242A565900829871 /* Resources */, 131 | ); 132 | buildRules = ( 133 | ); 134 | dependencies = ( 135 | ); 136 | name = iosApp; 137 | packageProductDependencies = ( 138 | ); 139 | productName = iosApp; 140 | productReference = 7555FF7B242A565900829871 /* swift-export-sample.app */; 141 | productType = "com.apple.product-type.application"; 142 | }; 143 | BDF814C42B90BF7200BACB2F /* Tests */ = { 144 | isa = PBXNativeTarget; 145 | buildConfigurationList = BDF814CB2B90BF7200BACB2F /* Build configuration list for PBXNativeTarget "Tests" */; 146 | buildPhases = ( 147 | BDF814C12B90BF7200BACB2F /* Sources */, 148 | BDF814C22B90BF7200BACB2F /* Frameworks */, 149 | BDF814C32B90BF7200BACB2F /* Resources */, 150 | ); 151 | buildRules = ( 152 | ); 153 | dependencies = ( 154 | BDF814CA2B90BF7200BACB2F /* PBXTargetDependency */, 155 | ); 156 | name = Tests; 157 | productName = "swift-export-sampleTests"; 158 | productReference = BDF814C52B90BF7200BACB2F /* Tests.xctest */; 159 | productType = "com.apple.product-type.bundle.unit-test"; 160 | }; 161 | /* End PBXNativeTarget section */ 162 | 163 | /* Begin PBXProject section */ 164 | 7555FF73242A565900829871 /* Project object */ = { 165 | isa = PBXProject; 166 | attributes = { 167 | LastSwiftUpdateCheck = 1520; 168 | LastUpgradeCheck = 1130; 169 | ORGANIZATIONNAME = orgName; 170 | TargetAttributes = { 171 | 7555FF7A242A565900829871 = { 172 | CreatedOnToolsVersion = 11.3.1; 173 | }; 174 | BDF814C42B90BF7200BACB2F = { 175 | CreatedOnToolsVersion = 15.2; 176 | TestTargetID = 7555FF7A242A565900829871; 177 | }; 178 | }; 179 | }; 180 | buildConfigurationList = 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */; 181 | compatibilityVersion = "Xcode 12.0"; 182 | developmentRegion = en; 183 | hasScannedForEncodings = 0; 184 | knownRegions = ( 185 | en, 186 | Base, 187 | ); 188 | mainGroup = 7555FF72242A565900829871; 189 | packageReferences = ( 190 | ); 191 | productRefGroup = 7555FF7C242A565900829871 /* Products */; 192 | projectDirPath = ""; 193 | projectRoot = ""; 194 | targets = ( 195 | 7555FF7A242A565900829871 /* iosApp */, 196 | BDF814C42B90BF7200BACB2F /* Tests */, 197 | ); 198 | }; 199 | /* End PBXProject section */ 200 | 201 | /* Begin PBXResourcesBuildPhase section */ 202 | 7555FF79242A565900829871 /* Resources */ = { 203 | isa = PBXResourcesBuildPhase; 204 | buildActionMask = 2147483647; 205 | files = ( 206 | 058557D9273AAEEB004C7B11 /* Preview Assets.xcassets in Resources */, 207 | 058557BB273AAA24004C7B11 /* Assets.xcassets in Resources */, 208 | ); 209 | runOnlyForDeploymentPostprocessing = 0; 210 | }; 211 | BDF814C32B90BF7200BACB2F /* Resources */ = { 212 | isa = PBXResourcesBuildPhase; 213 | buildActionMask = 2147483647; 214 | files = ( 215 | ); 216 | runOnlyForDeploymentPostprocessing = 0; 217 | }; 218 | /* End PBXResourcesBuildPhase section */ 219 | 220 | /* Begin PBXShellScriptBuildPhase section */ 221 | F36B1CEA2AD836FC00CB74D5 /* Compile Kotlin Framework */ = { 222 | isa = PBXShellScriptBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | ); 226 | inputFileListPaths = ( 227 | ); 228 | inputPaths = ( 229 | ); 230 | name = "Compile Kotlin Framework"; 231 | outputFileListPaths = ( 232 | ); 233 | outputPaths = ( 234 | ); 235 | runOnlyForDeploymentPostprocessing = 0; 236 | shellPath = /bin/sh; 237 | shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared:embedSwiftExportForXcode\n"; 238 | }; 239 | /* End PBXShellScriptBuildPhase section */ 240 | 241 | /* Begin PBXSourcesBuildPhase section */ 242 | 7555FF77242A565900829871 /* Sources */ = { 243 | isa = PBXSourcesBuildPhase; 244 | buildActionMask = 2147483647; 245 | files = ( 246 | 2152FB042600AC8F00CF470E /* iOSApp.swift in Sources */, 247 | 7555FF83242A565900829871 /* ContentView.swift in Sources */, 248 | ); 249 | runOnlyForDeploymentPostprocessing = 0; 250 | }; 251 | BDF814C12B90BF7200BACB2F /* Sources */ = { 252 | isa = PBXSourcesBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | BDF814C82B90BF7200BACB2F /* Tests.swift in Sources */, 256 | ); 257 | runOnlyForDeploymentPostprocessing = 0; 258 | }; 259 | /* End PBXSourcesBuildPhase section */ 260 | 261 | /* Begin PBXTargetDependency section */ 262 | BDF814CA2B90BF7200BACB2F /* PBXTargetDependency */ = { 263 | isa = PBXTargetDependency; 264 | target = 7555FF7A242A565900829871 /* iosApp */; 265 | targetProxy = BDF814C92B90BF7200BACB2F /* PBXContainerItemProxy */; 266 | }; 267 | /* End PBXTargetDependency section */ 268 | 269 | /* Begin XCBuildConfiguration section */ 270 | 7555FFA3242A565B00829871 /* Debug */ = { 271 | isa = XCBuildConfiguration; 272 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */; 273 | buildSettings = { 274 | ALWAYS_SEARCH_USER_PATHS = NO; 275 | CLANG_ANALYZER_NONNULL = YES; 276 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 277 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 278 | CLANG_CXX_LIBRARY = "libc++"; 279 | CLANG_ENABLE_MODULES = YES; 280 | CLANG_ENABLE_OBJC_ARC = YES; 281 | CLANG_ENABLE_OBJC_WEAK = YES; 282 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 283 | CLANG_WARN_BOOL_CONVERSION = YES; 284 | CLANG_WARN_COMMA = YES; 285 | CLANG_WARN_CONSTANT_CONVERSION = YES; 286 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 287 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 288 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 289 | CLANG_WARN_EMPTY_BODY = YES; 290 | CLANG_WARN_ENUM_CONVERSION = YES; 291 | CLANG_WARN_INFINITE_RECURSION = YES; 292 | CLANG_WARN_INT_CONVERSION = YES; 293 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 294 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 295 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 296 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 297 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 298 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 299 | CLANG_WARN_STRICT_PROTOTYPES = YES; 300 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 301 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 302 | CLANG_WARN_UNREACHABLE_CODE = YES; 303 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 304 | COPY_PHASE_STRIP = NO; 305 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 306 | ENABLE_STRICT_OBJC_MSGSEND = YES; 307 | ENABLE_TESTABILITY = YES; 308 | GCC_C_LANGUAGE_STANDARD = gnu11; 309 | GCC_DYNAMIC_NO_PIC = NO; 310 | GCC_NO_COMMON_BLOCKS = YES; 311 | GCC_OPTIMIZATION_LEVEL = 0; 312 | GCC_PREPROCESSOR_DEFINITIONS = ( 313 | "DEBUG=1", 314 | "$(inherited)", 315 | ); 316 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 317 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 318 | GCC_WARN_UNDECLARED_SELECTOR = YES; 319 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 320 | GCC_WARN_UNUSED_FUNCTION = YES; 321 | GCC_WARN_UNUSED_VARIABLE = YES; 322 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 323 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 324 | MTL_FAST_MATH = YES; 325 | ONLY_ACTIVE_ARCH = YES; 326 | SDKROOT = iphoneos; 327 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 328 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 329 | }; 330 | name = Debug; 331 | }; 332 | 7555FFA4242A565B00829871 /* Release */ = { 333 | isa = XCBuildConfiguration; 334 | baseConfigurationReference = AB3632DC29227652001CCB65 /* Config.xcconfig */; 335 | buildSettings = { 336 | ALWAYS_SEARCH_USER_PATHS = NO; 337 | CLANG_ANALYZER_NONNULL = YES; 338 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 339 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 340 | CLANG_CXX_LIBRARY = "libc++"; 341 | CLANG_ENABLE_MODULES = YES; 342 | CLANG_ENABLE_OBJC_ARC = YES; 343 | CLANG_ENABLE_OBJC_WEAK = YES; 344 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 345 | CLANG_WARN_BOOL_CONVERSION = YES; 346 | CLANG_WARN_COMMA = YES; 347 | CLANG_WARN_CONSTANT_CONVERSION = YES; 348 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 349 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 350 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 351 | CLANG_WARN_EMPTY_BODY = YES; 352 | CLANG_WARN_ENUM_CONVERSION = YES; 353 | CLANG_WARN_INFINITE_RECURSION = YES; 354 | CLANG_WARN_INT_CONVERSION = YES; 355 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 356 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 357 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 358 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 359 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 360 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 361 | CLANG_WARN_STRICT_PROTOTYPES = YES; 362 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 363 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 364 | CLANG_WARN_UNREACHABLE_CODE = YES; 365 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 366 | COPY_PHASE_STRIP = NO; 367 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 368 | ENABLE_NS_ASSERTIONS = NO; 369 | ENABLE_STRICT_OBJC_MSGSEND = YES; 370 | GCC_C_LANGUAGE_STANDARD = gnu11; 371 | GCC_NO_COMMON_BLOCKS = YES; 372 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 373 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 374 | GCC_WARN_UNDECLARED_SELECTOR = YES; 375 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 376 | GCC_WARN_UNUSED_FUNCTION = YES; 377 | GCC_WARN_UNUSED_VARIABLE = YES; 378 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 379 | MTL_ENABLE_DEBUG_INFO = NO; 380 | MTL_FAST_MATH = YES; 381 | SDKROOT = iphoneos; 382 | SWIFT_COMPILATION_MODE = wholemodule; 383 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 384 | VALIDATE_PRODUCT = YES; 385 | }; 386 | name = Release; 387 | }; 388 | 7555FFA6242A565B00829871 /* Debug */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 392 | CODE_SIGN_IDENTITY = "Apple Development"; 393 | CODE_SIGN_STYLE = Automatic; 394 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; 395 | DEVELOPMENT_TEAM = "${TEAM_ID}"; 396 | ENABLE_PREVIEWS = YES; 397 | FRAMEWORK_SEARCH_PATHS = ""; 398 | INFOPLIST_FILE = iosApp/Info.plist; 399 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 400 | LD_RUNPATH_SEARCH_PATHS = ( 401 | "$(inherited)", 402 | "@executable_path/Frameworks", 403 | ); 404 | OTHER_LDFLAGS = "$(inherited)"; 405 | PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}${TEAM_ID}"; 406 | PRODUCT_NAME = "${APP_NAME}"; 407 | PROVISIONING_PROFILE_SPECIFIER = ""; 408 | SWIFT_VERSION = 5.0; 409 | TARGETED_DEVICE_FAMILY = "1,2"; 410 | }; 411 | name = Debug; 412 | }; 413 | 7555FFA7242A565B00829871 /* Release */ = { 414 | isa = XCBuildConfiguration; 415 | buildSettings = { 416 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 417 | CODE_SIGN_IDENTITY = "Apple Development"; 418 | CODE_SIGN_STYLE = Automatic; 419 | DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; 420 | DEVELOPMENT_TEAM = "${TEAM_ID}"; 421 | ENABLE_PREVIEWS = YES; 422 | FRAMEWORK_SEARCH_PATHS = ""; 423 | INFOPLIST_FILE = iosApp/Info.plist; 424 | IPHONEOS_DEPLOYMENT_TARGET = 15.2; 425 | LD_RUNPATH_SEARCH_PATHS = ( 426 | "$(inherited)", 427 | "@executable_path/Frameworks", 428 | ); 429 | OTHER_LDFLAGS = "$(inherited)"; 430 | PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}${TEAM_ID}"; 431 | PRODUCT_NAME = "${APP_NAME}"; 432 | PROVISIONING_PROFILE_SPECIFIER = ""; 433 | SWIFT_VERSION = 5.0; 434 | TARGETED_DEVICE_FAMILY = "1,2"; 435 | }; 436 | name = Release; 437 | }; 438 | BDF814CC2B90BF7200BACB2F /* Debug */ = { 439 | isa = XCBuildConfiguration; 440 | buildSettings = { 441 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 442 | BUNDLE_LOADER = "$(TEST_HOST)"; 443 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 444 | CODE_SIGN_STYLE = Automatic; 445 | CURRENT_PROJECT_VERSION = 1; 446 | DEBUG_INFORMATION_FORMAT = dwarf; 447 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 448 | GCC_C_LANGUAGE_STANDARD = gnu17; 449 | GENERATE_INFOPLIST_FILE = YES; 450 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 451 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 452 | MARKETING_VERSION = 1.0; 453 | PRODUCT_BUNDLE_IDENTIFIER = "com.github.jetbrains.swiftexport.swift-export-sample-tests.swift-export-sampleTests"; 454 | PRODUCT_NAME = "$(TARGET_NAME)"; 455 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; 456 | SWIFT_EMIT_LOC_STRINGS = NO; 457 | SWIFT_VERSION = 5.0; 458 | TARGETED_DEVICE_FAMILY = "1,2"; 459 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/swift-export-sample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/swift-export-sample"; 460 | }; 461 | name = Debug; 462 | }; 463 | BDF814CD2B90BF7200BACB2F /* Release */ = { 464 | isa = XCBuildConfiguration; 465 | buildSettings = { 466 | ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; 467 | BUNDLE_LOADER = "$(TEST_HOST)"; 468 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; 469 | CODE_SIGN_STYLE = Automatic; 470 | CURRENT_PROJECT_VERSION = 1; 471 | ENABLE_USER_SCRIPT_SANDBOXING = YES; 472 | GCC_C_LANGUAGE_STANDARD = gnu17; 473 | GENERATE_INFOPLIST_FILE = YES; 474 | IPHONEOS_DEPLOYMENT_TARGET = 17.2; 475 | LOCALIZATION_PREFERS_STRING_CATALOGS = YES; 476 | MARKETING_VERSION = 1.0; 477 | PRODUCT_BUNDLE_IDENTIFIER = "com.github.jetbrains.swiftexport.swift-export-sample-tests.swift-export-sampleTests"; 478 | PRODUCT_NAME = "$(TARGET_NAME)"; 479 | SWIFT_EMIT_LOC_STRINGS = NO; 480 | SWIFT_VERSION = 5.0; 481 | TARGETED_DEVICE_FAMILY = "1,2"; 482 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/swift-export-sample.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/swift-export-sample"; 483 | }; 484 | name = Release; 485 | }; 486 | /* End XCBuildConfiguration section */ 487 | 488 | /* Begin XCConfigurationList section */ 489 | 7555FF76242A565900829871 /* Build configuration list for PBXProject "iosApp" */ = { 490 | isa = XCConfigurationList; 491 | buildConfigurations = ( 492 | 7555FFA3242A565B00829871 /* Debug */, 493 | 7555FFA4242A565B00829871 /* Release */, 494 | ); 495 | defaultConfigurationIsVisible = 0; 496 | defaultConfigurationName = Release; 497 | }; 498 | 7555FFA5242A565B00829871 /* Build configuration list for PBXNativeTarget "iosApp" */ = { 499 | isa = XCConfigurationList; 500 | buildConfigurations = ( 501 | 7555FFA6242A565B00829871 /* Debug */, 502 | 7555FFA7242A565B00829871 /* Release */, 503 | ); 504 | defaultConfigurationIsVisible = 0; 505 | defaultConfigurationName = Release; 506 | }; 507 | BDF814CB2B90BF7200BACB2F /* Build configuration list for PBXNativeTarget "Tests" */ = { 508 | isa = XCConfigurationList; 509 | buildConfigurations = ( 510 | BDF814CC2B90BF7200BACB2F /* Debug */, 511 | BDF814CD2B90BF7200BACB2F /* Release */, 512 | ); 513 | defaultConfigurationIsVisible = 0; 514 | defaultConfigurationName = Release; 515 | }; 516 | /* End XCConfigurationList section */ 517 | }; 518 | rootObject = 7555FF73242A565900829871 /* Project object */; 519 | } 520 | -------------------------------------------------------------------------------- /iosApp/iosApp.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/AccentColor.colorset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "colors" : [ 3 | { 4 | "idiom" : "universal" 5 | } 6 | ], 7 | "info" : { 8 | "author" : "xcode", 9 | "version" : 1 10 | } 11 | } -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "platform" : "ios", 6 | "size" : "1024x1024" 7 | } 8 | ], 9 | "info" : { 10 | "author" : "xcode", 11 | "version" : 1 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /iosApp/iosApp/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /iosApp/iosApp/ContentView.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | import Shared 3 | import ModuleA 4 | import ModuleB 5 | 6 | struct ContentView: View { 7 | @State private var showContent = false 8 | 9 | var body: some View { 10 | VStack(spacing: 8) { 11 | //Different modules 12 | let moduleA = useClassFromA() 13 | Text("Module A: \(moduleA.hello())") 14 | let moduleB = useClassFromB() 15 | Text("Module B: \(moduleB.hello()) ") 16 | 17 | //Typealias 18 | let myClass = MyClass(property: 5) 19 | let nestedClass = MyNested(nestedProperty: 6) 20 | Text("Type alias class is \(nestedClass.nestedProperty)") 21 | 22 | //Top-level function 23 | Text("The sum is: \(sum(a: myClass, b: nestedClass))") 24 | } 25 | .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .center) 26 | .padding() 27 | } 28 | 29 | func testSwiftExport(){ 30 | //Extension function 31 | let _ = repeated("Hello!", times: 3) 32 | //Extension property 33 | let _ = getLen("Hello") 34 | //Overloading functions 35 | overloaded(x: "hello") 36 | } 37 | } 38 | 39 | struct ContentView_Previews: PreviewProvider { 40 | static var previews: some View { 41 | ContentView() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /iosApp/iosApp/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | CADisableMinimumFrameDurationOnPhone 24 | 25 | UIApplicationSceneManifest 26 | 27 | UIApplicationSupportsMultipleScenes 28 | 29 | 30 | UILaunchScreen 31 | 32 | UIRequiredDeviceCapabilities 33 | 34 | armv7 35 | 36 | UISupportedInterfaceOrientations 37 | 38 | UIInterfaceOrientationPortrait 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | UISupportedInterfaceOrientations~ipad 43 | 44 | UIInterfaceOrientationPortrait 45 | UIInterfaceOrientationPortraitUpsideDown 46 | UIInterfaceOrientationLandscapeLeft 47 | UIInterfaceOrientationLandscapeRight 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /iosApp/iosApp/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } -------------------------------------------------------------------------------- /iosApp/iosApp/iOSApp.swift: -------------------------------------------------------------------------------- 1 | import SwiftUI 2 | 3 | @main 4 | struct iOSApp: App { 5 | var body: some Scene { 6 | WindowGroup { 7 | ContentView() 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /module-a/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.kotlinMultiplatform) 3 | } 4 | 5 | version = "1.0.5" 6 | 7 | kotlin { 8 | iosX64() 9 | iosArm64() 10 | iosSimulatorArm64() 11 | } -------------------------------------------------------------------------------- /module-a/src/commonMain/kotlin/com/github/jetbrains/modulea/ACommon.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.modulea 2 | 3 | class ClassFromA(private val name: String) { 4 | 5 | fun hello(): String { 6 | return "Hello from $name" 7 | } 8 | } 9 | 10 | fun moduleAFunction(): Int = 5 -------------------------------------------------------------------------------- /module-a/src/iosMain/kotlin/com/github/jetbrains/modulea/IOSASource.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.modulea 2 | 3 | fun iosModuleABar(): Int = 54321 -------------------------------------------------------------------------------- /module-b/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | alias(libs.plugins.kotlinMultiplatform) 3 | } 4 | 5 | version = "1.0.2" 6 | 7 | kotlin { 8 | iosX64() 9 | iosArm64() 10 | iosSimulatorArm64() 11 | } -------------------------------------------------------------------------------- /module-b/src/commonMain/kotlin/com/github/jetbrains/moduleb/BCommon.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.moduleb 2 | 3 | class ClassFromB(private val name: String) { 4 | 5 | fun hello(): String { 6 | return "Hello from $name" 7 | } 8 | } 9 | 10 | fun moduleBFunction(): Int = 10 -------------------------------------------------------------------------------- /module-b/src/iosMain/kotlin/com/github/jetbrains/moduleb/IOSBSource.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.moduleb 2 | 3 | fun iosModuleBBar(): Int = 12345 -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | rootProject.name = "swift-export-sample" 2 | enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") 3 | 4 | pluginManagement { 5 | repositories { 6 | maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") {} 7 | gradlePluginPortal() 8 | mavenCentral() 9 | 10 | } 11 | } 12 | 13 | dependencyResolutionManagement { 14 | repositories { 15 | maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/") {} 16 | mavenCentral() 17 | } 18 | } 19 | 20 | include(":shared") 21 | include(":module-a") 22 | include(":module-b") -------------------------------------------------------------------------------- /shared/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import org.jetbrains.kotlin.gradle.swiftexport.ExperimentalSwiftExportDsl 2 | 3 | plugins { 4 | alias(libs.plugins.kotlinMultiplatform) 5 | } 6 | 7 | kotlin { 8 | iosX64() 9 | iosArm64() 10 | iosSimulatorArm64() 11 | 12 | @OptIn(ExperimentalSwiftExportDsl::class) 13 | swiftExport { 14 | // Root module name 15 | moduleName = "Shared" 16 | 17 | // Collapse rule 18 | flattenPackage = "com.github.jetbrains.swiftexport" 19 | 20 | // Export external modules 21 | export(projects.moduleA) { 22 | // Exported module name 23 | moduleName = "ModuleA" 24 | // Collapse exported dependency rule 25 | flattenPackage = "com.github.jetbrains.modulea" 26 | } 27 | 28 | export(projects.moduleB) { 29 | // Exported module name 30 | moduleName = "ModuleB" 31 | // Collapse exported dependency rule 32 | flattenPackage = "com.github.jetbrains.moduleb" 33 | } 34 | } 35 | 36 | sourceSets.commonMain.dependencies { 37 | api(projects.moduleA) 38 | api(projects.moduleB) 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /shared/src/commonMain/kotlin/com/github/jetbrains/swiftexport/Common.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.swiftexport 2 | 3 | import com.github.jetbrains.modulea.ClassFromA 4 | import com.github.jetbrains.moduleb.ClassFromB 5 | 6 | class MyClass(val property: Int) { 7 | class Nested(val nestedProperty: Int) 8 | } 9 | 10 | typealias MyNested = MyClass.Nested 11 | 12 | fun sum(a: MyClass, b: MyNested): Int = 13 | a.property + b.nestedProperty 14 | 15 | fun useClassFromA(): ClassFromA { 16 | return ClassFromA("class_A") 17 | } 18 | 19 | fun useClassFromB(): ClassFromB { 20 | return ClassFromB("class_B") 21 | } 22 | 23 | fun sharedFunction(): Int = 15 24 | 25 | fun String.repeated(times: Int): String { 26 | return "hello hello!" 27 | } 28 | 29 | val String.len: Int get() = length 30 | 31 | fun overloaded(x: String) {} 32 | fun overloaded(x: Int) {} 33 | fun overloaded(x: Double) {} 34 | 35 | -------------------------------------------------------------------------------- /shared/src/iosMain/kotlin/com/github/jetbrains/swiftexport/IOSSource.kt: -------------------------------------------------------------------------------- 1 | package com.github.jetbrains.swiftexport 2 | 3 | fun iosBar(): Int = 125 --------------------------------------------------------------------------------