Skip to content

Conversation

@birunts
Copy link
Contributor

@birunts birunts commented May 28, 2025

Previously generated filegroup targets can contain dependency cycle.

The case here is that defined filegroup of a package should not have deps of other packages but rather to its :data package.

This change removes potential dependency cycles and makes references to package's :data.

Resolves #163 & Closes #163.

@thesayyn
Copy link
Contributor

I don't think this solves the problem. By not depending on the :data target only, you are excluding the transitive dependencies, that's why you don't see the problem anymore but this basically breaks everything if i am not mistaken.

@birunts
Copy link
Contributor Author

birunts commented May 29, 2025

Agree. But currently package filegroups are defined wrong and you cannot even use it (bazelisk build @bookworm//libgcc-s1:libgcc-s1). If package should be done this way to contain transitive dependencies, definitely it cannot be filegroup but rather custom rule who will be able to handle that somehow.

From another side gathering all needed _PACKAGES is pointless as if packages should handle transitive dependencies then this list should contain only those explicitly specified in bookworm.yaml file where transitive deps will be resolved.
So even better that real filegroup package (e.g. @bookworm//libgcc-s1/amd64:amd64) do not contain deps but only its :data and

Indeed current change is not a fix but rather a quick workaround. What I see now, the real package (e.g. @bookworm//libgcc-s1/amd64:amd64) is a custom rule who contains package :data only and returns a provider with its (Depends,Recommends,Suggests,Breaks) dependencies similarly as dep packages do.
Then main package container is also a custom rule who can use that provider(s) and produce a target with full list of packages :data to be installed.

At least this is mine understanding of current state 🤷‍♂️

Simplifying to only one arch `amd64`, we have
main package (e.g. `libgcc-1s`) defined as:

```bzl

alias(
    name = "data",
    actual = "//libgcc-s1/amd64:data",
    visibility = ["//visibility:public"],
)

filegroup(
    name = "libgcc-1s",
    srcs = [
        "//libgcc-s1/amd64:amd64",
    ] + [":data"],
)
```

The appropriate arch target is of:

```bzl
alias(
    name = "data",
    actual = "@@rules_distroless++apt+bookworm_libgcc-s1_12.2.0-14-p-deb12u1_amd64//:data",
    visibility = ["//visibility:public"],
)

filegroup(
    name = "amd64",
    srcs = [
        "//libc6/amd64",
        "//gcc-12-base/amd64",
    ] + [":data"],
    visibility = ["//visibility:public"],
)
```

In the end main `libgcc-s1` contains redundant `//libgcc-s1/amd64:data` target,
thus remove redundant `:data` target from main package definition.
Eliminate circular dependencies within package definitions.
Bazel dependency graph rely on DAG (Directed Acyclic Graph).

Provided sources (`srcs`) to the target are already all transitive
package dependencies taken from the lockfile, thus its `:data`
is sufficient to fully cover package and all its dependencies.

Taking above and current implementation, all package deps should be
listed with `:data`. E.g. for `libgcc-s1/amd64:amd64` package, it is:

```bzl
filegroup(
    name = "amd64",
    srcs = [
        "//libc6/amd64:data",
        "//gcc-12-base/amd64:data",
    ] + [":data"],
    visibility = ["//visibility:public"],
)
```
is equal
@birunts birunts force-pushed the filegroup_circular_deps branch from fdd5757 to a9e67d1 Compare October 25, 2025 17:20
@birunts
Copy link
Contributor Author

birunts commented Oct 25, 2025

One more look at the issue 😉

I have checked generated package defs and first commit removes redundant + [:data]. It points to the same target as the :data within <package>/<arch> definition. Actually no big deal.

When it comes to the second commit all the package's data dependencies should be listed with <package>:data. We do not loose any transitive dependencies because the inserted list comes from the lockfile package dependency list, i.e. package["dependencies"], where it covers already all transitive deps of the package.

Bazel dependency graph is of Directed Acyclic Graph, thus current filegroup's definition is wrong, making cycle in dependency graph.

@thesayyn & @alexeagle plase have a look once again for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cycle error when using all-in-one target

2 participants