Using a single shell script for both 'cinterop' and 'konanc'.
This commit is contained in:
committed by
alexander-gorshenev
parent
1b56b8912b
commit
fe5945aebe
@@ -249,6 +249,7 @@ task list_dist(dependsOn: "listDist")
|
||||
task distCompiler(type: Copy) {
|
||||
dependsOn ':backend.native:jars'
|
||||
dependsOn ':tools:helpers:jar'
|
||||
dependsOn ':utilities:jar'
|
||||
|
||||
destinationDir file('dist')
|
||||
|
||||
@@ -288,6 +289,9 @@ task distCompiler(type: Copy) {
|
||||
into('konan/nativelib')
|
||||
}
|
||||
|
||||
from(project(':utilities').file('build/libs')) {
|
||||
into('konan/lib')
|
||||
}
|
||||
|
||||
from(file('cmd')) {
|
||||
fileMode(0755)
|
||||
|
||||
Regular → Executable
+5
-87
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2010-2017 JetBrains s.r.o.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,89 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
else
|
||||
JAVACMD=java
|
||||
fi
|
||||
[ -n "$JAVACMD" ] || JAVACMD=java
|
||||
DIR="${BASH_SOURCE[0]%/*}"
|
||||
: ${DIR:="."}
|
||||
|
||||
declare -a java_args
|
||||
declare -a java_opts
|
||||
declare -a interop_args
|
||||
|
||||
OUTPUT_FILE_NAME=nativelib
|
||||
TARGET=host
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-D*)
|
||||
java_args=("${java_args[@]}" "$1")
|
||||
shift
|
||||
;;
|
||||
-J*)
|
||||
java_args=("${java_args[@]}" "${1:2}")
|
||||
shift
|
||||
;;
|
||||
-o)
|
||||
OUTPUT_FILE_NAME="$2"
|
||||
shift 2
|
||||
;;
|
||||
-target)
|
||||
TARGET="$2"
|
||||
shift 2
|
||||
;;
|
||||
*)
|
||||
interop_args=("${interop_args[@]}" "$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
findHome() {
|
||||
local source="${BASH_SOURCE[0]}"
|
||||
while [ -h "$source" ] ; do
|
||||
local linked="$(readlink "$source")"
|
||||
local dir="$(cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd)"
|
||||
source="$dir/$(basename "$linked")"
|
||||
done
|
||||
(cd -P "$(dirname "$source")/.." && pwd)
|
||||
}
|
||||
KONAN_HOME="$(findHome)"
|
||||
|
||||
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
|
||||
java_opts=(-ea \
|
||||
"-Djava.library.path=${NATIVE_LIB}" \
|
||||
"-Dkonan.home=${KONAN_HOME}" \
|
||||
-Dfile.encoding=UTF-8)
|
||||
|
||||
STUB_GENERATOR_JAR="${KONAN_HOME}/konan/lib/StubGenerator.jar"
|
||||
KOTLIN_JAR="${KONAN_HOME}/konan/lib/kotlin-compiler.jar"
|
||||
INTEROP_INDEXER_JAR="${KONAN_HOME}/konan/lib/Indexer.jar"
|
||||
INTEROP_RUNTIME_JAR="${KONAN_HOME}/konan/lib/Runtime.jar"
|
||||
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"
|
||||
|
||||
GENERATED_DIR="$OUTPUT_FILE_NAME-build/kotlin"
|
||||
GENERATED_ARG="-generated $GENERATED_DIR"
|
||||
NATIVES_DIR="$OUTPUT_FILE_NAME-build/natives"
|
||||
NATIVES_ARG="-natives $NATIVES_DIR"
|
||||
CSTUBSNAME=cstubs
|
||||
CSTUBSNAME_ARG="-cstubsname $CSTUBSNAME"
|
||||
|
||||
LIBCLANG_DISABLE_CRASH_RECOVERY=1 \
|
||||
$JAVACMD "${java_opts[@]}" "${java_args[@]}" \
|
||||
-cp "$INTEROP_CLASSPATH" \
|
||||
$INTEROP_TOOL \
|
||||
$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.
|
||||
XMX_ARG=-J-Xmx3G
|
||||
|
||||
"${KONAN_HOME}/bin/konanc" $XMX_ARG "$GENERATED_DIR" -produce library -nativelibrary "$NATIVES_DIR/$CSTUBSNAME.bc" \
|
||||
-o "$OUTPUT_FILE_NAME" -target "$TARGET"
|
||||
"${DIR}"/run_konan cinterop "$@"
|
||||
|
||||
+4
-67
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
|
||||
# Copyright 2010-2017 JetBrains s.r.o.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -14,70 +14,7 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
else
|
||||
JAVACMD=java
|
||||
fi
|
||||
[ -n "$JAVACMD" ] || JAVACMD=java
|
||||
|
||||
declare -a java_args
|
||||
declare -a java_opts
|
||||
declare -a konan_args
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-D*)
|
||||
java_args=("${java_args[@]}" "$1")
|
||||
shift
|
||||
;;
|
||||
-J*)
|
||||
java_args=("${java_args[@]}" "${1:2}")
|
||||
shift
|
||||
;;
|
||||
-X*)
|
||||
echo "TODO: need to pass arguments to all the tools somehow."
|
||||
shift
|
||||
;;
|
||||
--time)
|
||||
konan_args=("${konan_args[@]}" --time)
|
||||
java_args=("${java_args[@]}" -agentlib:hprof=cpu=samples -Dkonan.profile=true)
|
||||
JAVACMD="time $JAVACMD"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
konan_args[${#konan_args[@]}]=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
findHome() {
|
||||
local source="${BASH_SOURCE[0]}"
|
||||
while [ -h "$source" ] ; do
|
||||
local linked="$(readlink "$source")"
|
||||
local dir="$(cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd)"
|
||||
source="$dir/$(basename "$linked")"
|
||||
done
|
||||
(cd -P "$(dirname "$source")/.." && pwd)
|
||||
}
|
||||
|
||||
KONAN_HOME="$(findHome)"
|
||||
|
||||
KONAN_JAR="${KONAN_HOME}/konan/lib/backend.native.jar"
|
||||
KOTLIN_JAR="${KONAN_HOME}/konan/lib/kotlin-compiler.jar"
|
||||
INTEROP_JAR="${KONAN_HOME}/konan/lib/Runtime.jar"
|
||||
HELPERS_JAR="${KONAN_HOME}/konan/lib/helpers.jar"
|
||||
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
|
||||
KONAN_CLASSPATH="$KOTLIN_JAR:$INTEROP_JAR:$KONAN_JAR:$HELPERS_JAR"
|
||||
KONAN_COMPILER=org.jetbrains.kotlin.cli.bc.K2NativeKt
|
||||
java_opts=(-ea -Dfile.encoding=UTF-8)
|
||||
|
||||
#
|
||||
# KONAN BACKEND INVOCATION
|
||||
#
|
||||
|
||||
java_args=("${java_args[@]}" -noverify "-Dkonan.home=${KONAN_HOME}" "-Djava.library.path=${NATIVE_LIB}")
|
||||
|
||||
"$JAVACMD" "${java_opts[@]}" "${java_args[@]}" -cp "$KONAN_CLASSPATH" "$KONAN_COMPILER" "${konan_args[@]}"
|
||||
DIR="${BASH_SOURCE[0]%/*}"
|
||||
: ${DIR:="."}
|
||||
|
||||
"${DIR}"/run_konan konanc "$@"
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@
|
||||
DIR="${BASH_SOURCE[0]%/*}"
|
||||
: ${DIR:="."}
|
||||
|
||||
"${DIR}"/konanc "$@"
|
||||
"${DIR}"/run_konan konanc "$@"
|
||||
|
||||
+1
-1
@@ -17,4 +17,4 @@
|
||||
DIR="${BASH_SOURCE[0]%/*}"
|
||||
: ${DIR:="."}
|
||||
|
||||
"${DIR}"/konanc "$@"
|
||||
"${DIR}"/run_konan konanc "$@"
|
||||
|
||||
Executable
+90
@@ -0,0 +1,90 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Copyright 2010-2017 JetBrains s.r.o.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
TOOL_NAME="$1"
|
||||
shift
|
||||
|
||||
if [ -z "$JAVACMD" -a -n "$JAVA_HOME" -a -x "$JAVA_HOME/bin/java" ]; then
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
else
|
||||
JAVACMD=java
|
||||
fi
|
||||
[ -n "$JAVACMD" ] || JAVACMD=java
|
||||
|
||||
declare -a java_args
|
||||
declare -a java_opts
|
||||
declare -a konan_args
|
||||
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
-D*)
|
||||
java_args=("${java_args[@]}" "$1")
|
||||
shift
|
||||
;;
|
||||
-J*)
|
||||
java_args=("${java_args[@]}" "${1:2}")
|
||||
shift
|
||||
;;
|
||||
-X*)
|
||||
echo "TODO: need to pass arguments to all the tools somehow."
|
||||
shift
|
||||
;;
|
||||
--time)
|
||||
konan_args=("${konan_args[@]}" --time)
|
||||
java_args=("${java_args[@]}" -agentlib:hprof=cpu=samples -Dkonan.profile=true)
|
||||
JAVACMD="time $JAVACMD"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
konan_args[${#konan_args[@]}]=$1
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
findHome() {
|
||||
local source="${BASH_SOURCE[0]}"
|
||||
while [ -h "$source" ] ; do
|
||||
local linked="$(readlink "$source")"
|
||||
local dir="$(cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd)"
|
||||
source="$dir/$(basename "$linked")"
|
||||
done
|
||||
(cd -P "$(dirname "$source")/.." && pwd)
|
||||
}
|
||||
KONAN_HOME="$(findHome)"
|
||||
|
||||
NATIVE_LIB="${KONAN_HOME}/konan/nativelib"
|
||||
|
||||
java_opts=(-ea \
|
||||
-Xmx3G \
|
||||
"-Djava.library.path=${NATIVE_LIB}" \
|
||||
"-Dkonan.home=${KONAN_HOME}" \
|
||||
-Dfile.encoding=UTF-8)
|
||||
|
||||
KONAN_JAR="${KONAN_HOME}/konan/lib/backend.native.jar"
|
||||
KOTLIN_JAR="${KONAN_HOME}/konan/lib/kotlin-compiler.jar"
|
||||
STUB_GENERATOR_JAR="${KONAN_HOME}/konan/lib/StubGenerator.jar"
|
||||
INTEROP_INDEXER_JAR="${KONAN_HOME}/konan/lib/Indexer.jar"
|
||||
INTEROP_JAR="${KONAN_HOME}/konan/lib/Runtime.jar"
|
||||
HELPERS_JAR="${KONAN_HOME}/konan/lib/helpers.jar"
|
||||
UTILITIES_JAR="${KONAN_HOME}/konan/lib/utilities.jar"
|
||||
KONAN_CLASSPATH="$KOTLIN_JAR:$INTEROP_JAR:$STUB_GENERATOR_JAR:$INTEROP_INDEXER_JAR:$KONAN_JAR:$HELPERS_JAR:$UTILITIES_JAR"
|
||||
#KONAN_COMPILER=org.jetbrains.kotlin.cli.bc.K2NativeKt
|
||||
KONAN_COMPILER=org.jetbrains.kotlin.cli.utilities.MainKt
|
||||
|
||||
LIBCLANG_DISABLE_CRASH_RECOVERY=1 \
|
||||
"$JAVACMD" "${java_opts[@]}" "${java_args[@]}" -cp "$KONAN_CLASSPATH" "$KONAN_COMPILER" "$TOOL_NAME" "${konan_args[@]}"
|
||||
|
||||
@@ -25,3 +25,4 @@ include ':common'
|
||||
include ':backend.native:tests'
|
||||
include ':tools:helpers'
|
||||
include ':tools:kotlin-native-gradle-plugin'
|
||||
include ':utilities'
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin'
|
||||
apply plugin: 'application'
|
||||
|
||||
mainClassName = "org.jetbrains.kotlin.cli.utilities.MainKt"
|
||||
|
||||
dependencies {
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||
compile project(':backend.native')
|
||||
compile project(':Interop:StubGenerator')
|
||||
compile project(':klib')
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package org.jetbrains.kotlin.cli.utilities
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.util.File
|
||||
import org.jetbrains.kotlin.cli.bc.main as konancMain
|
||||
import org.jetbrains.kotlin.native.interop.gen.jvm.main as cinteropMain
|
||||
|
||||
fun invokeCinterop(args: Array<String>) {
|
||||
var outputFileName = "nativelib"
|
||||
var target = "host"
|
||||
for (i in args.indices) {
|
||||
if (args[i].startsWith("-o"))
|
||||
outputFileName = args.getOrElse(i+1){outputFileName}
|
||||
if (args[i] == "-target")
|
||||
target = args.getOrElse(i+1){target}
|
||||
}
|
||||
|
||||
val buildDir = File("$outputFileName-build")
|
||||
val generatedDir = File(buildDir, "kotlin")
|
||||
val nativesDir = File(buildDir, "natives")
|
||||
val cstubsName ="cstubs"
|
||||
|
||||
val additionalArgs = listOf<String>(
|
||||
"-generated", generatedDir.path,
|
||||
"-natives", nativesDir.path,
|
||||
"-cstubsname", cstubsName,
|
||||
"-flavor", "native")
|
||||
|
||||
val cinteropArgs = (additionalArgs + args.toList()).toTypedArray()
|
||||
cinteropMain(cinteropArgs)
|
||||
|
||||
val konancArgs = arrayOf(
|
||||
generatedDir.path,
|
||||
"-produce", "library",
|
||||
"-nativelibrary", File(nativesDir, "$cstubsName.bc").path,
|
||||
"-o", outputFileName,
|
||||
"-target", target)
|
||||
konancMain(konancArgs)
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val utilityName = args[0]
|
||||
val utilityArgs = args.drop(1).toTypedArray()
|
||||
when (utilityName) {
|
||||
"konanc" ->
|
||||
konancMain(utilityArgs)
|
||||
"cinterop" ->
|
||||
invokeCinterop(utilityArgs)
|
||||
"klib" ->
|
||||
println("would run: klib $utilityArgs")
|
||||
else ->
|
||||
println("Unexpected utility name")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user