bazelbuild / bazelbuild/bazel

A way to get an execpath to a directory rather than a file

Open
#23,139 4 comments 3 reactions 0 assignees View on GitHub
P3 team-Rules-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the feature request:

Several times, I've wanted to be able to reference an execpath to a directory, for the purposes of adding a directory containing several files to an include search path. Something along the lines of:

```starlark
cc_library(
name = "lib",
srcs = [...],
copts = ["-I$(execpath @openssl//include:__pkg__)"],
)
```

If you're lucky, some tools support `/..` so you can write something like:

```starlark
cc_library(
name = "lib",
srcs = [...],
copts = ["-I$(execpath @openssl//include:openssl/some_header.h)/../.."],
)
```

but many do not.

Note that we want to be able to be very precise about which directory is returned. In a world where you have:

`@openssl//include:BUILD.bazel`:
```starlark
filegroup(
name = "headers",
srcs = [
"openssl/header1.h",
"openssl/header2.h",
],
)
```

it may be important to specifically reference the execpath of `@openssl//include` _not_ `openssl//include/headers` because of how the headers are `#include`d.

### Which category does this issue belong to?

Rules API

### Have you found anything relevant by searching the web?

See discussion in https://bazelbuild.slack.com/archives/C014RARENH0/p1722250875317499?thread_ts=1721325151.660949&cid=C014RARENH0

Contributor guide

Open the contributing guide

Research direction

Start with the Rules API and the execpath behavior described in the issue, then review the linked Slack discussion for prior design context. The work is done when users can precisely reference a declared package directory, rather than only a file or an imprecise derived path, for include search paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.