Skip to content

Missing 'select' expression in case of only a single platform defined #202

Description

@mateusz-olczyk

When only a single platform is configured, e.g.:

# gazelle:cc_platform linux x86_64 @platforms//os:linux

and then we guard an #include directive with a platform-specific macro:

#ifdef __linux__
#include "lib.h"
#endif

then we would expect:

cc_library(
    name = "my_library",
    srcs = ["my_library.cc"],
    implementation_deps = select({
        "@platforms//os:linux": [
            ":lib",
        ],
        "//conditions:default": [],
    }),
    visibility = ["//visibility:public"],
)

but we get:

cc_library(
    name = "my_library",
    srcs = ["my_library.cc"],
    implementation_deps = [":lib"],
    visibility = ["//visibility:public"],
)

The reason is how ccLanguage.getFileInfo() classifies a header as platform-specific:

isPlatformSpecific := len(usedByPlatforms) != len(platformEnvs)

Because there's only one platform and #include "lib.h" is actually reachable by it, then the expression above effectively evaluates to:

isPlatformSpecific := 1 != 1 // false

However, even if a directive is reachable on all configured platforms, it doesn't mean it isn't platform-specific.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions