Fixed samples for the latest changes in Gradle plugin.
- Smaller gradle scripts. - More structure in sample projects. - Simplified build/run. - Added gradle to the rest two samples. - Almost removed all sh scripts. - Gradle now works only inside of build directory. - Fixed READMEs according to the new changes.
This commit is contained in:
committed by
SvyatoslavScherbina
parent
f1fa5327f3
commit
bc941269f0
@@ -1833,13 +1833,13 @@ kotlinNativeInterop {
|
||||
}
|
||||
|
||||
sockets {
|
||||
defFile '../../samples/socket/sockets.def'
|
||||
defFile '../../samples/socket/src/c_interop/sockets.def'
|
||||
flavor 'native'
|
||||
}
|
||||
|
||||
if (isMac()) {
|
||||
opengl {
|
||||
defFile '../../samples/opengl/opengl.def'
|
||||
defFile '../../samples/opengl/src/c_interop/opengl.def'
|
||||
linkerOpts '-framework', 'OpenGL', '-framework', 'GLUT'
|
||||
flavor 'native'
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
# Concurrent
|
||||
|
||||
This example shows how to implement concurrent programming in Kotlin/Native.
|
||||
In this example we start multiple threads running concurrently and exchange messages with them.
|
||||
|
||||
To build cpp use `./buildCpp.sh`.
|
||||
To build kotlin native use `../gradlew build` or `./build.sh`.
|
||||
|
||||
To run use `../gradlew run`
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/MessageChannel/MessageChannel.kexe
|
||||
|
||||
It will print all passed messages.
|
||||
@@ -0,0 +1,14 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
MessageChannel {
|
||||
includeDirs "${project.projectDir}/src/main/cpp"
|
||||
}
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
MessageChannel {
|
||||
useInterop "MessageChannel"
|
||||
nativeLibrary "${project.buildDir.canonicalPath}/clang/MessageChannel.bc"
|
||||
}
|
||||
}
|
||||
+15
-12
@@ -1,8 +1,8 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=.
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DEPS=$(dirname `type -p konanc`)/../dependencies
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
@@ -12,19 +12,22 @@ case "$OSTYPE" in
|
||||
esac
|
||||
fi
|
||||
|
||||
CLANG_linux=$DEPS/clang-llvm-3.9.0-linux-x86-64/bin/clang++
|
||||
CLANG_macbook=$DEPS/clang-llvm-3.9.0-darwin-macos/bin/clang++
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
var=CLANG_${TARGET}
|
||||
CLANG=${!var}
|
||||
|
||||
$CLANG -std=c++11 -c $DIR/MessageChannel.cpp -o $DIR/MessageChannel.bc -emit-llvm || exit 1
|
||||
cinterop -def $DIR/MessageChannel.def -compilerOpts "-I$DIR" -target $TARGET -o $DIR/MessageChannel || exit 1
|
||||
konanc $DIR/Concurrent.kt -library $DIR/MessageChannel \
|
||||
-nativelibrary $DIR/MessageChannel.bc -o Concurrent || exit 1
|
||||
mkdir -p $DIR/build/c_interop
|
||||
mkdir -p $DIR/build/bin
|
||||
|
||||
$DIR/buildCpp.sh
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/MessageChannel.def -copt "-I$DIR/src/main/cpp" -target $TARGET \
|
||||
-o $DIR/build/c_interop/MessageChannel.kt.bc || exit 1
|
||||
|
||||
konanc $DIR/src/main/kotlin/Concurrent.kt -library $DIR/build/c_interop/MessageChannel.kt.bc \
|
||||
-nativelibrary $DIR/build/clang/MessageChannel.bc -o $DIR/build/bin/Concurrent.kexe || exit 1
|
||||
|
||||
echo "Artifact path is $DIR/build/bin/Concurrent.kexe"
|
||||
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
DEPS=$(dirname `type -p konanc`)/../dependencies
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook ;;
|
||||
linux*) TARGET=linux ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
CLANG_linux=$DEPS/clang-llvm-3.9.0-linux-x86-64/bin/clang++
|
||||
CLANG_macbook=$DEPS/clang-llvm-3.9.0-darwin-macos/bin/clang++
|
||||
|
||||
var=CLANG_${TARGET}
|
||||
CLANG=${!var}
|
||||
|
||||
mkdir -p $DIR/build/clang/
|
||||
|
||||
$CLANG -std=c++11 -c $DIR/src/main/cpp/MessageChannel.cpp -o $DIR/build/clang/MessageChannel.bc -emit-llvm || exit 1
|
||||
@@ -4,12 +4,16 @@
|
||||
A sample data [European Mammals Red List for 2009](https://data.europa.eu/euodp/en/data/dataset?res_format=CSV)
|
||||
from EU is being used.
|
||||
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
You also may use Gradle to build this sample: `../gradlew build`.
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
To run use
|
||||
To run use `../gradlew run`
|
||||
|
||||
./CsvParser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
To change run arguments, change property runArgs in gradle.propeties file
|
||||
or pass `-PrunArgs="./European_Mammals_Red_List_Nov_2009.csv 4 100"` to gradle run.
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/CsvParser/CsvParser.kexe ./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
|
||||
It will print number of all unique entries in fifth column
|
||||
(Family, zero-based index) in first 100 rows of the CSV file.
|
||||
|
||||
@@ -1,72 +1,11 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
stdio {
|
||||
defFile 'stdio.def'
|
||||
}
|
||||
stdio { }
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
CsvParser {
|
||||
inputFiles project.file('CsvParser.kt')
|
||||
useInterop 'stdio'
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanCsvParser.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanCsvParser.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dumpCompilationTask(Task task) {
|
||||
println()
|
||||
println("Compilation task: ${task.name}")
|
||||
println("outputDir : ${task.outputDir}")
|
||||
println("artifactPath : ${task.artifactPath}")
|
||||
println("inputFiles : ${task.inputFiles.files}")
|
||||
println("libraries : ${task.libraries}")
|
||||
println("nativeLibraries : ${task.nativeLibraries}")
|
||||
println("linkerOpts : ${task.linkerOpts}")
|
||||
println("produce : ${task.produce}")
|
||||
println("noStdLib : ${task.noStdLib}")
|
||||
println("noMain : ${task.noMain}")
|
||||
println("enableOptimization : ${task.enableOptimization}")
|
||||
println("enableAssertions : ${task.enableAssertions}")
|
||||
println("target : ${task.target}")
|
||||
println("languageVersion : ${task.languageVersion}")
|
||||
println("apiVersion : ${task.apiVersion}")
|
||||
}
|
||||
|
||||
void dumpInteropTask(Task task) {
|
||||
println()
|
||||
println("Stub generation task: ${task.name}")
|
||||
println("stubsDir : ${task.stubsDir}")
|
||||
println("libsDir : ${task.libsDir}")
|
||||
println("defFile : ${task.defFile}")
|
||||
println("target : ${task.target}")
|
||||
println("pkg : ${task.pkg}")
|
||||
println("linker : ${task.linker}")
|
||||
println("compilerOpts : ${task.compilerOpts}")
|
||||
println("linkerOpts : ${task.linkerOpts}")
|
||||
println("headers : ${task.headers.files}")
|
||||
println("linkFiles : ${task.linkFiles}")
|
||||
}
|
||||
|
||||
task dumpParameters(type: DefaultTask) {
|
||||
doLast {
|
||||
dumpCompilationTask(konanArtifacts['CsvParser'].compilationTask)
|
||||
dumpInteropTask(konanInterop['stdio'].generateStubsTask)
|
||||
dumpCompilationTask(konanInterop['stdio'].compileStubsTask)
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=.
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
@@ -19,5 +19,12 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -def $DIR/stdio.def -compilerOpts "$CFLAGS" -target $TARGET -o stdio || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/CsvParser.kt -library stdio -o CsvParser || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/stdio.def -compilerOpts "$CFLAGS" -target $TARGET -o $DIR/build/c_interop/stdio.kt.bc || exit 1
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/CsvParser.kt -library $DIR/build/c_interop/stdio.kt.bc \
|
||||
-o $DIR/build/bin/CsvParser.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/CsvParser.kexe"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
runArgs=./European_Mammals_Red_List_Nov_2009.csv 4 100
|
||||
@@ -1,13 +1,17 @@
|
||||
# GIT frequency analyzer
|
||||
|
||||
This example shows how one could perform statistics on Git repository.
|
||||
This example shows how one could perform statistics on Git repository.
|
||||
libgit2 is required for this to work (`apt-get install libgit2-dev`).
|
||||
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
You also may use Gradle to build this sample: `../gradlew build`.
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
To run use
|
||||
To run use `../gradlew run`.
|
||||
|
||||
./GitChurn.kexe <path-to-some-git-repo>
|
||||
To change run arguments, change property runArgs in gradle.propeties file
|
||||
or pass `-PrunArgs="../../"` to gradle run.
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/GitChurn/GitChurn.kexe ../../
|
||||
|
||||
It will print most frequently modified (by number of commits) files in repository.
|
||||
|
||||
@@ -1,75 +1,14 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
|
||||
konanInterop {
|
||||
libgit2 {
|
||||
defFile 'libgit2.def'
|
||||
includeDirs '/opt/local/include', '/usr/include', '/usr/local/include'
|
||||
}
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
GitChurn {
|
||||
inputFiles project.fileTree('src')
|
||||
useInterop 'libgit2'
|
||||
linkerOpts "-L/opt/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/lib -lgit2"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanGitChurn.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanGitChurn.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void dumpCompilationTask(Task task) {
|
||||
println()
|
||||
println("Compilation task: ${task.name}")
|
||||
println("outputDir : ${task.outputDir}")
|
||||
println("artifactPath : ${task.artifactPath}")
|
||||
println("inputFiles : ${task.inputFiles.files}")
|
||||
println("libraries : ${task.libraries}")
|
||||
println("nativeLibraries : ${task.nativeLibraries}")
|
||||
println("linkerOpts : ${task.linkerOpts}")
|
||||
println("produce : ${task.produce}")
|
||||
println("noStdLib : ${task.noStdLib}")
|
||||
println("noMain : ${task.noMain}")
|
||||
println("enableOptimization : ${task.enableOptimization}")
|
||||
println("enableAssertions : ${task.enableAssertions}")
|
||||
println("target : ${task.target}")
|
||||
println("languageVersion : ${task.languageVersion}")
|
||||
println("apiVersion : ${task.apiVersion}")
|
||||
}
|
||||
|
||||
void dumpInteropTask(Task task) {
|
||||
println()
|
||||
println("Stub generation task: ${task.name}")
|
||||
println("stubsDir : ${task.stubsDir}")
|
||||
println("libsDir : ${task.libsDir}")
|
||||
println("defFile : ${task.defFile}")
|
||||
println("target : ${task.target}")
|
||||
println("pkg : ${task.pkg}")
|
||||
println("linker : ${task.linker}")
|
||||
println("compilerOpts : ${task.compilerOpts}")
|
||||
println("linkerOpts : ${task.linkerOpts}")
|
||||
println("headers : ${task.headers.files}")
|
||||
println("linkFiles : ${task.linkFiles}")
|
||||
}
|
||||
|
||||
task dumpParameters(type: DefaultTask) {
|
||||
doLast {
|
||||
dumpCompilationTask(konanArtifacts['GitChurn'].compilationTask)
|
||||
dumpInteropTask(konanInterop['libgit2'].generateStubsTask)
|
||||
dumpCompilationTask(konanInterop['libgit2'].compileStubsTask)
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
# Uncomment flags if your paths differ from these ones.
|
||||
CFLAGS_macbook=-I/opt/local/include
|
||||
#CFLAGS_macbook=-I/usr/local/include
|
||||
CFLAGS_macbook="-I/opt/local/include -compilerOpts -I/usr/local/include"
|
||||
CFLAGS_linux=-I/usr/include
|
||||
LINKER_ARGS_macbook="-L/opt/local/lib -lgit2"
|
||||
#LINKER_ARGS_macbook="-L/usr/local/lib -lgit2"
|
||||
LINKER_ARGS_macbook="-L/usr/local/lib -L/opt/local/lib -lgit2"
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lgit2"
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
@@ -26,5 +23,13 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -compilerOpts $CFLAGS -def $DIR/libgit2.def -target $TARGET -o libgit2 || exit 1
|
||||
konanc -target $TARGET src -library libgit2 -linkerArgs "$LINKER_ARGS" -o GitChurn || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -compilerOpts $CFLAGS -def $DIR/src/main/c_interop/libgit2.def -target $TARGET \
|
||||
-o $DIR/build/c_interop/libgit2.kt.bc || exit 1
|
||||
|
||||
konanc -target $TARGET $DIR/src/main/kotlin -library $DIR/build/c_interop/libgit2.kt.bc -linkerOpts "$LINKER_ARGS" \
|
||||
-o $DIR/build/bin/GitChurn.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/GitChurn.kexe"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
runArgs=../../
|
||||
@@ -1,3 +1,3 @@
|
||||
headers = git2.h time.h
|
||||
linkerOpts = -lgit2
|
||||
headerFilter = git2/** time.h
|
||||
headerFilter = git2/** time.h
|
||||
@@ -3,15 +3,18 @@
|
||||
This example shows how one may use _Kotlin/Native_ to build GUI
|
||||
applications with the GTK toolkit.
|
||||
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
You also may use gradle to build the sample: `../gradlew build`.
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
Do not forget to install GTK3.
|
||||
|
||||
On Mac use `port install gtk3`, on Debian flavours of Linux - `apt-get install libgtk-3-dev`.
|
||||
To run on Mac also install XQuartz X server (https://www.xquartz.org/), and then
|
||||
|
||||
./Gtk3Demo.kexe
|
||||
../gradlew run
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/Gtk3Demo/Gtk3Demo.kexe
|
||||
|
||||
Dialog box with the button will be shown, and application will print message
|
||||
and terminate on button click.
|
||||
|
||||
@@ -7,30 +7,12 @@ konanInterop {
|
||||
includeDirs "$it/atk-1.0", "$it/gdk-pixbuf-2.0", "$it/cairo", "$it/pango-1.0", "$it/gtk-3.0", "$it/glib-2.0"
|
||||
}
|
||||
includeDirs '/opt/local/lib/glib-2.0/include', '/usr/lib/x86_64-linux-gnu/glib-2.0/include', '/usr/local/lib/glib-2.0/include'
|
||||
defFile 'gtk3.def'
|
||||
}
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
Gtk3Demo {
|
||||
inputFiles project.fileTree('src')
|
||||
useInterop 'gtk3'
|
||||
linkerOpts "-L/opt/local/lib -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lgdk-3.0 -lgtk-3 -lgio-2.0 -lgobject-2.0"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanGtk3Demo.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanGtk3Demo.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
+16
-11
@@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
IPREFIX_macbook=-I/opt/local/include
|
||||
#IPREFIX_macbook=-I/usr/local/include
|
||||
IPREFIX_linux=-I/usr/include
|
||||
LINKER_ARGS_macbook="-L/opt/local/lib -lglib-2.0 -lgdk-3.0 -lgtk-3 -lgio-2.0 -lgobject-2.0"
|
||||
LINKER_ARGS_macbook="-L/opt/local/lib -L/usr/local/lib -lglib-2.0 -lgdk-3.0 -lgtk-3 -lgio-2.0 -lgobject-2.0"
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lglib-2.0 -lgdk-3 -lgtk-3 -lgio-2.0 -lgobject-2.0"
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
@@ -24,11 +24,16 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
if [ ! -f $DIR/gtk3.klib ]; then
|
||||
echo "Generating GTK stubs (once), may take few mins depending on the hardware..."
|
||||
cinterop -J-Xmx8g -compilerOpts "$IPREFIX/atk-1.0 $IPREFIX/gdk-pixbuf-2.0 $IPREFIX/cairo $IPREFIX/pango-1.0 \
|
||||
-I/opt/local/lib/glib-2.0/include -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/local/lib/glib-2.0/include \
|
||||
$IPREFIX/gtk-3.0 $IPREFIX/glib-2.0" -def $DIR/gtk3.def \
|
||||
-target $TARGET -o $DIR/gtk3 || exit 1
|
||||
fi
|
||||
konanc -target $TARGET $DIR/src -library $DIR/gtk3 -linkerOpts "$LINKER_ARGS" -o $DIR/Gtk3Demo || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
echo "Generating GTK stubs, may take few mins depending on the hardware..."
|
||||
cinterop -J-Xmx8g -copt $IPREFIX/atk-1.0 -compilerOpts $IPREFIX/gdk-pixbuf-2.0 -copt $IPREFIX/cairo -copt $IPREFIX/pango-1.0 \
|
||||
-copt -I/opt/local/lib/glib-2.0/include -copt -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -copt -I/usr/local/lib/glib-2.0/include \
|
||||
-copt $IPREFIX/gtk-3.0 -copt $IPREFIX/glib-2.0 -def $DIR/src/main/c_interop/gtk3.def \
|
||||
-target $TARGET -o $DIR/build/c_interop/gtk3.bc || exit 1
|
||||
|
||||
konanc -target $TARGET $DIR/src/main/kotlin -library $DIR/build/c_interop/gtk3.bc -linkerOpts "$LINKER_ARGS" \
|
||||
-o $DIR/build/bin/Gtk3Demo.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/Gtk3Demo.kexe"
|
||||
@@ -2,11 +2,16 @@
|
||||
|
||||
This example shows how to communicate with libcurl, HTTP/HTTPS/FTP/etc client library.
|
||||
Debian-like distros may need to `apt-get install libcurl4-openssl-dev`.
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
You also may use Gradle to build this sample: `../gradlew build`.
|
||||
|
||||
To run use
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
./Curl.kexe https://www.jetbrains.com
|
||||
To run use `../gradlew run`
|
||||
|
||||
To change run arguments, change property runArgs in gradle.propeties file
|
||||
or pass `-PrunArgs="https://www.jetbrains.com"` to gradle run.
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/Curl/Curl.kexe https://www.jetbrains.com
|
||||
|
||||
It will perform HTTP get and print out the data obtained.
|
||||
|
||||
@@ -2,31 +2,13 @@ apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
libcurl {
|
||||
defFile 'libcurl.def'
|
||||
includeDirs '/usr/include', '/opt/local/include', '/usr/local/opt/curl/include', '.'
|
||||
}
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
Curl {
|
||||
inputFiles project.fileTree('src')
|
||||
useInterop 'libcurl'
|
||||
linkerOpts "-L/opt/local/lib -L/usr/lib/x86_64-linux-gnu -L/usr/local/opt/curl/lib -lcurl"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanCurl.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanCurl.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
CFLAGS_macbook="-I /opt/local/include"
|
||||
CFLAGS_macbook=-I/opt/local/include
|
||||
CFLAGS_linux="-I /usr/include -I /usr/include/x86_64-linux-gnu"
|
||||
LINKER_ARGS_macbook="-L/opt/local/lib -lcurl"
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lcurl"
|
||||
@@ -23,5 +23,13 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -compilerOpts "$CFLAGS" -def $DIR/libcurl.def -target $TARGET -o libcurl || exit 1
|
||||
konanc -target $TARGET src -library libcurl -linkerOpts "$LINKER_ARGS" -o Curl || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -compilerOpts "$CFLAGS" -compilerOpts -I$DIR -compilerOpts -I/usr/include -def $DIR/src/main/c_interop/libcurl.def -target $TARGET \
|
||||
-o $DIR/build/c_interop/libcurl.bc || exit 1
|
||||
|
||||
konanc -target $TARGET $DIR/src/main/kotlin -library $DIR/build/c_interop/libcurl.bc -linkerOpts "$LINKER_ARGS" \
|
||||
-o $DIR/build/bin/Curl.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/Curl.kexe"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
runArgs=https://www.jetbrains.com
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
Executable → Regular
@@ -7,17 +7,18 @@ are being suspended and resumed whenever relevant.
|
||||
Thus, while server can process multiple connections concurrently,
|
||||
each individual connection handler is written in simple linear manner.
|
||||
|
||||
Compile the echo server (in EAP only supported on Mac host):
|
||||
|
||||
./build.sh
|
||||
|
||||
You also may use Gradle to build the server:
|
||||
|
||||
../gradlew build
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
Run the server:
|
||||
|
||||
./EchoServer.kexe 3000 &
|
||||
../gradlew run
|
||||
|
||||
To change run arguments, change property runArgs in gradle.propeties file
|
||||
or pass `-PrunArgs="3000"` to gradle run.
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/EchoServer/EchoServer.kexe 3000 &
|
||||
|
||||
Test the server by connecting to it, for example with telnet:
|
||||
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
sockets {
|
||||
defFile "sockets.def"
|
||||
}
|
||||
sockets { }
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
EchoServer {
|
||||
inputFiles project.file("EchoServer.kt")
|
||||
useInterop "sockets"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanEchoServer.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanEchoServer.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
@@ -18,5 +18,13 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -def $DIR/sockets.def -copt "$CFLAGS" -target $TARGET -o sockets || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/EchoServer.kt -library sockets -o EchoServer || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/sockets.def -copt "$CFLAGS" -target $TARGET \
|
||||
-o $DIR/build/c_interop/sockets.kt.bc || exit 1
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/EchoServer.kt \
|
||||
-library $DIR/build/c_interop/sockets.kt.bc -o $DIR/build/bin/EchoServer.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/EchoServer.kexe"
|
||||
@@ -0,0 +1 @@
|
||||
runArgs=3000
|
||||
@@ -3,12 +3,13 @@
|
||||
This example shows interaction with OpenGL library, to render classical 3D test model. Linux build requires `apt-get install freeglut3-dev` or similar,
|
||||
MacOS shall work as is.
|
||||
|
||||
To build use `./build.sh` script without arguments (or specify `TARGET` variable if cross-compiling).
|
||||
You also may use Gradle to build this sample: `../gradlew build`.
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
To run use
|
||||
To run use `../gradlew run`
|
||||
|
||||
./OpenGlTeapot.kexe
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/OpenGlTeapot${target}/OpenGlTeapot${target}.kexe
|
||||
|
||||
It will render 3D model of teapot. Feel free to experiment with it, the whole power of OpenGL
|
||||
is at your hands.
|
||||
|
||||
@@ -1,39 +1,20 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
opengl {
|
||||
defFile 'opengl.def'
|
||||
}
|
||||
opengl { }
|
||||
}
|
||||
|
||||
|
||||
konanArtifacts {
|
||||
OpenGlTeapot {
|
||||
inputFiles project.file("OpenGlTeapot.kt")
|
||||
OpenGlTeapotMacbook {
|
||||
useInterop 'opengl'
|
||||
def osName = System.getProperty("os.name")
|
||||
if (osName.equals("Mac OS X")) {
|
||||
linkerOpts "-framework OpenGL -framework GLUT"
|
||||
}
|
||||
if (osName.equals("Linux")) {
|
||||
linkerOpts "-L/usr/lib/x86_64-linux-gnu -lglut -lGL -lGLU"
|
||||
}
|
||||
linkerOpts "-framework OpenGL -framework GLUT"
|
||||
target "macbook"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanOpenGlTeapot.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanOpenGlTeapot.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
OpenGlTeapotLinux {
|
||||
useInterop 'opengl'
|
||||
linkerOpts "-L/usr/lib/x86_64-linux-gnu -lglut -lGL -lGLU"
|
||||
target "linux"
|
||||
}
|
||||
}
|
||||
+12
-4
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
LINKER_ARGS_macbook="-framework OpenGL -framework GLUT"
|
||||
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lglut -lGL -lGLU"
|
||||
@@ -21,5 +21,13 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -def $DIR/opengl.def -target $TARGET -o opengl || exit 1
|
||||
konanc -target $TARGET $DIR/OpenGlTeapot.kt -library opengl -linkerOpts "$LINKER_ARGS" -o OpenGlTeapot || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/opengl.def -target $TARGET \
|
||||
-o $DIR/build/c_interop/opengl.kt.bc || exit 1
|
||||
|
||||
konanc -target $TARGET $DIR/src/main/kotlin/OpenGlTeapot.kt -library $DIR/build/c_interop/opengl.kt.bc \
|
||||
-linkerOpts "$LINKER_ARGS" -o $DIR/build/bin/OpenGlTeapot.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/OpenGlTeapot.kexe"
|
||||
|
||||
@@ -6,5 +6,6 @@ include ':nonBlockingEchoServer'
|
||||
include ':opengl'
|
||||
include ':socket'
|
||||
include ':tetris'
|
||||
|
||||
include ':tensorflow'
|
||||
include ':concurrent'
|
||||
includeBuild '../'
|
||||
|
||||
@@ -6,3 +6,5 @@ include ':nonBlockingEchoServer'
|
||||
include ':opengl'
|
||||
include ':socket'
|
||||
include ':tetris'
|
||||
include ':tensorflow'
|
||||
include ':concurrent'
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
# Sockets demo
|
||||
|
||||
Compile the echo server (in EAP only supported on Mac host):
|
||||
|
||||
./build.sh
|
||||
|
||||
You also may use Gradle to build the server:
|
||||
|
||||
../gradlew build
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
Run the server:
|
||||
|
||||
./EchoServer.kexe 3000 &
|
||||
../gradlew run
|
||||
|
||||
To change run arguments, change property runArgs in gradle.propeties file
|
||||
or pass `-PrunArgs="3000"` to gradle run.
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/EchoServer/EchoServer.kexe 3000 &
|
||||
|
||||
Test the server by conecting to it, for example with telnet:
|
||||
|
||||
|
||||
@@ -1,30 +1,11 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
sockets {
|
||||
defFile "sockets.def"
|
||||
}
|
||||
sockets { }
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
EchoServer {
|
||||
inputFiles project.file("EchoServer.kt")
|
||||
useInterop "sockets"
|
||||
}
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext { outputFile = "${projectDir.canonicalPath}/${file(compileKonanEchoServer.artifactPath).name}" }
|
||||
doLast {
|
||||
copy {
|
||||
from compileKonanEchoServer.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
delete outputFile
|
||||
}
|
||||
}
|
||||
+13
-4
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
@@ -18,5 +18,14 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -def $DIR/sockets.def -copt "$CFLAGS" -target $TARGET -o sockets || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/EchoServer.kt -library sockets -o EchoServer || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/sockets.def -copt "$CFLAGS" -target $TARGET \
|
||||
-o $DIR/build/c_interop/sockets.kt.bc || exit 1
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/EchoServer.kt \
|
||||
-library $DIR/build/c_interop/sockets.kt.bc \
|
||||
-o $DIR/build/bin/EchoServer.kexe || exit 1
|
||||
|
||||
echo "Artifact path is ./build/bin/EchoServer.kexe"
|
||||
@@ -0,0 +1 @@
|
||||
runArgs=3000
|
||||
@@ -10,14 +10,20 @@ showing how a TensorFlow client in Kotlin/Native could look like.
|
||||
|
||||
## Installation
|
||||
|
||||
./build.sh
|
||||
./downloadTensorflow.sh
|
||||
|
||||
will install [TensorFlow for C](https://www.tensorflow.org/versions/r1.1/install/install_c) into
|
||||
`$HOME/.konan/third-party/tensorflow` (if not yet done) and build the example.
|
||||
`$HOME/.konan/third-party/tensorflow` (if not yet done).
|
||||
|
||||
./HelloTensorflow.kexe
|
||||
To build use `../gradlew build` or `./build.sh`.
|
||||
|
||||
Then run
|
||||
|
||||
will then run the example.
|
||||
../gradlew run
|
||||
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
./build/konan/bin/Tensorflow/Tensorflow.kexe
|
||||
|
||||
You may need to specify `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` to `$HOME/.konan/third-party/tensorflow/lib`
|
||||
if the TensorFlow dynamic library cannot be found.
|
||||
@@ -0,0 +1,14 @@
|
||||
apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
tensorflow {
|
||||
includeDirs "${System.getProperty("user.home")}/.konan/third-party/tensorflow/include"
|
||||
}
|
||||
}
|
||||
|
||||
konanArtifacts {
|
||||
Tensorflow {
|
||||
useInterop "tensorflow"
|
||||
linkerOpts "-L${System.getProperty("user.home")}/.konan/third-party/tensorflow/lib -ltensorflow"
|
||||
}
|
||||
}
|
||||
+19
-15
@@ -1,13 +1,13 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
./downloadTensorflow.sh
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
TF_TARGET_DIRECTORY="$HOME/.konan/third-party/tensorflow"
|
||||
TF_TYPE="cpu" # Change to "gpu" for GPU support
|
||||
|
||||
CFLAGS_macbook="-I ${TF_TARGET_DIRECTORY}/include"
|
||||
CFLAGS_linux="-I ${TF_TARGET_DIRECTORY}/include"
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook; TF_TARGET=darwin ;;
|
||||
@@ -16,6 +16,9 @@ case "$OSTYPE" in
|
||||
esac
|
||||
fi
|
||||
|
||||
CFLAGS_macbook="-I${TF_TARGET_DIRECTORY}/include"
|
||||
CFLAGS_linux="-I${TF_TARGET_DIRECTORY}/include"
|
||||
|
||||
var=CFLAGS_${TARGET}
|
||||
CFLAGS=${!var}
|
||||
var=LINKER_ARGS_${TARGET}
|
||||
@@ -23,16 +26,17 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
if [ ! -d $TF_TARGET_DIRECTORY/include/tensorflow ]; then
|
||||
echo "Installing TensorFlow into $TF_TARGET_DIRECTORY ..."
|
||||
mkdir -p $TF_TARGET_DIRECTORY
|
||||
curl -s -L \
|
||||
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${TF_TARGET}-x86_64-1.1.0.tar.gz" |
|
||||
tar -C $TF_TARGET_DIRECTORY -xz
|
||||
fi
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/tensorflow.def -compilerOpts "$CFLAGS" -target $TARGET -o tensorflow || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/HelloTensorflow.kt -library tensorflow -o HelloTensorflow \
|
||||
-linkerOpts "-L$TF_TARGET_DIRECTORY/lib -ltensorflow" || exit 1
|
||||
cinterop -def $DIR/src/main/c_interop/tensorflow.def -compilerOpts "$CFLAGS" -target $TARGET \
|
||||
-o $DIR/build/c_interop/tensorflow.kt.bc || exit 1
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/HelloTensorflow.kt \
|
||||
-library $DIR/build/c_interop/tensorflow.kt.bc \
|
||||
-o $DIR/build/bin/HelloTensorflow.kexe \
|
||||
-linkerOpts "-L$TF_TARGET_DIRECTORY/lib -ltensorflow" || exit 1
|
||||
|
||||
echo "Note: You may need to specify LD_LIBRARY_PATH or DYLD_LIBRARY_PATH env variables to $TF_TARGET_DIRECTORY/lib if the TensorFlow dynamic library cannot be found."
|
||||
|
||||
echo "Artifact path is ./build/bin/HelloTensorflow.kexe"
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
|
||||
TF_TARGET_DIRECTORY="$HOME/.konan/third-party/tensorflow"
|
||||
TF_TYPE="cpu" # Change to "gpu" for GPU support
|
||||
|
||||
if [ x$TARGET == x ]; then
|
||||
case "$OSTYPE" in
|
||||
darwin*) TARGET=macbook; TF_TARGET=darwin ;;
|
||||
linux*) TARGET=linux; TF_TARGET=linux ;;
|
||||
*) echo "unknown: $OSTYPE" && exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
||||
if [ ! -d $TF_TARGET_DIRECTORY/include/tensorflow ]; then
|
||||
echo "Installing TensorFlow into $TF_TARGET_DIRECTORY ..."
|
||||
mkdir -p $TF_TARGET_DIRECTORY
|
||||
curl -s -L \
|
||||
"https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-${TF_TYPE}-${TF_TARGET}-x86_64-1.1.0.tar.gz" |
|
||||
tar -C $TF_TARGET_DIRECTORY -xz
|
||||
fi
|
||||
+11
-10
@@ -13,26 +13,27 @@ use `apt-get install libsdl2-dev`.
|
||||
For Windows - `pacman -S mingw-w64-x86_64-SDL2` in MinGW64 console, if you do
|
||||
not have MSYS2-MinGW64 installed - install it first as described in http://www.msys2.org
|
||||
|
||||
To build Tetris application for your host platform use
|
||||
To build Tetris application for your host platform (Mac or Linux) use `../gradlew build`.
|
||||
|
||||
For Mac and Linux:
|
||||
Aleternatively for Mac and Linux `./build.sh`.
|
||||
|
||||
./build.sh
|
||||
For Windows use `build.bat`.
|
||||
|
||||
This task builds the sample for your host platform. Note that SDL2 must be installed on the host.
|
||||
|
||||
For Windows:
|
||||
To run it on the host use `../gradlew run`
|
||||
|
||||
build.bat
|
||||
Alternatively you can run artifact directly
|
||||
|
||||
You also may use gradle to build this sample: `../gradlew build`. This task builds the sample for all platforms
|
||||
supported by the host. Note that SDL2 must be installed on the host.
|
||||
./build/konan/bin/Tetris${target}/Tetris${target}.kexe
|
||||
|
||||
For cross-compilation to iOS (on Mac host) use
|
||||
For cross-compilation to iOS (on Mac host) use gradle property
|
||||
|
||||
TARGET=iphone ./build.sh
|
||||
konan.build.targets=iphone
|
||||
|
||||
For cross-compilation to Raspberry Pi (on Linux host) use
|
||||
|
||||
TARGET=raspberrypi ./build.sh
|
||||
konan.build.targets=raspberrypi
|
||||
|
||||
During build process compilation script creates interoperability bindings to SDL2, using SDL C headers,
|
||||
and then compiles an application with the produced bindings.
|
||||
|
||||
@@ -10,10 +10,11 @@ set "CFLAGS=-I%MINGW%\include\SDL2"
|
||||
rem Add -Wl,--subsystem,windows for making GUI subsystem application.
|
||||
set "LFLAGS=%DIR%\Tetris.res -L%MINGW%\lib -lSDL2"
|
||||
|
||||
call cinterop -def "%DIR%\sdl.def" -compilerOpts "%CFLAGS%" -target "%TARGET%" -o sdl || exit /b
|
||||
call cinterop -def "%DIR%\src\main\c_interop\sdl.def" -compilerOpts "%CFLAGS%" -target "%TARGET%" -o sdl || exit /b
|
||||
rem Windows build requires Windows Resource Compiler in paths.
|
||||
call windres "%DIR%\Tetris.rc" -O coff -o "%DIR%\Tetris.res" || exit /b
|
||||
call konanc -target "%TARGET%" "%DIR%\Tetris.kt" -library sdl -linkerOpts "%LFLAGS%" -opt -o Tetris || exit /b
|
||||
call konanc -target "%TARGET%" "%DIR%\src\main\kotlin\Tetris.kt" -library sdl -linkerOpts "%LFLAGS%" -opt -o Tetris || exit /b
|
||||
|
||||
copy Tetris.kexe Tetris.exe
|
||||
copy %MINGW%\bin\SDL2.dll SDL2.dll
|
||||
copy src\main\resources\tetris_all.bmp tetris_all.bmp
|
||||
|
||||
+11
-25
@@ -2,7 +2,8 @@ apply plugin: 'konan'
|
||||
|
||||
konanInterop {
|
||||
sdlMacbook {
|
||||
defFile 'sdl.def'
|
||||
defFile 'src/main/c_interop/sdl.def'
|
||||
pkg 'sdl'
|
||||
includeDirs '/Library/Frameworks/SDL2.framework/Headers',
|
||||
"${System.getProperty("user.home")}/Library/Frameworks/SDL2.framework/Headers",
|
||||
'/opt/local/include/SDL2',
|
||||
@@ -12,19 +13,22 @@ konanInterop {
|
||||
}
|
||||
|
||||
sdlLinux {
|
||||
defFile 'sdl.def'
|
||||
defFile 'src/main/c_interop/sdl.def'
|
||||
pkg 'sdl'
|
||||
includeDirs '/usr/include/SDL2'
|
||||
target 'linux'
|
||||
}
|
||||
|
||||
sdlIphone {
|
||||
defFile 'sdl.def'
|
||||
defFile 'src/main/c_interop/sdl.def'
|
||||
pkg 'sdl'
|
||||
includeDirs "${project.property("konan.home")}/dependencies/target-sysroot-2-darwin-ios/System/Library/Frameworks/SDL2.framework/Headers"
|
||||
target 'iphone'
|
||||
}
|
||||
|
||||
sdlRaspberry {
|
||||
defFile 'sdl.def'
|
||||
defFile 'src/main/c_interop/sdl.def'
|
||||
pkg 'sdl'
|
||||
includeDirs "${project.property("konan.home")}/dependencies/target-sysroot-1-raspberrypi/usr/include/SDL2"
|
||||
target 'raspberrypi'
|
||||
}
|
||||
@@ -32,7 +36,6 @@ konanInterop {
|
||||
|
||||
konanArtifacts {
|
||||
TetrisMacbook {
|
||||
inputFiles project.file('Tetris.kt')
|
||||
useInterop 'sdlMacbook'
|
||||
linkerOpts "-F ${System.getProperty("user.home")}/Library/Frameworks -F /Library/Frameworks -framework SDL2"
|
||||
// Use this line instead of the previous one if you've got a 'No SDL-framework' error.
|
||||
@@ -41,18 +44,13 @@ konanArtifacts {
|
||||
}
|
||||
|
||||
TetrisLinux {
|
||||
inputFiles project.file('Tetris.kt')
|
||||
useInterop 'sdlLinux'
|
||||
|
||||
linkerOpts '-L/usr/lib/x86_64-linux-gnu -lSDL2'
|
||||
target 'linux'
|
||||
}
|
||||
|
||||
TetrisIphone {
|
||||
|
||||
inputFiles project.file('Tetris.kt')
|
||||
useInterop 'sdlIphone'
|
||||
|
||||
linkerOpts '-framework SDL2 -framework AVFoundation -framework CoreGraphics -framework CoreMotion ' +
|
||||
'-framework Foundation -framework GameController -framework AudioToolbox -framework OpenGLES ' +
|
||||
'-framework QuartzCore -framework UIKit'
|
||||
@@ -61,34 +59,22 @@ konanArtifacts {
|
||||
}
|
||||
|
||||
TetrisRaspberry {
|
||||
inputFiles project.file('Tetris.kt')
|
||||
useInterop 'sdlRaspberry'
|
||||
|
||||
linkerOpts '-lSDL2'
|
||||
target 'raspberrypi'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
build {
|
||||
project.ext {
|
||||
buildTasks = getTaskDependencies().getDependencies().findAll { task -> task.name.startsWith("compileKonan") }
|
||||
outputFiles = buildTasks.collect { task -> "${projectDir.canonicalPath}/${file(task.artifactPath).name}" }
|
||||
}
|
||||
doLast {
|
||||
buildTasks.forEach() { task ->
|
||||
copy {
|
||||
from task.artifactPath
|
||||
into projectDir.canonicalPath
|
||||
from 'src/main/resources'
|
||||
into file(task.artifactPath).parentFile
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clean {
|
||||
doLast {
|
||||
outputFiles.forEach {
|
||||
delete it
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-5
@@ -1,10 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PATH=../../dist/bin:../../bin:$PATH
|
||||
DIR=.
|
||||
DIR=$(cd "$(dirname "${BASH_SOURCE[0]}" )" && pwd )
|
||||
PATH=$DIR/../../dist/bin:$DIR/../../bin:$PATH
|
||||
DEPS=$(dirname `type -p konanc`)/../dependencies
|
||||
|
||||
CFLAGS_macbook="-I $HOME/Library/Frameworks/SDL2.framework/Headers"
|
||||
CFLAGS_macbook=-I$HOME/Library/Frameworks/SDL2.framework/Headers
|
||||
LINKER_ARGS_macbook="-F $HOME/Library/Frameworks -framework SDL2"
|
||||
COMPILER_ARGS_macbook=
|
||||
# Uncomment this if your path to SDL differs from the one above.
|
||||
@@ -42,5 +42,15 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -def $DIR/sdl.def -compilerOpts "$CFLAGS" -target $TARGET -o sdl || exit 1
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/Tetris.kt -library sdl -linkerOpts "$LINKER_ARGS" -o Tetris || exit 1
|
||||
mkdir -p $DIR/build/c_interop/
|
||||
mkdir -p $DIR/build/bin/
|
||||
|
||||
cinterop -def $DIR/src/main/c_interop/sdl.def -compilerOpts "$CFLAGS" -target $TARGET -o $DIR/build/c_interop/sdl.kt.bc || exit 1
|
||||
|
||||
konanc $COMPILER_ARGS -target $TARGET $DIR/src/main/kotlin/Tetris.kt \
|
||||
-library $DIR/build/c_interop/sdl.kt.bc -linkerOpts "$LINKER_ARGS" \
|
||||
-o $DIR/build/bin/Tetris.kexe || exit 1
|
||||
|
||||
cp -R $DIR/src/main/resources/ $DIR/build/bin/
|
||||
|
||||
echo "Artifact path is ./build/bin/Tetris.kexe"
|
||||
|
||||
Executable → Regular
|
Before Width: | Height: | Size: 110 KiB After Width: | Height: | Size: 110 KiB |
Reference in New Issue
Block a user