Skip to content

Commit

Permalink
Update generator dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMayes committed Sep 23, 2023
1 parent 88f35df commit 1e13556
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 76 deletions.
4 changes: 4 additions & 0 deletions generator/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[*.{kt,kts}]
ktlint_code_style = ktlint_official
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
32 changes: 19 additions & 13 deletions generator/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
application
kotlin("jvm") version "1.4.10"
id("org.jlleitschuh.gradle.ktlint") version "9.3.0"
kotlin("jvm") version "1.9.10"
id("org.jlleitschuh.gradle.ktlint") version "11.6.0"
}

application {
mainClassName = "com.kylemayes.generator.MainKt"
mainClass.set("com.kylemayes.generator.MainKt")
}

group = "com.kylemayes"
Expand All @@ -19,20 +20,25 @@ repositories {

dependencies {
implementation(kotlin("stdlib"))
implementation("com.github.ajalt.clikt:clikt:3.0.1")
implementation("com.vladsch.flexmark:flexmark-all:0.62.2")
implementation("io.github.microutils:kotlin-logging-jvm:2.0.2")
implementation("org.jetbrains:annotations:20.0.0")
implementation("org.kohsuke:github-api:1.116")
implementation("org.slf4j:slf4j-simple:1.7.29")
testImplementation(platform("org.junit:junit-bom:5.7.0"))
testImplementation("org.junit.jupiter:junit-jupiter")
implementation("com.github.ajalt.clikt:clikt:4.2.0")
implementation("com.vladsch.flexmark:flexmark-all:0.64.8")
implementation("io.github.microutils:kotlin-logging-jvm:3.0.5")
implementation("org.jetbrains:annotations:24.0.1")
implementation("org.kohsuke:github-api:1.316")
implementation("org.slf4j:slf4j-simple:2.0.9")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

java {
sourceCompatibility = JavaVersion.VERSION_13
targetCompatibility = JavaVersion.VERSION_13
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "9"
kotlinOptions.jvmTarget = "13"
}

tasks.test {
tasks.named<Test>("test") {
useJUnitPlatform()
}
Binary file modified generator/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion generator/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 16 additions & 19 deletions generator/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ esac

CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar


# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
Expand Down Expand Up @@ -125,10 +126,11 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`

JAVACMD=`cygpath --unix "$JAVACMD"`

# We build the pattern for arguments to be converted via cygpath
Expand All @@ -154,19 +156,19 @@ if $cygwin ; then
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
i=`expr $i + 1`
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi

Expand All @@ -175,14 +177,9 @@ save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=$(save "$@")
APP_ARGS=`save "$@"`

# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"

# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")"
fi

exec "$JAVACMD" "$@"
25 changes: 7 additions & 18 deletions generator/gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

Expand All @@ -37,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand All @@ -51,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto init
if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
Expand All @@ -61,28 +64,14 @@ echo location of your Java installation.

goto fail

:init
@rem Get command-line arguments, handling Windows variants

if not "%OS%" == "Windows_NT" goto win9xME_args

:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2

:win9xME_args_slurp
if "x%~1" == "x" goto execute

set CMD_LINE_ARGS=%*

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
Expand Down
2 changes: 2 additions & 0 deletions generator/src/main/kotlin/com/kylemayes/generator/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ class Update : CliktCommand(help = "Updates generated Vulkan bindings") {

/** The repository Vulkan files are pulled from. */
private const val repository = "KhronosGroup/Vulkan-Docs"

/** The branch Vulkan files are pulled from. */
private const val branch = "main"

/** The name of the file the current commit hash is stored in. */
private const val file = "Vulkan-Docs"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ $structs
/** Generates a Rust struct for a group of Vulkan commands of the same type. */
private fun Registry.generateCommandStruct(type: CommandType, commands: List<Command>) =
"""
/// Loaded Vulkan ${type.display.toLowerCase()} commands.
/// Loaded Vulkan ${type.display.lowercase()} commands.
#[derive(Copy, Clone)]
pub struct ${type.display}Commands {
${commands.joinToString { "pub ${it.name}: PFN_${it.name.original}" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ private fun Registry.generateExtensionTrait(extension: Extension): String {
val deprecation = generateDeprecation(extension)?.let { "\n$it" } ?: ""

val name = "${extension.name.value.toPascalCase()}Extension"
val type = extension.type!!.capitalize()
val type = extension.type!!.replaceFirstChar { it.uppercase() }

val commands = extension.require.commands.mapNotNull { commands[it] }.sortedBy { it.name }

val implAttributes = listOf(
if (extension.provisional) { "#[cfg(feature = \"provisional\")]" } else { "" },
if (deprecation.isNotEmpty()) { "#[allow(deprecated)]" } else { "" }
if (deprecation.isNotEmpty()) { "#[allow(deprecated)]" } else { "" },
).filter { it.isNotBlank() }.joinToString("\n")

return """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ${generateAliases(handles.keys)}
/** Generates a Rust struct for a Vulkan handle. */
private fun Registry.generateHandle(handle: Handle): String {
val repr = if (handle.dispatchable) { "usize" } else { "u64" }
val type = handle.name.value.toSnakeCase().toUpperCase()
val type = handle.name.value.toSnakeCase().uppercase()
return """
/// <${generateManualUrl(handle)}>
#[repr(transparent)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use super::*;
CommandType.ENTRY,
"EntryV$suffix",
previousSuffix?.let { "EntryV$previousSuffix" },
false
false,
)

versions += generateVersionTrait(
Expand All @@ -43,7 +43,7 @@ use super::*;
CommandType.INSTANCE,
"InstanceV$suffix",
previousSuffix?.let { "InstanceV$previousSuffix" },
true
true,
)

versions += generateVersionTrait(
Expand All @@ -52,7 +52,7 @@ use super::*;
CommandType.DEVICE,
"DeviceV$suffix",
previousSuffix?.let { "DeviceV$previousSuffix" },
true
true,
)

previousSuffix = suffix
Expand All @@ -71,7 +71,7 @@ private fun Registry.generateVersionTrait(
handle: Boolean,
) =
"""
/// Vulkan ${version.number} ${type.display.toLowerCase()} command wrappers.
/// Vulkan ${version.number} ${type.display.lowercase()} command wrappers.
pub trait $name${extends?.let { ": $it" } ?: ""} {
${if (extends == null) { "fn commands(&self) -> &${type.display}Commands;\n" } else { "" }}
${if (handle && extends == null) { "fn handle(&self) -> ${type.display};\n" } else { "" }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ private val INSTANCE = setOf("vkCreateDevice")
enum class CommandType(val display: String) {
/** A command which is loaded from the Vulkan dynamic library. */
STATIC("Static"),

/** A command which is loaded with `vkGetInstanceProcAddr` and a null instance. */
ENTRY("Entry"),

/** A command which is loaded with `vkGetInstanceProcAddr` and a valid instance. */
INSTANCE("Instance"),

/** A command which is loaded with `vkGetDeviceProcAddr` and a valid device. */
DEVICE("Device"),
}
Expand Down Expand Up @@ -48,7 +51,7 @@ private val getExtensionCommandTypes = thunk { ->
extensions.values
.filter { e -> e.type != null }
.flatMap { e -> e.require.commands.map { c -> Pair(e, c) } }
.associate { (e, c) -> c to CommandType.valueOf(e.type!!.toUpperCase()) }
.associate { (e, c) -> c to CommandType.valueOf(e.type!!.uppercase()) }
}

/** Gets the non-`SUCCESS` and non-`INCOMPLETE` success codes for a Vulkan command. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,15 +302,15 @@ unsafe fn ${command.name}$generics(&self, ${params.joinToString()})$outputType {
private fun Registry.generateInputSliceTypeAndCast(pointer: PointerType): Pair<String, String> = when {
structs.containsKey(pointer.pointee.getIdentifier()) -> Pair(
"impl Cast<Target=${pointer.pointee.generate()}>",
".cast()"
".cast()",
)
pointer.pointee.getIdentifier()?.value == "void" -> Pair(
"u8",
"as ${"c_void".generatePtr(pointer.const)}"
"as ${"c_void".generatePtr(pointer.const)}",
)
pointer.pointee is PointerType -> Pair(
"&${pointer.pointee.pointee.generate()}",
".cast()"
".cast()",
)
else -> Pair(pointer.pointee.generate(), "")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ private fun extractRequireValue(e: Element): RequireValue? {
interface Entity {
/** The name of this entity. */
val name: Identifier

/** The Vulkan API this entity is for. */
val api: String?

Expand Down Expand Up @@ -522,8 +523,10 @@ private val primitives = mapOf(
interface Type {
/** Generates the Rust type for this type. */
fun generate(): String

/** Generates the Rust type for this type as it would appear in a command. */
fun generateForCommand(): String = generate()

/** Generates the Rust default expression for this type. */
fun generateDefault(): String
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private fun Registry.getUnsupportedEntities(): Set<Identifier> {
unsupportedEntities.addAll(
extensions.values
.filter { !it.isSupported() || !it.isVulkanApi() }
.flatMap { it.require.commands + it.require.types.map { n -> n.intern() } }
.flatMap { it.require.commands + it.require.types.map { n -> n.intern() } },
)

// Add entities only present in unsupported versions.
Expand All @@ -74,7 +74,7 @@ private fun Registry.getUnsupportedEntities(): Set<Identifier> {
unsupportedEntities.addAll(
nonvulkan
.flatMap { it.require.commands + it.require.types.map { n -> n.intern() } }
.filter { !vulkanEntities.contains(it) }
.filter { !vulkanEntities.contains(it) },
)

return unsupportedEntities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private fun renameCommand(name: String) = name
/** Renames a constant (e.g., `VK_UUID_SIZE` to `UUID_SIZE`). */
private fun renameConstant(name: String) = name
.removePrefix("VK_")
.toUpperCase()
.uppercase()

/** Renames a member or parameter (e.g, `deviceLUIDValid` to `device_luid_valid`). */
private fun renameMemberOrParameter(name: String) = name
Expand All @@ -107,7 +107,7 @@ private fun renameVariantOrBitflag(name: String, parent: String, bitflag: Boolea
var prefix = parent
.substring(0, parent.length - extension.length)
.toSnakeCase()
.toUpperCase()
.uppercase()
if (bitflag) prefix = prefix.replace(Regex("FLAGS(\\d*)"), "$1")
if (!prefix.endsWith('_')) prefix = "${prefix}_"

Expand All @@ -124,7 +124,7 @@ private fun renameVariantOrBitflag(name: String, parent: String, bitflag: Boolea
.replace(Regex("^([0-9])"), "_$1")
// Some value names include lowercase characters that need to be
// capitalized (e.g., `VK_FORMAT_ASTC_4x4_SFLOAT_BLOCK_EXT`).
.toUpperCase()
.uppercase()

// Remove `BIT` component from bitflag name even when followed by extension author.
return if (bitflag) {
Expand Down
Loading

0 comments on commit 1e13556

Please sign in to comment.