-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(go): require go 1.16, use native embed (#2603)
Instead of generating code to build byte slices with the embedded assets, upgraded the baseline go requirement to go 1.16, and use the new native embed feature released as part of this go release. This includes the update to `jsii/superhain` to the correct go release, updates to the `.github/workflows/main.yml` workflow to ensure the correct go version is installed in PR validation builds, and the changes in `jsii-pacmak` and `@jsii/go-runtime` to leverage the feature. This makes the code easier to deal with by IDEs (the byte slices were otherwise very large and caused IDEs to occasionally choke on them), and removes the risk we make a mistake in generating the slices. It also makes the generated code easier to troubleshoot, as the tarball is present as-is, and can be inspected without additional hoop jumping. See: https://pkg.go.dev/embed
- Loading branch information
1 parent
ffb0032
commit 67cd3ce
Showing
16 changed files
with
221 additions
and
260 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/jsii-calc/ | ||
*.generated.go | ||
*.generated_test.go | ||
/jsii-runtime-go/embedded/resources/ | ||
*.generated.* | ||
|
||
*.js | ||
*.d.ts |
This file contains 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
56 changes: 56 additions & 0 deletions
56
packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package embedded | ||
|
||
import ( | ||
"embed" | ||
"os" | ||
"path" | ||
) | ||
|
||
// embeddedRootDir is the name of the root directory for the embeddedFS variable. | ||
const embeddedRootDir string = "resources" | ||
|
||
//go:embed resources/* | ||
var embeddedFS embed.FS | ||
|
||
// entrypointName is the path to the entry point relative to the embeddedRootDir. | ||
var entrypointName string = path.Join("bin", "jsii-runtime.js") | ||
|
||
// ExtractRuntime extracts a copy of the embedded runtime library into | ||
// the designated directory. | ||
func ExtractRuntime(into string) (entrypoint string, err error) { | ||
err = extractRuntime(into, embeddedRootDir) | ||
if err == nil { | ||
entrypoint = path.Join(into, entrypointName) | ||
} | ||
return | ||
} | ||
|
||
// extractRuntime copies the contents of embeddedFS at "from" to the provided "into" | ||
// directory, recursively. | ||
func extractRuntime(into string, from string) error { | ||
files, err := embeddedFS.ReadDir(from) | ||
if err != nil { | ||
return err | ||
} | ||
for _, file := range files { | ||
src := path.Join(from, file.Name()) | ||
dest := path.Join(into, file.Name()) | ||
if file.IsDir() { | ||
if err = os.Mkdir(dest, 0o700); err != nil { | ||
return err | ||
} | ||
if err = extractRuntime(dest, src); err != nil { | ||
return err | ||
} | ||
} else { | ||
data, err := embeddedFS.ReadFile(src) | ||
if err != nil { | ||
return err | ||
} | ||
if err = os.WriteFile(dest, data, 0o600); err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
return nil | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/@jsii/go-runtime/jsii-runtime-go/embedded/embedded_test.go
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package embedded | ||
|
||
import ( | ||
"path" | ||
"testing" | ||
) | ||
|
||
func TestEntryPointExists(t *testing.T) { | ||
if bytes, err := embeddedFS.ReadFile(path.Join(embeddedRootDir, entrypointName)); err != nil { | ||
t.Errorf("unable to read entry point data: %v", err) | ||
} else if len(bytes) == 0 { | ||
t.Error("entry point file is empty") | ||
} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/aws/jsii-runtime-go | ||
|
||
go 1.15 | ||
go 1.16 |
Oops, something went wrong.