Interop: do not use hardcoded paths to LLVM

also use the defined LLVM toolchain to build JNI interop stub libs
This commit is contained in:
Svyatoslav Scherbina
2016-09-26 14:02:51 +03:00
parent f9f418c51b
commit 1a83fce002
7 changed files with 30 additions and 16 deletions
@@ -2,13 +2,13 @@ libName = clangbridge
headers = clang-c/Index.h headers = clang-c/Index.h
compiler = cc compiler = clang
compilerOpts = -std=c99 -I/usr/local/Cellar/llvm/3.8.1/include -fPIC compilerOpts = -std=c99 -fPIC
linker = cc linker = clang
linkerOpts = -fPIC \ linkerOpts = -fPIC \
-L/usr/local/Cellar/llvm/3.8.1/lib -lclang -lclang
excludedFunctions = excludedFunctions =
@@ -7,6 +7,8 @@ import java.util.*
import kotlin.system.exitProcess import kotlin.system.exitProcess
fun main(args: Array<String>) { fun main(args: Array<String>) {
val llvmInstallPath = System.getProperty("llvmInstallPath")!!
val ktSrcRoot = args[0] val ktSrcRoot = args[0]
val ktGenRoot = args[1] val ktGenRoot = args[1]
val nativeLibsDir = args[2] val nativeLibsDir = args[2]
@@ -59,7 +61,7 @@ fun main(args: Array<String>) {
val javaHome = System.getProperty("java.home") val javaHome = System.getProperty("java.home")
val compilerArgsForJniIncludes = listOf("", "linux", "darwin").map { "-I$javaHome/../include/$it" }.toTypedArray() val compilerArgsForJniIncludes = listOf("", "linux", "darwin").map { "-I$javaHome/../include/$it" }.toTypedArray()
val compilerCmd = arrayOf(compiler, *compilerOpts.toTypedArray(), val compilerCmd = arrayOf("$llvmInstallPath/bin/$compiler", *compilerOpts.toTypedArray(),
*compilerArgsForJniIncludes, *compilerArgsForJniIncludes,
"-c", outCFile.path, "-o", outOFile.path) "-c", outCFile.path, "-o", outOFile.path)
@@ -78,7 +80,7 @@ fun main(args: Array<String>) {
val outLib = nativeLibsDir + "/" + System.mapLibraryName(libName) val outLib = nativeLibsDir + "/" + System.mapLibraryName(libName)
val linkerCmd = arrayOf(linker, *linkerOpts, outOFile.path, "-shared", "-o", outLib, val linkerCmd = arrayOf("$llvmInstallPath/bin/$linker", *linkerOpts, outOFile.path, "-shared", "-o", outLib,
"-Wl,-flat_namespace,-undefined,dynamic_lookup") "-Wl,-flat_namespace,-undefined,dynamic_lookup")
println(linkerCmd.joinToString(" ")) println(linkerCmd.joinToString(" "))
+6
View File
@@ -22,4 +22,10 @@ dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
} }
genInteropStubs {
// these variables will be passed to native toolchain used by stub generator:
environment 'CPATH' : "$llvmInstallPath/include"
environment 'LIBRARY_PATH' : "$llvmInstallPath/lib"
}
mainClassName = 'MainKt' mainClassName = 'MainKt'
@@ -3,27 +3,27 @@ libName = llvmbridge
headers = llvm-c/Core.h llvm-c/ExecutionEngine.h llvm-c/Target.h llvm-c/Analysis.h llvm-c/BitWriter.h headers = llvm-c/Core.h llvm-c/ExecutionEngine.h llvm-c/Target.h llvm-c/Analysis.h llvm-c/BitWriter.h
compiler = cc compiler = clang
compilerOpts = -std=c99 -I/opt/local/libexec/llvm-3.8/include -fPIC \ compilerOpts = -std=c99 -fPIC \
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers \
-pedantic -Wno-long-long -Wcovered-switch-default -Wdelete-non-virtual-dtor \ -pedantic -Wno-long-long -Wcovered-switch-default -Wdelete-non-virtual-dtor \
-DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
linker = c++ linker = clang++
linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \ linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \
-pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \ -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \
-std=c++11 \ -std=c++11 \
-DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \
-L/opt/local/libexec/llvm-3.8/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names \ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \ -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \
-lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \ -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \
-lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \ -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \
-lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \ -lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \
-lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \ -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \
-L/opt/local/lib -lffi -lffi
excludedFunctions = excludedFunctions =
@@ -29,6 +29,7 @@ class NativeInteropPlugin implements Plugin<Project> {
main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt" main = "org.jetbrains.kotlin.native.interop.gen.jvm.MainKt"
args = [srcDir, generatedSrcDir, nativeLibsDir] args = [srcDir, generatedSrcDir, nativeLibsDir]
systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs") systemProperties "java.library.path" : new File(prj.findProject(":Interop:Indexer").buildDir, "nativelibs")
systemProperties "llvmInstallPath" : prj.llvmInstallPath
environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1" environment "LIBCLANG_DISABLE_CRASH_RECOVERY": "1"
environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib" environment "DYLD_LIBRARY_PATH": "${prj.llvmInstallPath}/lib"
+5
View File
@@ -42,3 +42,8 @@ sourceSets {
main.java.srcDirs += 'src/main/kotlin' main.java.srcDirs += 'src/main/kotlin'
} }
genInteropStubs {
environment 'CPATH' : "$llvmInstallPath/include"
environment 'LIBRARY_PATH' : "$llvmInstallPath/lib"
}
@@ -3,27 +3,27 @@ libName = llvmbridge
headers = llvm-c/Core.h llvm-c/ExecutionEngine.h llvm-c/Target.h llvm-c/Analysis.h llvm-c/BitWriter.h headers = llvm-c/Core.h llvm-c/ExecutionEngine.h llvm-c/Target.h llvm-c/Analysis.h llvm-c/BitWriter.h
compiler = cc compiler = clang
compilerOpts = -std=c99 -I/opt/local/libexec/llvm-3.8/include -fPIC \ compilerOpts = -std=c99 -fPIC \
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers \
-pedantic -Wno-long-long -Wcovered-switch-default -Wdelete-non-virtual-dtor \ -pedantic -Wno-long-long -Wcovered-switch-default -Wdelete-non-virtual-dtor \
-DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
linker = c++ linker = clang++
linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \ linkerOpts = -stdlib=libc++ -fPIC -fvisibility-inlines-hidden \
-Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \ -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers \
-pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \ -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -Wdelete-non-virtual-dtor \
-std=c++11 \ -std=c++11 \
-DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \ -DNDEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS \
-L/opt/local/libexec/llvm-3.8/lib -Wl,-search_paths_first -Wl,-headerpad_max_install_names \ -Wl,-search_paths_first -Wl,-headerpad_max_install_names \
-lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \ -lLLVMX86Disassembler -lLLVMX86AsmParser -lLLVMX86CodeGen -lLLVMSelectionDAG -lLLVMAsmPrinter \
-lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \ -lLLVMX86Desc -lLLVMMCDisassembler -lLLVMX86Info -lLLVMX86AsmPrinter -lLLVMX86Utils -lLLVMInterpreter \
-lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \ -lLLVMCodeGen -lLLVMScalarOpts -lLLVMInstCombine -lLLVMInstrumentation -lLLVMProfileData -lLLVMTransformUtils \
-lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \ -lLLVMBitWriter -lLLVMExecutionEngine -lLLVMTarget -lLLVMAnalysis -lLLVMRuntimeDyld -lLLVMObject -lLLVMMCParser \
-lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \ -lLLVMBitReader -lLLVMMC -lLLVMCore -lLLVMSupport -lcurses -lpthread -lz -lm \
-L/opt/local/lib -lffi -lffi
excludedFunctions = excludedFunctions =