# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

assert(is_mac || is_ios)

import("//build/config/darwin/darwin_sdk.gni")

config("compiler") {
  # swiftc -sdk flag.
  if (is_ios) {
    _sdk_root = ios_sdk_path
    if (create_xcode_symlinks) {
      _sdk_root = rebase_path(ios_sdk_path, root_build_dir)
    }
  } else if (is_mac) {
    _sdk_root = mac_sdk_path
    if (create_xcode_symlinks) {
      _sdk_root = rebase_path(mac_sdk_path, root_build_dir)
    }
  } else {
    assert(false, "unsupported platform")
  }

  # OS and deployment target.
  if (is_ios) {
    _triplet_os = "apple-ios"
    _deployment_target = ios_deployment_target
  } else if (is_mac) {
    _triplet_os = "apple-macos"
    _deployment_target = mac_deployment_target
  }

  # swiftc -swift-version flag.
  #
  # Swift 6 transition: As of April 2025, no public Flutter framework API is
  # authored in Swift. Swift 6 is ABI-compatible with Swift 5, but not
  # source-compatible. If any public API *is* written in Swift, it's possible
  # we may need to prepare concurrent Swift 5 and 6 builds during a transition
  # period.
  _swift_version = "5"

  # TODO(cbracken): https://github.com/flutter/flutter/issues/167592
  # Look up xcode_version in apple_sdk.gni
  #
  # This is here so that all files get recompiled after an Xcode update.
  # (defines are passed via the command line, and build system rebuild things
  # when their commandline changes). Nothing should ever read this define.
  #defines = [ "CR_XCODE_VERSION=$xcode_version" ]

  swiftflags = [
    "-sdk",
    _sdk_root,
    "--target-cpu",
    current_cpu,
    "--target-os",
    _triplet_os,
    "--deployment-target",
    _deployment_target,
    "-swift-version",
    _swift_version,
  ]

  if (use_ios_simulator) {
    swiftflags += [ "--use-simulator" ]
  }
}
