feat: support CUE @embed via data attr on cue_instance and cue_module#26
Open
feat: support CUE @embed via data attr on cue_instance and cue_module#26
Conversation
CUE v0.12.0+ supports embedding sibling non-.cue files via @embed directives, resolved relative to the referring .cue file's directory. Under Bazel, this requires staging those sibling files in the same sandbox location as the .cue file. Previously cue_instance.srcs was .cue-only with no companion attribute, so @embed directives couldn't find their targets. Add a data attribute (allow_files = True) to both cue_instance and cue_module, threading declared files through CUEInstanceInfo.transitive_files and the module runfiles depset. No changes to cue-run-from-runfiles: Bazel's runfiles tree already places data files at their workspace-relative paths, which mirror the CUE module layout, so CUE's embed interpreter resolves them naturally. Module-boundary enforcement is deferred to CUE at evaluation time. Adds integration tests for three scenarios: single-file @embed(file=...), multi-file @embed(glob=...), and a transitive case where an instance's dep embeds its own siblings. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds an embed_module_data test that registers a data file on cue_module.data (not on any cue_instance.data) and embeds it from a consuming instance, locking in CUEModuleInfo.external_data_files propagation. Also clarifies the data-attr docs to say runfile paths (workspace-relative within the containing repository) and fixes a pre-existing pacakge typo. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dataattribute (allow_files = True) to bothcue_instanceandcue_moduleso non-.cuefiles can be staged alongside a package's.cuefiles in the Bazel sandbox.@embed(file=…)/@embed(glob=…)directives (activated per file with@extern(embed)), which resolve paths relative to the directory containing the referring.cuefile. Todaycue_instance.srcsis.cue-only (allow_files = [".cue"]), and the existingsrcs/qualified_srcson the output-producing rules are passed to CUE as CLI "packageless file" args (merged into evaluation, not staged as siblings). So@embeddirectives can't find their targets under Bazel.datafiles throughCUEInstanceInfo.transitive_filesand the module-runfiles depset. No changes tocue-run-from-runfiles: Bazel's runfiles tree already places the files at their workspace-relative paths, which mirror the CUE module layout, so CUE's embed interpreter resolves them naturally...escapes, no symlink escapes) is deferred to CUE at evaluation time rather than duplicated in Starlark — avoids drift from CUE's canonical rules.Changes
cue/cue.bzl:CUEModuleInfogains anexternal_data_filesdepset field.cue_moduleandcue_instanceboth gain adata = attr.label_list(allow_files = True)attribute._cue_instance_implincludesctx.files.data(and the module'sexternal_data_files) intransitive_files._cue_module_runfiles_implincludesexternal_data_filesin its runfiles depset so module-leveldatareaches consumers (e.g.cue_exported_files).Test plan
Notes