Provide entry point customization (#352)
This commit is contained in:
+9
-1
@@ -1148,7 +1148,7 @@ class StubGenerator(
|
||||
/**
|
||||
* Produces to [out] the contents of C source file to be compiled into JNI lib used for Kotlin bindings impl.
|
||||
*/
|
||||
fun generateCFile(headerFiles: List<String>) {
|
||||
fun generateCFile(headerFiles: List<String>, entryPoint: String?) {
|
||||
out("#include <stdint.h>")
|
||||
if (platform == KotlinPlatform.JVM) {
|
||||
out("#include <jni.h>")
|
||||
@@ -1167,6 +1167,14 @@ class StubGenerator(
|
||||
System.err.println("Warning: cannot generate C JNI function definition ${func.name}")
|
||||
}
|
||||
}
|
||||
|
||||
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("}")
|
||||
}
|
||||
}
|
||||
|
||||
private tailrec fun Type.unwrapTypedefs(): Type = if (this is Typedef) {
|
||||
|
||||
+2
-1
@@ -238,6 +238,7 @@ private fun processLib(konanHome: String,
|
||||
defaultOpts + additionalCompilerOpts
|
||||
val compiler = "clang"
|
||||
val language = Language.C
|
||||
val entryPoint = config.getSpaceSeparated("entryPoint").singleOrNull()
|
||||
val linkerOpts =
|
||||
config.getSpaceSeparated("linkerOpts").toTypedArray() +
|
||||
defaultOpts + additionalLinkerOpts
|
||||
@@ -282,7 +283,7 @@ private fun processLib(konanHome: String,
|
||||
|
||||
outCFile.bufferedWriter().use { out ->
|
||||
gen.withOutput({ out.appendln(it) }) {
|
||||
gen.generateCFile(headerFiles)
|
||||
gen.generateCFile(headerFiles, entryPoint)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ OBJ_GETTER(setupArgs, int argc, char** argv) {
|
||||
}
|
||||
|
||||
//--- main --------------------------------------------------------------------//
|
||||
extern "C" KInt Konan_start(const ObjHeader* );
|
||||
extern "C" KInt Konan_start(const ObjHeader*);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
extern "C" int Konan_main(int argc, char** argv) {
|
||||
RuntimeState* state = InitRuntime();
|
||||
|
||||
if (state == nullptr) {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
extern "C" int Konan_main(int argc, char** argv);
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
return Konan_main(argc, argv);
|
||||
}
|
||||
@@ -4,6 +4,8 @@ DIR=.
|
||||
DIST=../../dist
|
||||
OSX_CFLAGS=-I/Library/Frameworks/SDL2.framework/Headers
|
||||
OSX_LINKER_ARGS="-F /Library/Frameworks -framework SDL2"
|
||||
#OSX_CFLAGS=-I/opt/local/include/SDL2
|
||||
#OSX_LINKER_ARGS="-L/opt/local/lib -lSDL2"
|
||||
LINUX_CFLAGS=-I/usr/include/SDL2
|
||||
LINUX_LINKER_ARGS="-L/usr/lib/x86_64-linux-gnu -lSDL2"
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ headers = SDL.h stdio.h string.h unistd.h stdlib.h time.h
|
||||
excludedFunctions = _IO_flockfile _IO_funlockfile _IO_ftrylockfile \
|
||||
_IO_cleanup_region_start _IO_cleanup_region_end \
|
||||
mkstemp_dprotected_np
|
||||
entryPoint = SDL_main
|
||||
|
||||
compilerOpts.osx = -D_POSIX_SOURCE -mxsave -mavx -mf16c
|
||||
compilerOpts.linux = -D_REENTRANT
|
||||
|
||||
@@ -491,10 +491,6 @@ class Game(width: Int, height: Int, val visualizer: GameFieldVisualizer, val use
|
||||
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
SDL_main(args)
|
||||
}
|
||||
|
||||
fun get_SDL_Error() = SDL_GetError()!!.asCString().toString()
|
||||
|
||||
class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, UserInput {
|
||||
@@ -806,8 +802,7 @@ class SDL_Visualizer(val width: Int, val height: Int): GameFieldVisualizer, User
|
||||
}
|
||||
}
|
||||
|
||||
@ExportForCppRuntime("SDL_main")
|
||||
fun SDL_main(args: Array<String>) {
|
||||
fun main(args: Array<String>) {
|
||||
var startLevel = 0
|
||||
var width = 10
|
||||
var height = 20
|
||||
@@ -828,4 +823,4 @@ fun SDL_main(args: Array<String>) {
|
||||
game.startNewGame(startLevel)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user