Move everything under kotlin-native folder
I was forced to manually do update the following files, because otherwise they would be ignored according .gitignore settings. Probably they should be deleted from repo. Interop/.idea/compiler.xml Interop/.idea/gradle.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_runtime_1_0_3.xml Interop/.idea/libraries/Gradle__org_jetbrains_kotlin_kotlin_stdlib_1_0_3.xml Interop/.idea/modules.xml Interop/.idea/modules/Indexer/Indexer.iml Interop/.idea/modules/Runtime/Runtime.iml Interop/.idea/modules/StubGenerator/StubGenerator.iml backend.native/backend.native.iml backend.native/bc.frontend/bc.frontend.iml backend.native/cli.bc/cli.bc.iml backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2Native.kt backend.native/cli.bc/src/org/jetbrains/kotlin/cli/bc/K2NativeCompilerArguments.kt backend.native/tests/link/lib/foo.kt backend.native/tests/link/lib/foo2.kt backend.native/tests/teamcity-test.property
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# HTTP client
|
||||
|
||||
This example shows how to communicate with libcurl, HTTP/HTTPS/FTP/etc client library and how to
|
||||
depend on an artifact published in a maven repository. The sample depends on a library
|
||||
built by [libcurl sample](../libcurl) so you need to run it first.
|
||||
|
||||
To build use `../gradlew assemble`.
|
||||
|
||||
To run use `../gradlew runReleaseExecutableCurl` or execute the program directly:
|
||||
|
||||
./build/bin/curl/main/release/executable/curl.kexe 'https://www.jetbrains.com/'
|
||||
|
||||
It will perform HTTP get and print out the data obtained.
|
||||
@@ -0,0 +1,71 @@
|
||||
plugins {
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
val localRepo = rootProject.file("build/.m2-local")
|
||||
|
||||
repositories {
|
||||
maven("file://$localRepo")
|
||||
}
|
||||
|
||||
val mingwPath = File(System.getenv("MINGW64_DIR") ?: "C:/msys64/mingw64")
|
||||
|
||||
kotlin {
|
||||
// Determine host preset.
|
||||
val hostOs = System.getProperty("os.name")
|
||||
val isMingwX64 = hostOs.startsWith("Windows")
|
||||
|
||||
// Create target for the host platform.
|
||||
val hostTarget = when {
|
||||
hostOs == "Mac OS X" -> macosX64("curl")
|
||||
hostOs == "Linux" -> linuxX64("curl")
|
||||
isMingwX64 -> mingwX64("curl")
|
||||
else -> throw GradleException("Host OS '$hostOs' is not supported in Kotlin/Native $project.")
|
||||
}
|
||||
|
||||
hostTarget.apply {
|
||||
binaries {
|
||||
executable {
|
||||
entryPoint = "sample.curl.main"
|
||||
if (isMingwX64) {
|
||||
// Add lib path to `libcurl` and its dependencies:
|
||||
linkerOpts("-L${mingwPath.resolve("lib")}")
|
||||
runTask?.environment("PATH" to mingwPath.resolve("bin"))
|
||||
}
|
||||
runTask?.args("https://www.jetbrains.com/")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
val curlMain by getting {
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin.sample.native:libcurl:1.0")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The code snippet below is needed to make all compile tasks depend on publication of
|
||||
// "libcurl" library. So that to the time of compilation the library will already be
|
||||
// in Maven repo and will be successfully resolved as a dependency of this project.
|
||||
tasks.withType(AbstractCompile::class) {
|
||||
dependsOn(":libcurl:publish")
|
||||
}
|
||||
|
||||
// The following snippet is needed to give instructions for IDEA user who just imported project
|
||||
// and sees "Could not resolve..." message in IDEA console.
|
||||
gradle.buildFinished {
|
||||
val configurationName = kotlin.targets["curl"].compilations["main"].compileDependencyConfigurationName
|
||||
val configuration = project.configurations[configurationName]
|
||||
if (configuration.isCanBeResolved && configuration.state == Configuration.State.RESOLVED_WITH_FAILURES) {
|
||||
println(
|
||||
"""
|
||||
|
|
||||
|IMPORTANT:
|
||||
|The message about unresolved "libcurl" dependency likely means that "libcurl" has not been built and published to local Maven repo yet.
|
||||
|Please run "publish" task for "libcurl" sub-project and re-import Kotlin/Native samples in IDEA.
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
kotlin.code.style=official
|
||||
kotlin.import.noCommonSourceSets=true
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package sample.curl
|
||||
|
||||
import sample.libcurl.*
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (args.isEmpty())
|
||||
return help()
|
||||
|
||||
val curl = CUrl(args[0])
|
||||
curl.header += {
|
||||
println("[H] $it")
|
||||
}
|
||||
|
||||
curl.body += {
|
||||
println("[B] $it")
|
||||
}
|
||||
|
||||
curl.fetch()
|
||||
curl.close()
|
||||
}
|
||||
|
||||
fun help() {
|
||||
println("ERROR: missing URL command line argument")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user