All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jtransc.gen.cs.CSharpCompiler.kt Maven / Gradle / Ivy

Go to download

JVM AOT compiler currently generating JavaScript, C++, Haxe, with initial focus on Kotlin and games.

There is a newer version: 0.6.8
Show newest version
package com.jtransc.gen.cs

import com.jtransc.env.OS
import com.jtransc.error.invalidOp
import com.jtransc.sys.Arch
import com.jtransc.vfs.LocalVfs
import java.io.File

object CSharpCompiler {
	val dotNetV4Folder by lazy {
		//println(System.getProperty("os.arch"))

		val folder = when (Arch.CURRENT) {
			Arch.X86 -> System.getenv("SystemRoot") + "\\Microsoft.NET\\Framework"
			Arch.X64 -> System.getenv("SystemRoot") + "\\Microsoft.NET\\Framework64"
			else -> System.getenv("SystemRoot") + "\\Microsoft.NET\\Framework"
		}
		val local = LocalVfs(File(folder))

		val dotnetv4 = local.listdir().filter { it.name.startsWith("v4") }.firstOrNull() ?: invalidOp("JTransc can't find .net framework v4")
		dotnetv4.file
	}

	fun genCommand(programFile: File, debug: Boolean = false, libs: List = listOf()): List {
		if (OS.isWindows) {
			return listOf(Windows.CSC, "/debug:full", "/unsafe+", "/checked-", "/optimize+", "/define:UNSAFE", programFile.absolutePath)
		} else {
			return listOf(Mono.MCS, "-debug", "-unsafe+", "-checked-", "-optimize+", "-define:UNSAFE", programFile.absolutePath)
		}
	}

	object Mono {
		val MCS = "mcs"
	}

	object Windows {
		val CSC = dotNetV4Folder["csc"].realpathOS
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy