Skip to content

Commit

Permalink
Chore/cherry pick from godot 3 version (#457)
Browse files Browse the repository at this point in the history
* Fix typo in your-first-class doc (#378)

* Generate `.gdignore` files for the `build` and the `gradle` directories (#366)

* Add task to generate `.gdignore` files for the `build` and the `gradle` directories

* Improve task setup and add jre folders to ignored folders

* Implement generics check (#375)

This check verifies that the user does not try to register any generic types as these won't compile

* enh: Move jvm types registration code from GDKotlin to TypeManager (#357)

* Export android x86_64 target (#381)

* Export android x86_64 target

* Fix path for debug builds

(cherry picked from commit b57ab94)

# Conflicts:
#	.github/actions/create-android-export-template/action.yaml
#	.github/workflows/check-pr-engine-export-template-debug.yaml
#	.github/workflows/check-pr-engine-export-template-release.yaml
#	.github/workflows/deploy-export-template.yaml

* Improve changelog header to be more explict about which files are for what (#392)

(cherry picked from commit c741582)

* Fix constructor with generic args registration (#396)

* Fix registration of constructors with multiple args

* Add test class

(cherry picked from commit 6384dc4)

* Fix reflection usage in usercode (#452)

* Add `kotlin-reflect` dependency to godot-library

* Temporarily fix scons version

* Add graal reflection configuration file option and update comment on existing option

* Add additional graal options needed for reflection to work and also commit the standard configuration for kotlin-reflection

(cherry picked from commit c273de5)

---------

Co-authored-by: Cristian Heitt <[email protected]>
Co-authored-by: Pierre-Thomas Meisels <[email protected]>
  • Loading branch information
3 people authored Mar 25, 2023
1 parent 8d8970b commit d9484a6
Show file tree
Hide file tree
Showing 38 changed files with 448 additions and 90 deletions.
4 changes: 4 additions & 0 deletions .github/actions/create-android-export-template/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ runs:
uses: actions/download-artifact@v3
with:
name: android-export-${{ inputs.target }}-binary-arm64
- name: Download android ${{ inputs.target }} export x86_64 binary
uses: actions/download-artifact@v3
with:
name: android-export-${{ inputs.target }}-binary-x86_64
- name: Build android ${{ inputs.target }} export template
shell: bash
run: |
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/check-pr-engine-export-template-debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
build-export-debug:
strategy:
matrix:
name: [ Linux, MacOs-x64, MacOs-arm64, Windows, Android-armv7, Android-armv8 ]
name: [ Linux, MacOs-x64, MacOs-arm64, Windows, Android-armv7, Android-armv8, Android-x86_64 ]
include:
# always use the oldest still supported LTS version of github actions. See: https://github.com/utopia-rise/godot-kotlin-jvm/issues/224
- name: Linux
Expand Down Expand Up @@ -47,6 +47,11 @@ jobs:
platform: android
arch: arm64
output_folder: platform/android/java/lib/libs/debug/arm64-v8a/
- name: Android-x86_64
os: ubuntu-latest
platform: android
arch: x86_64
output_folder: platform/android/java/lib/libs/debug/x86_64/
runs-on: ${{ matrix.os }}
steps:
- name: Clone Godot Engine
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build-export-release:
strategy:
matrix:
name: [ Linux, MacOs-x64, MacOs-arm64, Windows, Android-armv7, Android-armv8 ]
name: [ Linux, MacOs-x64, MacOs-arm64, Windows, Android-armv7, Android-armv8, Android-x86_64 ]
include:
# always use the oldest still supported LTS version of github actions. See: https://github.com/utopia-rise/godot-kotlin-jvm/issues/224
- name: Linux
Expand Down Expand Up @@ -46,6 +46,11 @@ jobs:
platform: android
arch: arm64
output_folder: platform/android/java/lib/libs/release/arm64-v8a/
- name: Android-x86_64
os: ubuntu-latest
platform: android
arch: x86_64
output_folder: platform/android/java/lib/libs/release/x86_64/
runs-on: ${{ matrix.os }}
steps:
- name: Clone Godot Engine
Expand Down
26 changes: 23 additions & 3 deletions .github/workflows/deploy-export-template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
deploy-export-template:
strategy:
matrix:
name: [ Linux-release, MacOs-x64-release, MacOs-arm64-release, Windows-release, Android-armv7-release, Android-armv8-release, Linux-debug, MacOs-x64-debug, MacOs-arm64-debug, Windows-debug, Android-armv7-debug, Android-armv8-debug ]
name: [ Linux-release, MacOs-x64-release, MacOs-arm64-release, Windows-release, Android-armv7-release, Android-armv8-release, Android-x86_64-release, Linux-debug, MacOs-x64-debug, MacOs-arm64-debug, Windows-debug, Android-armv7-debug, Android-armv8-debug, Android-x86_64-debug ]
include:
- name: Linux-release
# always use the oldest still supported LTS version of github actions. See: https://github.com/utopia-rise/godot-kotlin-jvm/issues/224
Expand Down Expand Up @@ -60,6 +60,14 @@ jobs:
arch: arm64v8
output_folder: platform/android/java/lib/libs/release/arm64-v8a/
target: template_release
- name: Android-x86_64-release
os: ubuntu-latest
platform: android
binary: android_release.apk
cat_command: cat
arch: x86_64
output_folder: platform/android/java/lib/libs/release/x86_64/
target: template_release
- name: Linux-debug
# always use the oldest still supported LTS version of github actions. See: https://github.com/utopia-rise/godot-kotlin-jvm/issues/224
os: ubuntu-20.04
Expand Down Expand Up @@ -105,6 +113,14 @@ jobs:
arch: arm64v8
output_folder: platform/android/java/lib/libs/debug/arm64-v8a/
target: template_debug
- name: Android-x86_64-debug
os: ubuntu-latest
platform: android
binary: android_debug.apk
cat_command: cat
arch: x86_64
output_folder: platform/android/java/lib/libs/debug/x86_64/
target: release_debug
runs-on: ${{ matrix.os }}
steps:
# has to be the first step as the download url is only valid for 1 minute! See: https://stackoverflow.com/a/65049722
Expand Down Expand Up @@ -154,6 +170,10 @@ jobs:
run: |
sh misc/scripts/install_vulkan_sdk_macos.sh
- name: Fix scons version
run: |
python -m pip install scons==4.4.0
# Upload cache on completion and check it out now
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
Expand Down Expand Up @@ -181,7 +201,7 @@ jobs:
sconsflags: arch=${{ matrix.arch }} -j${{ steps.cpu-cores.outputs.count }}
platform: ${{ matrix.platform }}
target: ${{ matrix.target }}


- name: Build android ${{ matrix.target }} export template binary
if: matrix.platform == 'android'
Expand All @@ -190,7 +210,7 @@ jobs:
sconsflags: android_arch=${{ matrix.arch }} -j${{ steps.cpu-cores.outputs.count }}
platform: ${{ matrix.platform }}
target: ${{ matrix.target }}


- name: Upload android binary
if: matrix.platform == 'android'
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/deploy-godot-editor-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ jobs:
run: |
python -m pip install scons==4.4.0
- name: Fix scons version
run: |
python -m pip install scons==4.4.0
# Upload cache on completion and check it out now
- name: Setup Godot build cache
uses: ./.github/actions/godot-cache
Expand Down
2 changes: 1 addition & 1 deletion docs/src/doc/getting-started/your-first-class.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The [classes](../user-guide/classes.md) section covers in detail what we did her
./gradlew build
```

Once the build completes, you will be able to use your class in Godot. Simply attach the `kt` file containing registered clas to a node like you would do in GDScript. If you rebuild the project while the editor is open, your classes will be reloaded automatically in Godot and you can use them.
Once the build completes, you will be able to use your class in Godot. Simply attach the `kt` file containing registered class to a node like you would do in GDScript. If you rebuild the project while the editor is open, your classes will be reloaded automatically in Godot and you can use them.

![Attach Node Script](../assets/img/attach.png)

Expand Down
12 changes: 11 additions & 1 deletion harness/tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@ godot {

//uncomment to test graal vm native image
// isGraalNativeImageExportEnabled.set(true)
// nativeImageToolPath.set(File("${System.getenv("GRAALVM_HOME")}/bin/native-image"))
// nativeImageToolPath.set(File("${System.getenv("JAVA_HOME")}/bin/native-image"))
// additionalGraalResourceConfigurationFiles.set(
// arrayOf(
// projectDir.resolve("graal").resolve("resource-config.json").absolutePath,
// )
// )
// additionalGraalReflectionConfigurationFiles.set(
// arrayOf(
// projectDir.resolve("graal").resolve("reflect-config.json").absolutePath,
// )
// )
// windowsDeveloperVCVarsPath.set(System.getenv("VC_VARS_PATH"))
}

Expand Down
25 changes: 25 additions & 0 deletions harness/tests/export_presets.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,28 @@ notarization/apple_team_id=""
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false

[preset.3]

name="Linux/X11"
platform="Linux/X11"
runnable=true
custom_features=""
export_filter="all_resources"
include_filter="*.txt, *.cfg"
exclude_filter=""
export_path="./Godot Kotlin Tests.x86_64"
script_export_mode=0
script_encryption_key=""

[preset.3.options]

custom_template/debug="../../../../bin/godot.x11.opt.debug.64"
custom_template/release=""
binary_format/64_bits=true
binary_format/embed_pck=false
texture_format/bptc=false
texture_format/s3tc=true
texture_format/etc=false
texture_format/etc2=false
texture_format/no_bptc_fallbacks=true
22 changes: 22 additions & 0 deletions harness/tests/graal/reflect-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"name": "kotlin.reflect.jvm.internal.ReflectionFactoryImpl",
"allDeclaredConstructors":true
},
{
"name": "kotlin.KotlinVersion",
"allPublicMethods": true,
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allDeclaredConstructors":true
},
{
"name": "kotlin.KotlinVersion[]"
},
{
"name": "kotlin.KotlinVersion$Companion"
},
{
"name": "kotlin.KotlinVersion$Companion[]"
}
]
7 changes: 7 additions & 0 deletions harness/tests/graal/resource-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"resources":[
{"pattern":"META-INF/.*.kotlin_module$"},
{"pattern":"META-INF/services/.*"},
{"pattern":".*.kotlin_builtins"}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package godot.tests.constructor

import godot.Node
import godot.annotation.RegisterClass
import godot.annotation.RegisterConstructor
import godot.core.Dictionary
import godot.core.VariantArray

@RegisterClass
class ConstructorRegistrationTest(): Node() {

@RegisterConstructor
constructor(param1: Dictionary<Any, Any?>, param2: VariantArray<Long>): this()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package godot.tests.reflection

import godot.Node
import godot.annotation.RegisterClass
import godot.annotation.RegisterFunction
import kotlin.reflect.full.hasAnnotation

@RegisterClass
class BaseReflectionTest: Node() {

@RegisterFunction
fun hasRegisterClassAnnotation(): Boolean {
return BaseReflectionTest::class.hasAnnotation<RegisterClass>()
}
}
7 changes: 7 additions & 0 deletions harness/tests/test/unit/test_reflection.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends "res://addons/gut/test.gd"


func test_reflection_working() -> void:
var reflection_test_script = load("res://src/main/kotlin/godot/tests/reflection/BaseReflectionTest.kt").new()
assert_true(reflection_test_script.has_register_class_annotation(), "Should return true without throwing an exception")
reflection_test_script.free()
3 changes: 2 additions & 1 deletion kt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ tasks {
val fromTag = tags.getOrNull(1)
val toTag = tags.getOrNull(0)
val changeLogPrefix = """
The pre built engines are the zip files.
The files prefixed with `godot-kotlin-jvm_editor_` are the editors.
`godot-kotlin-jvm_editor_server_*.zip` is a headless editor which you can use for CI/CD.
The other files are export templates needed for exporting your game. See [exporting](https://godot-kotl.in/en/latest/user-guide/exporting/) documentation on how to use them.
**Changelog:**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ object ConstructorRegistrationGenerator {

if (valueParameter.typeArguments.isNotEmpty()) {
append("<")
valueParameter.typeArguments.forEach { typeArgument ->
append("%T")
templateArgs.add(
ClassName(
typeArgument.fqName.substringBeforeLast("."),
typeArgument.fqName.substringAfterLast(".")
append(
valueParameter.typeArguments.joinToString("") { typeArgument ->
templateArgs.add(
ClassName(
typeArgument.fqName.substringBeforeLast("."),
typeArgument.fqName.substringAfterLast(".")
)
)
)
if (typeArgument.isNullable) {
append("?")
if (typeArgument.isNullable) {
"%T?"
} else {
"%T"
}
}
}
)
append(">")
}

Expand Down
6 changes: 6 additions & 0 deletions kt/godot-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ apiGenerator {
docsDir.set(project.file("$projectDir/../../../../doc/classes"))
}

dependencies {
// added here as a transitive dependency so the user can use reflection
// we need to add it here so reflection is available where the code is loaded (Bootstrap.kt) otherwise it will not work
api(kotlin("reflect"))
}

tasks {
compileKotlin {
dependsOn(generateAPI)
Expand Down
3 changes: 3 additions & 0 deletions kt/plugins/godot-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies {
implementation("gradle.plugin.com.github.johnrengelman:shadow:${DependenciesVersions.shadowJarPluginVersion}")
implementation("com.google.devtools.ksp:com.google.devtools.ksp.gradle.plugin:${DependenciesVersions.kspVersion}")

// used for idea sync gradle task integration (ex. generateGdIgnoreFilesTask)
implementation("org.jetbrains.gradle.plugin.idea-ext:org.jetbrains.gradle.plugin.idea-ext.gradle.plugin:1.1.6")

implementation(project(":godot-build-props"))
implementation("com.utopia-rise:tools-common:$fullGodotKotlinJvmVersion")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,26 @@ open class GodotExtension(objects: ObjectFactory) {
val windowsDeveloperVCVarsPath: Property<String> = objects.property(String::class.java)

/**
* Additional Graal JNI/reflection configurations.
* Additional Graal JNI configurations.
*
* example: arrayOf("my-jni-configuration-file.json", "another-conf.json")
*/
val additionalGraalJniConfigurationFiles: Property<Array<String>> = objects.property(Array<String>::class.java)

/**
* Additional Graal reflection configurations.
*
* example: arrayOf("my-reflection-configuration-file.json", "another-conf.json")
*/
val additionalGraalReflectionConfigurationFiles = objects.property(Array<String>::class.java)

/**
* Additional Graal resource configurations.
*
* example: arrayOf("my-resource-configuration-file.json", "another-conf.json")
*/
val additionalGraalResourceConfigurationFiles = objects.property(Array<String>::class.java)

/**
* enable verbose mode on native image generation.
*
Expand Down Expand Up @@ -176,6 +190,8 @@ open class GodotExtension(objects: ObjectFactory) {
isGraalNativeImageExportEnabled.set(false)
nativeImageToolPath.set(System.getenv("native-image")?.let { File(it) })
additionalGraalJniConfigurationFiles.set(arrayOf())
additionalGraalReflectionConfigurationFiles.set(arrayOf())
additionalGraalResourceConfigurationFiles.set(arrayOf())
isGraalVmNativeImageGenerationVerbose.set(false)
windowsDeveloperVCVarsPath.set("\"%VC_VARS_PATH%\"")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ import com.google.devtools.ksp.gradle.KspGradleSubplugin
import godot.tools.common.constants.FileExtensions
import org.gradle.api.Project
import org.gradle.plugins.ide.idea.IdeaPlugin
import org.jetbrains.gradle.ext.IdeaExtPlugin
import java.io.File

fun Project.configureThirdPartyPlugins() {
//apply needed third party plugins
repositories.google() //add google repository for ksp (kotlin symbol processing
pluginManager.apply(KspGradleSubplugin::class.java)
pluginManager.apply(IdeaPlugin::class.java) //needed so idea can find and index the generated sources from ksp
pluginManager.apply(IdeaExtPlugin::class.java) //needed so idea can find and index the generated sources from ksp
pluginManager.apply(ShadowPlugin::class.java)

addKspGeneratedSourcesToMainSourceSet()
Expand Down
Loading

0 comments on commit d9484a6

Please sign in to comment.