def _swift_parsing_flags(ctx):
  """Returns additional parsing flags for swiftc."""
  srcs = ctx.files.srcs

  # swiftc has two different parsing modes: script and library.
  # The difference is that in script mode top-level expressions are allowed.
  # This mode is triggered when the file compiled is called main.swift.
  # Additionally, script mode is used when there's just one file in the
  # compilation. we would like to avoid that and therefore force library mode
  # when there's only one source and it's not called main.
  if len(srcs) == 1 and srcs[0].basename != "main.swift":
    return ["-parse-as-library"]
  return []