load("@build_bazel_rules_apple//apple:macos.bzl", "macos_bundle")

# Native Sparkle plugin for Unity
# This plugin initializes Sparkle auto-updater at runtime
objc_library(
    name = "sparkle_plugin_lib",
    srcs = ["SparklePlugin.m"],
    copts = [
        "-fmodules",
        "-fobjc-arc",
        "-fvisibility=default",  # Export symbols for Unity P/Invoke
    ],
    sdk_frameworks = ["Foundation"],
    deps = ["@sparkle//:Sparkle"],
)

macos_bundle(
    name = "SparklePlugin",
    bundle_id = "net.eagle0.SparklePlugin",
    bundle_name = "SparklePlugin",
    infoplists = ["Info.plist"],
    linkopts = [
        # Export symbols for Unity P/Invoke
        "-exported_symbol",
        "_SparklePlugin_Initialize",
        "-exported_symbol",
        "_SparklePlugin_CheckForUpdates",
        "-exported_symbol",
        "_SparklePlugin_CheckForUpdatesInBackground",
        "-exported_symbol",
        "_SparklePlugin_IsCheckingForUpdates",
        "-exported_symbol",
        "_SparklePlugin_GetAutomaticallyChecksForUpdates",
        "-exported_symbol",
        "_SparklePlugin_SetAutomaticallyChecksForUpdates",
        "-exported_symbol",
        "_SparklePlugin_IsRunningFromReadOnlyVolume",
        "-exported_symbol",
        "_SparklePlugin_ShowDMGWarning",
    ],
    minimum_os_version = "10.13",
    visibility = ["//visibility:public"],
    deps = [":sparkle_plugin_lib"],
)
