bazelbuild / bazelbuild/rules_swift

Unable to use swift_library with a directory

Open
#969 7 comments 6 reactions 0 assignees View on GitHub
Dominant language
Starlark
Stars
353
Forks
172
Avg merge
23h 14m
Merged PRs (30d)
8

Description

When using a directory in the `srcs` of `swift_library`, the rules declare an incorrect intermediate object file for the directory and the build fails:

```
swift_worker: Could not copy bazel-out/darwin_arm64-fastbuild/bin/_swift_incremental/d_objs/c.o to bazel-out/darwin_arm64-fastbuild/bin/d_objs/c.o (No such file or directory)
```

> **NOTE**: Where the failure happens is less important than there always is a `.o` object file declared

This works using `objc_library`:

Repro (credit @thii)

```
# rule.bzl
def _impl(ctx):
dir_name = ctx.attr.name
out = ctx.actions.declare_directory(dir_name)
ctx.actions.run_shell(
outputs = [out],
command = """
cd {}
mkdir {}
touch {}/File{}
""".format(
ctx.bin_dir.path,
dir_name,
dir_name,
ctx.attr.ext,
dir_name,
ctx.attr.ext,
),
)
return [DefaultInfo(files = depset([out]))]

my_rule = rule(
_impl,
attrs = {
"ext": attr.string()
},
)
```

```
# BUILD
load(":rule.bzl", "my_rule")
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")

my_rule(
name = "a",
ext = ".m",
)
objc_library(
name = "b",
srcs = [":a"],
)

my_rule(
name = "c",
ext = ".swift",
)
swift_library(
name = "d",
srcs = [":c"],
)
```

Contributor guide

Open the contributing guide

Research direction

Inspect the swift_library handling of directory artifacts, comparing it with the shown objc_library case. Reproduce the issue using the provided rule.bzl and BUILD example; done when a directory-valued srcs entry no longer declares a .o object and the Swift build completes without the reported copy failure.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.