<commit_before>import com.github.vlsi.gradle.properties.dsl.stringProperty

plugins {
    java
    id("dev.nokee.jni-library")
    id("dev.nokee.objective-cpp-language")
    `uber-jni-jar`
    `use-prebuilt-binaries`
    `apple-m1-toolchain`
}

repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/weisj/JavaNativeFoundation")
        credentials {
            username = project.stringProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
            password = project.stringProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
        }
    }
}

val jnfConfig: Configuration by configurations.creating {
    attributes {
        attribute(Attribute.of("dev.nokee.architecture", String::class.java), "arm64")
    }
}

dependencies {
    jnfConfig("com.github.weisj:java-native-foundation:1.0.0")
}

val nativeResourcePath = "com/github/weisj/darklaf/platform/${project.name}"

tasks.jar {
    jnfConfig.asFileTree.forEach {
        from(zipTree(it)) {
            into("$nativeResourcePath/JavaNativeFoundation.framework")
            include("Versions/A/JavaNativeFoundation*")
            exclude("**/*.tbd")
        }
    }
}

library {
    dependencies {
        jvmImplementation(projects.darklafTheme)
        jvmImplementation(projects.darklafNativeUtils)
        jvmImplementation(projects.darklafUtils)
        jvmImplementation(projects.darklafPlatformBase)
        jvmImplementation(projects.darklafPropertyLoader)
        // nativeLibImplementation(libs.macos.appKit)
        // nativeLibImplementation(libs.macos.cocoa)
        nativeLibImplementation(libs.macos.javaNativeFoundation)
    }

    targetMachines.addAll(machines.macOS.x86_64, machines.macOS.architecture("arm64"))
    variants.configureEach {
        resourcePath.set("$nativeResourcePath/${targetMachine.variantName}")
        sharedLibrary {
            val isArm = targetMachine.architectureString == "arm64"
            val minOs = if (isArm) "11" else "10.10"
            compileTasks.configureEach {
                compilerArgs.addAll("-mmacosx-version-min=$minOs")
                // Build type not modeled yet, assuming release
                optimizedBinary()
            }
            linkTask.configure {
                linkerArgs.addAll(
                    "-lobjc", "-mmacosx-version-min=$minOs",
                    "-framework", "AppKit",
                    "-framework", "Cocoa",
                    // The custom JNF framework specified @rpath for searching. As we aren't actually linking
                    // with the dynamic library of the framework we specifically have to add the system framework
                    // search paths accordingly.
                    // -- Search paths for x86-64 based macs --
                    "-rpath", "/System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks",
                    "-rpath", "/System/Library/Frameworks",
                    // -- Search path for arm based macs. We load our drop in replacement --
                    "-rpath", "@loader_path"
                )
            }
        }
    }
}<commit_msg>Build: Also search the executable path (the jdk) for the JNF framework<commit_after>import com.github.vlsi.gradle.properties.dsl.stringProperty

plugins {
    java
    id("dev.nokee.jni-library")
    id("dev.nokee.objective-cpp-language")
    `uber-jni-jar`
    `use-prebuilt-binaries`
    `apple-m1-toolchain`
}

repositories {
    maven {
        name = "GitHubPackages"
        url = uri("https://maven.pkg.github.com/weisj/JavaNativeFoundation")
        credentials {
            username = project.stringProperty("gpr.user") ?: System.getenv("GITHUB_ACTOR")
            password = project.stringProperty("gpr.key") ?: System.getenv("GITHUB_TOKEN")
        }
    }
}

val jnfConfig: Configuration by configurations.creating {
    attributes {
        attribute(Attribute.of("dev.nokee.architecture", String::class.java), "arm64")
    }
}

dependencies {
    jnfConfig("com.github.weisj:java-native-foundation:1.0.0")
}

val nativeResourcePath = "com/github/weisj/darklaf/platform/${project.name}"

tasks.jar {
    jnfConfig.asFileTree.forEach {
        from(zipTree(it)) {
            into("$nativeResourcePath/JavaNativeFoundation.framework")
            include("Versions/A/JavaNativeFoundation*")
            exclude("**/*.tbd")
        }
    }
}

library {
    dependencies {
        jvmImplementation(projects.darklafTheme)
        jvmImplementation(projects.darklafNativeUtils)
        jvmImplementation(projects.darklafUtils)
        jvmImplementation(projects.darklafPlatformBase)
        jvmImplementation(projects.darklafPropertyLoader)
        nativeLibImplementation(libs.macos.appKit)
        nativeLibImplementation(libs.macos.cocoa)
        nativeLibImplementation(libs.macos.javaNativeFoundation)
    }

    targetMachines.addAll(machines.macOS.x86_64, machines.macOS.architecture("arm64"))
    variants.configureEach {
        resourcePath.set("$nativeResourcePath/${targetMachine.variantName}")
        sharedLibrary {
            val isArm = targetMachine.architectureString == "arm64"
            val minOs = if (isArm) "11" else "10.10"
            compileTasks.configureEach {
                compilerArgs.addAll("-mmacosx-version-min=$minOs")
                // Build type not modeled yet, assuming release
                optimizedBinary()
            }
            linkTask.configure {
                linkerArgs.addAll(
                    "-lobjc", "-mmacosx-version-min=$minOs",
                    // "-framework", "AppKit",
                    // "-framework", "Cocoa",
                    // The custom JNF framework specified @rpath for searching. As we aren't actually linking
                    // with the dynamic library of the framework we specifically have to add the system framework
                    // search paths accordingly.
                    // First try any system provided framework (this will fail on arm64):
                    "-rpath", "/System/Library/Frameworks",
                    "-rpath", "/System/Library/Frameworks/JavaVM.framework/Versions/A/Frameworks",
                    // Then try the jdk provided framework:
                    "-rpath", "@executable_path/../lib",
                    // Lastly use our bundled drop-in replacement:
                    "-rpath", "@loader_path"
                )
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.1123717749456015, 'fraction_numerical': 0.007149518184644078, 'mean_word_length': 2.176209279368213, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '317819', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1788, 'n_words': 300}