Fix names, samples (#426)

This commit is contained in:
Nikolay Igotti
2017-03-30 19:41:15 +03:00
committed by GitHub
parent d34e5205ae
commit a368818863
13 changed files with 52 additions and 49 deletions
+10 -13
View File
@@ -1,17 +1,17 @@
# Kotlin N interoperability #
# _Kotlin/Native_ interoperability #
## Introduction ##
_Kotlin N_ follows general tradition of Kotlin to provide excellent
_Kotlin/Native_ follows general tradition of Kotlin to provide excellent
existing platform software interoperability. In case of native platform
most important interoperability target is a C library. Thus _Kotlin N_
comes with an `interop` tool, which could be used to quickly generate
most important interoperability target is a C library. Thus _Kotlin/Native_
comes with an `cinterop` tool, which could be used to quickly generate
everything needed to interact with an external library.
Following workflow is expected when interacting with the native library.
* create `.def` file describing what to include into bindings
* use `interop` tool to produce Kotlin bindings
* run _Kotlin N_ compiler on an application to produce the final executable
* use `cinterop` tool to produce Kotlin bindings
* run _Kotlin/Native_ compiler on an application to produce the final executable
Interoperability tool analyses C headers and produces "natural" mapping of
types, function and constants into the Kotlin world. Generated stubs can be
@@ -24,7 +24,7 @@ Build the dependencies and the compiler (see `README.md`).
Prepare stubs for the system sockets library:
cd samples/socket
../../dist/bin/interop -def:sockets.def -o:sockets.kt.bc
../../dist/bin/cinterop -def:sockets.def -o:sockets.kt.bc
Compile the echo server:
@@ -45,9 +45,6 @@ Test the server by conecting to it, for example with telnet:
Write something to console and watch server echoing it back.
~~Quit telnet by pressing ctrl+] ctrl+D~~
## Creating bindings for a new library ##
To create bindings for a new library, start by creating `.def` file.
@@ -57,14 +54,14 @@ Structurally it's a simple property file, looking like this:
header = zlib.h
compilerOpts = -std=c99
Then run interop tool with something like (note that for host libraries not included
Then run `cinterop` tool with something like (note that for host libraries not included
in sysroot search paths for headers may be needed):
interop -def:zlib.def -copt:-I/opt/local/include -o:zlib.kt.bc
cinterop -def:zlib.def -copt:-I/opt/local/include -o:zlib.kt.bc
This command will produce `zlib.kt.bc` compiled library and
`zlib.kt.bc-build/kotlin` directory containing Kotlin source code for the library.
``
If behavior for certain platform shall be modified, one may use format like
`compilerOpts.osx` or `compilerOpts.linux` to provide platform-specific values
to options.
@@ -1352,8 +1352,9 @@ class StubGenerator(
if (entryPoint != null) {
out("extern int Konan_main(int argc, char** argv);")
out("")
out("int $entryPoint(int argc, char** argv) {")
out(" return Konan_main(argc, argv);")
out("__attribute__((__used__))")
out("int $entryPoint(int argc, char** argv) {")
out(" return Konan_main(argc, argv);")
out("}")
}
}
+6 -7
View File
@@ -1,10 +1,9 @@
# Kotlin N #
# Kotlin/Native #
Kotlin Native backend, codenamed _Kotlin N_, is a LLVM backend for the Kotlin
compiler, runtime implementation and native code generation facility
using LLVM toolchain.
_Kotlin/Native_ is a LLVM backend for the Kotlin compiler, runtime
implementation and native code generation facility using LLVM toolchain.
_Kotlin N_ is primarily designed to allow compilation for platforms where
_Kotlin/Native_ is primarily designed to allow compilation for platforms where
virtual machines are not desirable or possible (such as iOS, embedded targets),
or where developer is willing to produce reasonably-sized self-contained program
without need to ship an additional execution runtime.
@@ -38,8 +37,8 @@ For some tests, use:
./gradlew backend.native:tests:run
To generate interoperability stubs create library definition file
(take a look on `samples/tetris/tetris.sdl`) and run `interop` tool like this:
(take a look on `samples/tetris/tetris.sdl`) and run `cinterop` tool like this:
interop -def:lib.def
cinterop -def:lib.def
See provided samples and `INTEROP.md` for more details.
+13 -11
View File
@@ -2,23 +2,23 @@
## Introduction ##
Kotlin Native backend, codenamed _Kotlin N_, is a LLVM backend for the Kotlin
compiler. It consists of a native code generation facility using the LLVM toolchain
_Kotlin/Native_, is a LLVM backend for the Kotlin compiler.
It consists of a native code generation facility using the LLVM toolchain
and a native runtime implementation.
_Kotlin N_ is primarily designed to allow compilation for platforms where
_Kotlin/Native_ is primarily designed to allow compilation for platforms where
virtual machines are not desirable or possible (such as iOS, embedded targets),
or where the developer needs to produce a reasonably-sized self-contained program
that doesn't require an additional execution runtime.
## Supported platforms ##
_Kotlin N_ compiler produces mostly portable (modulo pointer size and target
_Kotlin/Native_ compiler produces mostly portable (modulo pointer size and target
triplet) LLVM bitcode, and as such can easily support any platform, as long as there's a LLVM
codegenerator for the platform.
However, as actual producing of the native code requires a platform linker and some
basic runtime shipped with the translator, we only support a subset of all possible
target platforms. Currently _Kotlin N_ is being shipped and tested with support for
target platforms. Currently _Kotlin/Native_ is being shipped and tested with support for
the following platforms:
* Mac OS X 10.10 and later (x86-64)
@@ -32,20 +32,22 @@ the following platforms:
## Compatibility and features ##
To run _Kotlin/Native_ JDK8 or later for the host platform has to be installed.
The language and library version supported by this EAP release mostly match Kotlin 1.1.
However, there are certain limitations, see section [Known Limitations](#limitations).
Currently _Kotlin N_ uses reference counting based memory management scheme with cycles
Currently _Kotlin/Native_ uses reference counting based memory management scheme with cycles
garbage collection algorithm. Multiple threads could be used, but no objects shared
between threads are allowed.
_Kotlin N_ provides efficient interoperability with libraries written in C, and supports
_Kotlin/Native_ provides efficient interoperability with libraries written in C, and supports
automatic generation of Kotlin bindings from a C header file.
See samples coming with the distribution.
## Getting Started ##
Download Kotlin N distribution and unpack it. You can run command line compiler with
Download _Kotlin/Native_ distribution and unpack it. You can run command line compiler with
bin/kotlinc <some_file>.kt <dir_with_kt_files> -o <executable>.kexe
@@ -61,12 +63,12 @@ For documentation on C interoperability stubs see INTEROP.md.
*** DO NOT USE THIS PREVIEW RELEASE FOR ANY PERFORMANCE ANALYSIS ***
This is purely a technology preview of Kotlin N technology, and is not yet tuned
This is purely a technology preview of _Kotlin/Native_ technology, and is not yet tuned
for benchmarking and competitive analysis of any kind.
### Standard Library ###
The standard library in Kotlin N is known to be incomplete and doesn't include
The standard library in _Kotlin/Native_ is known to be incomplete and doesn't include
certain methods available in standard library of Kotlin.
### Coroutines ###
@@ -81,5 +83,5 @@ Notice that property delegation (including lazy properties) *does* work.
### Microsoft Windows support ###
Due to significant difference in exception handling model on MS Windows and
other LLVM targets, current _Kotlin N_ may not produce executables working on
other LLVM targets, current _Kotlin/Native_ may not produce executables working on
MS Windows. This situation could be improved in upcoming releases.
+7 -3
View File
@@ -25,6 +25,7 @@ declare -a java_args
declare -a interop_args
OUTPUT_FILE_NAME=nativelib.kt.bc
TARGET=host
while [ $# -gt 0 ]; do
case "$1" in
@@ -40,6 +41,10 @@ while [ $# -gt 0 ]; do
OUTPUT_FILE_NAME="${1:3}"
shift
;;
-target:*)
TARGET="${1:8}"
shift
;;
*)
interop_args=("${interop_args[@]}" "$1")
shift
@@ -47,7 +52,6 @@ while [ $# -gt 0 ]; do
esac
done
findHome() {
local source="${BASH_SOURCE[0]}"
while [ -h "$source" ] ; do
@@ -87,11 +91,11 @@ $JAVACMD $JAVA_OPTS ${java_args[@]} \
-cp $INTEROP_CLASSPATH \
$INTEROP_TOOL \
"$GENERATED_ARG" "$NATIVES_ARG" "$CSTUBSNAME_ARG" \
$FLAVOR_ARG "${interop_args[@]}" \
$FLAVOR_ARG -target:$TARGET "${interop_args[@]}" \
|| exit 1
# Stubs may be rather big, so we may need more heap space.
XMX_ARG=-J-Xmx3G
$KONAN_HOME/bin/konanc $XMX_ARG "$GENERATED_DIR" -nolink -nativelibrary "$NATIVES_DIR/$CSTUBSNAME.bc" \
-o "$OUTPUT_FILE_NAME"
-o "$OUTPUT_FILE_NAME" -target "$TARGET"
+1 -1
View File
@@ -18,5 +18,5 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -def:$DIR/stdio.def -copt:"$CFLAGS" -target:$TARGET -o:stdio.kt.bc || exit 1
cinterop -def:$DIR/stdio.def -copt:"$CFLAGS" -target:$TARGET -o:stdio.kt.bc || exit 1
konanc $COMPILER_ARGS -target $TARGET $DIR/CsvParser.kt -library stdio.kt.bc -o CsvParser.kexe || exit 1
+1 -1
View File
@@ -23,5 +23,5 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -copt:$CFLAGS -def:$DIR/libgit2.def -target:$TARGET -o:libgit2.kt.bc || exit 1
cinterop -copt:$CFLAGS -def:$DIR/libgit2.def -target:$TARGET -o:libgit2.kt.bc || exit 1
konanc -target $TARGET src -library libgit2.kt.bc -linkerArgs "$LINKER_ARGS" -o GitChurn.kexe || exit 1
+1 -1
View File
@@ -5,6 +5,6 @@ To build use `./build.sh` script without arguments (or specify `TARGET` variable
To run use
./Curl.kexe https://jetbrains.com
./Curl.kexe https://www.jetbrains.com
It will perform HTTP get and print out the data obtained.
+2 -2
View File
@@ -23,5 +23,5 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -copt:"$CFLAGS" -copt:-I. -def:$DIR/libcurl.def -target:$TARGET || exit 1
konanc -target $TARGET src libcurl -nativelibrary libcurlstubs.bc -linkerArgs "$LINKER_ARGS" -o Curl.kexe || exit 1
cinterop -copt:"$CFLAGS" -copt:-I. -def:$DIR/libcurl.def -target:$TARGET -o:libcurl.bc || exit 1
konanc -target $TARGET src -library libcurl.bc -linkerArgs "$LINKER_ARGS" -o Curl.kexe || exit 1
+1 -1
View File
@@ -21,5 +21,5 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -def:$DIR/opengl.def -target:$TARGET -o:opengl.kt.bc || exit 1
cinterop -def:$DIR/opengl.def -target:$TARGET -o:opengl.kt.bc || exit 1
konanc -target $TARGET $DIR/OpenGlTeapot.kt -library opengl.kt.bc -linkerArgs "$LINKER_ARGS" -o OpenGlTeapot.kexe || exit 1
+1 -1
View File
@@ -18,5 +18,5 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -def:$DIR/sockets.def -copt:"$CFLAGS" -target:$TARGET -o:sockets.kt.bc || exit 1
cinterop -def:$DIR/sockets.def -copt:"$CFLAGS" -target:$TARGET -o:sockets.kt.bc || exit 1
konanc $COMPILER_ARGS -target $TARGET $DIR/EchoServer.kt -library sockets.kt.bc -o EchoServer.kexe || exit 1
+1 -1
View File
@@ -927,7 +927,7 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
SDL_SCANCODE_LEFT -> commands.add(UserCommand.LEFT)
SDL_SCANCODE_RIGHT -> commands.add(UserCommand.RIGHT)
SDL_SCANCODE_DOWN -> commands.add(UserCommand.DOWN)
SDL_SCANCODE_Z -> commands.add(UserCommand.ROTATE)
SDL_SCANCODE_Z, SDL_SCANCODE_SPACE -> commands.add(UserCommand.ROTATE)
SDL_SCANCODE_UP -> commands.add(UserCommand.DROP)
SDL_SCANCODE_ESCAPE -> commands.add(UserCommand.EXIT)
}
+5 -5
View File
@@ -4,11 +4,11 @@ PATH=../../dist/bin:../../bin:$PATH
DIR=.
DEPS=$(dirname `type -p konanc`)/../dependencies
CFLAGS_macbook=-I/Library/Frameworks/SDL2.framework/Headers
LINKER_ARGS_macbook="-F /Library/Frameworks -framework SDL2"
CFLAGS_macbook=-I$HOME/Library/Frameworks/SDL2.framework/Headers
LINKER_ARGS_macbook="-F $HOME/Library/Frameworks -framework SDL2"
COMPILER_ARGS_macbook=
CFLAGS_macbook=-I/opt/local/include/SDL2
LINKER_ARGS_macbook="-L/opt/local/lib -lSDL2"
#CFLAGS_macbook=-I/opt/local/include/SDL2
#LINKER_ARGS_macbook="-L/opt/local/lib -lSDL2"
CFLAGS_linux=-I/usr/include/SDL2
LINKER_ARGS_linux="-L/usr/lib/x86_64-linux-gnu -lSDL2"
@@ -39,6 +39,6 @@ LINKER_ARGS=${!var}
var=COMPILER_ARGS_${TARGET}
COMPILER_ARGS=${!var} # add -opt for an optimized build.
interop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET -o:sdl.kt.bc || exit 1
cinterop -def:$DIR/sdl.def -copt:"$CFLAGS" -target:$TARGET -o:sdl.kt.bc || exit 1
konanc $COMPILER_ARGS -target $TARGET $DIR/Tetris.kt -library sdl.kt.bc -linkerArgs "$LINKER_ARGS" -o Tetris.kexe || exit 1
#strip Tetris.kexe