loader: support "all:" prefix in //go:embed patterns#5213
Open
abgoyal wants to merge 1 commit intotinygo-org:devfrom
Open
loader: support "all:" prefix in //go:embed patterns#5213abgoyal wants to merge 1 commit intotinygo-org:devfrom
abgoyal wants to merge 1 commit intotinygo-org:devfrom
Conversation
Author
|
The circleci failed test looks like a flaky test/race unrelated to my patch. Could a maintainer please look into my PR? |
eliasnaur
reviewed
Feb 21, 2026
eliasnaur
reviewed
Feb 21, 2026
loader/loader.go
Outdated
| // The "all:" prefix (if present) is stripped and reflected in includeHidden. | ||
| type embedPattern struct { | ||
| pattern string // the glob pattern (without "all:" prefix) | ||
| includeHidden bool // true if "all:" prefix was present |
Contributor
There was a problem hiding this comment.
I suspect this data structure is just as efficient:
type embedPattern string
func (e embedPattern) Match(file string) bool {
includeHidden := strings.HasPrefix(s, "all:")
...
}The "all:" prefix in //go:embed directives instructs the compiler to include hidden files (starting with "." or "_") when embedding a directory. Previously, the prefix was passed literally to path.Match, which would never match. Introduce an embedPattern struct that parses and validates the pattern at construction time via newEmbedPattern(). The "all:" prefix is stripped once and stored along with the glob pattern, avoiding repeated string prefix checks. Pattern validation is absorbed into the constructor, guaranteeing that any embedPattern value is valid and eliminating the need for separate validation loops. Fixes embedding with patterns like "//go:embed all:static".
dfc474a to
4a74cf4
Compare
Author
|
Do you think this one works better? i have incorporated the separate pattern validation into the ep creation itself, and then just use that all over. I think it works well. and instead of striping out the prefix later, I just strip it out once at ep creation time - not really from a performance pov, which i think is same either way, just clarity and non-repetitiveness pov. |
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
Fixes handling of the
all:prefix in//go:embeddirectives. This prefix tells Go to include hidden files (starting with.or_) when embedding a directory.Previously, TinyGo passed patterns like
all:dirnameliterally topath.Match, which never matched any files since no file is actually named "all:dirname". This caused//go:embed all:...to silently embed nothing.Changes
all:prefix before pattern matchingincludeHiddenflag tomatchPatternfunctionincludeHiddenis falseall:prefix before pattern validation inparseGoEmbedall:prefixExample
Test
Added test in testdata/embed/ that verifies: