embedded stdlib

This PR embeds the stdlib into the dagger binary itself for convenience.
Long term we will want to source the stdlib directly from git.

- Updated go to 1.16 to use the new built-in embedding functionality
- The `stdlib` go package now contains an embed of the stdlib

Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
Andrea Luzzardi
2021-02-16 17:54:43 -08:00
parent 31f1cd9f1d
commit 5ba6dd1617
13 changed files with 85 additions and 108 deletions

View File

@@ -1,6 +1,5 @@
package dagger
// Any component can be referenced as a directory, since
// every dagger script outputs a filesystem state (aka a directory)
#Dir: #dagger: compute: [...#Op]
@@ -40,7 +39,7 @@ package dagger
env?: [string]: string
always?: true | *false
dir: string | *"/"
mount: [string]: "tmp" | "cache" | { from: _, path: string | *"/" }
mount: [string]: "tmp" | "cache" | {from: _, path: string | *"/"}
}
#FetchContainer: {

49
stdlib/stdlib.go Normal file
View File

@@ -0,0 +1,49 @@
package stdlib
import (
"embed"
"fmt"
"io/fs"
"path"
"path/filepath"
cueload "cuelang.org/go/cue/load"
)
// FS contains the filesystem of the stdlib.
//go:embed **/*.cue
var FS embed.FS
const (
stdlibPackageName = "dagger.cloud"
)
func Overlay(prefixPath string) (map[string]cueload.Source, error) {
overlay := map[string]cueload.Source{}
err := fs.WalkDir(FS, ".", func(p string, entry fs.DirEntry, err error) error {
if err != nil {
return err
}
if !entry.Type().IsRegular() {
return nil
}
if filepath.Ext(entry.Name()) != ".cue" {
return nil
}
contents, err := FS.ReadFile(p)
if err != nil {
return fmt.Errorf("%s: %w", p, err)
}
overlayPath := path.Join(prefixPath, "cue.mod", "pkg", stdlibPackageName, p)
overlay[overlayPath] = cueload.FromBytes(contents)
return nil
})
return overlay, err
}

View File

@@ -54,7 +54,7 @@ import (
dir: "/src"
mount: {
"/src": from: source
"/cache/yarn": dagger.#MountCache
"/cache/yarn": "cache"
}
},
dagger.#Subdir & {