//! Emit the `build.gradle.kts` for a Kotlin/Native project.

use crate::core::config::ResolvedCrateConfig;
use crate::core::template_versions;

/// Generate the `build.gradle.kts` contents for the Kotlin/Native module.
pub(super) fn emit_gradle_build(config: &ResolvedCrateConfig) -> String {
    let crate_name = &config.name;
    let kotlin_version = template_versions::maven::KOTLIN_JVM_PLUGIN;

    format!(
        r#"// Generated by alef. Do not edit by hand.
// To build for a different host triple, replace `linuxX64()` with
// `macosX64()` or `macosArm64()` and update the linkerOpts path accordingly.

plugins {{
    kotlin("multiplatform") version "{kotlin_version}"
}}

kotlin {{
    linuxX64 {{
        compilations["main"].cinterops {{
            val {crate_name} by creating {{
                defFile = project.file("{crate_name}.def")
            }}
        }}
        binaries {{
            sharedLib()
        }}
    }}
}}
"#
    )
}
