Unverified Commit 784e398a authored by Nikolay Igotti's avatar Nikolay Igotti Committed by GitHub

Build MPP sampel on Windows (#291)

parent ef876646
...@@ -47,15 +47,15 @@ val unzipTask = tasks.register("unzipWasm", Copy::class) { ...@@ -47,15 +47,15 @@ val unzipTask = tasks.register("unzipWasm", Copy::class) {
kotlin { kotlin {
val targets = mutableListOf<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>() val targets = mutableListOf<org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget>()
if (hostOs == "macos") {
val nativeHostTarget = when (host) { val nativeHostTarget = when (host) {
"macos-x64" -> macosX64() "macos-x64" -> macosX64()
"macos-arm64" -> macosArm64() "macos-arm64" -> macosArm64()
else -> throw GradleException("Host OS is not supported yet") else -> throw GradleException("Host OS is not supported yet")
} }
targets.add(nativeHostTarget) targets.add(nativeHostTarget)
if (hostOs == "macos") {
targets.add(iosX64()) targets.add(iosX64())
targets.add(iosArm64()) targets.add(iosArm64())
} }
...@@ -115,6 +115,8 @@ kotlin { ...@@ -115,6 +115,8 @@ kotlin {
dependsOn(nativeMain) dependsOn(nativeMain)
} }
if (hostOs == "macos") {
val archTargetMain = when (host) { val archTargetMain = when (host) {
"macos-x64" -> { "macos-x64" -> {
val macosX64Main by getting { val macosX64Main by getting {
...@@ -130,8 +132,6 @@ kotlin { ...@@ -130,8 +132,6 @@ kotlin {
} }
else -> throw GradleException("Host OS is not supported") else -> throw GradleException("Host OS is not supported")
} }
if (hostOs == "macos") {
val iosMain by creating { val iosMain by creating {
dependsOn(nativeMain) dependsOn(nativeMain)
} }
...@@ -200,15 +200,17 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach ...@@ -200,15 +200,17 @@ tasks.withType<org.jetbrains.kotlin.gradle.dsl.KotlinJsCompile>().configureEach
dependsOn(unzipTask) dependsOn(unzipTask)
} }
// Create Xcode integration tasks.
val sdkName: String? = System.getenv("SDK_NAME")
enum class Target(val simulator: Boolean, val key: String) { enum class Target(val simulator: Boolean, val key: String) {
WATCHOS_X86(true, "watchos"), WATCHOS_ARM64(false, "watchos"), WATCHOS_X86(true, "watchos"), WATCHOS_ARM64(false, "watchos"),
IOS_X64(true, "iosX64"), IOS_ARM64(false, "iosArm64") IOS_X64(true, "iosX64"), IOS_ARM64(false, "iosArm64")
} }
val target = sdkName.orEmpty().let {
if (hostOs == "macos") {
// Create Xcode integration tasks.
val sdkName: String? = System.getenv("SDK_NAME")
val target = sdkName.orEmpty().let {
when { when {
it.startsWith("iphoneos") -> Target.IOS_ARM64 it.startsWith("iphoneos") -> Target.IOS_ARM64
it.startsWith("iphonesimulator") -> Target.IOS_X64 it.startsWith("iphonesimulator") -> Target.IOS_X64
...@@ -216,25 +218,25 @@ val target = sdkName.orEmpty().let { ...@@ -216,25 +218,25 @@ val target = sdkName.orEmpty().let {
it.startsWith("watchsimulator") -> Target.WATCHOS_X86 it.startsWith("watchsimulator") -> Target.WATCHOS_X86
else -> Target.IOS_X64 else -> Target.IOS_X64
} }
} }
val targetBuildDir: String? = System.getenv("TARGET_BUILD_DIR") val targetBuildDir: String? = System.getenv("TARGET_BUILD_DIR")
val executablePath: String? = System.getenv("EXECUTABLE_PATH") val executablePath: String? = System.getenv("EXECUTABLE_PATH")
val buildType = System.getenv("CONFIGURATION")?.let { val buildType = System.getenv("CONFIGURATION")?.let {
org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.valueOf(it.toUpperCase()) org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.valueOf(it.toUpperCase())
} ?: org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG } ?: org.jetbrains.kotlin.gradle.plugin.mpp.NativeBuildType.DEBUG
val currentTarget = kotlin.targets[target.key] as org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget val currentTarget = kotlin.targets[target.key] as org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
val kotlinBinary = currentTarget.binaries.getExecutable(buildType) val kotlinBinary = currentTarget.binaries.getExecutable(buildType)
val xcodeIntegrationGroup = "Xcode integration" val xcodeIntegrationGroup = "Xcode integration"
val packForXCode = if (sdkName == null || targetBuildDir == null || executablePath == null) { val packForXCode = if (sdkName == null || targetBuildDir == null || executablePath == null) {
// The build is launched not by Xcode -> // The build is launched not by Xcode ->
// We cannot create a copy task and just show a meaningful error message. // We cannot create a copy task and just show a meaningful error message.
tasks.create("packForXCode").doLast { tasks.create("packForXCode").doLast {
throw IllegalStateException("Please run the task from Xcode") throw IllegalStateException("Please run the task from Xcode")
} }
} else { } else {
// Otherwise copy the executable into the Xcode output directory. // Otherwise copy the executable into the Xcode output directory.
tasks.create("packForXCode", Copy::class.java) { tasks.create("packForXCode", Copy::class.java) {
dependsOn(kotlinBinary.linkTask) dependsOn(kotlinBinary.linkTask)
...@@ -255,6 +257,7 @@ val packForXCode = if (sdkName == null || targetBuildDir == null || executablePa ...@@ -255,6 +257,7 @@ val packForXCode = if (sdkName == null || targetBuildDir == null || executablePa
rename { executablePath } rename { executablePath }
} }
} }
}
} }
// a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273 // a temporary workaround for a bug in jsRun invocation - see https://youtrack.jetbrains.com/issue/KT-48273
......
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment