From 94add3cc20a1c1d197f69c67f78bb418860aeab3 Mon Sep 17 00:00:00 2001 From: SvyatoslavScherbina Date: Fri, 2 Jun 2017 13:50:27 +0300 Subject: [PATCH] Add compiler scripts for Windows (#625) --- build.gradle | 3 + cmd/cinterop.bat | 117 ++++++++++++++++++++++++++++++++++++ cmd/konanc.bat | 82 +++++++++++++++++++++++++ cmd/kotlinc-native.bat | 17 ++++++ cmd/kotlinc.bat | 17 ++++++ samples/csvparser/build.bat | 13 ++++ 6 files changed, 249 insertions(+) create mode 100644 cmd/cinterop.bat create mode 100644 cmd/konanc.bat create mode 100644 cmd/kotlinc-native.bat create mode 100644 cmd/kotlinc.bat create mode 100644 samples/csvparser/build.bat diff --git a/build.gradle b/build.gradle index f63860cd45d..6da6627e5f8 100644 --- a/build.gradle +++ b/build.gradle @@ -284,6 +284,9 @@ task distCompiler(type: Copy) { from(file('cmd')) { fileMode(0755) into('bin') + if (!isWindows()) { + exclude('**/*.bat') + } } from(konanPropertiesFile) { into('konan') diff --git a/cmd/cinterop.bat b/cmd/cinterop.bat new file mode 100644 index 00000000000..682c536b1b1 --- /dev/null +++ b/cmd/cinterop.bat @@ -0,0 +1,117 @@ +@echo off +rem based on scalac.bat from the Scala distribution +rem ########################################################################## +rem # Copyright 2002-2011, LAMP/EPFL +rem # Copyright 2011-2017, JetBrains +rem # +rem # This is free software; see the distribution for copying conditions. +rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +rem # PARTICULAR PURPOSE. +rem ########################################################################## + +setlocal enabledelayedexpansion +call :set_home +call :set_path + +if not "%JAVA_HOME%"=="" ( + if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" +) + +if "%_JAVACMD%"=="" set _JAVACMD=java + +set OUTPUT_FILE_NAME=nativelib +set TARGET=host +set JAVA_ARGS= +set INTEROP_ARGS= + +:again +set "ARG=%1" +if not "!ARG!" == "" ( + if "!ARG:~0,2!" == "-D" ( + set "JAVA_ARGS=%JAVA_ARGS% %ARG%" + goto next + ) + if "!ARG:~0,2!" == "-J" ( + set "JAVA_ARGS=%JAVA_ARGS% !ARG:~2!" + goto next + ) + if "!ARG!" == "-o" ( + set "OUTPUT_FILE_NAME=%2" + shift + goto next + ) + if "!ARG!" == "-target" ( + set "TARGET=%2" + shift + goto next + ) + + set "INTEROP_ARGS=%INTEROP_ARGS% %ARG%" + + :next + shift + goto again +) + +set "NATIVE_LIB=%_KONAN_HOME%\konan\nativelib" +set JAVA_OPTS=-ea ^ + "-Djava.library.path=%NATIVE_LIB%" ^ + "-Dkonan.home=%_KONAN_HOME%" ^ + -Dfile.encoding=UTF-8 + +set "STUB_GENERATOR_JAR=%_KONAN_HOME%\konan\lib\StubGenerator.jar" +set "KOTLIN_JAR=%_KONAN_HOME%\konan\lib\kotlin-compiler.jar" +set "INTEROP_INDEXER_JAR=%_KONAN_HOME%\konan\lib\Indexer.jar" +set "INTEROP_RUNTIME_JAR=%_KONAN_HOME%\konan\lib\Runtime.jar" +set "HELPERS_JAR=%_KONAN_HOME%\konan\lib\helpers.jar" +set "INTEROP_CLASSPATH=%STUB_GENERATOR_JAR%;%KOTLIN_JAR%;%INTEROP_INDEXER_JAR%;%INTEROP_RUNTIME_JAR%;%HELPERS_JAR%" +set "INTEROP_TOOL=org.jetbrains.kotlin.native.interop.gen.jvm.MainKt" + +set "FLAVOR_ARG=-flavor native" + +set "GENERATED_DIR=%OUTPUT_FILE_NAME%-build/kotlin" +set "GENERATED_ARG=-generated "%GENERATED_DIR%"" +set "NATIVES_DIR=%OUTPUT_FILE_NAME%-build/natives" +set "NATIVES_ARG=-natives "%NATIVES_DIR%"" +set "CSTUBSNAME=cstubs" +set "CSTUBSNAME_ARG=-cstubsname %CSTUBSNAME%" + +set 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% + +if ERRORLEVEL 1 exit /b %ERRORLEVEL% + +rem Stubs may be rather big, so we may need more heap space. +set XMX_ARG=-J-Xmx3G + +call "%_KONAN_HOME%\bin\konanc.bat" %XMX_ARG% "%GENERATED_DIR%" -produce library ^ + -nativelibrary "%NATIVES_DIR%/%CSTUBSNAME%.bc" ^ + -o "%OUTPUT_FILE_NAME%" -target "%TARGET%" + + +exit /b %ERRORLEVEL% +goto end + +rem ########################################################################## +rem # subroutines + +:set_home + set _BIN_DIR= + for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi + set _KONAN_HOME=%_BIN_DIR%.. +goto :eof + +:set_path + rem libclang.dll is dynamically linked and thus requires correct PATH to be loaded. + rem TODO: remove this hack. + set "PATH=%_KONAN_HOME%\dependencies\msys2-mingw-w64-x86_64-gcc-6.3.0-clang-llvm-3.9.1-windows-x86-64\bin;%PATH%" +goto :eof + +:end +endlocal + diff --git a/cmd/konanc.bat b/cmd/konanc.bat new file mode 100644 index 00000000000..3880190847c --- /dev/null +++ b/cmd/konanc.bat @@ -0,0 +1,82 @@ +@echo off +rem based on scalac.bat from the Scala distribution +rem ########################################################################## +rem # Copyright 2002-2011, LAMP/EPFL +rem # Copyright 2011-2017, JetBrains +rem # +rem # This is free software; see the distribution for copying conditions. +rem # There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A +rem # PARTICULAR PURPOSE. +rem ########################################################################## + +setlocal enabledelayedexpansion +call :set_home + +if "%_KONAN_COMPILER%"=="" set _KONAN_COMPILER=org.jetbrains.kotlin.cli.bc.K2NativeKt + +if not "%JAVA_HOME%"=="" ( + if exist "%JAVA_HOME%\bin\java.exe" set "_JAVACMD=%JAVA_HOME%\bin\java.exe" +) + +if "%_JAVACMD%"=="" set _JAVACMD=java + +set JAVA_ARGS= +set KONAN_ARGS= + +:again +set "ARG=%1" +if not "!ARG!" == "" ( + if "!ARG:~0,2!" == "-D" ( + set "JAVA_ARGS=%JAVA_ARGS% %ARG%" + goto next + ) + if "!ARG:~0,2!" == "-J" ( + set "JAVA_ARGS=%JAVA_ARGS% !ARG:~2!" + goto next + ) + if "!ARG:~0,2!" == "-X" ( + echo "TODO: need to pass arguments to all the tools somehow." + goto next + ) + if "!ARG!" == "--time" ( + set "KONAN_ARGS=%KONAN_ARGS% --time" + set "JAVA_ARGS=%JAVA_ARGS% -agentlib:hprof=cpu=samples -Dkonan.profile=true" + goto next + ) + + set "KONAN_ARGS=%KONAN_ARGS% %ARG%" + + :next + shift + goto again +) + +set "KONAN_JAR=%_KONAN_HOME%\konan\lib\backend.native.jar" +set "KOTLIN_JAR=%_KONAN_HOME%\konan\lib\kotlin-compiler.jar" +set "INTEROP_JAR=%_KONAN_HOME%\konan\lib\Runtime.jar" +set "HELPERS_JAR=%_KONAN_HOME%\konan\lib\helpers.jar" +set "NATIVE_LIB=%_KONAN_HOME%\konan\nativelib" +set "KONAN_CLASSPATH=%KOTLIN_JAR%;%INTEROP_JAR%;%KONAN_JAR%;%HELPERS_JAR%" +set "JAVA_OPTS=-ea -Dfile.encoding=UTF-8" + + + +set "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% + +exit /b %ERRORLEVEL% +goto end + +rem ########################################################################## +rem # subroutines + +:set_home + set _BIN_DIR= + for %%i in (%~sf0) do set _BIN_DIR=%_BIN_DIR%%%~dpsi + set _KONAN_HOME=%_BIN_DIR%.. +goto :eof + +:end +endlocal + diff --git a/cmd/kotlinc-native.bat b/cmd/kotlinc-native.bat new file mode 100644 index 00000000000..70da3b6b49c --- /dev/null +++ b/cmd/kotlinc-native.bat @@ -0,0 +1,17 @@ +@echo off + +rem Copyright 2010-2017 JetBrains s.r.o. +rem +rem Licensed under the Apache License, Version 2.0 (the "License"); +rem you may not use this file except in compliance with the License. +rem You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + +call %~dps0konanc.bat %* diff --git a/cmd/kotlinc.bat b/cmd/kotlinc.bat new file mode 100644 index 00000000000..70da3b6b49c --- /dev/null +++ b/cmd/kotlinc.bat @@ -0,0 +1,17 @@ +@echo off + +rem Copyright 2010-2017 JetBrains s.r.o. +rem +rem Licensed under the Apache License, Version 2.0 (the "License"); +rem you may not use this file except in compliance with the License. +rem You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, software +rem distributed under the License is distributed on an "AS IS" BASIS, +rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +rem See the License for the specific language governing permissions and +rem limitations under the License. + +call %~dps0konanc.bat %* diff --git a/samples/csvparser/build.bat b/samples/csvparser/build.bat new file mode 100644 index 00000000000..f97370e945d --- /dev/null +++ b/samples/csvparser/build.bat @@ -0,0 +1,13 @@ +@echo off + +setlocal + +set DIR=. +set "PATH=..\..\dist\bin;..\..\bin;%PATH%" +if "%TARGET%" == "" set TARGET=mingw + +call cinterop -def "%DIR%\stdio.def" -target "%TARGET%" -o stdio +if ERRORLEVEL 1 exit /b %ERRORLEVEL% + +call konanc -target "%TARGET%" "%DIR%\CsvParser.kt" -library stdio -o CsvParser +exit /b %ERRORLEVEL% \ No newline at end of file