No colon cinterop flags (#428)
* Taught cinterop a 'host' target. * Last minute switch from -foo:bar flags to -foo bar flags in cinterop tool.
This commit is contained in:
committed by
Nikolay Igotti
parent
b2a57e7cb3
commit
c9c9aee7bb
+2
-2
@@ -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/cinterop -def:sockets.def -o:sockets.kt.bc
|
||||
../../dist/bin/cinterop -def sockets.def -o sockets.kt.bc
|
||||
|
||||
Compile the echo server:
|
||||
|
||||
@@ -57,7 +57,7 @@ Structurally it's a simple property file, looking like this:
|
||||
Then run `cinterop` tool with something like (note that for host libraries not included
|
||||
in sysroot search paths for headers may be needed):
|
||||
|
||||
cinterop -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.
|
||||
|
||||
+27
-30
@@ -34,7 +34,23 @@ fun main(args: Array<String>) {
|
||||
"os" to (System.getenv("TARGET_OS") ?: detectHost())
|
||||
)
|
||||
|
||||
processLib(konanHome, substitutions, args.asList())
|
||||
processLib(konanHome, substitutions, parseArgs(args))
|
||||
}
|
||||
|
||||
private fun parseArgs(args: Array<String>): Map<String, List<String>> {
|
||||
val commandLine = mutableMapOf<String, MutableList<String>>()
|
||||
for(index in 0..args.size-1 step 2) {
|
||||
val key = args[index]
|
||||
if (key[0] != '-') {
|
||||
throw IllegalArgumentException("Expected a flag with initial dash: $key")
|
||||
}
|
||||
if (index+1 == args.size) {
|
||||
throw IllegalArgumentException("Expected an value after $key")
|
||||
}
|
||||
val value = args[index+1]
|
||||
commandLine[key] ?. add(value) ?: commandLine.put(key, mutableListOf(value))
|
||||
}
|
||||
return commandLine
|
||||
}
|
||||
|
||||
private fun detectHost(): String {
|
||||
@@ -53,6 +69,7 @@ private fun detectHost(): String {
|
||||
private fun defaultTarget() = detectHost()
|
||||
|
||||
private val knownTargets = mapOf(
|
||||
"host" to defaultTarget(),
|
||||
"linux" to "linux",
|
||||
"macbook" to "osx",
|
||||
"iphone" to "osx-ios",
|
||||
@@ -83,24 +100,6 @@ private fun substitute(properties: Properties, substitutions: Map<String, String
|
||||
}
|
||||
}
|
||||
|
||||
private fun getArgPrefix(arg: String): String {
|
||||
val index = arg.indexOf(':')
|
||||
if (index == -1) {
|
||||
return ""
|
||||
} else {
|
||||
return arg.substring(0, index)
|
||||
}
|
||||
}
|
||||
|
||||
private fun dropPrefix(arg: String): String {
|
||||
val index = arg.indexOf(':')
|
||||
if (index == -1) {
|
||||
return ""
|
||||
} else {
|
||||
return arg.substring(index + 1)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ProcessBuilder.runExpectingSuccess() {
|
||||
val res = this.start().waitFor()
|
||||
if (res != 0) {
|
||||
@@ -257,23 +256,21 @@ private fun loadProperties(file: File?, substitutions: Map<String, String>): Pro
|
||||
|
||||
private fun usage() {
|
||||
println("""
|
||||
Run interop tool with -def:<def_file_for_lib>.def
|
||||
Run interop tool with -def <def_file_for_lib>.def
|
||||
Following flags are supported:
|
||||
-def:<file>.def specifies library definition file
|
||||
-copt:<c compiler flags> specifies flags passed to clang
|
||||
-lopt:<linker flags> specifies flags passed to linker
|
||||
-verbose increases verbosity
|
||||
-shims adds generation of shims tracing native library calls
|
||||
-pkg:<fully qualified package name>
|
||||
-h:<file>.h header files to parse
|
||||
-def <file>.def specifies library definition file
|
||||
-copt <c compiler flags> specifies flags passed to clang
|
||||
-lopt <linker flags> specifies flags passed to linker
|
||||
-verbose <boolean> increases verbosity
|
||||
-shims <boolean> adds generation of shims tracing native library calls
|
||||
-pkg <fully qualified package name> place the resulting definitions into the package
|
||||
-h <file>.h header files to parse
|
||||
""")
|
||||
}
|
||||
|
||||
private fun processLib(konanHome: String,
|
||||
substitutions: Map<String, String>,
|
||||
commandArgs: List<String>) {
|
||||
|
||||
val args = commandArgs.groupBy ({ getArgPrefix(it) }, { dropPrefix(it) }) // TODO
|
||||
args: Map<String, List<String>>) {
|
||||
|
||||
val userDir = System.getProperty("user.dir")
|
||||
val ktGenRoot = args["-generated"]?.single() ?: userDir
|
||||
|
||||
@@ -39,6 +39,6 @@ For some tests, use:
|
||||
To generate interoperability stubs create library definition file
|
||||
(take a look on `samples/tetris/tetris.sdl`) and run `cinterop` tool like this:
|
||||
|
||||
cinterop -def:lib.def
|
||||
cinterop -def lib.def
|
||||
|
||||
See provided samples and `INTEROP.md` for more details.
|
||||
See provided samples and `INTEROP.md` for more details.
|
||||
|
||||
@@ -206,42 +206,42 @@ class NamedNativeInteropConfig implements Named {
|
||||
|
||||
linkerOpts += linkFiles.files
|
||||
|
||||
args "-properties:" + project.findProject(":backend.native").file("konan.properties")
|
||||
args "-generated:" + generatedSrcDir
|
||||
args "-natives:" + nativeLibsDir
|
||||
args "-flavor:" + this.flavor
|
||||
args '-properties', project.findProject(":backend.native").file("konan.properties")
|
||||
args '-generated', generatedSrcDir
|
||||
args '-natives', nativeLibsDir
|
||||
args '-flavor', this.flavor
|
||||
// Uncomment to debug.
|
||||
// args "-verbose:true"
|
||||
// args '-verbose', 'true'
|
||||
|
||||
if (defFile != null) {
|
||||
args "-def:" + project.file(defFile)
|
||||
args '-def', project.file(defFile)
|
||||
}
|
||||
|
||||
if (pkg != null) {
|
||||
args "-pkg:" + pkg
|
||||
args '-pkg', pkg
|
||||
}
|
||||
|
||||
if (linker != null) {
|
||||
args "-linker:" + linker
|
||||
args '-linker', linker
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
args "-target:" + target
|
||||
args '-target', target
|
||||
}
|
||||
|
||||
// TODO: the interop plugin should probably be reworked to execute clang from build scripts directly
|
||||
environment['PATH'] = project.files(project.clangPath).asPath +
|
||||
File.pathSeparator + environment['PATH']
|
||||
|
||||
args compilerOpts.collect { "-copt:$it" }
|
||||
args linkerOpts.collect { "-lopt:$it" }
|
||||
args compilerOpts.collectMany { ['-copt', it] }
|
||||
args linkerOpts.collectMany { ['-lopt', it] }
|
||||
|
||||
headers.each {
|
||||
args "-h:$it"
|
||||
args '-h', it
|
||||
}
|
||||
|
||||
if (project.hasProperty("shims")) {
|
||||
args "-shims:$project.ext.shims"
|
||||
if (project.hasProperty('shims')) {
|
||||
args '-shims', project.ext.shims
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
-12
@@ -37,13 +37,13 @@ while [ $# -gt 0 ]; do
|
||||
java_args=("${java_args[@]}" "${1:2}")
|
||||
shift
|
||||
;;
|
||||
-o:*)
|
||||
OUTPUT_FILE_NAME="${1:3}"
|
||||
shift
|
||||
-o)
|
||||
OUTPUT_FILE_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
-target:*)
|
||||
TARGET="${1:8}"
|
||||
shift
|
||||
-target)
|
||||
TARGET="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
interop_args=("${interop_args[@]}" "$1")
|
||||
@@ -76,22 +76,22 @@ HELPERS_JAR="${KONAN_HOME}/konan/lib/helpers.jar"
|
||||
INTEROP_CLASSPATH="$STUB_GENERATOR_JAR:$KOTLIN_JAR:$INTEROP_INDEXER_JAR:$INTEROP_RUNTIME_JAR:$HELPERS_JAR"
|
||||
INTEROP_TOOL=org.jetbrains.kotlin.native.interop.gen.jvm.MainKt
|
||||
|
||||
FLAVOR_ARG=-flavor:native
|
||||
FLAVOR_ARG="-flavor native"
|
||||
|
||||
GENERATED_DIR="$OUTPUT_FILE_NAME-build/kotlin"
|
||||
GENERATED_ARG="-generated:$GENERATED_DIR"
|
||||
GENERATED_ARG="-generated $GENERATED_DIR"
|
||||
NATIVES_DIR="$OUTPUT_FILE_NAME-build/natives"
|
||||
NATIVES_ARG="-natives:$NATIVES_DIR"
|
||||
NATIVES_ARG="-natives $NATIVES_DIR"
|
||||
CSTUBSNAME=cstubs
|
||||
CSTUBSNAME_ARG="-cstubsname:$CSTUBSNAME"
|
||||
CSTUBSNAME_ARG="-cstubsname $CSTUBSNAME"
|
||||
|
||||
LIBCLANG_DISABLE_CRASH_RECOVERY=1 \
|
||||
LD_LIBRARY_PATH=${NATIVE_LIB} \
|
||||
$JAVACMD $JAVA_OPTS ${java_args[@]} \
|
||||
-cp $INTEROP_CLASSPATH \
|
||||
$INTEROP_TOOL \
|
||||
"$GENERATED_ARG" "$NATIVES_ARG" "$CSTUBSNAME_ARG" \
|
||||
$FLAVOR_ARG -target:$TARGET "${interop_args[@]}" \
|
||||
$GENERATED_ARG $NATIVES_ARG $CSTUBSNAME_ARG \
|
||||
$FLAVOR_ARG -target $TARGET "${interop_args[@]}" \
|
||||
|| exit 1
|
||||
|
||||
# Stubs may be rather big, so we may need more heap space.
|
||||
|
||||
@@ -18,5 +18,5 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -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
|
||||
|
||||
@@ -23,5 +23,5 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -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
|
||||
|
||||
@@ -23,5 +23,5 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -copt:"$CFLAGS" -copt:-I. -def:$DIR/libcurl.def -target:$TARGET -o:libcurl.bc || 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
|
||||
|
||||
@@ -21,5 +21,5 @@ 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.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
|
||||
|
||||
@@ -18,5 +18,5 @@ 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.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
|
||||
|
||||
@@ -39,6 +39,6 @@ LINKER_ARGS=${!var}
|
||||
var=COMPILER_ARGS_${TARGET}
|
||||
COMPILER_ARGS=${!var} # add -opt for an optimized build.
|
||||
|
||||
cinterop -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
|
||||
|
||||
Reference in New Issue
Block a user