tulsi icon indicating copy to clipboard operation
tulsi copied to clipboard

Tulsi swift_test support

Open tinder-cwybranowski opened this issue 3 years ago • 0 comments

Hello! I've been experimenting with Tulsi for Swift CLI tooling development, and I noticed that it doesn't currently support swift_test targets. Although there is a workaround (described below), it would be awesome to see support for this target type.


Setup

  • Bazel 4.0.0
  • Xcode 12.4

Demo Repository

I've created a public repository that demonstrates this issue, and a couple others related to .tulsigen configuration file generation: tulsi-swift-test-demo.

Everything should be detailed in the README of that repository, but I'll post some information below for visibility.


swift_test support

Although Tulsi appears to handle swift_library targets correctly, it fails to generate a Tulsi project for swift_test targets.

Here is the BUILD file, copied from the demo repository linked above:

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library", "swift_test")

swift_library(
    name = "DemoTarget",
    srcs = glob(["Sources/*.swift"]),
    module_name = "DemoTarget",
    visibility = ["//visibility:public"]
)

swift_test(
    name = "DemoTargetTests",
    srcs = glob(["Tests/*.swift"]),
    deps = [":DemoTarget"]
)

Here is the warning we receive after executing the --genconfig command:

[Error] Generate[FAIL]: 10.6267s Unsupported target type: swift_test (target //demo-target:DemoTargetTests)
Xcode project generation failed

In order to fix this temporarily, we have to define new swift_library and macos_unit_test libraries for this test target:

load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
load("@build_bazel_rules_apple//apple:macos.bzl", "macos_unit_test")

swift_library(
    name = "DemoTargetTestsLibrary",
    srcs = glob(["Tests/*.swift"]),
    deps = [":DemoTarget"]
    module_name = "DemoTargetTestsLibrary",
    visibility = ["//visibility:private"],
)

macos_unit_test(
    name = "DemoTargetTests",
    deps = [":DemoTargetTestsLibrary"],
    minimum_os_version = "10.15",
    visibility = ["//visibility:public"]
)

tinder-cwybranowski avatar Mar 04 '21 19:03 tinder-cwybranowski