Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access or generation of repo mapping files in Starlark #19937

Closed
purkhusid opened this issue Oct 25, 2023 · 4 comments
Closed

Allow access or generation of repo mapping files in Starlark #19937

purkhusid opened this issue Oct 25, 2023 · 4 comments
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged

Comments

@purkhusid
Copy link

purkhusid commented Oct 25, 2023

Description of the feature request:

There is currently no way to access the repo mapping file in Starlark. This causes problems when you need to make an binary that uses a runfiles libraries runnable outside of Bazel e.g. in an container or if you just want to package the binary in some way.

To make the binary runnable outside of bazel the .repo_mapping file is required so that runfiles lookups don't fail. That means that there needs to be an way to either generate or copy the .repo_mapping file in starlark so that e.g. a tar rule can list the repo mapping file in it's inputs.

There is currently an workaround for this for Python zip that is not available to others: 4e60992#diff-06b3fa5571583c2c73ec269859f1b9194038c26cc6c0e9c8897f53b992731658R382

This API could be publicly exposed or if it's possible the repo mapping could be exposed on the FilesToRunProvider like the runfiles manifest is exposed today.

Tagging @fmeum and @Wyverald since there is some context in a couple of Slack threads that they were part of:
https://bazelbuild.slack.com/archives/C014RARENH0/p1698153613312699
https://bazelbuild.slack.com/archives/CA3NW13MH/p1697050350018059?thread_ts=1697034827.979009&cid=CA3NW13MH

Which category does this issue belong to?

Rules API

@purkhusid
Copy link
Author

I also think that this should be solved in 7.0 since this will make migrations to bzlmod more painful.

@fmeum
Copy link
Collaborator

fmeum commented Oct 25, 2023

Exposing the repo mapping on FilesToRunProvider seems very low risk to me, but only allows you to get the repo mapping for existing executable targets, not arbitrary collections of runfiles. When packaging multiple binary targets this would require some kind of merging logic.

@purkhusid Would this be sufficient for your use case?

Edit: Whatever we decide to do here, the change should be straightforward and cherry-pickable.

@purkhusid
Copy link
Author

My exact use case i only packaging a single executable with it's runfiles so that would be sufficient for me. It could be a first step if you want to think a bit better about an public API for generating mappings files for arbitrary runfiles.

@Pavank1992 Pavank1992 added the team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts label Oct 25, 2023
bazel-io pushed a commit to bazel-io/bazel that referenced this issue Nov 2, 2023
The new `repo_mapping_manifest` field on `FilesToRunProvider` allows Starlark rule implementations to access the `File` containing the repo mapping manifest for an executable target, e.g. to include the manifest into a synthetic runfiles structure for packaging purposes.

Fixes bazelbuild#19937

Closes bazelbuild#19944.

PiperOrigin-RevId: 578735848
Change-Id: Ida78778af5aef4ba0c216815563aef4b54c9d1db
iancha1992 pushed a commit that referenced this issue Nov 2, 2023
The new `repo_mapping_manifest` field on `FilesToRunProvider` allows
Starlark rule implementations to access the `File` containing the repo
mapping manifest for an executable target, e.g. to include the manifest
into a synthetic runfiles structure for packaging purposes.

Fixes #19937

Closes #19944.

Commit
3575211

PiperOrigin-RevId: 578735848
Change-Id: Ida78778af5aef4ba0c216815563aef4b54c9d1db

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
@iancha1992
Copy link
Member

A fix for this issue has been included in Bazel 7.0.0 RC5. Please test out the release candidate and report any issues as soon as possible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Rules-API API for writing rules/aspects: providers, runfiles, actions, artifacts type: feature request untriaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@fmeum @purkhusid @Pavank1992 @iancha1992 and others